MediaWiki master
SpecialTalkPage.php
Go to the documentation of this file.
1<?php
8
16
23
24 private TitleParser $titleParser;
25
26 public function __construct( TitleParser $titleParser ) {
27 parent::__construct( 'TalkPage' );
28 $this->titleParser = $titleParser;
29 }
30
32 protected function getFormFields() {
33 return [
34 'target' => [
35 'type' => 'title',
36 'name' => 'target',
37 'label-message' => 'special-talkpage-target',
38 'default' => $this->par,
39 ],
40 ];
41 }
42
43 protected function alterForm( HTMLForm $form ) {
44 if ( $this->par ) { // immediately submit with subpage value
45 $form->setMethod( 'get' );
46 }
47 $form->setSubmitTextMsg( 'special-talkpage-submit' );
48 }
49
51 public function onSubmit( array $formData ) {
52 $target = $formData['target'];
53 try {
54 $title = $this->titleParser->parseTitle( $target );
55 } catch ( MalformedTitleException $e ) {
56 return Status::newFatal( $e->getMessageObject() );
57 }
58 $title = Title::newFromLinkTarget( $title );
59 $talk = $title->getTalkPageIfDefined();
60 if ( $talk === null ) {
61 return Status::newFatal( 'title-invalid-talk-namespace' );
62 }
63
64 // HTTP 302: Found; cache for the Parser Cache length, as an appropriate long time
65 $this->getOutput()->redirect( $talk->getFullUrlForRedirect(), '302' );
66 $this->getOutput()->enableClientCache();
67 $this->getOutput()->setCdnMaxage(
69 );
70 return true;
71 }
72
74 protected function getDisplayFormat() {
75 return 'ooui';
76 }
77
79 public function requiresWrite() {
80 return false;
81 }
82
84 public function requiresUnblock() {
85 return false;
86 }
87
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:195
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
setMethod( $method='post')
Set the method used to submit the form.
A class containing constants representing the names of configuration variables.
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()bool
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()bool
onSubmit(array $formData)
Process the form on submission.bool|string|array|Status As documented for HTMLForm::trySubmit.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:44
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
A title parser service for MediaWiki.
Represents a title within MediaWiki.
Definition Title.php:69