MediaWiki master
SpecialDiff.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
12
28 public function __construct() {
29 parent::__construct( 'Diff' );
30 $this->mAllowedRedirectParams = [ // T419253
31 'action',
32 'bot',
33 'diffonly',
34 'unhide'
35 ];
36 }
37
42 public function getRedirect( $subpage ) {
43 $parts = $subpage !== null ? explode( '/', $subpage ) : [];
44
45 // Try to parse the values given, generating somewhat pretty URLs if possible
46 if ( count( $parts ) === 1 && $parts[0] !== '' ) {
47 $this->mAddedRedirectParams['diff'] = $parts[0];
48 } elseif ( count( $parts ) === 2 ) {
49 $this->mAddedRedirectParams['oldid'] = $parts[0];
50 $this->mAddedRedirectParams['diff'] = $parts[1];
51 } else {
52 return false;
53 }
54
55 return true;
56 }
57
58 protected function showNoRedirectPage() {
59 $this->addHelpLink( 'Help:Diff' );
60 $this->setHeaders();
61 $this->outputHeader();
62 $this->showForm();
63 }
64
65 private function showForm() {
66 $form = HTMLForm::factory( 'ooui', [
67 'oldid' => [
68 'name' => 'oldid',
69 'type' => 'int',
70 'label-message' => 'diff-form-oldid',
71 ],
72 'diff' => [
73 'name' => 'diff',
74 // FIXME Set the type for the other field to int - T256425
75 'type' => 'selectorother',
76 'options-messages' => [
77 'diff-form-other-revid' => 'other',
78 'last' => 'prev',
79 'cur' => 'cur',
80 'next' => 'next',
81 ],
82 'label-message' => 'diff-form-revid',
83 // Remove validation callback when using int type - T256425
84 'validation-callback' => function ( $value ) {
85 $value = trim( $value ?? '' );
86 if ( preg_match( '/^\d*$/', $value )
87 || in_array( $value, [ 'prev', 'cur', 'next' ], true )
88 ) {
89 return true;
90 }
91 return $this->msg( 'diff-form-error-revid' );
92 },
93 ],
94 ], $this->getContext(), 'diff-form' );
95 $form->setSubmitTextMsg( 'diff-form-submit' );
96 $form->setSubmitCallback( $this->onFormSubmit( ... ) );
97 $form->show();
98 }
99
103 private function onFormSubmit( $formData ) {
104 $params = [];
105 if ( $formData['oldid'] ) {
106 $params[] = $formData['oldid'];
107 }
108 if ( $formData['diff'] ) {
109 // Remove trim when using int type - T256425
110 $params[] = trim( $formData['diff'] );
111 }
112 $title = $this->getPageTitle( $params ? implode( '/', $params ) : null );
113 $url = $title->getFullUrlForRedirect();
114 $this->getOutput()->redirect( $url );
115 }
116
118 public function getDescription() {
119 // 'diff' message is in lowercase, using own message
120 return $this->msg( 'diff-form' );
121 }
122
124 public function getName() {
125 return 'diff-form';
126 }
127
129 public function isListed() {
130 return true;
131 }
132
134 protected function getGroupName() {
135 return 'redirects';
136 }
137}
138
139// @codeCoverageIgnoreStart
141class_alias( SpecialDiff::class, 'SpecialDiff' );
142// @codeCoverageIgnoreEnd
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:214
Shortcut to construct a special page alias.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getPageTitle( $subpage=false)
Get a self-referential title object.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Redirect from Special:Diff/### to index.php?diff=### and from Special:Diff/###/### to index....
getDescription()
Returns the name that goes in the <h1> in the special page itself, and also the name that will be l...
isListed()
Whether this special page is listed in Special:SpecialPages.to override 1.3 (r3583) bool
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getName()
Get the canonical, unlocalized name of this special page without namespace.string
Represents a title within MediaWiki.
Definition Title.php:69
array $params
The job parameters.