MediaWiki master
SpecialDiff.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
26
42 public function __construct() {
43 parent::__construct( 'Diff' );
44 $this->mAllowedRedirectParams = [];
45 }
46
51 public function getRedirect( $subpage ) {
52 $parts = $subpage !== null ? explode( '/', $subpage ) : [];
53
54 // Try to parse the values given, generating somewhat pretty URLs if possible
55 if ( count( $parts ) === 1 && $parts[0] !== '' ) {
56 $this->mAddedRedirectParams['diff'] = $parts[0];
57 } elseif ( count( $parts ) === 2 ) {
58 $this->mAddedRedirectParams['oldid'] = $parts[0];
59 $this->mAddedRedirectParams['diff'] = $parts[1];
60 } else {
61 return false;
62 }
63
64 return true;
65 }
66
67 protected function showNoRedirectPage() {
68 $this->addHelpLink( 'Help:Diff' );
69 $this->setHeaders();
70 $this->outputHeader();
71 $this->showForm();
72 }
73
74 private function showForm() {
75 $form = HTMLForm::factory( 'ooui', [
76 'oldid' => [
77 'name' => 'oldid',
78 'type' => 'int',
79 'label-message' => 'diff-form-oldid',
80 ],
81 'diff' => [
82 'name' => 'diff',
83 // FIXME Set the type for the other field to int - T256425
84 'type' => 'selectorother',
85 'options-messages' => [
86 'diff-form-other-revid' => 'other',
87 'last' => 'prev',
88 'cur' => 'cur',
89 'next' => 'next',
90 ],
91 'label-message' => 'diff-form-revid',
92 // Remove validation callback when using int type - T256425
93 'validation-callback' => function ( $value ) {
94 $value = trim( $value ?? '' );
95 if ( preg_match( '/^\d*$/', $value )
96 || in_array( $value, [ 'prev', 'cur', 'next' ], true )
97 ) {
98 return true;
99 }
100 return $this->msg( 'diff-form-error-revid' );
101 },
102 ],
103 ], $this->getContext(), 'diff-form' );
104 $form->setSubmitTextMsg( 'diff-form-submit' );
105 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
106 $form->show();
107 }
108
109 public function onFormSubmit( $formData ) {
110 $params = [];
111 if ( $formData['oldid'] ) {
112 $params[] = $formData['oldid'];
113 }
114 if ( $formData['diff'] ) {
115 // Remove trim when using int type - T256425
116 $params[] = trim( $formData['diff'] );
117 }
118 $title = $this->getPageTitle( $params ? implode( '/', $params ) : null );
119 $url = $title->getFullUrlForRedirect();
120 $this->getOutput()->redirect( $url );
121 }
122
123 public function getDescription() {
124 // 'diff' message is in lowercase, using own message
125 return $this->msg( 'diff-form' );
126 }
127
128 public function getName() {
129 return 'diff-form';
130 }
131
132 public function isListed() {
133 return true;
134 }
135
136 protected function getGroupName() {
137 return 'redirects';
138 }
139}
140
142class_alias( SpecialDiff::class, 'SpecialDiff' );
array $params
The job parameters.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:206
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.
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.
Represents a title within MediaWiki.
Definition Title.php:78