MediaWiki  1.23.6
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 
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  'validation-callback' => array( $this, 'checkExistingTitle' ),
61  ),
62  'Revision1' => array(
63  'type' => 'int',
64  'name' => 'rev1',
65  'label-message' => 'compare-rev1',
66  'size' => '8',
67  'section' => 'page1',
68  'validation-callback' => array( $this, 'checkExistingRevision' ),
69  ),
70  'Page2' => array(
71  'type' => 'text',
72  'name' => 'page2',
73  'label-message' => 'compare-page2',
74  'size' => '40',
75  'section' => 'page2',
76  'validation-callback' => array( $this, 'checkExistingTitle' ),
77  ),
78  'Revision2' => array(
79  'type' => 'int',
80  'name' => 'rev2',
81  'label-message' => 'compare-rev2',
82  'size' => '8',
83  'section' => 'page2',
84  'validation-callback' => array( $this, 'checkExistingRevision' ),
85  ),
86  'Action' => array(
87  'type' => 'hidden',
88  'name' => 'action',
89  ),
90  'Diffonly' => array(
91  'type' => 'hidden',
92  'name' => 'diffonly',
93  ),
94  'Unhide' => array(
95  'type' => 'hidden',
96  'name' => 'unhide',
97  ),
98  ), $this->getContext(), 'compare' );
99  $form->setSubmitTextMsg( 'compare-submit' );
100  $form->suppressReset();
101  $form->setMethod( 'get' );
102  $form->setSubmitCallback( array( __CLASS__, 'showDiff' ) );
103 
104  $form->loadData();
105  $form->displayForm( '' );
106  $form->trySubmit();
107  }
108 
109  public static function showDiff( $data, HTMLForm $form ) {
110  $rev1 = self::revOrTitle( $data['Revision1'], $data['Page1'] );
111  $rev2 = self::revOrTitle( $data['Revision2'], $data['Page2'] );
112 
113  if ( $rev1 && $rev2 ) {
114  $revision = Revision::newFromId( $rev1 );
115 
116  if ( $revision ) { // NOTE: $rev1 was already checked, should exist.
117  $contentHandler = $revision->getContentHandler();
118  $de = $contentHandler->createDifferenceEngine( $form->getContext(),
119  $rev1,
120  $rev2,
121  null, // rcid
122  ( $data['Action'] == 'purge' ),
123  ( $data['Unhide'] == '1' )
124  );
125  $de->showDiffPage( true );
126  }
127  }
128  }
129 
130  public static function revOrTitle( $revision, $title ) {
131  if ( $revision ) {
132  return $revision;
133  } elseif ( $title ) {
135  if ( $title instanceof Title ) {
136  return $title->getLatestRevID();
137  }
138  }
139 
140  return null;
141  }
142 
143  public function checkExistingTitle( $value, $alldata ) {
144  if ( $value === '' || $value === null ) {
145  return true;
146  }
148  if ( !$title instanceof Title ) {
149  return $this->msg( 'compare-invalid-title' )->parseAsBlock();
150  }
151  if ( !$title->exists() ) {
152  return $this->msg( 'compare-title-not-exists' )->parseAsBlock();
153  }
154 
155  return true;
156  }
157 
158  public function checkExistingRevision( $value, $alldata ) {
159  if ( $value === '' || $value === null ) {
160  return true;
161  }
162  $revision = Revision::newFromId( $value );
163  if ( $revision === null ) {
164  return $this->msg( 'compare-revision-not-exists' )->parseAsBlock();
165  }
166 
167  return true;
168  }
169 
170  protected function getGroupName() {
171  return 'pagetools';
172  }
173 }
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:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Revision\newFromId
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:88
$form
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead $form
Definition: hooks.txt:2573
SpecialComparePages\checkExistingRevision
checkExistingRevision( $value, $alldata)
Definition: SpecialComparePages.php:158
SpecialComparePages\$opts
$opts
Definition: SpecialComparePages.php:34
SpecialComparePages\$skin
$skin
Definition: SpecialComparePages.php:34
SpecialComparePages\checkExistingTitle
checkExistingTitle( $value, $alldata)
Definition: SpecialComparePages.php:143
SpecialComparePages
Implements Special:ComparePages.
Definition: SpecialComparePages.php:31
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:352
SpecialComparePages\showDiff
static showDiff( $data, HTMLForm $form)
Definition: SpecialComparePages.php:109
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:508
SpecialComparePages\__construct
__construct()
Definition: SpecialComparePages.php:39
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
$value
$value
Definition: styleTest.css.php:45
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:609
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:33
SpecialComparePages\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialComparePages.php:170
SpecialComparePages\$showNavigation
$showNavigation
Definition: SpecialComparePages.php:37
Title
Represents a title within MediaWiki.
Definition: Title.php:35
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:130
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:443
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:100