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