MediaWiki master
SpecialMytalk.php
Go to the documentation of this file.
1<?php
9
18
33
34 private bool $shouldRedirect = true;
35
36 public function __construct(
37 private readonly TempUserConfig $tempUserConfig,
38 private readonly TempUserCreator $tempUserCreator,
39 private readonly AuthManager $authManager,
40 ) {
41 parent::__construct( 'Mytalk' );
42 }
43
45 public function execute( $subpage ) {
46 if ( $this->tempUserConfig->isEnabled() && $this->getUser()->isAnon() ) {
47 $this->shouldRedirect = false;
48 $block = $this->getUser()->getBlock();
49 if ( $block && $block->isUsertalkEditAllowed() ) {
50 // Show the user a form for creating a temporary user to appeal their block
51 $this->setHeaders();
52 $this->outputHeader( 'mytalk-appeal-summary' );
53 $form = $this->getUserTalkAppealForm();
54 $status = $form->show();
55 if ( $status && $status->isOK() ) {
56 // Set the context user to the new temporary user, and continue to
57 // redirect to the talk page.
58 $this->authManager->setRequestContextUserFromSessionUser();
59 } else {
60 if ( $status instanceof Status ) {
61 $this->getOutput()->addWikiMsg( $status->getMessage() );
62 }
63 return;
64 }
65 } else {
66 // Redirect to login for anon users when temp accounts are enabled.
67 $this->requireLogin();
68 return;
69 }
70 }
71 parent::execute( $subpage );
72 }
73
77 private function getUserTalkAppealForm() {
78 $form = HTMLForm::factory( 'ooui', [], $this->getContext() );
79 $form->setMethod( 'post' )
80 ->setSubmitTextMsg( 'mytalk-appeal-submit' )
81 ->setSubmitCallback( $this->onSubmit( ... ) );
82 return $form;
83 }
84
90 public function onSubmit() {
91 $tags = [];
92 $block = $this->getUser()->getBlock();
93 if ( $block && $block->isCreateAccountBlocked() && $block->appliesToNamespace( NS_USER_TALK ) ) {
94 // Apply a designated tag because temporary accounts created from IPs blocked from account creation
95 // may be confusing. Limit this to sitewide blocks (and partial blocks affecting NS_USER_TALK), since
96 // temporary accounts created under partial blocks can still edit pages other than their own talk page
97 $tags[] = ChangeTags::TAG_IPBLOCK_APPEAL;
98 }
99 return $this->tempUserCreator->create(
100 null,
101 $this->getContext()->getRequest(),
102 $tags
103 );
104 }
105
107 public function getDescription() {
108 if ( !$this->shouldRedirect ) {
109 return $this->msg( 'mytalk-appeal' );
110 }
111 }
112
114 public function getRedirect( $subpage ) {
115 if ( $this->tempUserConfig->isEnabled() && $this->getUser()->isAnon() ) {
116 return false;
117 }
118
119 if ( $subpage === null || $subpage === '' ) {
120 return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() );
121 }
122
123 return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() . '/' . $subpage );
124 }
125
133 return true;
134 }
135}
140class_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:207
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(private readonly TempUserConfig $tempUserConfig, private readonly TempUserCreator $tempUserCreator, private readonly 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:69
Service for temporary user creation.
Interface for temporary user creation config and name matching.