xref: /dokuwiki/lib/plugins/revert/admin.php (revision e3776c06c37cc197709dac60892604dfea894ac2)
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    /**
24168f9feeSAndreas Gohr     * return some info
25168f9feeSAndreas Gohr     */
26168f9feeSAndreas Gohr    function getInfo(){
27168f9feeSAndreas Gohr        return array(
28168f9feeSAndreas Gohr            'author' => 'Andreas Gohr',
29168f9feeSAndreas Gohr            'email'  => 'andi@splitbrain.org',
305c93146aSAndreas Gohr            'date'   => '2008-12-10',
31168f9feeSAndreas Gohr            'name'   => 'Revert Manager',
32168f9feeSAndreas Gohr            'desc'   => 'Allows you to mass revert recent edits',
33f46c9e83SAnika Henke            'url'    => 'http://dokuwiki.org/plugin:revert',
34168f9feeSAndreas Gohr        );
35168f9feeSAndreas Gohr    }
36168f9feeSAndreas Gohr
37168f9feeSAndreas Gohr    /**
38f8cc712eSAndreas Gohr     * access for managers
39f8cc712eSAndreas Gohr     */
40f8cc712eSAndreas Gohr    function forAdminOnly(){
41f8cc712eSAndreas Gohr        return false;
42f8cc712eSAndreas Gohr    }
43f8cc712eSAndreas Gohr
44f8cc712eSAndreas Gohr    /**
45168f9feeSAndreas Gohr     * return sort order for position in admin menu
46168f9feeSAndreas Gohr     */
47168f9feeSAndreas Gohr    function getMenuSort() {
48168f9feeSAndreas Gohr        return 40;
49168f9feeSAndreas Gohr    }
50168f9feeSAndreas Gohr
51168f9feeSAndreas Gohr    /**
52168f9feeSAndreas Gohr     * handle user request
53168f9feeSAndreas Gohr     */
54168f9feeSAndreas Gohr    function handle() {
55168f9feeSAndreas Gohr    }
56168f9feeSAndreas Gohr
57168f9feeSAndreas Gohr    /**
58168f9feeSAndreas Gohr     * output appropriate html
59168f9feeSAndreas Gohr     */
60168f9feeSAndreas Gohr    function html() {
61168f9feeSAndreas Gohr
62122b469fSAndreas Gohr        echo $this->plugin_locale_xhtml('intro');
63168f9feeSAndreas Gohr
64122b469fSAndreas Gohr        $this->_searchform();
65168f9feeSAndreas Gohr
66634d7150SAndreas Gohr        if(is_array($_REQUEST['revert']) && checkSecurityToken()){
6790f99567SAndreas Gohr            $this->_revert($_REQUEST['revert'],$_REQUEST['filter']);
68122b469fSAndreas Gohr        }elseif(isset($_REQUEST['filter'])){
69168f9feeSAndreas Gohr            $this->_list($_REQUEST['filter']);
70168f9feeSAndreas Gohr        }
71122b469fSAndreas Gohr    }
72168f9feeSAndreas Gohr
73122b469fSAndreas Gohr    /**
74122b469fSAndreas Gohr     * Display the form for searching spam pages
75122b469fSAndreas Gohr     */
76122b469fSAndreas Gohr    function _searchform(){
77122b469fSAndreas Gohr        global $lang;
782404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
79122b469fSAndreas Gohr        echo '<label>'.$this->getLang('filter').': </label>';
80122b469fSAndreas Gohr        echo '<input type="text" name="filter" class="edit" value="'.hsc($_REQUEST['filter']).'" />';
81122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$lang['btn_search'].'" />';
8290f99567SAndreas Gohr        echo ' <span>'.$this->getLang('note1').'</span>';
832404d0edSAnika Henke        echo '</div></form><br /><br />';
84122b469fSAndreas Gohr    }
85122b469fSAndreas Gohr
86122b469fSAndreas Gohr    /**
87122b469fSAndreas Gohr     * Start the reversion process
88122b469fSAndreas Gohr     */
8990f99567SAndreas Gohr    function _revert($revert,$filter){
90168f9feeSAndreas Gohr        global $conf;
91122b469fSAndreas Gohr
92122b469fSAndreas Gohr        echo '<hr /><br />';
93122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstart').'</p>';
94122b469fSAndreas Gohr
95122b469fSAndreas Gohr        echo '<ul>';
96168f9feeSAndreas Gohr        foreach($revert as $id){
97168f9feeSAndreas Gohr            global $REV;
9890f99567SAndreas Gohr
9990f99567SAndreas Gohr            // find the last non-spammy revision
10090f99567SAndreas Gohr            $data = '';
10190f99567SAndreas Gohr            $old  = getRevisions($id, 0, $this->max_revs);
10290f99567SAndreas Gohr            if(count($old)){
10390f99567SAndreas Gohr                foreach($old as $REV){
10490f99567SAndreas Gohr                    $data = rawWiki($id,$REV);
10590f99567SAndreas Gohr                    if(strpos($data,$filter) === false) break;
10690f99567SAndreas Gohr                }
10790f99567SAndreas Gohr            }
10890f99567SAndreas Gohr
10990f99567SAndreas Gohr            if($data){
11090f99567SAndreas Gohr                saveWikiText($id,$data,'old revision restored',false);
111122b469fSAndreas Gohr                printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV);
112168f9feeSAndreas Gohr            }else{
113168f9feeSAndreas Gohr                saveWikiText($id,'','',false);
11490f99567SAndreas Gohr                printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id);
115168f9feeSAndreas Gohr            }
116168f9feeSAndreas Gohr            @set_time_limit(10);
117168f9feeSAndreas Gohr            flush();
118168f9feeSAndreas Gohr        }
119122b469fSAndreas Gohr        echo '</ul>';
120122b469fSAndreas Gohr
121122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstop').'</p>';
122168f9feeSAndreas Gohr    }
123168f9feeSAndreas Gohr
124122b469fSAndreas Gohr    /**
125122b469fSAndreas Gohr     * List recent edits matching the given filter
126122b469fSAndreas Gohr     */
127168f9feeSAndreas Gohr    function _list($filter){
128168f9feeSAndreas Gohr        global $conf;
129de3eb1d7SAdrian Lang        global $lang;
130122b469fSAndreas Gohr        echo '<hr /><br />';
1312404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
132122b469fSAndreas Gohr        echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />';
133634d7150SAndreas Gohr        formSecurityToken();
134168f9feeSAndreas Gohr
13590f99567SAndreas Gohr        $recents = getRecents(0,$this->max_lines);
136122b469fSAndreas Gohr        echo '<ul>';
137168f9feeSAndreas Gohr
138122b469fSAndreas Gohr
139122b469fSAndreas Gohr        $cnt = 0;
140168f9feeSAndreas Gohr        foreach($recents as $recent){
141168f9feeSAndreas Gohr            if($filter){
142168f9feeSAndreas Gohr                if(strpos(rawWiki($recent['id']),$filter) === false) continue;
143168f9feeSAndreas Gohr            }
144168f9feeSAndreas Gohr
145122b469fSAndreas Gohr            $cnt++;
146eb947fb3SAndreas Gohr            $date = strftime($conf['dformat'],$recent['date']);
147168f9feeSAndreas Gohr
148ebf1501fSBen Coburn            echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
149122b469fSAndreas Gohr            echo '<div class="li">';
150122b469fSAndreas Gohr            echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />';
151122b469fSAndreas Gohr            echo '<label for="revert__'.$cnt.'">'.$date.'</label> ';
152168f9feeSAndreas Gohr
153122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=diff").'">';
154168f9feeSAndreas Gohr            $p = array();
155168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/diff.png';
156168f9feeSAndreas Gohr            $p['width']  = 15;
157168f9feeSAndreas Gohr            $p['height'] = 11;
158168f9feeSAndreas Gohr            $p['title']  = $lang['diff'];
159168f9feeSAndreas Gohr            $p['alt']    = $lang['diff'];
160168f9feeSAndreas Gohr            $att = buildAttributes($p);
161122b469fSAndreas Gohr            echo "<img $att />";
162122b469fSAndreas Gohr            echo '</a> ';
163168f9feeSAndreas Gohr
164122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=revisions").'">';
165168f9feeSAndreas Gohr            $p = array();
166168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/history.png';
167168f9feeSAndreas Gohr            $p['width']  = 12;
168168f9feeSAndreas Gohr            $p['height'] = 14;
169168f9feeSAndreas Gohr            $p['title']  = $lang['btn_revs'];
170168f9feeSAndreas Gohr            $p['alt']    = $lang['btn_revs'];
171168f9feeSAndreas Gohr            $att = buildAttributes($p);
172122b469fSAndreas Gohr            echo "<img $att />";
173122b469fSAndreas Gohr            echo '</a> ';
174168f9feeSAndreas Gohr
1755c93146aSAndreas Gohr            echo html_wikilink(':'.$recent['id'],(useHeading('navigation'))?NULL:$recent['id']);
176122b469fSAndreas Gohr            echo ' &ndash; '.htmlspecialchars($recent['sum']);
177168f9feeSAndreas Gohr
178122b469fSAndreas Gohr            echo ' <span class="user">';
179122b469fSAndreas Gohr                echo $recent['user'].' '.$recent['ip'];
180122b469fSAndreas Gohr            echo '</span>';
181168f9feeSAndreas Gohr
182122b469fSAndreas Gohr            echo '</div>';
183122b469fSAndreas Gohr            echo '</li>';
184168f9feeSAndreas Gohr
185168f9feeSAndreas Gohr            @set_time_limit(10);
186168f9feeSAndreas Gohr            flush();
187168f9feeSAndreas Gohr        }
188122b469fSAndreas Gohr        echo '</ul>';
189168f9feeSAndreas Gohr
19090f99567SAndreas Gohr        echo '<p>';
191122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$this->getLang('revert').'" /> ';
19290f99567SAndreas Gohr        printf($this->getLang('note2'),hsc($filter));
19390f99567SAndreas Gohr        echo '</p>';
194122b469fSAndreas Gohr
1952404d0edSAnika Henke        echo '</div></form>';
196168f9feeSAndreas Gohr    }
197168f9feeSAndreas Gohr
198168f9feeSAndreas Gohr}
199*e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
200