GPL Headers for all!
[lhc/web/wiklou.git] / includes / specials / SpecialComparePages.php
1 <?php
2 /**
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 /**
21 * implements Special:ComparePages
22 * @ingroup SpecialPage
23 */
24 class SpecialComparePages extends SpecialPage {
25
26 // Stored objects
27 protected $opts, $skin;
28
29 // Some internal settings
30 protected $showNavigation = false;
31
32 public function __construct() {
33 parent::__construct( 'ComparePages' );
34 $this->includable( false );
35 }
36
37 protected function setup( $par ) {
38 global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
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()->getPrefixedDBkey() );
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()->getPrefixedDBkey() );
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 global $wgLang, $wgOut;
87
88 $this->setHeaders();
89 $this->outputHeader();
90
91 $this->setup( $par );
92
93 // Settings
94 $this->form();
95
96 if( $this->opts->getValue( 'rev1' ) && $this->opts->getValue( 'rev2' ) ) {
97 $de = new DifferenceEngine( null,
98 $this->opts->getValue( 'rev1' ),
99 $this->opts->getValue( 'rev2' ),
100 null, // rcid
101 ($this->opts->getValue( 'action') == "purge" ? true : false ),
102 false );
103 $de->showDiffPage( (bool)$this->opts->getValue( 'diffonly' ) );
104 }
105 }
106
107 protected function form() {
108 global $wgOut, $wgScript;
109
110 // Consume values
111 $page1 = $this->opts->consumeValue( 'page1' );
112 $page2 = $this->opts->consumeValue( 'page2' );
113 $rev1 = $this->opts->consumeValue( 'rev1' );
114 $rev2 = $this->opts->consumeValue( 'rev2' );
115
116 // Store query values in hidden fields so that form submission doesn't lose them
117 $hidden = array();
118 foreach ( $this->opts->getUnconsumedValues() as $key => $value ) {
119 $hidden[] = Xml::hidden( $key, $value );
120 }
121 $hidden = implode( "\n", $hidden );
122
123 $form = Xml::openElement( 'form', array( 'action' => $wgScript ) ) .
124 Xml::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
125 Xml::fieldset( wfMsg( 'compare-selector') ) .
126 Xml::openElement( 'table', array( 'id' => 'mw-diff-table', 'width' => '100%' ) ) .
127 "<tr>
128 <td class='mw-label' width='10%'>" .
129 Xml::label( wfMsg( 'compare-page1' ), 'page1' ) .
130 "</td>
131 <td class='mw-input' width='40%'>" .
132 Xml::input( 'page1', 40, $page1, array( 'type' => 'text' ) ) .
133 "</td>
134 <td class='mw-label' width='10%'>" .
135 Xml::label( wfMsg( 'compare-page2' ), 'page2' ) .
136 "</td>
137 <td class='mw-input' width='40%'>" .
138 Xml::input( 'page2', 40, $page2, array( 'type' => 'text' ) ) .
139 "</td>
140 </tr>" .
141 "<tr>
142 <td class='mw-label'>" .
143 Xml::label( wfMsg( 'compare-rev1' ), 'rev1' ) .
144 "</td>
145 <td class='mw-input'>" .
146 Xml::input( 'rev1', 8, $rev1, array( 'type' => 'text' ) ) .
147 "</td>
148 <td class='mw-label'>" .
149 Xml::label( wfMsg( 'compare-rev2' ), 'rev2' ) .
150 "</td>
151 <td class='mw-input'>" .
152 Xml::input( 'rev2', 8, $rev2, array( 'type' => 'text' ) ) .
153 "</td>
154 </tr>" .
155 "<tr> <td></td>
156 <td class='mw-submit' colspan='3'>" .
157 Xml::submitButton( wfMsg( 'compare-submit') ) .
158 "</td>
159 </tr>" .
160 Xml::closeElement( 'table' ) .
161 Xml::closeElement( 'fieldset' ) .
162 $hidden .
163 Xml::closeElement( 'form' );
164
165 $wgOut->addHTML( $form );
166 }
167 }