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