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