Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / includes / specials / SpecialComparePages.php
blob0f8b7291b1e77a071abc593946957d367abe4ec2
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 = new HTMLForm( array(
55 'Page1' => array(
56 'type' => 'text',
57 'name' => 'page1',
58 'cssclass' => 'mw-searchInput',
59 'label-message' => 'compare-page1',
60 'size' => '40',
61 'section' => 'page1',
62 'validation-callback' => array( $this, 'checkExistingTitle' ),
64 'Revision1' => array(
65 'type' => 'int',
66 'name' => 'rev1',
67 'label-message' => 'compare-rev1',
68 'size' => '8',
69 'section' => 'page1',
70 'validation-callback' => array( $this, 'checkExistingRevision' ),
72 'Page2' => array(
73 'type' => 'text',
74 'name' => 'page2',
75 'cssclass' => 'mw-searchInput',
76 'label-message' => 'compare-page2',
77 'size' => '40',
78 'section' => 'page2',
79 'validation-callback' => array( $this, 'checkExistingTitle' ),
81 'Revision2' => array(
82 'type' => 'int',
83 'name' => 'rev2',
84 'label-message' => 'compare-rev2',
85 'size' => '8',
86 'section' => 'page2',
87 'validation-callback' => array( $this, 'checkExistingRevision' ),
89 'Action' => array(
90 'type' => 'hidden',
91 'name' => 'action',
93 'Diffonly' => array(
94 'type' => 'hidden',
95 'name' => 'diffonly',
97 'Unhide' => array(
98 'type' => 'hidden',
99 'name' => 'unhide',
101 ), $this->getContext(), 'compare' );
102 $form->setSubmitTextMsg( 'compare-submit' );
103 $form->suppressReset();
104 $form->setMethod( 'get' );
105 $form->setSubmitCallback( array( __CLASS__, 'showDiff' ) );
107 $form->loadData();
108 $form->displayForm( '' );
109 $form->trySubmit();
112 public static function showDiff( $data, HTMLForm $form ) {
113 $rev1 = self::revOrTitle( $data['Revision1'], $data['Page1'] );
114 $rev2 = self::revOrTitle( $data['Revision2'], $data['Page2'] );
116 if ( $rev1 && $rev2 ) {
117 $revision = Revision::newFromId( $rev1 );
119 if ( $revision ) { // NOTE: $rev1 was already checked, should exist.
120 $contentHandler = $revision->getContentHandler();
121 $de = $contentHandler->createDifferenceEngine( $form->getContext(),
122 $rev1,
123 $rev2,
124 null, // rcid
125 ( $data['Action'] == 'purge' ),
126 ( $data['Unhide'] == '1' )
128 $de->showDiffPage( true );
133 public static function revOrTitle( $revision, $title ) {
134 if ( $revision ) {
135 return $revision;
136 } elseif ( $title ) {
137 $title = Title::newFromText( $title );
138 if ( $title instanceof Title ) {
139 return $title->getLatestRevID();
143 return null;
146 public function checkExistingTitle( $value, $alldata ) {
147 if ( $value === '' || $value === null ) {
148 return true;
150 $title = Title::newFromText( $value );
151 if ( !$title instanceof Title ) {
152 return $this->msg( 'compare-invalid-title' )->parseAsBlock();
154 if ( !$title->exists() ) {
155 return $this->msg( 'compare-title-not-exists' )->parseAsBlock();
158 return true;
161 public function checkExistingRevision( $value, $alldata ) {
162 if ( $value === '' || $value === null ) {
163 return true;
165 $revision = Revision::newFromId( $value );
166 if ( $revision === null ) {
167 return $this->msg( 'compare-revision-not-exists' )->parseAsBlock();
170 return true;
173 protected function getGroupName() {
174 return 'pagetools';