MediaWiki master
MarkpatrolledAction.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Actions;
11
23use StatusValue;
24
31
32 private LinkRenderer $linkRenderer;
33 private PatrolManager $patrolManager;
34 private RecentChangeLookup $recentChangeLookup;
35
43 public function __construct(
44 Article $article,
46 LinkRenderer $linkRenderer,
47 PatrolManager $patrolManager,
48 RecentChangeLookup $recentChangeLookup
49 ) {
50 parent::__construct( $article, $context );
51
52 $this->linkRenderer = $linkRenderer;
53 $this->patrolManager = $patrolManager;
54 $this->recentChangeLookup = $recentChangeLookup;
55 }
56
58 public function getName() {
59 return 'markpatrolled';
60 }
61
63 protected function getDescription() {
64 // Disable default header "subtitle"
65 return '';
66 }
67
69 public function getRestriction() {
70 return 'patrol';
71 }
72
74 protected function usesOOUI() {
75 return true;
76 }
77
82 protected function getRecentChange( $data = null ) {
83 $rc = null;
84 // Note: This works both on initial GET url and after submitting the form
85 $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
86 if ( $rcId ) {
87 $rc = $this->recentChangeLookup->getRecentChangeById( $rcId );
88 }
89 if ( !$rc ) {
90 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
91 }
92 return $rc;
93 }
94
96 protected function preText() {
97 $rc = $this->getRecentChange();
98 $title = $rc->getTitle();
99
100 // Based on logentry-patrol-patrol (see PatrolLogFormatter)
101 $revId = $rc->getAttribute( 'rc_this_oldid' );
102 $query = [
103 'curid' => $rc->getAttribute( 'rc_cur_id' ),
104 'diff' => $revId,
105 'oldid' => $rc->getAttribute( 'rc_last_oldid' )
106 ];
107 $revlink = $this->linkRenderer->makeLink( $title, $revId, [], $query );
108 $pagelink = $this->linkRenderer->makeLink( $title, $title->getPrefixedText() );
109
110 return $this->msg( 'confirm-markpatrolled-top' )->params(
111 $title->getPrefixedText(),
112 // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
113 Message::rawParam( $pagelink ),
114 Message::rawParam( $revlink )
115 )->parse();
116 }
117
118 protected function alterForm( HTMLForm $form ) {
119 $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
120 $form->setTokenSalt( 'patrol' );
121 $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
122 }
123
128 public function onSubmit( $data ) {
129 $rc = $this->getRecentChange( $data );
130 $status = $this->patrolManager->markPatrolled( $rc, $this->getAuthority() );
131
132 if ( $status->hasMessage( 'rcpatroldisabled' ) ) {
133 throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
134 }
135
136 // Guess where the user came from
137 // TODO: Would be nice to see where the user actually came from
138 if ( $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_NEW ) {
139 $returnTo = 'Newpages';
140 } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
141 $returnTo = 'Newfiles';
142 } else {
143 $returnTo = 'Recentchanges';
144 }
145 $return = SpecialPage::getTitleFor( $returnTo );
146
147 if ( $status->hasMessage( 'markedaspatrollederror-noautopatrol' ) ) {
148 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrollederror' ) );
149 $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
150 $this->getOutput()->returnToMain( null, $return );
151 return true;
152 }
153
154 if ( !$status->isGood() ) {
155 if ( !$status->hasMessage( 'hookaborted' ) ) {
156 throw new PermissionsError( 'patrol', $status );
157 }
158 // The MarkPatrolled hook itself has handled any output
159 return $status;
160 }
161
162 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrolled' ) );
163 $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
164 $this->getOutput()->returnToMain( null, $return );
165 return true;
166 }
167
169 public function onSuccess() {
170 // Required by parent class. Redundant as our onSubmit handles output already.
171 }
172
174 public function doesWrites() {
175 return true;
176 }
177}
178
180class_alias( MarkpatrolledAction::class, 'MarkpatrolledAction' );
IContextSource null $context
IContextSource if specified; otherwise we'll use the Context from the Page.
Definition Action.php:66
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:227
getRequest()
Get the WebRequest being used for this instance.
Definition Action.php:133
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:143
getAuthority()
Shortcut to get the Authority executing this instance.
Definition Action.php:163
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, PatrolManager $patrolManager, RecentChangeLookup $recentChangeLookup)
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:195
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:144
Legacy class representing an editable page and handling UI for some page actions.
Definition Article.php:64
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.