xref: /dokuwiki/lib/plugins/revert/admin.php (revision e260f93b6cea05bc39bbd77b9db5bdc0c2c424bf)
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() {
47168f9feeSAndreas Gohr
48122b469fSAndreas Gohr        echo $this->plugin_locale_xhtml('intro');
49168f9feeSAndreas Gohr
50122b469fSAndreas Gohr        $this->_searchform();
51168f9feeSAndreas Gohr
52634d7150SAndreas Gohr        if(is_array($_REQUEST['revert']) && checkSecurityToken()){
5390f99567SAndreas Gohr            $this->_revert($_REQUEST['revert'],$_REQUEST['filter']);
54122b469fSAndreas Gohr        }elseif(isset($_REQUEST['filter'])){
55168f9feeSAndreas Gohr            $this->_list($_REQUEST['filter']);
56168f9feeSAndreas Gohr        }
57122b469fSAndreas Gohr    }
58168f9feeSAndreas Gohr
59122b469fSAndreas Gohr    /**
60122b469fSAndreas Gohr     * Display the form for searching spam pages
61122b469fSAndreas Gohr     */
62122b469fSAndreas Gohr    function _searchform(){
63122b469fSAndreas Gohr        global $lang;
642404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
65122b469fSAndreas Gohr        echo '<label>'.$this->getLang('filter').': </label>';
66122b469fSAndreas Gohr        echo '<input type="text" name="filter" class="edit" value="'.hsc($_REQUEST['filter']).'" />';
67122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$lang['btn_search'].'" />';
6890f99567SAndreas Gohr        echo ' <span>'.$this->getLang('note1').'</span>';
692404d0edSAnika Henke        echo '</div></form><br /><br />';
70122b469fSAndreas Gohr    }
71122b469fSAndreas Gohr
72122b469fSAndreas Gohr    /**
73122b469fSAndreas Gohr     * Start the reversion process
74122b469fSAndreas Gohr     */
7590f99567SAndreas Gohr    function _revert($revert,$filter){
76168f9feeSAndreas Gohr        global $conf;
77122b469fSAndreas Gohr
78122b469fSAndreas Gohr        echo '<hr /><br />';
79122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstart').'</p>';
80122b469fSAndreas Gohr
81122b469fSAndreas Gohr        echo '<ul>';
82168f9feeSAndreas Gohr        foreach($revert as $id){
83168f9feeSAndreas Gohr            global $REV;
8490f99567SAndreas Gohr
8590f99567SAndreas Gohr            // find the last non-spammy revision
8690f99567SAndreas Gohr            $data = '';
8790f99567SAndreas Gohr            $old  = getRevisions($id, 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
125122b469fSAndreas Gohr        $cnt = 0;
126168f9feeSAndreas Gohr        foreach($recents as $recent){
127168f9feeSAndreas Gohr            if($filter){
128168f9feeSAndreas Gohr                if(strpos(rawWiki($recent['id']),$filter) === false) continue;
129168f9feeSAndreas Gohr            }
130168f9feeSAndreas Gohr
131122b469fSAndreas Gohr            $cnt++;
132eb947fb3SAndreas Gohr            $date = strftime($conf['dformat'],$recent['date']);
133168f9feeSAndreas Gohr
134ebf1501fSBen Coburn            echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
135122b469fSAndreas Gohr            echo '<div class="li">';
136122b469fSAndreas Gohr            echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />';
137122b469fSAndreas Gohr            echo '<label for="revert__'.$cnt.'">'.$date.'</label> ';
138168f9feeSAndreas Gohr
139122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=diff").'">';
140168f9feeSAndreas Gohr            $p = array();
141168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/diff.png';
142168f9feeSAndreas Gohr            $p['width']  = 15;
143168f9feeSAndreas Gohr            $p['height'] = 11;
144168f9feeSAndreas Gohr            $p['title']  = $lang['diff'];
145168f9feeSAndreas Gohr            $p['alt']    = $lang['diff'];
146168f9feeSAndreas Gohr            $att = buildAttributes($p);
147122b469fSAndreas Gohr            echo "<img $att />";
148122b469fSAndreas Gohr            echo '</a> ';
149168f9feeSAndreas Gohr
150122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=revisions").'">';
151168f9feeSAndreas Gohr            $p = array();
152168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/history.png';
153168f9feeSAndreas Gohr            $p['width']  = 12;
154168f9feeSAndreas Gohr            $p['height'] = 14;
155168f9feeSAndreas Gohr            $p['title']  = $lang['btn_revs'];
156168f9feeSAndreas Gohr            $p['alt']    = $lang['btn_revs'];
157168f9feeSAndreas Gohr            $att = buildAttributes($p);
158122b469fSAndreas Gohr            echo "<img $att />";
159122b469fSAndreas Gohr            echo '</a> ';
160168f9feeSAndreas Gohr
1615c93146aSAndreas Gohr            echo html_wikilink(':'.$recent['id'],(useHeading('navigation'))?NULL:$recent['id']);
162*e260f93bSAnika Henke            echo ' – '.htmlspecialchars($recent['sum']);
163168f9feeSAndreas Gohr
164122b469fSAndreas Gohr            echo ' <span class="user">';
165122b469fSAndreas Gohr                echo $recent['user'].' '.$recent['ip'];
166122b469fSAndreas Gohr            echo '</span>';
167168f9feeSAndreas Gohr
168122b469fSAndreas Gohr            echo '</div>';
169122b469fSAndreas Gohr            echo '</li>';
170168f9feeSAndreas Gohr
171168f9feeSAndreas Gohr            @set_time_limit(10);
172168f9feeSAndreas Gohr            flush();
173168f9feeSAndreas Gohr        }
174122b469fSAndreas Gohr        echo '</ul>';
175168f9feeSAndreas Gohr
17690f99567SAndreas Gohr        echo '<p>';
177122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$this->getLang('revert').'" /> ';
17890f99567SAndreas Gohr        printf($this->getLang('note2'),hsc($filter));
17990f99567SAndreas Gohr        echo '</p>';
180122b469fSAndreas Gohr
1812404d0edSAnika Henke        echo '</div></form>';
182168f9feeSAndreas Gohr    }
183168f9feeSAndreas Gohr
184168f9feeSAndreas Gohr}
185e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
186