wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / specials / SpecialComparePages.php
blob50a48c3a9a89c1297d5c5bf4be19c2a825112bca
1 <?php
2 /**
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
22 * @file
23 * @ingroup SpecialPage
26 /**
27 * Implements Special:ComparePages
29 * @ingroup SpecialPage
31 class SpecialComparePages extends SpecialPage {
33 // Stored objects
34 protected $opts, $skin;
36 // Some internal settings
37 protected $showNavigation = false;
39 public function __construct() {
40 parent::__construct( 'ComparePages' );
43 /**
44 * Show a form for filtering namespace and username
46 * @param string $par
47 * @return string
49 public function execute( $par ) {
50 $this->setHeaders();
51 $this->outputHeader();
53 # Form (.mw-searchInput enables suggestions)
54 $form = HTMLForm::factory( 'ooui', array(
55 'Page1' => array(
56 'type' => 'title',
57 'name' => 'page1',
58 'label-message' => 'compare-page1',
59 'size' => '40',
60 'section' => 'page1',
61 'validation-callback' => array( $this, 'checkExistingTitle' ),
63 'Revision1' => array(
64 'type' => 'int',
65 'name' => 'rev1',
66 'label-message' => 'compare-rev1',
67 'size' => '8',
68 'section' => 'page1',
69 'validation-callback' => array( $this, 'checkExistingRevision' ),
71 'Page2' => array(
72 'type' => 'title',
73 'name' => 'page2',
74 'label-message' => 'compare-page2',
75 'size' => '40',
76 'section' => 'page2',
77 'validation-callback' => array( $this, 'checkExistingTitle' ),
79 'Revision2' => array(
80 'type' => 'int',
81 'name' => 'rev2',
82 'label-message' => 'compare-rev2',
83 'size' => '8',
84 'section' => 'page2',
85 'validation-callback' => array( $this, 'checkExistingRevision' ),
87 'Action' => array(
88 'type' => 'hidden',
89 'name' => 'action',
91 'Diffonly' => array(
92 'type' => 'hidden',
93 'name' => 'diffonly',
95 'Unhide' => array(
96 'type' => 'hidden',
97 'name' => 'unhide',
99 ), $this->getContext(), 'compare' );
100 $form->setSubmitTextMsg( 'compare-submit' );
101 $form->suppressReset();
102 $form->setMethod( 'get' );
103 $form->setSubmitCallback( array( __CLASS__, 'showDiff' ) );
105 $form->loadData();
106 $form->displayForm( '' );
107 $form->trySubmit();
110 public static function showDiff( $data, HTMLForm $form ) {
111 $rev1 = self::revOrTitle( $data['Revision1'], $data['Page1'] );
112 $rev2 = self::revOrTitle( $data['Revision2'], $data['Page2'] );
114 if ( $rev1 && $rev2 ) {
115 $revision = Revision::newFromId( $rev1 );
117 if ( $revision ) { // NOTE: $rev1 was already checked, should exist.
118 $contentHandler = $revision->getContentHandler();
119 $de = $contentHandler->createDifferenceEngine( $form->getContext(),
120 $rev1,
121 $rev2,
122 null, // rcid
123 ( $data['Action'] == 'purge' ),
124 ( $data['Unhide'] == '1' )
126 $de->showDiffPage( true );
131 public static function revOrTitle( $revision, $title ) {
132 if ( $revision ) {
133 return $revision;
134 } elseif ( $title ) {
135 $title = Title::newFromText( $title );
136 if ( $title instanceof Title ) {
137 return $title->getLatestRevID();
141 return null;
144 public function checkExistingTitle( $value, $alldata ) {
145 if ( $value === '' || $value === null ) {
146 return true;
148 $title = Title::newFromText( $value );
149 if ( !$title instanceof Title ) {
150 return $this->msg( 'compare-invalid-title' )->parseAsBlock();
152 if ( !$title->exists() ) {
153 return $this->msg( 'compare-title-not-exists' )->parseAsBlock();
156 return true;
159 public function checkExistingRevision( $value, $alldata ) {
160 if ( $value === '' || $value === null ) {
161 return true;
163 $revision = Revision::newFromId( $value );
164 if ( $revision === null ) {
165 return $this->msg( 'compare-revision-not-exists' )->parseAsBlock();
168 return true;
171 protected function getGroupName() {
172 return 'pagetools';