MediaWiki REL1_35
SpecialComparePages.php
Go to the documentation of this file.
1<?php
29
36
37 // Stored objects
38 protected $opts, $skin;
39
40 // Some internal settings
41 protected $showNavigation = false;
42
43 public function __construct() {
44 parent::__construct( 'ComparePages' );
45 }
46
52 public function execute( $par ) {
53 $this->setHeaders();
54 $this->outputHeader();
55 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
56 $this->addHelpLink( 'Help:Diff' );
57
58 $form = HTMLForm::factory( 'ooui', [
59 'Page1' => [
60 'type' => 'title',
61 'name' => 'page1',
62 'label-message' => 'compare-page1',
63 'size' => '40',
64 'section' => 'page1',
65 'validation-callback' => [ $this, 'checkExistingTitle' ],
66 'required' => false,
67 ],
68 'Revision1' => [
69 'type' => 'int',
70 'name' => 'rev1',
71 'label-message' => 'compare-rev1',
72 'size' => '8',
73 'section' => 'page1',
74 'validation-callback' => [ $this, 'checkExistingRevision' ],
75 ],
76 'Page2' => [
77 'type' => 'title',
78 'name' => 'page2',
79 'label-message' => 'compare-page2',
80 'size' => '40',
81 'section' => 'page2',
82 'validation-callback' => [ $this, 'checkExistingTitle' ],
83 'required' => false,
84 ],
85 'Revision2' => [
86 'type' => 'int',
87 'name' => 'rev2',
88 'label-message' => 'compare-rev2',
89 'size' => '8',
90 'section' => 'page2',
91 'validation-callback' => [ $this, 'checkExistingRevision' ],
92 ],
93 'Action' => [
94 'type' => 'hidden',
95 'name' => 'action',
96 ],
97 'Diffonly' => [
98 'type' => 'hidden',
99 'name' => 'diffonly',
100 ],
101 'Unhide' => [
102 'type' => 'hidden',
103 'name' => 'unhide',
104 ],
105 ], $this->getContext(), 'compare' );
106 $form->setSubmitTextMsg( 'compare-submit' );
107 $form->suppressReset();
108 $form->setMethod( 'get' );
109 $form->setSubmitCallback( [ __CLASS__, 'showDiff' ] );
110
111 $form->loadData();
112 $form->displayForm( '' );
113 $form->trySubmit();
114 }
115
116 public static function showDiff( $data, HTMLForm $form ) {
117 $rev1 = self::revOrTitle( $data['Revision1'], $data['Page1'] );
118 $rev2 = self::revOrTitle( $data['Revision2'], $data['Page2'] );
119
120 if ( $rev1 && $rev2 ) {
121 $revisionRecord = MediaWikiServices::getInstance()
122 ->getRevisionLookup()
123 ->getRevisionById( $rev1 );
124
125 if ( $revisionRecord ) { // NOTE: $rev1 was already checked, should exist.
126 $contentModel = $revisionRecord->getSlot(
127 SlotRecord::MAIN,
128 RevisionRecord::RAW
129 )->getModel();
130 $contentHandler = MediaWikiServices::getInstance()
131 ->getContentHandlerFactory()
132 ->getContentHandler( $contentModel );
133 $de = $contentHandler->createDifferenceEngine( $form->getContext(),
134 $rev1,
135 $rev2,
136 null, // rcid
137 ( $data['Action'] == 'purge' ),
138 ( $data['Unhide'] == '1' )
139 );
140 $de->showDiffPage( true );
141 }
142 }
143 }
144
145 public static function revOrTitle( $revision, $title ) {
146 if ( $revision ) {
147 return $revision;
148 } elseif ( $title ) {
149 $title = Title::newFromText( $title );
150 if ( $title instanceof Title ) {
151 return $title->getLatestRevID();
152 }
153 }
154
155 return null;
156 }
157
158 public function checkExistingTitle( $value, $alldata ) {
159 if ( $value === '' || $value === null ) {
160 return true;
161 }
162 $title = Title::newFromText( $value );
163 if ( !$title instanceof Title ) {
164 return $this->msg( 'compare-invalid-title' )->parseAsBlock();
165 }
166 if ( !$title->exists() ) {
167 return $this->msg( 'compare-title-not-exists' )->parseAsBlock();
168 }
169
170 return true;
171 }
172
173 public function checkExistingRevision( $value, $alldata ) {
174 if ( $value === '' || $value === null ) {
175 return true;
176 }
177 $revisionRecord = MediaWikiServices::getInstance()
178 ->getRevisionLookup()
179 ->getRevisionById( $value );
180 if ( $revisionRecord === null ) {
181 return $this->msg( 'compare-revision-not-exists' )->parseAsBlock();
182 }
183
184 return true;
185 }
186
187 protected function getGroupName() {
188 return 'pagetools';
189 }
190}
getContext()
Get the base IContextSource object.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:135
MediaWikiServices is the service locator for the application scope of MediaWiki.
Page revision base class.
Value object representing a content slot associated with a page revision.
Implements Special:ComparePages.
static revOrTitle( $revision, $title)
checkExistingTitle( $value, $alldata)
static showDiff( $data, HTMLForm $form)
execute( $par)
Show a form for filtering namespace and username.
checkExistingRevision( $value, $alldata)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!...
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Represents a title within MediaWiki.
Definition Title.php:42