MediaWiki 1.44.0
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
59 public function getName() {
60 return 'markpatrolled';
61 }
62
63 protected function getDescription() {
64 // Disable default header "subtitle"
65 return '';
66 }
67
68 public function getRestriction() {
69 return 'patrol';
70 }
71
72 protected function usesOOUI() {
73 return true;
74 }
75
76 protected function getRecentChange( $data = null ) {
77 $rc = null;
78 // Note: This works both on initial GET url and after submitting the form
79 $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
80 if ( $rcId ) {
81 $rc = RecentChange::newFromId( $rcId );
82 }
83 if ( !$rc ) {
84 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
85 }
86 return $rc;
87 }
88
89 protected function preText() {
90 $rc = $this->getRecentChange();
91 $title = $rc->getTitle();
92
93 // Based on logentry-patrol-patrol (see PatrolLogFormatter)
94 $revId = $rc->getAttribute( 'rc_this_oldid' );
95 $query = [
96 'curid' => $rc->getAttribute( 'rc_cur_id' ),
97 'diff' => $revId,
98 'oldid' => $rc->getAttribute( 'rc_last_oldid' )
99 ];
100 $revlink = $this->linkRenderer->makeLink( $title, $revId, [], $query );
101 $pagelink = $this->linkRenderer->makeLink( $title, $title->getPrefixedText() );
102
103 return $this->msg( 'confirm-markpatrolled-top' )->params(
104 $title->getPrefixedText(),
105 // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
106 Message::rawParam( $pagelink ),
107 Message::rawParam( $revlink )
108 )->parse();
109 }
110
111 protected function alterForm( HTMLForm $form ) {
112 $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
113 $form->setTokenSalt( 'patrol' );
114 $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
115 }
116
121 public function onSubmit( $data ) {
122 $rc = $this->getRecentChange( $data );
123 $status = $rc->markPatrolled( $this->getAuthority() );
124
125 if ( $status->hasMessage( 'rcpatroldisabled' ) ) {
126 throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
127 }
128
129 // Guess where the user came from
130 // TODO: Would be nice to see where the user actually came from
131 if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) {
132 $returnTo = 'Newpages';
133 } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
134 $returnTo = 'Newfiles';
135 } else {
136 $returnTo = 'Recentchanges';
137 }
138 $return = SpecialPage::getTitleFor( $returnTo );
139
140 if ( $status->hasMessage( 'markedaspatrollederror-noautopatrol' ) ) {
141 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrollederror' ) );
142 $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
143 $this->getOutput()->returnToMain( null, $return );
144 return true;
145 }
146
147 if ( !$status->isGood() ) {
148 if ( !$status->hasMessage( 'hookaborted' ) ) {
149 throw new PermissionsError( 'patrol', $status );
150 }
151 // The MarkPatrolled hook itself has handled any output
152 return $status;
153 }
154
155 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrolled' ) );
156 $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
157 $this->getOutput()->returnToMain( null, $return );
158 return true;
159 }
160
161 public function onSuccess() {
162 // Required by parent class. Redundant as our onSubmit handles output already.
163 }
164
165 public function doesWrites() {
166 return true;
167 }
168}
169
171class_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.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
onSuccess()
Do something exciting on successful processing of the form.
usesOOUI()
Whether the form should use OOUI.
__construct(Article $article, IContextSource $context, LinkRenderer $linkRenderer)
getDescription()
Returns the description that goes below the <h1> element.
preText()
Add pre- or post-text to the form.
getRestriction()
Get the permission required to perform this action.
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.