MediaWiki  1.32.5
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 
49  public function execute( $par ) {
50  $this->setHeaders();
51  $this->outputHeader();
52  $this->getOutput()->addModuleStyles( 'mediawiki.special' );
53 
54  $form = HTMLForm::factory( 'ooui', [
55  'Page1' => [
56  'type' => 'title',
57  'name' => 'page1',
58  'label-message' => 'compare-page1',
59  'size' => '40',
60  'section' => 'page1',
61  'validation-callback' => [ $this, 'checkExistingTitle' ],
62  'required' => false,
63  ],
64  'Revision1' => [
65  'type' => 'int',
66  'name' => 'rev1',
67  'label-message' => 'compare-rev1',
68  'size' => '8',
69  'section' => 'page1',
70  'validation-callback' => [ $this, 'checkExistingRevision' ],
71  ],
72  'Page2' => [
73  'type' => 'title',
74  'name' => 'page2',
75  'label-message' => 'compare-page2',
76  'size' => '40',
77  'section' => 'page2',
78  'validation-callback' => [ $this, 'checkExistingTitle' ],
79  'required' => false,
80  ],
81  'Revision2' => [
82  'type' => 'int',
83  'name' => 'rev2',
84  'label-message' => 'compare-rev2',
85  'size' => '8',
86  'section' => 'page2',
87  'validation-callback' => [ $this, 'checkExistingRevision' ],
88  ],
89  'Action' => [
90  'type' => 'hidden',
91  'name' => 'action',
92  ],
93  'Diffonly' => [
94  'type' => 'hidden',
95  'name' => 'diffonly',
96  ],
97  'Unhide' => [
98  'type' => 'hidden',
99  'name' => 'unhide',
100  ],
101  ], $this->getContext(), 'compare' );
102  $form->setSubmitTextMsg( 'compare-submit' );
103  $form->suppressReset();
104  $form->setMethod( 'get' );
105  $form->setSubmitCallback( [ __CLASS__, 'showDiff' ] );
106 
107  $form->loadData();
108  $form->displayForm( '' );
109  $form->trySubmit();
110  }
111 
112  public static function showDiff( $data, HTMLForm $form ) {
113  $rev1 = self::revOrTitle( $data['Revision1'], $data['Page1'] );
114  $rev2 = self::revOrTitle( $data['Revision2'], $data['Page2'] );
115 
116  if ( $rev1 && $rev2 ) {
117  $revision = Revision::newFromId( $rev1 );
118 
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' )
127  );
128  $de->showDiffPage( true );
129  }
130  }
131  }
132 
133  public static function revOrTitle( $revision, $title ) {
134  if ( $revision ) {
135  return $revision;
136  } elseif ( $title ) {
138  if ( $title instanceof Title ) {
139  return $title->getLatestRevID();
140  }
141  }
142 
143  return null;
144  }
145 
146  public function checkExistingTitle( $value, $alldata ) {
147  if ( $value === '' || $value === null ) {
148  return true;
149  }
151  if ( !$title instanceof Title ) {
152  return $this->msg( 'compare-invalid-title' )->parseAsBlock();
153  }
154  if ( !$title->exists() ) {
155  return $this->msg( 'compare-title-not-exists' )->parseAsBlock();
156  }
157 
158  return true;
159  }
160 
161  public function checkExistingRevision( $value, $alldata ) {
162  if ( $value === '' || $value === null ) {
163  return true;
164  }
165  $revision = Revision::newFromId( $value );
166  if ( $revision === null ) {
167  return $this->msg( 'compare-revision-not-exists' )->parseAsBlock();
168  }
169 
170  return true;
171  }
172 
173  protected function getGroupName() {
174  return 'pagetools';
175  }
176 }
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:280
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:114
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:725
SpecialComparePages\checkExistingRevision
checkExistingRevision( $value, $alldata)
Definition: SpecialComparePages.php:161
SpecialComparePages\$opts
$opts
Definition: SpecialComparePages.php:34
SpecialComparePages\$skin
$skin
Definition: SpecialComparePages.php:34
SpecialComparePages\checkExistingTitle
checkExistingTitle( $value, $alldata)
Definition: SpecialComparePages.php:146
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
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
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:112
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:173
SpecialComparePages\$showNavigation
$showNavigation
Definition: SpecialComparePages.php:37
Title
Represents a title within MediaWiki.
Definition: Title.php:39
SpecialComparePages\execute
execute( $par)
Show a form for filtering namespace and username.
Definition: SpecialComparePages.php:49
SpecialComparePages\revOrTitle
static revOrTitle( $revision, $title)
Definition: SpecialComparePages.php:133
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:136