MediaWiki master
SpecialMytalk.php
Go to the documentation of this file.
1<?php
9
18
33
34 private TempUserConfig $tempUserConfig;
35 private TempUserCreator $tempUserCreator;
36 private AuthManager $authManager;
37 private bool $shouldRedirect = true;
38
39 public function __construct(
40 TempUserConfig $tempUserConfig,
41 TempUserCreator $tempUserCreator,
42 AuthManager $authManager
43 ) {
44 parent::__construct( 'Mytalk' );
45
46 $this->tempUserConfig = $tempUserConfig;
47 $this->tempUserCreator = $tempUserCreator;
48 $this->authManager = $authManager;
49 }
50
52 public function execute( $subpage ) {
53 if ( $this->tempUserConfig->isEnabled() && $this->getUser()->isAnon() ) {
54 $this->shouldRedirect = false;
55 $block = $this->getUser()->getBlock();
56 if ( $block && $block->isUsertalkEditAllowed() ) {
57 // Show the user a form for creating a temporary user to appeal their block
58 $this->setHeaders();
59 $this->outputHeader( 'mytalk-appeal-summary' );
60 $form = $this->getUserTalkAppealForm();
61 $status = $form->show();
62 if ( $status && $status->isOK() ) {
63 // Set the context user to the new temporary user, and continue to
64 // redirect to the talk page.
65 $this->authManager->setRequestContextUserFromSessionUser();
66 } else {
67 if ( $status instanceof Status ) {
68 $this->getOutput()->addWikiMsg( $status->getMessage() );
69 }
70 return;
71 }
72 } else {
73 // Redirect to login for anon users when temp accounts are enabled.
74 $this->requireLogin();
75 return;
76 }
77 }
78 parent::execute( $subpage );
79 }
80
84 private function getUserTalkAppealForm() {
85 $form = HTMLForm::factory( 'ooui', [], $this->getContext() );
86 $form->setMethod( 'post' )
87 ->setSubmitTextMsg( 'mytalk-appeal-submit' )
88 ->setSubmitCallback( $this->onSubmit( ... ) );
89 return $form;
90 }
91
97 public function onSubmit() {
98 return $this->tempUserCreator->create(
99 null,
100 $this->getContext()->getRequest(),
101 [ ChangeTags::TAG_IPBLOCK_APPEAL ]
102 );
103 }
104
106 public function getDescription() {
107 if ( !$this->shouldRedirect ) {
108 return $this->msg( 'mytalk-appeal' );
109 }
110 }
111
113 public function getRedirect( $subpage ) {
114 if ( $this->tempUserConfig->isEnabled() && $this->getUser()->isAnon() ) {
115 return false;
116 }
117
118 if ( $subpage === null || $subpage === '' ) {
119 return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() );
120 }
121
122 return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() . '/' . $subpage );
123 }
124
132 return true;
133 }
134}
139class_alias( SpecialMytalk::class, 'SpecialMytalk' );
const NS_USER_TALK
Definition Defines.php:54
AuthManager is the authentication system in MediaWiki and serves entry point for authentication.
Recent changes tagging.
makeTitle( $linkId)
Convert a link ID to a Title.to override Title
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:195
Helper for any RedirectSpecialPage which redirects the user to a particular article (as opposed to us...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
getName()
Get the canonical, unlocalized name of this special page without namespace.
Special page pointing to current user's talk page.
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.False otherwise....
__construct(TempUserConfig $tempUserConfig, TempUserCreator $tempUserCreator, AuthManager $authManager)
onSubmit()
Attempt to create a new temporary user on form submission.
personallyIdentifiableTarget()
Target identifies a specific User.
getDescription()
Returns the name that goes in the <h1> in the special page itself, and also the name that will be l...
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:44
Represents a title within MediaWiki.
Definition Title.php:70
Service for temporary user creation.
Interface for temporary user creation config and name matching.