MediaWiki master
MarkpatrolledAction.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Actions;
24
34use StatusValue;
35
42
43 private LinkRenderer $linkRenderer;
44
50 public function __construct(
51 Article $article,
53 LinkRenderer $linkRenderer
54 ) {
55 parent::__construct( $article, $context );
56 $this->linkRenderer = $linkRenderer;
57 }
58
60 public function getName() {
61 return 'markpatrolled';
62 }
63
65 protected function getDescription() {
66 // Disable default header "subtitle"
67 return '';
68 }
69
71 public function getRestriction() {
72 return 'patrol';
73 }
74
76 protected function usesOOUI() {
77 return true;
78 }
79
84 protected function getRecentChange( $data = null ) {
85 $rc = null;
86 // Note: This works both on initial GET url and after submitting the form
87 $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
88 if ( $rcId ) {
89 $rc = RecentChange::newFromId( $rcId );
90 }
91 if ( !$rc ) {
92 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
93 }
94 return $rc;
95 }
96
98 protected function preText() {
99 $rc = $this->getRecentChange();
100 $title = $rc->getTitle();
101
102 // Based on logentry-patrol-patrol (see PatrolLogFormatter)
103 $revId = $rc->getAttribute( 'rc_this_oldid' );
104 $query = [
105 'curid' => $rc->getAttribute( 'rc_cur_id' ),
106 'diff' => $revId,
107 'oldid' => $rc->getAttribute( 'rc_last_oldid' )
108 ];
109 $revlink = $this->linkRenderer->makeLink( $title, $revId, [], $query );
110 $pagelink = $this->linkRenderer->makeLink( $title, $title->getPrefixedText() );
111
112 return $this->msg( 'confirm-markpatrolled-top' )->params(
113 $title->getPrefixedText(),
114 // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
115 Message::rawParam( $pagelink ),
116 Message::rawParam( $revlink )
117 )->parse();
118 }
119
120 protected function alterForm( HTMLForm $form ) {
121 $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
122 $form->setTokenSalt( 'patrol' );
123 $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
124 }
125
130 public function onSubmit( $data ) {
131 $rc = $this->getRecentChange( $data );
132 $status = $rc->markPatrolled( $this->getAuthority() );
133
134 if ( $status->hasMessage( 'rcpatroldisabled' ) ) {
135 throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
136 }
137
138 // Guess where the user came from
139 // TODO: Would be nice to see where the user actually came from
140 if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) {
141 $returnTo = 'Newpages';
142 } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
143 $returnTo = 'Newfiles';
144 } else {
145 $returnTo = 'Recentchanges';
146 }
147 $return = SpecialPage::getTitleFor( $returnTo );
148
149 if ( $status->hasMessage( 'markedaspatrollederror-noautopatrol' ) ) {
150 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrollederror' ) );
151 $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
152 $this->getOutput()->returnToMain( null, $return );
153 return true;
154 }
155
156 if ( !$status->isGood() ) {
157 if ( !$status->hasMessage( 'hookaborted' ) ) {
158 throw new PermissionsError( 'patrol', $status );
159 }
160 // The MarkPatrolled hook itself has handled any output
161 return $status;
162 }
163
164 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrolled' ) );
165 $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
166 $this->getOutput()->returnToMain( null, $return );
167 return true;
168 }
169
171 public function onSuccess() {
172 // Required by parent class. Redundant as our onSubmit handles output already.
173 }
174
176 public function doesWrites() {
177 return true;
178 }
179}
180
182class_alias( MarkpatrolledAction::class, 'MarkpatrolledAction' );
const RC_NEW
Definition Defines.php:118
IContextSource null $context
IContextSource if specified; otherwise we'll use the Context from the Page.
Definition Action.php:79
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:240
getRequest()
Get the WebRequest being used for this instance.
Definition Action.php:146
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:156
getAuthority()
Shortcut to get the Authority executing this instance.
Definition Action.php:176
An action which shows a form and does something based on the input from the form.
Mark a revision as patrolled on a page.
getName()
Return the name of the action this object responds to.1.17string Lowercase name
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
onSuccess()
Do something exciting on successful processing of the form.This might be to show a confirmation messa...
usesOOUI()
Whether the form should use OOUI.to override bool
__construct(Article $article, IContextSource $context, LinkRenderer $linkRenderer)
getDescription()
Returns the description that goes below the <h1> element.1.17 to override string HTML
preText()
Add pre- or post-text to the form.to override string HTML which will be sent to $form->addPreHtml()
getRestriction()
Get the permission required to perform this action.Often, but not always, the same as the action name...
An error page which can definitely be safely rendered using the OutputPage.
Show an error when a user tries to do something they do not have the necessary permissions for.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:209
setTokenSalt( $salt)
Set the salt for the edit token.
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output Array values are discarded for security reasons (per WebRequest::get...
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Class that generates HTML for internal links.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:157
Legacy class representing an editable page and handling UI for some page actions.
Definition Article.php:76
Utility class for creating and reading rows in the recentchanges table.
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Interface for objects which can provide a MediaWiki context on request.