Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 55 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
SpecialDiff | |
0.00% |
0 / 54 |
|
0.00% |
0 / 9 |
342 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getRedirect | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
30 | |||
showNoRedirectPage | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
showForm | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
12 | |||
onFormSubmit | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isListed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Specials; |
22 | |
23 | use MediaWiki\HTMLForm\HTMLForm; |
24 | use MediaWiki\SpecialPage\RedirectSpecialPage; |
25 | use MediaWiki\Title\Title; |
26 | |
27 | /** |
28 | * Redirect from Special:Diff/### to index.php?diff=### and |
29 | * from Special:Diff/###/### to index.php?oldid=###&diff=###. |
30 | * |
31 | * All of the following are valid usages: |
32 | * - [[Special:Diff/12345]] (diff of a revision with the previous one) |
33 | * - [[Special:Diff/12345/prev]] (diff of a revision with the previous one as well) |
34 | * - [[Special:Diff/12345/next]] (diff of a revision with the next one) |
35 | * - [[Special:Diff/12345/cur]] (diff of a revision with the latest one of that page) |
36 | * - [[Special:Diff/12345/98765]] (diff between arbitrary two revisions) |
37 | * |
38 | * @ingroup SpecialPage |
39 | * @since 1.23 |
40 | */ |
41 | class SpecialDiff extends RedirectSpecialPage { |
42 | public function __construct() { |
43 | parent::__construct( 'Diff' ); |
44 | $this->mAllowedRedirectParams = []; |
45 | } |
46 | |
47 | /** |
48 | * @param string|null $subpage |
49 | * @return Title|bool |
50 | */ |
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 | |
141 | /** @deprecated class alias since 1.41 */ |
142 | class_alias( SpecialDiff::class, 'SpecialDiff' ); |