MediaWiki master
SpecialTalkPage.php
Go to the documentation of this file.
1<?php
6
7namespace MediaWiki\Specials\Redirects;
8
9use MediaWiki\HTMLForm\HTMLForm;
10use MediaWiki\MainConfigNames;
11use MediaWiki\SpecialPage\FormSpecialPage;
12use MediaWiki\Status\Status;
13use MediaWiki\Title\MalformedTitleException;
14use MediaWiki\Title\Title;
15use MediaWiki\Title\TitleParser;
16
23
24 public function __construct( private readonly TitleParser $titleParser ) {
25 parent::__construct( 'TalkPage' );
26 }
27
29 protected function getFormFields() {
30 return [
31 'target' => [
32 'type' => 'title',
33 'name' => 'target',
34 'label-message' => 'special-talkpage-target',
35 'default' => $this->par,
36 ],
37 ];
38 }
39
40 protected function alterForm( HTMLForm $form ) {
41 if ( $this->par ) { // immediately submit with subpage value
42 $form->setMethod( 'get' );
43 }
44 $form->setSubmitTextMsg( 'special-talkpage-submit' );
45 }
46
48 public function onSubmit( array $formData ) {
49 $target = $formData['target'];
50 try {
51 $title = $this->titleParser->parseTitle( $target );
52 } catch ( MalformedTitleException $e ) {
53 return Status::newFatal( $e->getMessageObject() );
54 }
55 $title = Title::newFromLinkTarget( $title );
56 $talk = $title->getTalkPageIfDefined();
57 if ( $talk === null ) {
58 return Status::newFatal( 'title-invalid-talk-namespace' );
59 }
60
61 // HTTP 302: Found; cache for the Parser Cache length, as an appropriate long time
62 $this->getOutput()->redirect( $talk->getFullUrlForRedirect(), '302' );
63 $this->getOutput()->enableClientCache();
64 $this->getOutput()->setCdnMaxage(
66 );
67 return true;
68 }
69
71 protected function getDisplayFormat() {
72 return 'ooui';
73 }
74
76 public function requiresWrite() {
77 return false;
78 }
79
81 public function requiresUnblock() {
82 return false;
83 }
84
89 public function isListed() {
90 return false;
91 }
92
94 protected function getMessagePrefix() {
95 return 'special-talkpage';
96 }
97
99 public function getDescription() {
100 // "talkpage" is already taken by CologneBlue
101 return $this->msg( 'special-talkpage' );
102 }
103
104}
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:214
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
setMethod( $method='post')
Set the method used to submit the form.
const ParserCacheExpireTime
Name constant for the ParserCacheExpireTime setting, for use with Config\get().
Special page which uses an HTMLForm to handle processing.
string null $par
The subpage of the special page.
getConfig()
Shortcut to get main config object.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
Redirect to the talk page of a given page.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
isListed()
Whether this special page is listed in Special:SpecialPages.to override 1.3 (r3583) bool
requiresUnblock()
Whether this action cannot be executed by a blocked user, default to requiresPost()....
getDescription()
Returns the name that goes in the <h1> in the special page itself, and also the name that will be l...
getDisplayFormat()
Get display format for the form.See HTMLForm documentation for available values.1....
getFormFields()
Get an HTMLForm descriptor array.array
getMessagePrefix()
Get message prefix for HTMLForm.1.21 string
requiresWrite()
Whether this action requires the wiki not to be locked, default to requiresPost()....
__construct(private readonly TitleParser $titleParser)
onSubmit(array $formData)
Process the form on submission.bool|string|array|Status As documented for HTMLForm\trySubmit.
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
A title parser service for MediaWiki.