MediaWiki  1.33.0
SpecialDiff.php
Go to the documentation of this file.
1 <?php
40  public function __construct() {
41  parent::__construct( 'Diff' );
42  $this->mAllowedRedirectParams = [];
43  }
44 
49  public function getRedirect( $subpage ) {
50  $parts = explode( '/', $subpage );
51 
52  // Try to parse the values given, generating somewhat pretty URLs if possible
53  if ( count( $parts ) === 1 && $parts[0] !== '' ) {
54  $this->mAddedRedirectParams['diff'] = $parts[0];
55  } elseif ( count( $parts ) === 2 ) {
56  $this->mAddedRedirectParams['oldid'] = $parts[0];
57  $this->mAddedRedirectParams['diff'] = $parts[1];
58  } else {
59  return false;
60  }
61 
62  return true;
63  }
64 
65  protected function showNoRedirectPage() {
66  $this->addHelpLink( 'Help:Diff' );
67  $this->setHeaders();
68  $this->outputHeader();
69  $this->showForm();
70  }
71 
72  private function showForm() {
73  $form = HTMLForm::factory( 'ooui', [
74  'oldid' => [
75  'name' => 'oldid',
76  'type' => 'int',
77  'label-message' => 'diff-form-oldid',
78  ],
79  'diff' => [
80  'name' => 'diff',
81  'class' => HTMLTextField::class,
82  'label-message' => 'diff-form-revid',
83  ],
84  ], $this->getContext(), 'diff-form' );
85  $form->setSubmitTextMsg( 'diff-form-submit' );
86  $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
87  $form->show();
88  }
89 
90  public function onFormSubmit( $formData ) {
91  $params = [];
92  if ( $formData['oldid'] ) {
93  $params[] = $formData['oldid'];
94  }
95  if ( $formData['diff'] ) {
96  $params[] = $formData['diff'];
97  }
98  $title = $this->getPageTitle( $params ? implode( '/', $params ) : null );
99  $url = $title->getFullUrlForRedirect();
100  $this->getOutput()->redirect( $url );
101  }
102 
103  public function getDescription() {
104  // 'diff' message is in lowercase, using own message
105  return $this->msg( 'diff-form' )->text();
106  }
107 
108  public function getName() {
109  return 'diff-form';
110  }
111 
112  public function isListed() {
113  return true;
114  }
115 
116  protected function getGroupName() {
117  return 'redirects';
118  }
119 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:678
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:796
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:725
captcha-old.count
count
Definition: captcha-old.py:249
$params
$params
Definition: styleTest.css.php:44
RedirectSpecialPage
Shortcut to construct a special page alias.
Definition: RedirectSpecialPage.php:29
SpecialDiff
Redirect from Special:Diff/### to index.php?diff=### and from Special:Diff/###/### to index....
Definition: SpecialDiff.php:39
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
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:832
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
SpecialDiff\onFormSubmit
onFormSubmit( $formData)
Definition: SpecialDiff.php:90
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:286
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:531
SpecialDiff\getDescription
getDescription()
Returns the name that goes in the <h1> in the special page itself, and also the name that will be l...
Definition: SpecialDiff.php:103
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:698
SpecialDiff\getRedirect
getRedirect( $subpage)
Definition: SpecialDiff.php:49
SpecialDiff\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialDiff.php:116
SpecialDiff\showNoRedirectPage
showNoRedirectPage()
Definition: SpecialDiff.php:65
SpecialDiff\showForm
showForm()
Definition: SpecialDiff.php:72
SpecialDiff\isListed
isListed()
Whether this special page is listed in Special:SpecialPages.
Definition: SpecialDiff.php:112
SpecialDiff\getName
getName()
Get the name of this Special Page.
Definition: SpecialDiff.php:108
SpecialDiff\__construct
__construct()
Definition: SpecialDiff.php:40
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
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