| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials\Redirects; |
| 22 |
|
| 23 |
use MediaWiki\HTMLForm\HTMLForm; |
| 24 |
use MediaWiki\MainConfigNames; |
| 25 |
use MediaWiki\SpecialPage\FormSpecialPage; |
| 26 |
use MediaWiki\Status\Status; |
| 27 |
use MediaWiki\Title\MalformedTitleException; |
| 28 |
use MediaWiki\Title\Title; |
| 29 |
use MediaWiki\Title\TitleParser; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class SpecialTalkPage extends FormSpecialPage { |
| 37 |
|
| 38 |
private TitleParser $titleParser; |
| 39 |
|
| 40 |
public function __construct( TitleParser $titleParser ) { |
| 41 |
parent::__construct( 'TalkPage' ); |
| 42 |
$this->titleParser = $titleParser; |
| 43 |
} |
| 44 |
|
| 45 |
protected function getFormFields() { |
| 46 |
return [ |
| 47 |
'target' => [ |
| 48 |
'type' => 'title', |
| 49 |
'name' => 'target', |
| 50 |
'label-message' => 'special-talkpage-target', |
| 51 |
'default' => $this->par, |
| 52 |
], |
| 53 |
]; |
| 54 |
} |
| 55 |
|
| 56 |
protected function alterForm( HTMLForm $form ) { |
| 57 |
if ( $this->par ) { |
| 58 |
$form->setMethod( 'get' ); |
| 59 |
} |
| 60 |
$form->setSubmitTextMsg( 'special-talkpage-submit' ); |
| 61 |
} |
| 62 |
|
| 63 |
public function onSubmit( array $formData ) { |
| 64 |
$target = $formData['target']; |
| 65 |
try { |
| 66 |
$title = $this->titleParser->parseTitle( $target ); |
| 67 |
} catch ( MalformedTitleException $e ) { |
| 68 |
return Status::newFatal( $e->getMessageObject() ); |
| 69 |
} |
| 70 |
$title = Title::newFromLinkTarget( $title ); |
| 71 |
$talk = $title->getTalkPageIfDefined(); |
| 72 |
if ( $talk === null ) { |
| 73 |
return Status::newFatal( 'title-invalid-talk-namespace' ); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
$this->getOutput()->redirect( $talk->getFullUrlForRedirect(), '302' ); |
| 78 |
$this->getOutput()->enableClientCache(); |
| 79 |
$this->getOutput()->setCdnMaxage( |
| 80 |
$this->getConfig()->get( MainConfigNames::ParserCacheExpireTime ) |
| 81 |
); |
| 82 |
return true; |
| 83 |
} |
| 84 |
|
| 85 |
protected function getDisplayFormat() { |
| 86 |
return 'ooui'; |
| 87 |
} |
| 88 |
|
| 89 |
public function requiresWrite() { |
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
public function requiresUnblock() { |
| 94 |
return false; |
| 95 |
} |
| 96 |
|
| 97 |
public function isListed() { |
| 98 |
return false; |
| 99 |
} |
| 100 |
|
| 101 |
protected function getMessagePrefix() { |
| 102 |
return 'special-talkpage'; |
| 103 |
} |
| 104 |
|
| 105 |
public function getDescription() { |
| 106 |
|
| 107 |
return $this->msg( 'special-talkpage' ); |
| 108 |
} |
| 109 |
|
| 110 |
} |