Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
91.18% |
31 / 34 |
|
80.00% |
8 / 10 |
CRAP | |
0.00% |
0 / 1 |
SpecialTalkPage | |
91.18% |
31 / 34 |
|
80.00% |
8 / 10 |
13.12 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getFormFields | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
alterForm | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
onSubmit | |
85.71% |
12 / 14 |
|
0.00% |
0 / 1 |
3.03 | |||
getDisplayFormat | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
requiresWrite | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
requiresUnblock | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isListed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMessagePrefix | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDescription | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
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\Redirects; |
22 | |
23 | use MediaWiki\Config\Config; |
24 | use MediaWiki\HTMLForm\HTMLForm; |
25 | use MediaWiki\MainConfigNames; |
26 | use MediaWiki\SpecialPage\FormSpecialPage; |
27 | use MediaWiki\Status\Status; |
28 | use MediaWiki\Title\MalformedTitleException; |
29 | use MediaWiki\Title\Title; |
30 | use MediaWiki\Title\TitleParser; |
31 | |
32 | /** |
33 | * Redirect to the talk page of a given page. |
34 | * |
35 | * @ingroup SpecialPage |
36 | */ |
37 | class SpecialTalkPage extends FormSpecialPage { |
38 | |
39 | private Config $config; |
40 | private TitleParser $titleParser; |
41 | |
42 | public function __construct( Config $config, TitleParser $titleParser ) { |
43 | parent::__construct( 'TalkPage' ); |
44 | $this->config = $config; |
45 | $this->titleParser = $titleParser; |
46 | } |
47 | |
48 | protected function getFormFields() { |
49 | return [ |
50 | 'target' => [ |
51 | 'type' => 'title', |
52 | 'name' => 'target', |
53 | 'label-message' => 'special-talkpage-target', |
54 | 'default' => $this->par, |
55 | ], |
56 | ]; |
57 | } |
58 | |
59 | protected function alterForm( HTMLForm $form ) { |
60 | if ( $this->par ) { // immediately submit with subpage value |
61 | $form->setMethod( 'get' ); |
62 | } |
63 | $form->setSubmitTextMsg( 'special-talkpage-submit' ); |
64 | } |
65 | |
66 | public function onSubmit( array $formData ) { |
67 | $target = $formData['target']; |
68 | try { |
69 | $title = $this->titleParser->parseTitle( $target ); |
70 | } catch ( MalformedTitleException $e ) { |
71 | return Status::newFatal( $e->getMessageObject() ); |
72 | } |
73 | $title = Title::newFromLinkTarget( $title ); |
74 | $talk = $title->getTalkPageIfDefined(); |
75 | if ( $talk === null ) { |
76 | return Status::newFatal( 'title-invalid-talk-namespace' ); |
77 | } |
78 | |
79 | // HTTP 302: Found; cache for the Parser Cache length, as an appropriate long time |
80 | $this->getOutput()->redirect( $talk->getFullUrlForRedirect(), '302' ); |
81 | $this->getOutput()->enableClientCache(); |
82 | $this->getOutput()->setCdnMaxage( |
83 | $this->config->get( MainConfigNames::ParserCacheExpireTime ) |
84 | ); |
85 | return true; |
86 | } |
87 | |
88 | protected function getDisplayFormat() { |
89 | return 'ooui'; |
90 | } |
91 | |
92 | public function requiresWrite() { |
93 | return false; |
94 | } |
95 | |
96 | public function requiresUnblock() { |
97 | return false; |
98 | } |
99 | |
100 | public function isListed() { |
101 | return false; |
102 | } |
103 | |
104 | protected function getMessagePrefix() { |
105 | return 'special-talkpage'; |
106 | } |
107 | |
108 | public function getDescription() { |
109 | // "talkpage" is already taken by CologneBlue |
110 | return $this->msg( 'special-talkpage' ); |
111 | } |
112 | |
113 | } |