* Removed unused globals
[lhc/web/wiklou.git] / includes / specials / SpecialComparePages.php
1 <?php
2 /**
3 * Copyright (C) 2010 Derk-Jan Hartman <hartman@videolan.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 */
20
21 /**
22 * implements Special:ComparePages
23 * @ingroup SpecialPage
24 */
25 class SpecialComparePages extends SpecialPage {
26
27 // Stored objects
28 protected $opts, $skin;
29
30 // Some internal settings
31 protected $showNavigation = false;
32
33 public function __construct() {
34 parent::__construct( 'ComparePages' );
35 }
36
37 protected function setup( $par ) {
38 global $wgRequest, $wgUser;
39
40 // Options
41 $opts = new FormOptions();
42 $this->opts = $opts; // bind
43 $opts->add( 'page1', '' );
44 $opts->add( 'page2', '' );
45 $opts->add( 'rev1', '' );
46 $opts->add( 'rev2', '' );
47 $opts->add( 'action', '' );
48 $opts->add( 'diffonly', '' );
49
50 // Set values
51 $opts->fetchValuesFromRequest( $wgRequest );
52
53 $title1 = Title::newFromText( $opts->getValue( 'page1' ) );
54 $title2 = Title::newFromText( $opts->getValue( 'page2' ) );
55
56 if( $title1 && $title1->exists() && $opts->getValue( 'rev1' ) == '' ) {
57 $pda = new Article( $title1 );
58 $pdi = $pda->getID();
59 $pdLastRevision = Revision::loadFromPageId( wfGetDB( DB_SLAVE ), $pdi );
60 $opts->setValue( 'rev1', $pdLastRevision->getId() );
61 } elseif ( $opts->getValue( 'rev1' ) != '' ) {
62 $pdrev = Revision::newFromId( $opts->getValue( 'rev1' ) );
63 if( $pdrev ) $opts->setValue( 'page1', $pdrev->getTitle()->getPrefixedText() );
64 }
65 if( $title2 && $title2->exists() && $opts->getValue( 'rev2' ) == '' ) {
66 $pda = new Article( $title2 );
67 $pdi = $pda->getID();
68 $pdLastRevision = Revision::loadFromPageId( wfGetDB( DB_SLAVE ), $pdi );
69 $opts->setValue('rev2', $pdLastRevision->getId() );
70 } elseif ( $opts->getValue( 'rev2' ) != '' ) {
71 $pdrev = Revision::newFromId( $opts->getValue( 'rev2' ) );
72 if( $pdrev ) $opts->setValue( 'page2', $pdrev->getTitle()->getPrefixedText() );
73 }
74
75 // Store some objects
76 $this->skin = $wgUser->getSkin();
77 }
78
79 /**
80 * Show a form for filtering namespace and username
81 *
82 * @param $par String
83 * @return String
84 */
85 public function execute( $par ) {
86 $this->setHeaders();
87 $this->outputHeader();
88
89 $this->setup( $par );
90
91 // Settings
92 $this->form();
93
94 if( $this->opts->getValue( 'rev1' ) && $this->opts->getValue( 'rev2' ) ) {
95 $de = new DifferenceEngine( null,
96 $this->opts->getValue( 'rev1' ),
97 $this->opts->getValue( 'rev2' ),
98 null, // rcid
99 ($this->opts->getValue( 'action') == "purge" ? true : false ),
100 false );
101 $de->showDiffPage( (bool)$this->opts->getValue( 'diffonly' ) );
102 }
103 }
104
105 protected function form() {
106 global $wgOut, $wgScript;
107
108 // Consume values
109 $page1 = $this->opts->consumeValue( 'page1' );
110 $page2 = $this->opts->consumeValue( 'page2' );
111 $rev1 = $this->opts->consumeValue( 'rev1' );
112 $rev2 = $this->opts->consumeValue( 'rev2' );
113
114 // Store query values in hidden fields so that form submission doesn't lose them
115 $hidden = array();
116 foreach ( $this->opts->getUnconsumedValues() as $key => $value ) {
117 $hidden[] = Xml::hidden( $key, $value );
118 }
119 $hidden = implode( "\n", $hidden );
120
121 $form = Html::openElement( 'form', array( 'action' => $wgScript ) ) .
122 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
123 Xml::fieldset( wfMsg( 'compare-selector' ) ) .
124 Html::openElement( 'table', array( 'id' => 'mw-diff-table', 'style' => 'width:100%' ) ) .
125 "<tr>
126 <td class='mw-label' style='width:10%'>" .
127 Html::element( 'label', array( 'for' => 'page1' ), wfMsg( 'compare-page1' ) ) .
128 "</td>
129 <td class='mw-input' style='width:40%'>" .
130 Html::input( 'page1', $page1, 'text', array( 'size' => 40, 'id' => 'page1' ) ) .
131 "</td>
132 <td class='mw-label' style='width:10%'>" .
133 Html::element( 'label', array( 'for' => 'page2' ), wfMsg( 'compare-page2' ) ) .
134 "</td>
135 <td class='mw-input' style='width:40%'>" .
136 Html::input( 'page2', $page2, 'text', array( 'size' => 40, 'id' => 'page2' ) ) .
137 "</td>
138 </tr>" .
139 "<tr>
140 <td class='mw-label'>" .
141 Html::element( 'label', array( 'for' => 'rev1' ), wfMsg( 'compare-rev1' ) ) .
142 "</td>
143 <td class='mw-input'>" .
144 Html::input( 'rev1', $rev1, 'text', array( 'size' => 8, 'id' => 'rev1' ) ) .
145 "</td>
146 <td class='mw-label'>" .
147 Html::element( 'label', array( 'for' => 'rev2' ), wfMsg( 'compare-rev2' ) ) .
148 "</td>
149 <td class='mw-input'>" .
150 Html::input( 'rev2', $rev2, 'text', array( 'size' => 8, 'id' => 'rev2' ) ) .
151 "</td>
152 </tr>" .
153 "<tr> <td></td>
154 <td class='mw-submit' colspan='3'>" .
155 Xml::submitButton( wfMsg( 'compare-submit' ) ) .
156 "</td>
157 </tr>" .
158 Html::closeElement( 'table' ) .
159 Html::closeElement( 'fieldset' ) .
160 $hidden .
161 Html::closeElement( 'form' );
162
163 $wgOut->addHTML( $form );
164 }
165 }