xref: /dokuwiki/lib/plugins/revert/admin.php (revision 90f99567851007c1b66514527d4e3a065e0f07eb)
1168f9feeSAndreas Gohr<?php
2168f9feeSAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/');
3168f9feeSAndreas Gohrif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
4168f9feeSAndreas Gohrrequire_once(DOKU_PLUGIN.'admin.php');
5168f9feeSAndreas Gohrrequire_once(DOKU_INC.'inc/changelog.php');
6168f9feeSAndreas Gohr
7168f9feeSAndreas Gohr/**
8168f9feeSAndreas Gohr * All DokuWiki plugins to extend the admin function
9168f9feeSAndreas Gohr * need to inherit from this class
10168f9feeSAndreas Gohr */
11168f9feeSAndreas Gohrclass admin_plugin_revert extends DokuWiki_Admin_Plugin {
12168f9feeSAndreas Gohr    var $cmd;
13*90f99567SAndreas Gohr    // some vars which might need tuning later
14*90f99567SAndreas Gohr    var $max_lines = 800; // lines to read from changelog
15*90f99567SAndreas Gohr    var $max_revs  = 20;  // numer of old revisions to check
16*90f99567SAndreas Gohr
17168f9feeSAndreas Gohr
18168f9feeSAndreas Gohr    /**
19168f9feeSAndreas Gohr     * Constructor
20168f9feeSAndreas Gohr     */
21168f9feeSAndreas Gohr    function admin_plugin_revert(){
22168f9feeSAndreas Gohr        $this->setupLocale();
23168f9feeSAndreas Gohr    }
24168f9feeSAndreas Gohr
25168f9feeSAndreas Gohr    /**
26168f9feeSAndreas Gohr     * return some info
27168f9feeSAndreas Gohr     */
28168f9feeSAndreas Gohr    function getInfo(){
29168f9feeSAndreas Gohr        return array(
30168f9feeSAndreas Gohr            'author' => 'Andreas Gohr',
31168f9feeSAndreas Gohr            'email'  => 'andi@splitbrain.org',
32*90f99567SAndreas Gohr            'date'   => '2007-04-22',
33168f9feeSAndreas Gohr            'name'   => 'Revert Manager',
34168f9feeSAndreas Gohr            'desc'   => 'Allows you to mass revert recent edits',
35168f9feeSAndreas Gohr            'url'    => 'http://wiki.splitbrain.org/plugin:revert',
36168f9feeSAndreas Gohr        );
37168f9feeSAndreas Gohr    }
38168f9feeSAndreas Gohr
39168f9feeSAndreas Gohr    /**
40f8cc712eSAndreas Gohr     * access for managers
41f8cc712eSAndreas Gohr     */
42f8cc712eSAndreas Gohr    function forAdminOnly(){
43f8cc712eSAndreas Gohr        return false;
44f8cc712eSAndreas Gohr    }
45f8cc712eSAndreas Gohr
46f8cc712eSAndreas Gohr    /**
47168f9feeSAndreas Gohr     * return sort order for position in admin menu
48168f9feeSAndreas Gohr     */
49168f9feeSAndreas Gohr    function getMenuSort() {
50168f9feeSAndreas Gohr        return 40;
51168f9feeSAndreas Gohr    }
52168f9feeSAndreas Gohr
53168f9feeSAndreas Gohr    /**
54168f9feeSAndreas Gohr     * handle user request
55168f9feeSAndreas Gohr     */
56168f9feeSAndreas Gohr    function handle() {
57168f9feeSAndreas Gohr    }
58168f9feeSAndreas Gohr
59168f9feeSAndreas Gohr    /**
60168f9feeSAndreas Gohr     * output appropriate html
61168f9feeSAndreas Gohr     */
62168f9feeSAndreas Gohr    function html() {
63168f9feeSAndreas Gohr
64122b469fSAndreas Gohr        echo $this->plugin_locale_xhtml('intro');
65168f9feeSAndreas Gohr
66122b469fSAndreas Gohr        $this->_searchform();
67168f9feeSAndreas Gohr
68122b469fSAndreas Gohr        if(is_array($_REQUEST['revert'])){
69*90f99567SAndreas Gohr            $this->_revert($_REQUEST['revert'],$_REQUEST['filter']);
70122b469fSAndreas Gohr        }elseif(isset($_REQUEST['filter'])){
71168f9feeSAndreas Gohr            $this->_list($_REQUEST['filter']);
72168f9feeSAndreas Gohr        }
73122b469fSAndreas Gohr    }
74168f9feeSAndreas Gohr
75122b469fSAndreas Gohr    /**
76122b469fSAndreas Gohr     * Display the form for searching spam pages
77122b469fSAndreas Gohr     */
78122b469fSAndreas Gohr    function _searchform(){
79122b469fSAndreas Gohr        global $lang;
80122b469fSAndreas Gohr        echo '<form action="" method="post">';
81122b469fSAndreas Gohr        echo '<label>'.$this->getLang('filter').': </label>';
82122b469fSAndreas Gohr        echo '<input type="text" name="filter" class="edit" value="'.hsc($_REQUEST['filter']).'" />';
83122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$lang['btn_search'].'" />';
84*90f99567SAndreas Gohr        echo ' <span>'.$this->getLang('note1').'</span>';
85122b469fSAndreas Gohr        echo '</form><br /><br />';
86122b469fSAndreas Gohr    }
87122b469fSAndreas Gohr
88122b469fSAndreas Gohr    /**
89122b469fSAndreas Gohr     * Start the reversion process
90122b469fSAndreas Gohr     */
91*90f99567SAndreas Gohr    function _revert($revert,$filter){
92168f9feeSAndreas Gohr        global $conf;
93122b469fSAndreas Gohr
94122b469fSAndreas Gohr        echo '<hr /><br />';
95122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstart').'</p>';
96122b469fSAndreas Gohr
97122b469fSAndreas Gohr        echo '<ul>';
98168f9feeSAndreas Gohr        foreach($revert as $id){
99168f9feeSAndreas Gohr            global $REV;
100*90f99567SAndreas Gohr
101*90f99567SAndreas Gohr            // find the last non-spammy revision
102*90f99567SAndreas Gohr            $data = '';
103*90f99567SAndreas Gohr            $old  = getRevisions($id, 0, $this->max_revs);
104*90f99567SAndreas Gohr            if(count($old)){
105*90f99567SAndreas Gohr                foreach($old as $REV){
106*90f99567SAndreas Gohr                    $data = rawWiki($id,$REV);
107*90f99567SAndreas Gohr                    if(strpos($data,$filter) === false) break;
108*90f99567SAndreas Gohr                }
109*90f99567SAndreas Gohr            }
110*90f99567SAndreas Gohr
111*90f99567SAndreas Gohr            if($data){
112*90f99567SAndreas Gohr                saveWikiText($id,$data,'old revision restored',false);
113122b469fSAndreas Gohr                printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV);
114168f9feeSAndreas Gohr            }else{
115168f9feeSAndreas Gohr                saveWikiText($id,'','',false);
116*90f99567SAndreas Gohr                printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id);
117168f9feeSAndreas Gohr            }
118168f9feeSAndreas Gohr            @set_time_limit(10);
119168f9feeSAndreas Gohr            flush();
120168f9feeSAndreas Gohr        }
121122b469fSAndreas Gohr        echo '</ul>';
122122b469fSAndreas Gohr
123122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstop').'</p>';
124168f9feeSAndreas Gohr    }
125168f9feeSAndreas Gohr
126122b469fSAndreas Gohr    /**
127122b469fSAndreas Gohr     * List recent edits matching the given filter
128122b469fSAndreas Gohr     */
129168f9feeSAndreas Gohr    function _list($filter){
130168f9feeSAndreas Gohr        global $conf;
131122b469fSAndreas Gohr        echo '<hr /><br />';
132122b469fSAndreas Gohr        echo '<form action="" method="post">';
133122b469fSAndreas Gohr        echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />';
134168f9feeSAndreas Gohr
135*90f99567SAndreas 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++;
146168f9feeSAndreas Gohr            $date = date($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
175122b469fSAndreas Gohr            echo html_wikilink(':'.$recent['id'],$conf['useheading']?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
190*90f99567SAndreas Gohr        echo '<p>';
191122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$this->getLang('revert').'" /> ';
192*90f99567SAndreas Gohr        printf($this->getLang('note2'),hsc($filter));
193*90f99567SAndreas Gohr        echo '</p>';
194122b469fSAndreas Gohr
195168f9feeSAndreas Gohr        echo '</form>';
196168f9feeSAndreas Gohr    }
197168f9feeSAndreas Gohr
198168f9feeSAndreas Gohr}
199168f9feeSAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
200