xref: /dokuwiki/lib/plugins/revert/admin.php (revision 0c3a5702735953748f68955d51bb478538fb6eda)
1168f9feeSAndreas Gohr<?php
2*0c3a5702SAndreas Gohr
3*0c3a5702SAndreas Gohruse dokuwiki\ChangeLog\PageChangeLog;
4*0c3a5702SAndreas Gohr
5168f9feeSAndreas Gohr/**
6168f9feeSAndreas Gohr * All DokuWiki plugins to extend the admin function
7168f9feeSAndreas Gohr * need to inherit from this class
8168f9feeSAndreas Gohr */
92a7fef40SAndreas Gohrclass admin_plugin_revert extends DokuWiki_Admin_Plugin
102a7fef40SAndreas Gohr{
113dc2d50cSAndreas Gohr    protected $cmd;
1290f99567SAndreas Gohr    // some vars which might need tuning later
133dc2d50cSAndreas Gohr    protected $max_lines = 800; // lines to read from changelog
143dc2d50cSAndreas Gohr    protected $max_revs  = 20;  // numer of old revisions to check
1590f99567SAndreas Gohr
16168f9feeSAndreas Gohr
17168f9feeSAndreas Gohr    /**
18168f9feeSAndreas Gohr     * Constructor
19168f9feeSAndreas Gohr     */
202a7fef40SAndreas Gohr    public function __construct()
212a7fef40SAndreas Gohr    {
22168f9feeSAndreas Gohr        $this->setupLocale();
23168f9feeSAndreas Gohr    }
24168f9feeSAndreas Gohr
25168f9feeSAndreas Gohr    /**
26f8cc712eSAndreas Gohr     * access for managers
27f8cc712eSAndreas Gohr     */
282a7fef40SAndreas Gohr    public function forAdminOnly()
292a7fef40SAndreas Gohr    {
30f8cc712eSAndreas Gohr        return false;
31f8cc712eSAndreas Gohr    }
32f8cc712eSAndreas Gohr
33f8cc712eSAndreas Gohr    /**
34168f9feeSAndreas Gohr     * return sort order for position in admin menu
35168f9feeSAndreas Gohr     */
362a7fef40SAndreas Gohr    public function getMenuSort()
372a7fef40SAndreas Gohr    {
38168f9feeSAndreas Gohr        return 40;
39168f9feeSAndreas Gohr    }
40168f9feeSAndreas Gohr
41168f9feeSAndreas Gohr    /**
42168f9feeSAndreas Gohr     * handle user request
43168f9feeSAndreas Gohr     */
442a7fef40SAndreas Gohr    public function handle()
452a7fef40SAndreas Gohr    {
46168f9feeSAndreas Gohr    }
47168f9feeSAndreas Gohr
48168f9feeSAndreas Gohr    /**
49168f9feeSAndreas Gohr     * output appropriate html
50168f9feeSAndreas Gohr     */
512a7fef40SAndreas Gohr    public function html()
522a7fef40SAndreas Gohr    {
5300d58927SMichael Hamann        global $INPUT;
54168f9feeSAndreas Gohr
5519ff1b0bSAnika Henke        echo $this->locale_xhtml('intro');
56168f9feeSAndreas Gohr
572a7fef40SAndreas Gohr        $this->printSearchForm();
58168f9feeSAndreas Gohr
5900d58927SMichael Hamann        if (is_array($INPUT->param('revert')) && checkSecurityToken()) {
602a7fef40SAndreas Gohr            $this->revertEdits($INPUT->arr('revert'), $INPUT->str('filter'));
6100d58927SMichael Hamann        } elseif ($INPUT->has('filter')) {
622a7fef40SAndreas Gohr            $this->listEdits($INPUT->str('filter'));
63168f9feeSAndreas Gohr        }
64122b469fSAndreas Gohr    }
65168f9feeSAndreas Gohr
66122b469fSAndreas Gohr    /**
67122b469fSAndreas Gohr     * Display the form for searching spam pages
68122b469fSAndreas Gohr     */
692a7fef40SAndreas Gohr    protected function printSearchForm()
702a7fef40SAndreas Gohr    {
7100d58927SMichael Hamann        global $lang, $INPUT;
722404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
73122b469fSAndreas Gohr        echo '<label>'.$this->getLang('filter').': </label>';
7400d58927SMichael Hamann        echo '<input type="text" name="filter" class="edit" value="'.hsc($INPUT->str('filter')).'" /> ';
75ae614416SAnika Henke        echo '<button type="submit">'.$lang['btn_search'].'</button> ';
7690f99567SAndreas Gohr        echo '<span>'.$this->getLang('note1').'</span>';
772404d0edSAnika Henke        echo '</div></form><br /><br />';
78122b469fSAndreas Gohr    }
79122b469fSAndreas Gohr
80122b469fSAndreas Gohr    /**
81122b469fSAndreas Gohr     * Start the reversion process
82122b469fSAndreas Gohr     */
832a7fef40SAndreas Gohr    protected function revertEdits($revert, $filter)
842a7fef40SAndreas Gohr    {
85122b469fSAndreas Gohr        echo '<hr /><br />';
86122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstart').'</p>';
87122b469fSAndreas Gohr
88122b469fSAndreas Gohr        echo '<ul>';
89168f9feeSAndreas Gohr        foreach ($revert as $id) {
90168f9feeSAndreas Gohr            global $REV;
9190f99567SAndreas Gohr
9290f99567SAndreas Gohr            // find the last non-spammy revision
9390f99567SAndreas Gohr            $data = '';
94047bad06SGerrit Uitslag            $pagelog = new PageChangeLog($id);
95f523c971SGerrit Uitslag            $old  = $pagelog->getRevisions(0, $this->max_revs);
9690f99567SAndreas Gohr            if (count($old)) {
9790f99567SAndreas Gohr                foreach ($old as $REV) {
9890f99567SAndreas Gohr                    $data = rawWiki($id, $REV);
9990f99567SAndreas Gohr                    if (strpos($data, $filter) === false) break;
10090f99567SAndreas Gohr                }
10190f99567SAndreas Gohr            }
10290f99567SAndreas Gohr
10390f99567SAndreas Gohr            if ($data) {
10490f99567SAndreas Gohr                saveWikiText($id, $data, 'old revision restored', false);
105122b469fSAndreas Gohr                printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>', $id, $REV);
106168f9feeSAndreas Gohr            } else {
107168f9feeSAndreas Gohr                saveWikiText($id, '', '', false);
10890f99567SAndreas Gohr                printf('<li><div class="li">'.$this->getLang('removed').'</div></li>', $id);
109168f9feeSAndreas Gohr            }
110168f9feeSAndreas Gohr            @set_time_limit(10);
111168f9feeSAndreas Gohr            flush();
112168f9feeSAndreas Gohr        }
113122b469fSAndreas Gohr        echo '</ul>';
114122b469fSAndreas Gohr
115122b469fSAndreas Gohr        echo '<p>'.$this->getLang('revstop').'</p>';
116168f9feeSAndreas Gohr    }
117168f9feeSAndreas Gohr
118122b469fSAndreas Gohr    /**
119122b469fSAndreas Gohr     * List recent edits matching the given filter
120122b469fSAndreas Gohr     */
1212a7fef40SAndreas Gohr    protected function listEdits($filter)
1222a7fef40SAndreas Gohr    {
123168f9feeSAndreas Gohr        global $conf;
124de3eb1d7SAdrian Lang        global $lang;
125122b469fSAndreas Gohr        echo '<hr /><br />';
1262404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
127122b469fSAndreas Gohr        echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />';
128634d7150SAndreas Gohr        formSecurityToken();
129168f9feeSAndreas Gohr
13090f99567SAndreas Gohr        $recents = getRecents(0, $this->max_lines);
131122b469fSAndreas Gohr        echo '<ul>';
132168f9feeSAndreas Gohr
133122b469fSAndreas Gohr        $cnt = 0;
134168f9feeSAndreas Gohr        foreach ($recents as $recent) {
135168f9feeSAndreas Gohr            if ($filter) {
136168f9feeSAndreas Gohr                if (strpos(rawWiki($recent['id']), $filter) === false) continue;
137168f9feeSAndreas Gohr            }
138168f9feeSAndreas Gohr
139122b469fSAndreas Gohr            $cnt++;
140dc235f96SMatthias Schulte            $date = dformat($recent['date']);
141168f9feeSAndreas Gohr
142ebf1501fSBen Coburn            echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
143122b469fSAndreas Gohr            echo '<div class="li">';
14464159a61SAndreas Gohr            echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).
14564159a61SAndreas Gohr                '" checked="checked" id="revert__'.$cnt.'" />';
146122b469fSAndreas Gohr            echo ' <label for="revert__'.$cnt.'">'.$date.'</label> ';
147168f9feeSAndreas Gohr
148122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'], "do=diff").'">';
149168f9feeSAndreas Gohr            $p = array();
150168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/diff.png';
151168f9feeSAndreas Gohr            $p['width']  = 15;
152168f9feeSAndreas Gohr            $p['height'] = 11;
153168f9feeSAndreas Gohr            $p['title']  = $lang['diff'];
154168f9feeSAndreas Gohr            $p['alt']    = $lang['diff'];
155168f9feeSAndreas Gohr            $att = buildAttributes($p);
156122b469fSAndreas Gohr            echo "<img $att />";
157122b469fSAndreas Gohr            echo '</a> ';
158168f9feeSAndreas Gohr
159122b469fSAndreas Gohr            echo '<a href="'.wl($recent['id'], "do=revisions").'">';
160168f9feeSAndreas Gohr            $p = array();
161168f9feeSAndreas Gohr            $p['src']    = DOKU_BASE.'lib/images/history.png';
162168f9feeSAndreas Gohr            $p['width']  = 12;
163168f9feeSAndreas Gohr            $p['height'] = 14;
164168f9feeSAndreas Gohr            $p['title']  = $lang['btn_revs'];
165168f9feeSAndreas Gohr            $p['alt']    = $lang['btn_revs'];
166168f9feeSAndreas Gohr            $att = buildAttributes($p);
167122b469fSAndreas Gohr            echo "<img $att />";
168122b469fSAndreas Gohr            echo '</a> ';
169168f9feeSAndreas Gohr
1700ea51e63SMatt Perry            echo html_wikilink(':'.$recent['id'], (useHeading('navigation'))?null:$recent['id']);
171e260f93bSAnika Henke            echo ' – '.htmlspecialchars($recent['sum']);
172168f9feeSAndreas Gohr
173122b469fSAndreas Gohr            echo ' <span class="user">';
174122b469fSAndreas Gohr                echo $recent['user'].' '.$recent['ip'];
175122b469fSAndreas Gohr            echo '</span>';
176168f9feeSAndreas Gohr
177122b469fSAndreas Gohr            echo '</div>';
178122b469fSAndreas Gohr            echo '</li>';
179168f9feeSAndreas Gohr
180168f9feeSAndreas Gohr            @set_time_limit(10);
181168f9feeSAndreas Gohr            flush();
182168f9feeSAndreas Gohr        }
183122b469fSAndreas Gohr        echo '</ul>';
184168f9feeSAndreas Gohr
18590f99567SAndreas Gohr        echo '<p>';
186ae614416SAnika Henke        echo '<button type="submit">'.$this->getLang('revert').'</button> ';
18790f99567SAndreas Gohr        printf($this->getLang('note2'), hsc($filter));
18890f99567SAndreas Gohr        echo '</p>';
189122b469fSAndreas Gohr
1902404d0edSAnika Henke        echo '</div></form>';
191168f9feeSAndreas Gohr    }
192168f9feeSAndreas Gohr}
193e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
194