3 * Copyright (C) 2010 Derk-Jan Hartman <hartman@videolan.org>
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.
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.
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
22 * implements Special:ComparePages
23 * @ingroup SpecialPage
25 class SpecialComparePages
extends SpecialPage
{
28 protected $opts, $skin;
30 // Some internal settings
31 protected $showNavigation = false;
33 public function __construct() {
34 parent
::__construct( 'ComparePages' );
37 protected function setup( $par ) {
38 global $wgRequest, $wgUser;
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', '' );
51 $opts->fetchValuesFromRequest( $wgRequest );
53 $title1 = Title
::newFromText( $opts->getValue( 'page1' ) );
54 $title2 = Title
::newFromText( $opts->getValue( 'page2' ) );
56 if( $title1 && $title1->exists() && $opts->getValue( 'rev1' ) == '' ) {
57 $pda = new Article( $title1 );
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() );
65 if( $title2 && $title2->exists() && $opts->getValue( 'rev2' ) == '' ) {
66 $pda = new Article( $title2 );
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() );
76 $this->skin
= $wgUser->getSkin();
80 * Show a form for filtering namespace and username
85 public function execute( $par ) {
87 $this->outputHeader();
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' ),
99 ($this->opts
->getValue( 'action') == "purge" ?
true : false ),
101 $de->showDiffPage( (bool)$this->opts
->getValue( 'diffonly' ) );
105 protected function form() {
106 global $wgOut, $wgScript;
109 $page1 = $this->opts
->consumeValue( 'page1' );
110 $page2 = $this->opts
->consumeValue( 'page2' );
111 $rev1 = $this->opts
->consumeValue( 'rev1' );
112 $rev2 = $this->opts
->consumeValue( 'rev2' );
114 // Store query values in hidden fields so that form submission doesn't lose them
116 foreach ( $this->opts
->getUnconsumedValues() as $key => $value ) {
117 $hidden[] = Xml
::hidden( $key, $value );
119 $hidden = implode( "\n", $hidden );
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%' ) ) .
126 <td class='mw-label' style='width:10%'>" .
127 Html
::element( 'label', array( 'for' => 'page1' ), wfMsg( 'compare-page1' ) ) .
129 <td class='mw-input' style='width:40%'>" .
130 Html
::input( 'page1', $page1, 'text', array( 'size' => 40, 'id' => 'page1' ) ) .
132 <td class='mw-label' style='width:10%'>" .
133 Html
::element( 'label', array( 'for' => 'page2' ), wfMsg( 'compare-page2' ) ) .
135 <td class='mw-input' style='width:40%'>" .
136 Html
::input( 'page2', $page2, 'text', array( 'size' => 40, 'id' => 'page2' ) ) .
140 <td class='mw-label'>" .
141 Html
::element( 'label', array( 'for' => 'rev1' ), wfMsg( 'compare-rev1' ) ) .
143 <td class='mw-input'>" .
144 Html
::input( 'rev1', $rev1, 'text', array( 'size' => 8, 'id' => 'rev1' ) ) .
146 <td class='mw-label'>" .
147 Html
::element( 'label', array( 'for' => 'rev2' ), wfMsg( 'compare-rev2' ) ) .
149 <td class='mw-input'>" .
150 Html
::input( 'rev2', $rev2, 'text', array( 'size' => 8, 'id' => 'rev2' ) ) .
154 <td class='mw-submit' colspan='3'>" .
155 Xml
::submitButton( wfMsg( 'compare-submit' ) ) .
158 Html
::closeElement( 'table' ) .
159 Html
::closeElement( 'fieldset' ) .
161 Html
::closeElement( 'form' );
163 $wgOut->addHTML( $form );