xref: /dokuwiki/lib/plugins/revert/admin.php (revision f523c9718baf12a5bc99e2285bc0666796ab2a97)
1168f9feeSAndreas Gohr<?php
21687f569SGuy Brand// must be run within Dokuwiki
31687f569SGuy Brandif(!defined('DOKU_INC')) die();
41687f569SGuy Brand
5168f9feeSAndreas Gohr/**
6168f9feeSAndreas Gohr * All DokuWiki plugins to extend the admin function
7168f9feeSAndreas Gohr * need to inherit from this class
8168f9feeSAndreas Gohr */
9168f9feeSAndreas Gohrclass admin_plugin_revert extends DokuWiki_Admin_Plugin {
10168f9feeSAndreas Gohr    var $cmd;
1190f99567SAndreas Gohr    // some vars which might need tuning later
1290f99567SAndreas Gohr    var $max_lines = 800; // lines to read from changelog
1390f99567SAndreas Gohr    var $max_revs  = 20;  // numer of old revisions to check
1490f99567SAndreas Gohr
15168f9feeSAndreas Gohr
16168f9feeSAndreas Gohr    /**
17168f9feeSAndreas Gohr     * Constructor
18168f9feeSAndreas Gohr     */
19168f9feeSAndreas Gohr    function admin_plugin_revert(){
20168f9feeSAndreas Gohr        $this->setupLocale();
21168f9feeSAndreas Gohr    }
22168f9feeSAndreas Gohr
23168f9feeSAndreas Gohr    /**
24f8cc712eSAndreas Gohr     * access for managers
25f8cc712eSAndreas Gohr     */
26f8cc712eSAndreas Gohr    function forAdminOnly(){
27f8cc712eSAndreas Gohr        return false;
28f8cc712eSAndreas Gohr    }
29f8cc712eSAndreas Gohr
30f8cc712eSAndreas Gohr    /**
31168f9feeSAndreas Gohr     * return sort order for position in admin menu
32168f9feeSAndreas Gohr     */
33168f9feeSAndreas Gohr    function getMenuSort() {
34168f9feeSAndreas Gohr        return 40;
35168f9feeSAndreas Gohr    }
36168f9feeSAndreas Gohr
37168f9feeSAndreas Gohr    /**
38168f9feeSAndreas Gohr     * handle user request
39168f9feeSAndreas Gohr     */
40168f9feeSAndreas Gohr    function handle() {
41168f9feeSAndreas Gohr    }
42168f9feeSAndreas Gohr
43168f9feeSAndreas Gohr    /**
44168f9feeSAndreas Gohr     * output appropriate html
45168f9feeSAndreas Gohr     */
46168f9feeSAndreas Gohr    function html() {
4700d58927SMichael Hamann        global $INPUT;
48168f9feeSAndreas Gohr
4919ff1b0bSAnika Henke        echo $this->locale_xhtml('intro');
50168f9feeSAndreas Gohr
51122b469fSAndreas Gohr        $this->_searchform();
52168f9feeSAndreas Gohr
5300d58927SMichael Hamann        if(is_array($INPUT->param('revert')) && checkSecurityToken()){
5400d58927SMichael Hamann            $this->_revert($INPUT->arr('revert'),$INPUT->str('filter'));
5500d58927SMichael Hamann        }elseif($INPUT->has('filter')){
5600d58927SMichael Hamann            $this->_list($INPUT->str('filter'));
57168f9feeSAndreas Gohr        }
58122b469fSAndreas Gohr    }
59168f9feeSAndreas Gohr
60122b469fSAndreas Gohr    /**
61122b469fSAndreas Gohr     * Display the form for searching spam pages
62122b469fSAndreas Gohr     */
63122b469fSAndreas Gohr    function _searchform(){
6400d58927SMichael Hamann        global $lang, $INPUT;
652404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
66122b469fSAndreas Gohr        echo '<label>'.$this->getLang('filter').': </label>';
6700d58927SMichael Hamann        echo '<input type="text" name="filter" class="edit" value="'.hsc($INPUT->str('filter')).'" />';
68122b469fSAndreas Gohr        echo ' <input type="submit" class="button" value="'.$lang['btn_search'].'" />';
6990f99567SAndreas Gohr        echo ' <span>'.$this->getLang('note1').'</span>';
702404d0edSAnika Henke        echo '</div></form><br /><br />';
71122b469fSAndreas Gohr    }
72122b469fSAndreas Gohr
73122b469fSAndreas Gohr    /**
74122b469fSAndreas Gohr     * Start the reversion process
75122b469fSAndreas Gohr     */
7690f99567SAndreas Gohr    function _revert($revert,$filter){
77122b469fSAndreas Gohr        echo '<hr /><br />';
78122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstart').'</p>';
79122b469fSAndreas Gohr
80122b469fSAndreas Gohr        echo '<ul>';
81168f9feeSAndreas Gohr        foreach($revert as $id){
82168f9feeSAndreas Gohr            global $REV;
8390f99567SAndreas Gohr
8490f99567SAndreas Gohr            // find the last non-spammy revision
8590f99567SAndreas Gohr            $data = '';
86*f523c971SGerrit Uitslag            $pagelog = new PageRevisionLog($id);
87*f523c971SGerrit Uitslag            $old  = $pagelog->getRevisions(0, $this->max_revs);
8890f99567SAndreas Gohr            if(count($old)){
8990f99567SAndreas Gohr                foreach($old as $REV){
9090f99567SAndreas Gohr                    $data = rawWiki($id,$REV);
9190f99567SAndreas Gohr                    if(strpos($data,$filter) === false) break;
9290f99567SAndreas Gohr                }
9390f99567SAndreas Gohr            }
9490f99567SAndreas Gohr
9590f99567SAndreas Gohr            if($data){
9690f99567SAndreas Gohr                saveWikiText($id,$data,'old revision restored',false);
97122b469fSAndreas Gohr                printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV);
98168f9feeSAndreas Gohr            }else{
99168f9feeSAndreas Gohr                saveWikiText($id,'','',false);
10090f99567SAndreas Gohr                printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id);
101168f9feeSAndreas Gohr            }
102168f9feeSAndreas Gohr            @set_time_limit(10);
103168f9feeSAndreas Gohr            flush();
104168f9feeSAndreas Gohr        }
105122b469fSAndreas Gohr        echo '</ul>';
106122b469fSAndreas Gohr
107122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstop').'</p>';
108168f9feeSAndreas Gohr    }
109168f9feeSAndreas Gohr
110122b469fSAndreas Gohr    /**
111122b469fSAndreas Gohr     * List recent edits matching the given filter
112122b469fSAndreas Gohr     */
113168f9feeSAndreas Gohr    function _list($filter){
114168f9feeSAndreas Gohr        global $conf;
115de3eb1d7SAdrian Lang        global $lang;
116122b469fSAndreas Gohr        echo '<hr /><br />';
1172404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
118122b469fSAndreas Gohr        echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />';
119634d7150SAndreas Gohr        formSecurityToken();
120168f9feeSAndreas Gohr
12190f99567SAndreas Gohr        $recents = getRecents(0,$this->max_lines);
122122b469fSAndreas Gohr        echo '<ul>';
123168f9feeSAndreas Gohr
124122b469fSAndreas Gohr        $cnt = 0;
125168f9feeSAndreas Gohr        foreach($recents as $recent){
126168f9feeSAndreas Gohr            if($filter){
127168f9feeSAndreas Gohr                if(strpos(rawWiki($recent['id']),$filter) === false) continue;
128168f9feeSAndreas Gohr            }
129168f9feeSAndreas Gohr
130122b469fSAndreas Gohr            $cnt++;
131dc235f96SMatthias Schulte            $date = dformat($recent['date']);
132168f9feeSAndreas Gohr
133ebf1501fSBen Coburn            echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
134122b469fSAndreas Gohr            echo '<div class="li">';
135122b469fSAndreas Gohr            echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />';
136122b469fSAndreas Gohr            echo ' <label for="revert__'.$cnt.'">'.$date.'</label> ';
137168f9feeSAndreas Gohr
138122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=diff").'">';
139168f9feeSAndreas Gohr            $p = array();
140168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/diff.png';
141168f9feeSAndreas Gohr            $p['width']  = 15;
142168f9feeSAndreas Gohr            $p['height'] = 11;
143168f9feeSAndreas Gohr            $p['title']  = $lang['diff'];
144168f9feeSAndreas Gohr            $p['alt']    = $lang['diff'];
145168f9feeSAndreas Gohr            $att = buildAttributes($p);
146122b469fSAndreas Gohr            echo "<img $att />";
147122b469fSAndreas Gohr            echo '</a> ';
148168f9feeSAndreas Gohr
149122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=revisions").'">';
150168f9feeSAndreas Gohr            $p = array();
151168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/history.png';
152168f9feeSAndreas Gohr            $p['width']  = 12;
153168f9feeSAndreas Gohr            $p['height'] = 14;
154168f9feeSAndreas Gohr            $p['title']  = $lang['btn_revs'];
155168f9feeSAndreas Gohr            $p['alt']    = $lang['btn_revs'];
156168f9feeSAndreas Gohr            $att = buildAttributes($p);
157122b469fSAndreas Gohr            echo "<img $att />";
158122b469fSAndreas Gohr            echo '</a> ';
159168f9feeSAndreas Gohr
1600ea51e63SMatt Perry            echo html_wikilink(':'.$recent['id'],(useHeading('navigation'))?null:$recent['id']);
161e260f93bSAnika Henke            echo ' – '.htmlspecialchars($recent['sum']);
162168f9feeSAndreas Gohr
163122b469fSAndreas Gohr            echo ' <span class="user">';
164122b469fSAndreas Gohr                echo $recent['user'].' '.$recent['ip'];
165122b469fSAndreas Gohr            echo '</span>';
166168f9feeSAndreas Gohr
167122b469fSAndreas Gohr            echo '</div>';
168122b469fSAndreas Gohr            echo '</li>';
169168f9feeSAndreas Gohr
170168f9feeSAndreas Gohr            @set_time_limit(10);
171168f9feeSAndreas Gohr            flush();
172168f9feeSAndreas Gohr        }
173122b469fSAndreas Gohr        echo '</ul>';
174168f9feeSAndreas Gohr
17590f99567SAndreas Gohr        echo '<p>';
176122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$this->getLang('revert').'" /> ';
17790f99567SAndreas Gohr        printf($this->getLang('note2'),hsc($filter));
17890f99567SAndreas Gohr        echo '</p>';
179122b469fSAndreas Gohr
1802404d0edSAnika Henke        echo '</div></form>';
181168f9feeSAndreas Gohr    }
182168f9feeSAndreas Gohr
183168f9feeSAndreas Gohr}
184e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
185