xref: /dokuwiki/lib/plugins/revert/admin.php (revision 122b469f774df8026a8a6182d2bc026ae1a06e2b)
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;
13168f9feeSAndreas Gohr
14168f9feeSAndreas Gohr    /**
15168f9feeSAndreas Gohr     * Constructor
16168f9feeSAndreas Gohr     */
17168f9feeSAndreas Gohr    function admin_plugin_revert(){
18168f9feeSAndreas Gohr        $this->setupLocale();
19168f9feeSAndreas Gohr    }
20168f9feeSAndreas Gohr
21168f9feeSAndreas Gohr    /**
22168f9feeSAndreas Gohr     * return some info
23168f9feeSAndreas Gohr     */
24168f9feeSAndreas Gohr    function getInfo(){
25168f9feeSAndreas Gohr        return array(
26168f9feeSAndreas Gohr            'author' => 'Andreas Gohr',
27168f9feeSAndreas Gohr            'email'  => 'andi@splitbrain.org',
28*122b469fSAndreas Gohr            'date'   => '2005-11-10',
29168f9feeSAndreas Gohr            'name'   => 'Revert Manager',
30168f9feeSAndreas Gohr            'desc'   => 'Allows you to mass revert recent edits',
31168f9feeSAndreas Gohr            'url'    => 'http://wiki.splitbrain.org/plugin:revert',
32168f9feeSAndreas Gohr        );
33168f9feeSAndreas Gohr    }
34168f9feeSAndreas Gohr
35168f9feeSAndreas Gohr    /**
36168f9feeSAndreas Gohr     * return sort order for position in admin menu
37168f9feeSAndreas Gohr     */
38168f9feeSAndreas Gohr    function getMenuSort() {
39168f9feeSAndreas Gohr        return 40;
40168f9feeSAndreas Gohr    }
41168f9feeSAndreas Gohr
42168f9feeSAndreas Gohr    /**
43168f9feeSAndreas Gohr     * handle user request
44168f9feeSAndreas Gohr     */
45168f9feeSAndreas Gohr    function handle() {
46168f9feeSAndreas Gohr    }
47168f9feeSAndreas Gohr
48168f9feeSAndreas Gohr    /**
49168f9feeSAndreas Gohr     * output appropriate html
50168f9feeSAndreas Gohr     */
51168f9feeSAndreas Gohr    function html() {
52168f9feeSAndreas Gohr
53*122b469fSAndreas Gohr        echo $this->plugin_locale_xhtml('intro');
54168f9feeSAndreas Gohr
55*122b469fSAndreas Gohr        $this->_searchform();
56168f9feeSAndreas Gohr
57*122b469fSAndreas Gohr        if(is_array($_REQUEST['revert'])){
58*122b469fSAndreas Gohr            $this->_revert($_REQUEST['revert']);
59*122b469fSAndreas Gohr        }elseif(isset($_REQUEST['filter'])){
60168f9feeSAndreas Gohr            $this->_list($_REQUEST['filter']);
61168f9feeSAndreas Gohr        }
62*122b469fSAndreas Gohr    }
63168f9feeSAndreas Gohr
64*122b469fSAndreas Gohr    /**
65*122b469fSAndreas Gohr     * Display the form for searching spam pages
66*122b469fSAndreas Gohr     */
67*122b469fSAndreas Gohr    function _searchform(){
68*122b469fSAndreas Gohr        global $lang;
69*122b469fSAndreas Gohr        echo '<form action="" method="post">';
70*122b469fSAndreas Gohr        echo '<label>'.$this->getLang('filter').': </label>';
71*122b469fSAndreas Gohr        echo '<input type="text" name="filter" class="edit" value="'.hsc($_REQUEST['filter']).'" />';
72*122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$lang['btn_search'].'" />';
73*122b469fSAndreas Gohr        echo ' <span>'.$this->getLang('note').'</span>';
74*122b469fSAndreas Gohr        echo '</form><br /><br />';
75*122b469fSAndreas Gohr    }
76*122b469fSAndreas Gohr
77*122b469fSAndreas Gohr    /**
78*122b469fSAndreas Gohr     * Start the reversion process
79*122b469fSAndreas Gohr     */
80168f9feeSAndreas Gohr    function _revert($revert){
81168f9feeSAndreas Gohr        global $conf;
82*122b469fSAndreas Gohr
83*122b469fSAndreas Gohr        echo '<hr /><br />';
84*122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstart').'</p>';
85*122b469fSAndreas Gohr
86*122b469fSAndreas Gohr        echo '<ul>';
87168f9feeSAndreas Gohr        foreach($revert as $id){
88168f9feeSAndreas Gohr            global $REV;
89168f9feeSAndreas Gohr            $old = getRevisions($id, 0, 1);
90168f9feeSAndreas Gohr            $REV = $old[0];
91168f9feeSAndreas Gohr            if($REV){
92168f9feeSAndreas Gohr                saveWikiText($id,rawWiki($id,$REV),'old revision restored',false);
93*122b469fSAndreas Gohr                printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV);
94168f9feeSAndreas Gohr            }else{
95168f9feeSAndreas Gohr                saveWikiText($id,'','',false);
96*122b469fSAndreas Gohr                printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id,$REV);
97168f9feeSAndreas Gohr            }
98168f9feeSAndreas Gohr            @set_time_limit(10);
99168f9feeSAndreas Gohr            flush();
100168f9feeSAndreas Gohr        }
101*122b469fSAndreas Gohr        echo '</ul>';
102*122b469fSAndreas Gohr
103*122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstop').'</p>';
104168f9feeSAndreas Gohr    }
105168f9feeSAndreas Gohr
106*122b469fSAndreas Gohr    /**
107*122b469fSAndreas Gohr     * List recent edits matching the given filter
108*122b469fSAndreas Gohr     */
109168f9feeSAndreas Gohr    function _list($filter){
110168f9feeSAndreas Gohr        global $conf;
111*122b469fSAndreas Gohr        echo '<hr /><br />';
112*122b469fSAndreas Gohr        echo '<form action="" method="post">';
113*122b469fSAndreas Gohr        echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />';
114168f9feeSAndreas Gohr
115168f9feeSAndreas Gohr        $recents = getRecents(0,800);
116*122b469fSAndreas Gohr        echo '<ul>';
117168f9feeSAndreas Gohr
118*122b469fSAndreas Gohr
119*122b469fSAndreas Gohr        $cnt = 0;
120168f9feeSAndreas Gohr        foreach($recents as $recent){
121168f9feeSAndreas Gohr            if($filter){
122168f9feeSAndreas Gohr                if(strpos(rawWiki($recent['id']),$filter) === false) continue;
123168f9feeSAndreas Gohr            }
124168f9feeSAndreas Gohr
125*122b469fSAndreas Gohr            $cnt++;
126168f9feeSAndreas Gohr            $date = date($conf['dformat'],$recent['date']);
127168f9feeSAndreas Gohr
128*122b469fSAndreas Gohr            echo ($recent['type']==='e') ? '<li class="minor">' : '<li>';
129*122b469fSAndreas Gohr            echo '<div class="li">';
130*122b469fSAndreas Gohr            echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />';
131*122b469fSAndreas Gohr            echo '<label for="revert__'.$cnt.'">'.$date.'</label> ';
132168f9feeSAndreas Gohr
133*122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=diff").'">';
134168f9feeSAndreas Gohr            $p = array();
135168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/diff.png';
136168f9feeSAndreas Gohr            $p['width']  = 15;
137168f9feeSAndreas Gohr            $p['height'] = 11;
138168f9feeSAndreas Gohr            $p['title']  = $lang['diff'];
139168f9feeSAndreas Gohr            $p['alt']    = $lang['diff'];
140168f9feeSAndreas Gohr            $att = buildAttributes($p);
141*122b469fSAndreas Gohr            echo "<img $att />";
142*122b469fSAndreas Gohr            echo '</a> ';
143168f9feeSAndreas Gohr
144*122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=revisions").'">';
145168f9feeSAndreas Gohr            $p = array();
146168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/history.png';
147168f9feeSAndreas Gohr            $p['width']  = 12;
148168f9feeSAndreas Gohr            $p['height'] = 14;
149168f9feeSAndreas Gohr            $p['title']  = $lang['btn_revs'];
150168f9feeSAndreas Gohr            $p['alt']    = $lang['btn_revs'];
151168f9feeSAndreas Gohr            $att = buildAttributes($p);
152*122b469fSAndreas Gohr            echo "<img $att />";
153*122b469fSAndreas Gohr            echo '</a> ';
154168f9feeSAndreas Gohr
155*122b469fSAndreas Gohr            echo html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
156*122b469fSAndreas Gohr            echo ' &ndash; '.htmlspecialchars($recent['sum']);
157168f9feeSAndreas Gohr
158*122b469fSAndreas Gohr            echo ' <span class="user">';
159*122b469fSAndreas Gohr                echo $recent['user'].' '.$recent['ip'];
160*122b469fSAndreas Gohr            echo '</span>';
161168f9feeSAndreas Gohr
162*122b469fSAndreas Gohr            echo '</div>';
163*122b469fSAndreas Gohr            echo '</li>';
164168f9feeSAndreas Gohr
165168f9feeSAndreas Gohr            @set_time_limit(10);
166168f9feeSAndreas Gohr            flush();
167168f9feeSAndreas Gohr        }
168*122b469fSAndreas Gohr        echo '</ul>';
169168f9feeSAndreas Gohr
170*122b469fSAndreas Gohr        echo '<input type="submit" class="button" value="'.$this->getLang('revert').'" />';
171*122b469fSAndreas Gohr
172168f9feeSAndreas Gohr        echo '</form>';
173168f9feeSAndreas Gohr    }
174168f9feeSAndreas Gohr
175168f9feeSAndreas Gohr}
176168f9feeSAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
177