xref: /dokuwiki/lib/plugins/revert/admin.php (revision b5b0d7949c3ee36aa30680deb465f29320c4e98d)
1<?php
2// must be run within Dokuwiki
3if(!defined('DOKU_INC')) die();
4
5/**
6 * All DokuWiki plugins to extend the admin function
7 * need to inherit from this class
8 */
9class admin_plugin_revert extends DokuWiki_Admin_Plugin {
10    var $cmd;
11    // some vars which might need tuning later
12    var $max_lines = 800; // lines to read from changelog
13    var $max_revs  = 20;  // numer of old revisions to check
14
15
16    /**
17     * Constructor
18     */
19    function admin_plugin_revert(){
20        $this->setupLocale();
21    }
22
23    /**
24     * return some info
25     */
26    function getInfo(){
27        return array(
28            'author' => 'Andreas Gohr',
29            'email'  => 'andi@splitbrain.org',
30            'date'   => '2008-12-10',
31            'name'   => 'Revert Manager',
32            'desc'   => 'Allows you to mass revert recent edits',
33            'url'    => 'http://dokuwiki.org/plugin:revert',
34        );
35    }
36
37    /**
38     * access for managers
39     */
40    function forAdminOnly(){
41        return false;
42    }
43
44    /**
45     * return sort order for position in admin menu
46     */
47    function getMenuSort() {
48        return 40;
49    }
50
51    /**
52     * handle user request
53     */
54    function handle() {
55    }
56
57    /**
58     * output appropriate html
59     */
60    function html() {
61
62        echo $this->plugin_locale_xhtml('intro');
63
64        $this->_searchform();
65
66        if(is_array($_REQUEST['revert']) && checkSecurityToken()){
67            $this->_revert($_REQUEST['revert'],$_REQUEST['filter']);
68        }elseif(isset($_REQUEST['filter'])){
69            $this->_list($_REQUEST['filter']);
70        }
71    }
72
73    /**
74     * Display the form for searching spam pages
75     */
76    function _searchform(){
77        global $lang;
78        echo '<form action="" method="post"><div class="no">';
79        echo '<label>'.$this->getLang('filter').': </label>';
80        echo '<input type="text" name="filter" class="edit" value="'.hsc($_REQUEST['filter']).'" />';
81        echo '<input type="submit" class="button" value="'.$lang['btn_search'].'" />';
82        echo ' <span>'.$this->getLang('note1').'</span>';
83        echo '</div></form><br /><br />';
84    }
85
86    /**
87     * Start the reversion process
88     */
89    function _revert($revert,$filter){
90        global $conf;
91
92        echo '<hr /><br />';
93        echo '<p>'.$this->getLang('revstart').'</p>';
94
95        echo '<ul>';
96        foreach($revert as $id){
97            global $REV;
98
99            // find the last non-spammy revision
100            $data = '';
101            $old  = getRevisions($id, 0, $this->max_revs);
102            if(count($old)){
103                foreach($old as $REV){
104                    $data = rawWiki($id,$REV);
105                    if(strpos($data,$filter) === false) break;
106                }
107            }
108
109            if($data){
110                saveWikiText($id,$data,'old revision restored',false);
111                printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV);
112            }else{
113                saveWikiText($id,'','',false);
114                printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id);
115            }
116            @set_time_limit(10);
117            flush();
118        }
119        echo '</ul>';
120
121        echo '<p>'.$this->getLang('revstop').'</p>';
122    }
123
124    /**
125     * List recent edits matching the given filter
126     */
127    function _list($filter){
128        global $conf;
129        global $lang;
130        echo '<hr /><br />';
131        echo '<form action="" method="post"><div class="no">';
132        echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />';
133        formSecurityToken();
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 = strftime($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'],(useHeading('navigation'))?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 '</div></form>';
196    }
197
198}
199//Setup VIM: ex: et ts=4 enc=utf-8 :
200