MediaWiki  master
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  // FIXME Set the type for the other field to int - T256425
82  'type' => 'selectorother',
83  'options-messages' => [
84  'diff-form-other-revid' => 'other',
85  'last' => 'prev',
86  'cur' => 'cur',
87  'next' => 'next',
88  ],
89  'label-message' => 'diff-form-revid',
90  // Remove validation callback when using int type - T256425
91  'validation-callback' => function ( $value ) {
92  $value = trim( $value );
93  if ( preg_match( '/^\d*$/', $value )
94  || in_array( $value, [ 'prev', 'cur', 'next' ], true )
95  ) {
96  return true;
97  }
98  return $this->msg( 'diff-form-error-revid' );
99  },
100  ],
101  ], $this->getContext(), 'diff-form' );
102  $form->setSubmitTextMsg( 'diff-form-submit' );
103  $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
104  $form->show();
105  }
106 
107  public function onFormSubmit( $formData ) {
108  $params = [];
109  if ( $formData['oldid'] ) {
110  $params[] = $formData['oldid'];
111  }
112  if ( $formData['diff'] ) {
113  // Remove trim when using int type - T256425
114  $params[] = trim( $formData['diff'] );
115  }
116  $title = $this->getPageTitle( $params ? implode( '/', $params ) : null );
117  $url = $title->getFullUrlForRedirect();
118  $this->getOutput()->redirect( $url );
119  }
120 
121  public function getDescription() {
122  // 'diff' message is in lowercase, using own message
123  return $this->msg( 'diff-form' )->text();
124  }
125 
126  public function getName() {
127  return 'diff-form';
128  }
129 
130  public function isListed() {
131  return true;
132  }
133 
134  protected function getGroupName() {
135  return 'redirects';
136  }
137 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:669
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:800
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:716
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
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:836
SpecialDiff\onFormSubmit
onFormSubmit( $formData)
Definition: SpecialDiff.php:107
$title
$title
Definition: testCompression.php:38
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:551
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:121
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:689
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:134
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:130
SpecialDiff\getName
getName()
Get the name of this Special Page.
Definition: SpecialDiff.php:126
SpecialDiff\__construct
__construct()
Definition: SpecialDiff.php:40
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:311
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:636