MediaWiki master
MarkpatrolledAction.php
Go to the documentation of this file.
1<?php
28
35
36 private LinkRenderer $linkRenderer;
37
43 public function __construct(
44 Article $article,
45 IContextSource $context,
46 LinkRenderer $linkRenderer
47 ) {
48 parent::__construct( $article, $context );
49 $this->linkRenderer = $linkRenderer;
50 }
51
52 public function getName() {
53 return 'markpatrolled';
54 }
55
56 protected function getDescription() {
57 // Disable default header "subtitle"
58 return '';
59 }
60
61 public function getRestriction() {
62 return 'patrol';
63 }
64
65 protected function usesOOUI() {
66 return true;
67 }
68
69 protected function getRecentChange( $data = null ) {
70 $rc = null;
71 // Note: This works both on initial GET url and after submitting the form
72 $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
73 if ( $rcId ) {
74 $rc = RecentChange::newFromId( $rcId );
75 }
76 if ( !$rc ) {
77 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
78 }
79 return $rc;
80 }
81
82 protected function preText() {
83 $rc = $this->getRecentChange();
84 $title = $rc->getTitle();
85
86 // Based on logentry-patrol-patrol (see PatrolLogFormatter)
87 $revId = $rc->getAttribute( 'rc_this_oldid' );
88 $query = [
89 'curid' => $rc->getAttribute( 'rc_cur_id' ),
90 'diff' => $revId,
91 'oldid' => $rc->getAttribute( 'rc_last_oldid' )
92 ];
93 $revlink = $this->linkRenderer->makeLink( $title, $revId, [], $query );
94 $pagelink = $this->linkRenderer->makeLink( $title, $title->getPrefixedText() );
95
96 return $this->msg( 'confirm-markpatrolled-top' )->params(
97 $title->getPrefixedText(),
98 // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
99 Message::rawParam( $pagelink ),
100 Message::rawParam( $revlink )
101 )->parse();
102 }
103
104 protected function alterForm( HTMLForm $form ) {
105 $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
106 $form->setTokenSalt( 'patrol' );
107 $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
108 }
109
114 public function onSubmit( $data ) {
115 $rc = $this->getRecentChange( $data );
116 $status = $rc->markPatrolled( $this->getAuthority() );
117
118 if ( $status->hasMessage( 'rcpatroldisabled' ) ) {
119 throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
120 }
121
122 // Guess where the user came from
123 // TODO: Would be nice to see where the user actually came from
124 if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) {
125 $returnTo = 'Newpages';
126 } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
127 $returnTo = 'Newfiles';
128 } else {
129 $returnTo = 'Recentchanges';
130 }
131 $return = SpecialPage::getTitleFor( $returnTo );
132
133 if ( $status->hasMessage( 'markedaspatrollederror-noautopatrol' ) ) {
134 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrollederror' ) );
135 $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
136 $this->getOutput()->returnToMain( null, $return );
137 return true;
138 }
139
140 if ( !$status->isGood() ) {
141 if ( !$status->hasMessage( 'hookaborted' ) ) {
142 throw new PermissionsError( 'patrol', $status );
143 }
144 // The MarkPatrolled hook itself has handled any output
145 return $status;
146 }
147
148 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrolled' ) );
149 $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
150 $this->getOutput()->returnToMain( null, $return );
151 return true;
152 }
153
154 public function onSuccess() {
155 // Required by parent class. Redundant as our onSubmit handles output already.
156 }
157
158 public function doesWrites() {
159 return true;
160 }
161}
getRequest()
getAuthority()
const RC_NEW
Definition Defines.php:118
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:141
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:223
Legacy class representing an editable page and handling UI for some page actions.
Definition Article.php:70
An error page which can definitely be safely rendered using the OutputPage.
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.
usesOOUI()
Whether the form should use OOUI.
getDescription()
Returns the description that goes below the <h1> element.
getRestriction()
Get the permission required to perform this action.
onSuccess()
Do something exciting on successful processing of the form.
__construct(Article $article, IContextSource $context, LinkRenderer $linkRenderer)
preText()
Add pre- or post-text to the form.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:208
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:158
Parent class for all special pages.
Show an error when a user tries to do something they do not have the necessary permissions for.
Interface for objects which can provide a MediaWiki context on request.