MediaWiki master
MarkpatrolledAction.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Actions;
11
23use StatusValue;
24
31
32 public function __construct(
33 Article $article,
35 private readonly LinkRenderer $linkRenderer,
36 private readonly PatrolManager $patrolManager,
37 private readonly RecentChangeLookup $recentChangeLookup,
38 ) {
39 parent::__construct( $article, $context );
40 }
41
43 public function getName() {
44 return 'markpatrolled';
45 }
46
48 protected function getDescription() {
49 // Disable default header "subtitle"
50 return '';
51 }
52
54 public function getRestriction() {
55 return 'patrol';
56 }
57
59 protected function usesOOUI() {
60 return true;
61 }
62
67 protected function getRecentChange( $data = null ) {
68 $rc = null;
69 // Note: This works both on initial GET url and after submitting the form
70 $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
71 if ( $rcId ) {
72 $rc = $this->recentChangeLookup->getRecentChangeById( $rcId );
73 }
74 if ( !$rc ) {
75 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
76 }
77 return $rc;
78 }
79
81 protected function preText() {
82 $rc = $this->getRecentChange();
83 $title = $rc->getTitle();
84
85 // Based on logentry-patrol-patrol (see PatrolLogFormatter)
86 $revId = $rc->getAttribute( 'rc_this_oldid' );
87 $query = [
88 'curid' => $rc->getAttribute( 'rc_cur_id' ),
89 'diff' => $revId,
90 'oldid' => $rc->getAttribute( 'rc_last_oldid' )
91 ];
92 $revlink = $this->linkRenderer->makeLink( $title, $revId, [], $query );
93 $pagelink = $this->linkRenderer->makeLink( $title, $title->getPrefixedText() );
94
95 return $this->msg( 'confirm-markpatrolled-top' )->params(
96 $title->getPrefixedText(),
97 // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
98 Message::rawParam( $pagelink ),
99 Message::rawParam( $revlink )
100 )->parse();
101 }
102
103 protected function alterForm( HTMLForm $form ) {
104 $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
105 $form->setTokenSalt( 'patrol' );
106 $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
107 }
108
113 public function onSubmit( $data ) {
114 $rc = $this->getRecentChange( $data );
115 $status = $this->patrolManager->markPatrolled( $rc, $this->getAuthority() );
116
117 if ( $status->hasMessage( 'rcpatroldisabled' ) ) {
118 throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
119 }
120
121 // Guess where the user came from
122 // TODO: Would be nice to see where the user actually came from
123 if ( $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_NEW ) {
124 $returnTo = 'Newpages';
125 } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
126 $returnTo = 'Newfiles';
127 } else {
128 $returnTo = 'Recentchanges';
129 }
130 $return = SpecialPage::getTitleFor( $returnTo );
131
132 if ( $status->hasMessage( 'markedaspatrollederror-noautopatrol' ) ) {
133 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrollederror' ) );
134 $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
135 $this->getOutput()->returnToMain( null, $return );
136 return true;
137 }
138
139 if ( !$status->isGood() ) {
140 if ( !$status->hasMessage( 'hookaborted' ) ) {
141 throw new PermissionsError( 'patrol', $status );
142 }
143 // The MarkPatrolled hook itself has handled any output
144 return $status;
145 }
146
147 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrolled' ) );
148 $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
149 $this->getOutput()->returnToMain( null, $return );
150 return true;
151 }
152
154 public function onSuccess() {
155 // Required by parent class. Redundant as our onSubmit handles output already.
156 }
157
159 public function doesWrites() {
160 return true;
161 }
162}
163
165class_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, private readonly LinkRenderer $linkRenderer, private readonly PatrolManager $patrolManager, private readonly 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:207
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.