xref: /dokuwiki/lib/plugins/revert/admin.php (revision 634d7150e59d03e4a4987164bfe9948fb8828c70)
1168f9feeSAndreas Gohr<?php
21687f569SGuy Brand// must be run within Dokuwiki
31687f569SGuy Brandif(!defined('DOKU_INC')) die();
41687f569SGuy Brand
5168f9feeSAndreas Gohrif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
6168f9feeSAndreas Gohrrequire_once(DOKU_PLUGIN.'admin.php');
7168f9feeSAndreas Gohrrequire_once(DOKU_INC.'inc/changelog.php');
8168f9feeSAndreas Gohr
9168f9feeSAndreas Gohr/**
10168f9feeSAndreas Gohr * All DokuWiki plugins to extend the admin function
11168f9feeSAndreas Gohr * need to inherit from this class
12168f9feeSAndreas Gohr */
13168f9feeSAndreas Gohrclass admin_plugin_revert extends DokuWiki_Admin_Plugin {
14168f9feeSAndreas Gohr    var $cmd;
1590f99567SAndreas Gohr    // some vars which might need tuning later
1690f99567SAndreas Gohr    var $max_lines = 800; // lines to read from changelog
1790f99567SAndreas Gohr    var $max_revs  = 20;  // numer of old revisions to check
1890f99567SAndreas Gohr
19168f9feeSAndreas Gohr
20168f9feeSAndreas Gohr    /**
21168f9feeSAndreas Gohr     * Constructor
22168f9feeSAndreas Gohr     */
23168f9feeSAndreas Gohr    function admin_plugin_revert(){
24168f9feeSAndreas Gohr        $this->setupLocale();
25168f9feeSAndreas Gohr    }
26168f9feeSAndreas Gohr
27168f9feeSAndreas Gohr    /**
28168f9feeSAndreas Gohr     * return some info
29168f9feeSAndreas Gohr     */
30168f9feeSAndreas Gohr    function getInfo(){
31168f9feeSAndreas Gohr        return array(
32168f9feeSAndreas Gohr            'author' => 'Andreas Gohr',
33168f9feeSAndreas Gohr            'email'  => 'andi@splitbrain.org',
3490f99567SAndreas Gohr            'date'   => '2007-04-22',
35168f9feeSAndreas Gohr            'name'   => 'Revert Manager',
36168f9feeSAndreas Gohr            'desc'   => 'Allows you to mass revert recent edits',
37168f9feeSAndreas Gohr            'url'    => 'http://wiki.splitbrain.org/plugin:revert',
38168f9feeSAndreas Gohr        );
39168f9feeSAndreas Gohr    }
40168f9feeSAndreas Gohr
41168f9feeSAndreas Gohr    /**
42f8cc712eSAndreas Gohr     * access for managers
43f8cc712eSAndreas Gohr     */
44f8cc712eSAndreas Gohr    function forAdminOnly(){
45f8cc712eSAndreas Gohr        return false;
46f8cc712eSAndreas Gohr    }
47f8cc712eSAndreas Gohr
48f8cc712eSAndreas Gohr    /**
49168f9feeSAndreas Gohr     * return sort order for position in admin menu
50168f9feeSAndreas Gohr     */
51168f9feeSAndreas Gohr    function getMenuSort() {
52168f9feeSAndreas Gohr        return 40;
53168f9feeSAndreas Gohr    }
54168f9feeSAndreas Gohr
55168f9feeSAndreas Gohr    /**
56168f9feeSAndreas Gohr     * handle user request
57168f9feeSAndreas Gohr     */
58168f9feeSAndreas Gohr    function handle() {
59168f9feeSAndreas Gohr    }
60168f9feeSAndreas Gohr
61168f9feeSAndreas Gohr    /**
62168f9feeSAndreas Gohr     * output appropriate html
63168f9feeSAndreas Gohr     */
64168f9feeSAndreas Gohr    function html() {
65168f9feeSAndreas Gohr
66122b469fSAndreas Gohr        echo $this->plugin_locale_xhtml('intro');
67168f9feeSAndreas Gohr
68122b469fSAndreas Gohr        $this->_searchform();
69168f9feeSAndreas Gohr
70*634d7150SAndreas Gohr        if(is_array($_REQUEST['revert']) && checkSecurityToken()){
7190f99567SAndreas Gohr            $this->_revert($_REQUEST['revert'],$_REQUEST['filter']);
72122b469fSAndreas Gohr        }elseif(isset($_REQUEST['filter'])){
73168f9feeSAndreas Gohr            $this->_list($_REQUEST['filter']);
74168f9feeSAndreas Gohr        }
75122b469fSAndreas Gohr    }
76168f9feeSAndreas Gohr
77122b469fSAndreas Gohr    /**
78122b469fSAndreas Gohr     * Display the form for searching spam pages
79122b469fSAndreas Gohr     */
80122b469fSAndreas Gohr    function _searchform(){
81122b469fSAndreas Gohr        global $lang;
82122b469fSAndreas Gohr        echo '<form action="" method="post">';
83122b469fSAndreas Gohr        echo '<label>'.$this->getLang('filter').': </label>';
84122b469fSAndreas Gohr        echo '<input type="text" name="filter" class="edit" value="'.hsc($_REQUEST['filter']).'" />';
85122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$lang['btn_search'].'" />';
8690f99567SAndreas Gohr        echo ' <span>'.$this->getLang('note1').'</span>';
87122b469fSAndreas Gohr        echo '</form><br /><br />';
88122b469fSAndreas Gohr    }
89122b469fSAndreas Gohr
90122b469fSAndreas Gohr    /**
91122b469fSAndreas Gohr     * Start the reversion process
92122b469fSAndreas Gohr     */
9390f99567SAndreas Gohr    function _revert($revert,$filter){
94168f9feeSAndreas Gohr        global $conf;
95122b469fSAndreas Gohr
96122b469fSAndreas Gohr        echo '<hr /><br />';
97122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstart').'</p>';
98122b469fSAndreas Gohr
99122b469fSAndreas Gohr        echo '<ul>';
100168f9feeSAndreas Gohr        foreach($revert as $id){
101168f9feeSAndreas Gohr            global $REV;
10290f99567SAndreas Gohr
10390f99567SAndreas Gohr            // find the last non-spammy revision
10490f99567SAndreas Gohr            $data = '';
10590f99567SAndreas Gohr            $old  = getRevisions($id, 0, $this->max_revs);
10690f99567SAndreas Gohr            if(count($old)){
10790f99567SAndreas Gohr                foreach($old as $REV){
10890f99567SAndreas Gohr                    $data = rawWiki($id,$REV);
10990f99567SAndreas Gohr                    if(strpos($data,$filter) === false) break;
11090f99567SAndreas Gohr                }
11190f99567SAndreas Gohr            }
11290f99567SAndreas Gohr
11390f99567SAndreas Gohr            if($data){
11490f99567SAndreas Gohr                saveWikiText($id,$data,'old revision restored',false);
115122b469fSAndreas Gohr                printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV);
116168f9feeSAndreas Gohr            }else{
117168f9feeSAndreas Gohr                saveWikiText($id,'','',false);
11890f99567SAndreas Gohr                printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id);
119168f9feeSAndreas Gohr            }
120168f9feeSAndreas Gohr            @set_time_limit(10);
121168f9feeSAndreas Gohr            flush();
122168f9feeSAndreas Gohr        }
123122b469fSAndreas Gohr        echo '</ul>';
124122b469fSAndreas Gohr
125122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstop').'</p>';
126168f9feeSAndreas Gohr    }
127168f9feeSAndreas Gohr
128122b469fSAndreas Gohr    /**
129122b469fSAndreas Gohr     * List recent edits matching the given filter
130122b469fSAndreas Gohr     */
131168f9feeSAndreas Gohr    function _list($filter){
132168f9feeSAndreas Gohr        global $conf;
133122b469fSAndreas Gohr        echo '<hr /><br />';
134122b469fSAndreas Gohr        echo '<form action="" method="post">';
135122b469fSAndreas Gohr        echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />';
136*634d7150SAndreas Gohr        formSecurityToken();
137168f9feeSAndreas Gohr
13890f99567SAndreas Gohr        $recents = getRecents(0,$this->max_lines);
139122b469fSAndreas Gohr        echo '<ul>';
140168f9feeSAndreas Gohr
141122b469fSAndreas Gohr
142122b469fSAndreas Gohr        $cnt = 0;
143168f9feeSAndreas Gohr        foreach($recents as $recent){
144168f9feeSAndreas Gohr            if($filter){
145168f9feeSAndreas Gohr                if(strpos(rawWiki($recent['id']),$filter) === false) continue;
146168f9feeSAndreas Gohr            }
147168f9feeSAndreas Gohr
148122b469fSAndreas Gohr            $cnt++;
149168f9feeSAndreas Gohr            $date = date($conf['dformat'],$recent['date']);
150168f9feeSAndreas Gohr
151ebf1501fSBen Coburn            echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
152122b469fSAndreas Gohr            echo '<div class="li">';
153122b469fSAndreas Gohr            echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />';
154122b469fSAndreas Gohr            echo '<label for="revert__'.$cnt.'">'.$date.'</label> ';
155168f9feeSAndreas Gohr
156122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=diff").'">';
157168f9feeSAndreas Gohr            $p = array();
158168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/diff.png';
159168f9feeSAndreas Gohr            $p['width']  = 15;
160168f9feeSAndreas Gohr            $p['height'] = 11;
161168f9feeSAndreas Gohr            $p['title']  = $lang['diff'];
162168f9feeSAndreas Gohr            $p['alt']    = $lang['diff'];
163168f9feeSAndreas Gohr            $att = buildAttributes($p);
164122b469fSAndreas Gohr            echo "<img $att />";
165122b469fSAndreas Gohr            echo '</a> ';
166168f9feeSAndreas Gohr
167122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=revisions").'">';
168168f9feeSAndreas Gohr            $p = array();
169168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/history.png';
170168f9feeSAndreas Gohr            $p['width']  = 12;
171168f9feeSAndreas Gohr            $p['height'] = 14;
172168f9feeSAndreas Gohr            $p['title']  = $lang['btn_revs'];
173168f9feeSAndreas Gohr            $p['alt']    = $lang['btn_revs'];
174168f9feeSAndreas Gohr            $att = buildAttributes($p);
175122b469fSAndreas Gohr            echo "<img $att />";
176122b469fSAndreas Gohr            echo '</a> ';
177168f9feeSAndreas Gohr
178122b469fSAndreas Gohr            echo html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
179122b469fSAndreas Gohr            echo ' &ndash; '.htmlspecialchars($recent['sum']);
180168f9feeSAndreas Gohr
181122b469fSAndreas Gohr            echo ' <span class="user">';
182122b469fSAndreas Gohr                echo $recent['user'].' '.$recent['ip'];
183122b469fSAndreas Gohr            echo '</span>';
184168f9feeSAndreas Gohr
185122b469fSAndreas Gohr            echo '</div>';
186122b469fSAndreas Gohr            echo '</li>';
187168f9feeSAndreas Gohr
188168f9feeSAndreas Gohr            @set_time_limit(10);
189168f9feeSAndreas Gohr            flush();
190168f9feeSAndreas Gohr        }
191122b469fSAndreas Gohr        echo '</ul>';
192168f9feeSAndreas Gohr
19390f99567SAndreas Gohr        echo '<p>';
194122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$this->getLang('revert').'" /> ';
19590f99567SAndreas Gohr        printf($this->getLang('note2'),hsc($filter));
19690f99567SAndreas Gohr        echo '</p>';
197122b469fSAndreas Gohr
198168f9feeSAndreas Gohr        echo '</form>';
199168f9feeSAndreas Gohr    }
200168f9feeSAndreas Gohr
201168f9feeSAndreas Gohr}
202168f9feeSAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
203