MediaWiki  1.33.0
SpecialComparePages.php
Go to the documentation of this file.
1 <?php
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 
48  public function execute( $par ) {
49  $this->setHeaders();
50  $this->outputHeader();
51  $this->getOutput()->addModuleStyles( 'mediawiki.special' );
52 
53  $form = HTMLForm::factory( 'ooui', [
54  'Page1' => [
55  'type' => 'title',
56  'name' => 'page1',
57  'label-message' => 'compare-page1',
58  'size' => '40',
59  'section' => 'page1',
60  'validation-callback' => [ $this, 'checkExistingTitle' ],
61  'required' => false,
62  ],
63  'Revision1' => [
64  'type' => 'int',
65  'name' => 'rev1',
66  'label-message' => 'compare-rev1',
67  'size' => '8',
68  'section' => 'page1',
69  'validation-callback' => [ $this, 'checkExistingRevision' ],
70  ],
71  'Page2' => [
72  'type' => 'title',
73  'name' => 'page2',
74  'label-message' => 'compare-page2',
75  'size' => '40',
76  'section' => 'page2',
77  'validation-callback' => [ $this, 'checkExistingTitle' ],
78  'required' => false,
79  ],
80  'Revision2' => [
81  'type' => 'int',
82  'name' => 'rev2',
83  'label-message' => 'compare-rev2',
84  'size' => '8',
85  'section' => 'page2',
86  'validation-callback' => [ $this, 'checkExistingRevision' ],
87  ],
88  'Action' => [
89  'type' => 'hidden',
90  'name' => 'action',
91  ],
92  'Diffonly' => [
93  'type' => 'hidden',
94  'name' => 'diffonly',
95  ],
96  'Unhide' => [
97  'type' => 'hidden',
98  'name' => 'unhide',
99  ],
100  ], $this->getContext(), 'compare' );
101  $form->setSubmitTextMsg( 'compare-submit' );
102  $form->suppressReset();
103  $form->setMethod( 'get' );
104  $form->setSubmitCallback( [ __CLASS__, 'showDiff' ] );
105 
106  $form->loadData();
107  $form->displayForm( '' );
108  $form->trySubmit();
109  }
110 
111  public static function showDiff( $data, HTMLForm $form ) {
112  $rev1 = self::revOrTitle( $data['Revision1'], $data['Page1'] );
113  $rev2 = self::revOrTitle( $data['Revision2'], $data['Page2'] );
114 
115  if ( $rev1 && $rev2 ) {
116  $revision = Revision::newFromId( $rev1 );
117 
118  if ( $revision ) { // NOTE: $rev1 was already checked, should exist.
119  $contentHandler = $revision->getContentHandler();
120  $de = $contentHandler->createDifferenceEngine( $form->getContext(),
121  $rev1,
122  $rev2,
123  null, // rcid
124  ( $data['Action'] == 'purge' ),
125  ( $data['Unhide'] == '1' )
126  );
127  $de->showDiffPage( true );
128  }
129  }
130  }
131 
132  public static function revOrTitle( $revision, $title ) {
133  if ( $revision ) {
134  return $revision;
135  } elseif ( $title ) {
137  if ( $title instanceof Title ) {
138  return $title->getLatestRevID();
139  }
140  }
141 
142  return null;
143  }
144 
145  public function checkExistingTitle( $value, $alldata ) {
146  if ( $value === '' || $value === null ) {
147  return true;
148  }
150  if ( !$title instanceof Title ) {
151  return $this->msg( 'compare-invalid-title' )->parseAsBlock();
152  }
153  if ( !$title->exists() ) {
154  return $this->msg( 'compare-title-not-exists' )->parseAsBlock();
155  }
156 
157  return true;
158  }
159 
160  public function checkExistingRevision( $value, $alldata ) {
161  if ( $value === '' || $value === null ) {
162  return true;
163  }
164  $revision = Revision::newFromId( $value );
165  if ( $revision === null ) {
166  return $this->msg( 'compare-revision-not-exists' )->parseAsBlock();
167  }
168 
169  return true;
170  }
171 
172  protected function getGroupName() {
173  return 'pagetools';
174  }
175 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:306
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:796
Revision\newFromId
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:118
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:725
SpecialComparePages\checkExistingRevision
checkExistingRevision( $value, $alldata)
Definition: SpecialComparePages.php:160
SpecialComparePages\$opts
$opts
Definition: SpecialComparePages.php:34
SpecialComparePages\$skin
$skin
Definition: SpecialComparePages.php:34
SpecialComparePages\checkExistingTitle
checkExistingTitle( $value, $alldata)
Definition: SpecialComparePages.php:145
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$data
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Definition: generatePhpCharToUpperMappings.php:13
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:286
SpecialComparePages
Implements Special:ComparePages.
Definition: SpecialComparePages.php:31
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:531
SpecialComparePages\showDiff
static showDiff( $data, HTMLForm $form)
Definition: SpecialComparePages.php:111
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:698
SpecialComparePages\__construct
__construct()
Definition: SpecialComparePages.php:39
$value
$value
Definition: styleTest.css.php:49
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:36
SpecialComparePages\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialComparePages.php:172
SpecialComparePages\$showNavigation
$showNavigation
Definition: SpecialComparePages.php:37
Title
Represents a title within MediaWiki.
Definition: Title.php:40
SpecialComparePages\execute
execute( $par)
Show a form for filtering namespace and username.
Definition: SpecialComparePages.php:48
SpecialComparePages\revOrTitle
static revOrTitle( $revision, $title)
Definition: SpecialComparePages.php:132
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:633
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:133