Follow-up r83794, r83792: restore new SpecialBlock.php code from r83786. This revisi...
[lhc/web/wiklou.git] / includes / specials / SpecialComparePages.php
1 <?php
2 /**
3 * Implements Special:ComparePages
4 *
5 * Copyright © 2010 Derk-Jan Hartman <hartman@videolan.org>
6 *
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.
11 *
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.
16 *
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
21 *
22 * @file
23 * @ingroup SpecialPage
24 */
25
26 /**
27 * Implements Special:ComparePages
28 *
29 * @ingroup SpecialPage
30 */
31 class SpecialComparePages extends SpecialPage {
32
33 // Stored objects
34 protected $opts, $skin;
35
36 // Some internal settings
37 protected $showNavigation = false;
38
39 public function __construct() {
40 parent::__construct( 'ComparePages' );
41 }
42
43 /**
44 * Show a form for filtering namespace and username
45 *
46 * @param $par String
47 * @return String
48 */
49 public function execute( $par ) {
50 $this->setHeaders();
51 $this->outputHeader();
52
53 $form = new HTMLForm( array(
54 'Page1' => array(
55 'type' => 'text',
56 'name' => 'page1',
57 'label-message' => 'compare-page1',
58 'size' => '40',
59 'section' => 'page1',
60 ),
61 'Revision1' => array(
62 'type' => 'int',
63 'name' => 'rev1',
64 'label-message' => 'compare-rev1',
65 'size' => '8',
66 'section' => 'page1',
67 ),
68 'Page2' => array(
69 'type' => 'text',
70 'name' => 'page2',
71 'label-message' => 'compare-page2',
72 'size' => '40',
73 'section' => 'page2',
74 ),
75 'Revision2' => array(
76 'type' => 'int',
77 'name' => 'rev2',
78 'label-message' => 'compare-rev2',
79 'size' => '8',
80 'section' => 'page2',
81 ),
82 'Action' => array(
83 'type' => 'hidden',
84 'name' => 'action',
85 ),
86 'Diffonly' => array(
87 'type' => 'hidden',
88 'name' => 'diffonly',
89 ),
90 ), 'compare' );
91 $form->setSubmitText( wfMsg( 'compare-submit' ) );
92 $form->suppressReset();
93 $form->setMethod( 'get' );
94 $form->setTitle( $this->getTitle() );
95
96 $form->loadData();
97 $form->displayForm( '' );
98
99 self::showDiff( $form->mFieldData );
100 }
101
102 public static function showDiff( $data ){
103
104 if( $data['Revision1'] ){
105 $rev1 = $data['Revision1'];
106 } elseif( $data['Page1'] ) {
107 $title = Title::newFromText( $data['Page1'] );
108 if( $title instanceof Title ){
109 $rev1 = $title->getLatestRevID();
110 }
111 } else {
112 $rev1 = null;
113 }
114
115 if( $data['Revision2'] ){
116 $rev2 = $data['Revision2'];
117 } elseif( $data['Page2'] ) {
118 $title = Title::newFromText( $data['Page2'] );
119 if( $title instanceof Title ){
120 $rev2 = $title->getLatestRevID();
121 }
122 } else {
123 $rev2 = null;
124 }
125
126 if( $rev1 && $rev2 ) {
127 $de = new DifferenceEngine( null,
128 $rev1,
129 $rev2,
130 null, // rcid
131 ( $data["Action"] == 'purge' ),
132 false );
133 $de->showDiffPage( true );
134 }
135 }
136 }