xref: /dokuwiki/lib/plugins/revert/admin.php (revision 3dc2d50c5fda9c4bf708ff4c26e266ba239af62c)
1168f9feeSAndreas Gohr<?php
2168f9feeSAndreas Gohr/**
3168f9feeSAndreas Gohr * All DokuWiki plugins to extend the admin function
4168f9feeSAndreas Gohr * need to inherit from this class
5168f9feeSAndreas Gohr */
6168f9feeSAndreas Gohrclass admin_plugin_revert extends DokuWiki_Admin_Plugin {
7*3dc2d50cSAndreas Gohr    protected $cmd;
890f99567SAndreas Gohr    // some vars which might need tuning later
9*3dc2d50cSAndreas Gohr    protected $max_lines = 800; // lines to read from changelog
10*3dc2d50cSAndreas Gohr    protected $max_revs  = 20;  // numer of old revisions to check
1190f99567SAndreas Gohr
12168f9feeSAndreas Gohr
13168f9feeSAndreas Gohr    /**
14168f9feeSAndreas Gohr     * Constructor
15168f9feeSAndreas Gohr     */
16*3dc2d50cSAndreas Gohr    public function __construct(){
17168f9feeSAndreas Gohr        $this->setupLocale();
18168f9feeSAndreas Gohr    }
19168f9feeSAndreas Gohr
20168f9feeSAndreas Gohr    /**
21f8cc712eSAndreas Gohr     * access for managers
22f8cc712eSAndreas Gohr     */
23*3dc2d50cSAndreas Gohr    public function forAdminOnly(){
24f8cc712eSAndreas Gohr        return false;
25f8cc712eSAndreas Gohr    }
26f8cc712eSAndreas Gohr
27f8cc712eSAndreas Gohr    /**
28168f9feeSAndreas Gohr     * return sort order for position in admin menu
29168f9feeSAndreas Gohr     */
30*3dc2d50cSAndreas Gohr    public function getMenuSort() {
31168f9feeSAndreas Gohr        return 40;
32168f9feeSAndreas Gohr    }
33168f9feeSAndreas Gohr
34168f9feeSAndreas Gohr    /**
35168f9feeSAndreas Gohr     * handle user request
36168f9feeSAndreas Gohr     */
37*3dc2d50cSAndreas Gohr    public function handle() {
38168f9feeSAndreas Gohr    }
39168f9feeSAndreas Gohr
40168f9feeSAndreas Gohr    /**
41168f9feeSAndreas Gohr     * output appropriate html
42168f9feeSAndreas Gohr     */
43*3dc2d50cSAndreas Gohr    public function html() {
4400d58927SMichael Hamann        global $INPUT;
45168f9feeSAndreas Gohr
4619ff1b0bSAnika Henke        echo $this->locale_xhtml('intro');
47168f9feeSAndreas Gohr
48122b469fSAndreas Gohr        $this->_searchform();
49168f9feeSAndreas Gohr
5000d58927SMichael Hamann        if(is_array($INPUT->param('revert')) && checkSecurityToken()){
5100d58927SMichael Hamann            $this->_revert($INPUT->arr('revert'),$INPUT->str('filter'));
5200d58927SMichael Hamann        }elseif($INPUT->has('filter')){
5300d58927SMichael Hamann            $this->_list($INPUT->str('filter'));
54168f9feeSAndreas Gohr        }
55122b469fSAndreas Gohr    }
56168f9feeSAndreas Gohr
57122b469fSAndreas Gohr    /**
58122b469fSAndreas Gohr     * Display the form for searching spam pages
59122b469fSAndreas Gohr     */
60*3dc2d50cSAndreas Gohr    protected function _searchform(){
6100d58927SMichael Hamann        global $lang, $INPUT;
622404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
63122b469fSAndreas Gohr        echo '<label>'.$this->getLang('filter').': </label>';
6400d58927SMichael Hamann        echo '<input type="text" name="filter" class="edit" value="'.hsc($INPUT->str('filter')).'" /> ';
65ae614416SAnika Henke        echo '<button type="submit">'.$lang['btn_search'].'</button> ';
6690f99567SAndreas Gohr        echo '<span>'.$this->getLang('note1').'</span>';
672404d0edSAnika Henke        echo '</div></form><br /><br />';
68122b469fSAndreas Gohr    }
69122b469fSAndreas Gohr
70122b469fSAndreas Gohr    /**
71122b469fSAndreas Gohr     * Start the reversion process
72122b469fSAndreas Gohr     */
73*3dc2d50cSAndreas Gohr    protected function _revert($revert,$filter){
74122b469fSAndreas Gohr        echo '<hr /><br />';
75122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstart').'</p>';
76122b469fSAndreas Gohr
77122b469fSAndreas Gohr        echo '<ul>';
78168f9feeSAndreas Gohr        foreach($revert as $id){
79168f9feeSAndreas Gohr            global $REV;
8090f99567SAndreas Gohr
8190f99567SAndreas Gohr            // find the last non-spammy revision
8290f99567SAndreas Gohr            $data = '';
83047bad06SGerrit Uitslag            $pagelog = new PageChangeLog($id);
84f523c971SGerrit Uitslag            $old  = $pagelog->getRevisions(0, $this->max_revs);
8590f99567SAndreas Gohr            if(count($old)){
8690f99567SAndreas Gohr                foreach($old as $REV){
8790f99567SAndreas Gohr                    $data = rawWiki($id,$REV);
8890f99567SAndreas Gohr                    if(strpos($data,$filter) === false) break;
8990f99567SAndreas Gohr                }
9090f99567SAndreas Gohr            }
9190f99567SAndreas Gohr
9290f99567SAndreas Gohr            if($data){
9390f99567SAndreas Gohr                saveWikiText($id,$data,'old revision restored',false);
94122b469fSAndreas Gohr                printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV);
95168f9feeSAndreas Gohr            }else{
96168f9feeSAndreas Gohr                saveWikiText($id,'','',false);
9790f99567SAndreas Gohr                printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id);
98168f9feeSAndreas Gohr            }
99168f9feeSAndreas Gohr            @set_time_limit(10);
100168f9feeSAndreas Gohr            flush();
101168f9feeSAndreas Gohr        }
102122b469fSAndreas Gohr        echo '</ul>';
103122b469fSAndreas Gohr
104122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstop').'</p>';
105168f9feeSAndreas Gohr    }
106168f9feeSAndreas Gohr
107122b469fSAndreas Gohr    /**
108122b469fSAndreas Gohr     * List recent edits matching the given filter
109122b469fSAndreas Gohr     */
110*3dc2d50cSAndreas Gohr    protected function _list($filter){
111168f9feeSAndreas Gohr        global $conf;
112de3eb1d7SAdrian Lang        global $lang;
113122b469fSAndreas Gohr        echo '<hr /><br />';
1142404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
115122b469fSAndreas Gohr        echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />';
116634d7150SAndreas Gohr        formSecurityToken();
117168f9feeSAndreas Gohr
11890f99567SAndreas Gohr        $recents = getRecents(0,$this->max_lines);
119122b469fSAndreas Gohr        echo '<ul>';
120168f9feeSAndreas Gohr
121122b469fSAndreas Gohr        $cnt = 0;
122168f9feeSAndreas Gohr        foreach($recents as $recent){
123168f9feeSAndreas Gohr            if($filter){
124168f9feeSAndreas Gohr                if(strpos(rawWiki($recent['id']),$filter) === false) continue;
125168f9feeSAndreas Gohr            }
126168f9feeSAndreas Gohr
127122b469fSAndreas Gohr            $cnt++;
128dc235f96SMatthias Schulte            $date = dformat($recent['date']);
129168f9feeSAndreas Gohr
130ebf1501fSBen Coburn            echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
131122b469fSAndreas Gohr            echo '<div class="li">';
13264159a61SAndreas Gohr            echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).
13364159a61SAndreas Gohr                '" checked="checked" id="revert__'.$cnt.'" />';
134122b469fSAndreas Gohr            echo ' <label for="revert__'.$cnt.'">'.$date.'</label> ';
135168f9feeSAndreas Gohr
136122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=diff").'">';
137168f9feeSAndreas Gohr            $p = array();
138168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/diff.png';
139168f9feeSAndreas Gohr            $p['width']  = 15;
140168f9feeSAndreas Gohr            $p['height'] = 11;
141168f9feeSAndreas Gohr            $p['title']  = $lang['diff'];
142168f9feeSAndreas Gohr            $p['alt']    = $lang['diff'];
143168f9feeSAndreas Gohr            $att = buildAttributes($p);
144122b469fSAndreas Gohr            echo "<img $att />";
145122b469fSAndreas Gohr            echo '</a> ';
146168f9feeSAndreas Gohr
147122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'],"do=revisions").'">';
148168f9feeSAndreas Gohr            $p = array();
149168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/history.png';
150168f9feeSAndreas Gohr            $p['width']  = 12;
151168f9feeSAndreas Gohr            $p['height'] = 14;
152168f9feeSAndreas Gohr            $p['title']  = $lang['btn_revs'];
153168f9feeSAndreas Gohr            $p['alt']    = $lang['btn_revs'];
154168f9feeSAndreas Gohr            $att = buildAttributes($p);
155122b469fSAndreas Gohr            echo "<img $att />";
156122b469fSAndreas Gohr            echo '</a> ';
157168f9feeSAndreas Gohr
1580ea51e63SMatt Perry            echo html_wikilink(':'.$recent['id'],(useHeading('navigation'))?null:$recent['id']);
159e260f93bSAnika Henke            echo ' – '.htmlspecialchars($recent['sum']);
160168f9feeSAndreas Gohr
161122b469fSAndreas Gohr            echo ' <span class="user">';
162122b469fSAndreas Gohr                echo $recent['user'].' '.$recent['ip'];
163122b469fSAndreas Gohr            echo '</span>';
164168f9feeSAndreas Gohr
165122b469fSAndreas Gohr            echo '</div>';
166122b469fSAndreas Gohr            echo '</li>';
167168f9feeSAndreas Gohr
168168f9feeSAndreas Gohr            @set_time_limit(10);
169168f9feeSAndreas Gohr            flush();
170168f9feeSAndreas Gohr        }
171122b469fSAndreas Gohr        echo '</ul>';
172168f9feeSAndreas Gohr
17390f99567SAndreas Gohr        echo '<p>';
174ae614416SAnika Henke        echo '<button type="submit">'.$this->getLang('revert').'</button> ';
17590f99567SAndreas Gohr        printf($this->getLang('note2'),hsc($filter));
17690f99567SAndreas Gohr        echo '</p>';
177122b469fSAndreas Gohr
1782404d0edSAnika Henke        echo '</div></form>';
179168f9feeSAndreas Gohr    }
180168f9feeSAndreas Gohr
181168f9feeSAndreas Gohr}
182e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
183