31 private $differenceEngine;
37 parent::__construct(
'ComparePages' );
38 $this->revisionLookup = $revisionLookup;
39 $this->contentHandlerFactory = $contentHandlerFactory;
50 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
53 $form = HTMLForm::factory(
'ooui', [
58 'label-message' =>
'compare-page1',
66 'label-message' =>
'compare-rev1',
69 'validation-callback' => $this->checkExistingRevision( ... ),
75 'label-message' =>
'compare-page2',
83 'label-message' =>
'compare-rev2',
86 'validation-callback' => $this->checkExistingRevision( ... ),
99 ->setSubmitTextMsg(
'compare-submit' )
100 ->setSubmitCallback( $this->showDiff( ... ) )
103 if ( $this->differenceEngine ) {
104 $this->differenceEngine->showDiffPage(
true );
112 private function showDiff( $data,
HTMLForm $form ) {
113 $rev1 = $this->revOrTitle( $data[
'Revision1'], $data[
'Page1'] );
114 $rev2 = $this->revOrTitle( $data[
'Revision2'], $data[
'Page2'] );
116 if ( $rev1 && $rev2 ) {
118 $revisionRecord = $this->revisionLookup->getRevisionById( $rev1 );
119 $contentModel = $revisionRecord->getSlot(
123 $contentHandler = $this->contentHandlerFactory->getContentHandler( $contentModel );
124 $this->differenceEngine = $contentHandler->createDifferenceEngine( $form->
getContext(),
128 ( $data[
'Action'] ==
'purge' ),
129 ( $data[
'Unhide'] ==
'1' )
134 private function revOrTitle( ?
string $revision, ?
string $title ): ?int {
136 return (
int)$revision;
137 } elseif ( $title ) {
138 return Title::newFromText( $title )->getLatestRevID();
149 private function checkExistingRevision( $value, $alldata ) {
150 if ( $value ===
'' || $value ===
null ) {
153 $revisionRecord = $this->revisionLookup->getRevisionById( (
int)$value );
154 if ( $revisionRecord ===
null ) {
155 return $this->
msg(
'compare-revision-not-exists' )->parseAsBlock();
168class_alias( SpecialComparePages::class,
'SpecialComparePages' );
if(!defined('MW_SETUP_CALLBACK'))
DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
getContext()
Get the base IContextSource object.
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getContext()
Gets the context this SpecialPage is executed in.
getOutput()
Get the OutputPage being used for this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Implements Special:ComparePages.
execute( $par)
Show a form for filtering namespace and username.
__construct(RevisionLookup $revisionLookup, IContentHandlerFactory $contentHandlerFactory)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...