3 * Implements Special:ComparePages
5 * Copyright © 2010 Derk-Jan Hartman <hartman@videolan.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
23 * @ingroup SpecialPage
27 * Implements Special:ComparePages
29 * @ingroup SpecialPage
31 class SpecialComparePages
extends SpecialPage
{
34 protected $opts, $skin;
36 // Some internal settings
37 protected $showNavigation = false;
39 public function __construct() {
40 parent
::__construct( 'ComparePages' );
44 * Show a form for filtering namespace and username
49 public function execute( $par ) {
51 $this->outputHeader();
53 $form = new HTMLForm( array(
57 'label-message' => 'compare-page1',
60 'validation-callback' => array( $this, 'checkExistingTitle' ),
65 'label-message' => 'compare-rev1',
68 'validation-callback' => array( $this, 'checkExistingRevision' ),
73 'label-message' => 'compare-page2',
76 'validation-callback' => array( $this, 'checkExistingTitle' ),
81 'label-message' => 'compare-rev2',
84 'validation-callback' => array( $this, 'checkExistingRevision' ),
94 ), $this->getContext(), 'compare' );
95 $form->setSubmitText( wfMsg( 'compare-submit' ) );
96 $form->suppressReset();
97 $form->setMethod( 'get' );
98 $form->setSubmitCallback( array( __CLASS__
, 'showDiff' ) );
101 $form->displayForm( '' );
105 public static function showDiff( $data ){
106 $rev1 = self
::revOrTitle( $data['Revision1'], $data['Page1'] );
107 $rev2 = self
::revOrTitle( $data['Revision2'], $data['Page2'] );
109 if( $rev1 && $rev2 ) {
110 $de = new DifferenceEngine( null,
114 ( $data["Action"] == 'purge' ),
116 $de->showDiffPage( true );
120 public static function revOrTitle( $revision, $title ) {
124 $title = Title
::newFromText( $title );
125 if( $title instanceof Title
){
126 return $title->getLatestRevID();
132 public function checkExistingTitle( $value, $alldata ) {
133 if ( $value === '' ||
$value === null ) {
136 $title = Title
::newFromText( $value );
137 if ( !$title instanceof Title
) {
138 return wfMsgExt( 'compare-invalid-title', 'parse' );
140 if ( !$title->exists() ) {
141 return wfMsgExt( 'compare-title-not-exists', 'parse' );
146 public function checkExistingRevision( $value, $alldata ) {
147 if ( $value === '' ||
$value === null ) {
150 $revision = Revision
::newFromId( $value );
151 if ( $revision === null ) {
152 return wfMsgExt( 'compare-revision-not-exists', 'parse' );