xref: /dokuwiki/lib/plugins/revert/admin.php (revision f8cc712e2ad522d0bd56b9ba3983cd42abf664ad)
1<?php
2if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/');
3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
4require_once(DOKU_PLUGIN.'admin.php');
5require_once(DOKU_INC.'inc/changelog.php');
6
7/**
8 * All DokuWiki plugins to extend the admin function
9 * need to inherit from this class
10 */
11class admin_plugin_revert extends DokuWiki_Admin_Plugin {
12        var $cmd;
13
14    /**
15     * Constructor
16     */
17    function admin_plugin_revert(){
18        $this->setupLocale();
19    }
20
21    /**
22     * return some info
23     */
24    function getInfo(){
25        return array(
26            'author' => 'Andreas Gohr',
27            'email'  => 'andi@splitbrain.org',
28            'date'   => '2005-11-10',
29            'name'   => 'Revert Manager',
30            'desc'   => 'Allows you to mass revert recent edits',
31            'url'    => 'http://wiki.splitbrain.org/plugin:revert',
32        );
33    }
34
35    /**
36     * access for managers
37     */
38    function forAdminOnly(){
39        return false;
40    }
41
42    /**
43     * return sort order for position in admin menu
44     */
45    function getMenuSort() {
46        return 40;
47    }
48
49    /**
50     * handle user request
51     */
52    function handle() {
53    }
54
55    /**
56     * output appropriate html
57     */
58    function html() {
59
60        echo $this->plugin_locale_xhtml('intro');
61
62        $this->_searchform();
63
64        if(is_array($_REQUEST['revert'])){
65            $this->_revert($_REQUEST['revert']);
66        }elseif(isset($_REQUEST['filter'])){
67            $this->_list($_REQUEST['filter']);
68        }
69    }
70
71    /**
72     * Display the form for searching spam pages
73     */
74    function _searchform(){
75        global $lang;
76        echo '<form action="" method="post">';
77        echo '<label>'.$this->getLang('filter').': </label>';
78        echo '<input type="text" name="filter" class="edit" value="'.hsc($_REQUEST['filter']).'" />';
79        echo '<input type="submit" class="button" value="'.$lang['btn_search'].'" />';
80        echo ' <span>'.$this->getLang('note').'</span>';
81        echo '</form><br /><br />';
82    }
83
84    /**
85     * Start the reversion process
86     */
87    function _revert($revert){
88        global $conf;
89
90        echo '<hr /><br />';
91        echo '<p>'.$this->getLang('revstart').'</p>';
92
93        echo '<ul>';
94        foreach($revert as $id){
95            global $REV;
96            $old = getRevisions($id, 0, 1);
97            $REV = $old[0];
98            if($REV){
99                saveWikiText($id,rawWiki($id,$REV),'old revision restored',false);
100                printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV);
101            }else{
102                saveWikiText($id,'','',false);
103                printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id,$REV);
104            }
105            @set_time_limit(10);
106            flush();
107        }
108        echo '</ul>';
109
110        echo '<p>'.$this->getLang('revstop').'</p>';
111    }
112
113    /**
114     * List recent edits matching the given filter
115     */
116    function _list($filter){
117        global $conf;
118        echo '<hr /><br />';
119        echo '<form action="" method="post">';
120        echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />';
121
122        $recents = getRecents(0,800);
123        echo '<ul>';
124
125
126        $cnt = 0;
127        foreach($recents as $recent){
128            if($filter){
129                if(strpos(rawWiki($recent['id']),$filter) === false) continue;
130            }
131
132            $cnt++;
133            $date = date($conf['dformat'],$recent['date']);
134
135            echo ($recent['type']==='e') ? '<li class="minor">' : '<li>';
136            echo '<div class="li">';
137            echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />';
138            echo '<label for="revert__'.$cnt.'">'.$date.'</label> ';
139
140            echo '<a href="'.wl($recent['id'],"do=diff").'">';
141            $p = array();
142            $p['src']    = DOKU_BASE.'lib/images/diff.png';
143            $p['width']  = 15;
144            $p['height'] = 11;
145            $p['title']  = $lang['diff'];
146            $p['alt']    = $lang['diff'];
147            $att = buildAttributes($p);
148            echo "<img $att />";
149            echo '</a> ';
150
151            echo '<a href="'.wl($recent['id'],"do=revisions").'">';
152            $p = array();
153            $p['src']    = DOKU_BASE.'lib/images/history.png';
154            $p['width']  = 12;
155            $p['height'] = 14;
156            $p['title']  = $lang['btn_revs'];
157            $p['alt']    = $lang['btn_revs'];
158            $att = buildAttributes($p);
159            echo "<img $att />";
160            echo '</a> ';
161
162            echo html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
163            echo ' &ndash; '.htmlspecialchars($recent['sum']);
164
165            echo ' <span class="user">';
166                echo $recent['user'].' '.$recent['ip'];
167            echo '</span>';
168
169            echo '</div>';
170            echo '</li>';
171
172            @set_time_limit(10);
173            flush();
174        }
175        echo '</ul>';
176
177        echo '<input type="submit" class="button" value="'.$this->getLang('revert').'" />';
178
179        echo '</form>';
180    }
181
182}
183//Setup VIM: ex: et ts=4 enc=utf-8 :
184