MediaWiki REL1_39
MarkpatrolledAction.php
Go to the documentation of this file.
1<?php
24
31
33 private $linkRenderer;
34
40 public function __construct(
41 Page $page,
42 IContextSource $context,
43 LinkRenderer $linkRenderer
44 ) {
45 parent::__construct( $page, $context );
46 $this->linkRenderer = $linkRenderer;
47 }
48
49 public function getName() {
50 return 'markpatrolled';
51 }
52
53 protected function getDescription() {
54 // Disable default header "subtitle"
55 return '';
56 }
57
58 public function getRestriction() {
59 return 'patrol';
60 }
61
62 protected function usesOOUI() {
63 return true;
64 }
65
66 protected function getRecentChange( $data = null ) {
67 $rc = null;
68 // Note: This works both on initial GET url and after submitting the form
69 $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
70 if ( $rcId ) {
71 $rc = RecentChange::newFromId( $rcId );
72 }
73 if ( !$rc ) {
74 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
75 }
76 return $rc;
77 }
78
79 protected function preText() {
80 $rc = $this->getRecentChange();
81 $title = $rc->getTitle();
82
83 // Based on logentry-patrol-patrol (see PatrolLogFormatter)
84 $revId = $rc->getAttribute( 'rc_this_oldid' );
85 $query = [
86 'curid' => $rc->getAttribute( 'rc_cur_id' ),
87 'diff' => $revId,
88 'oldid' => $rc->getAttribute( 'rc_last_oldid' )
89 ];
90 $revlink = $this->linkRenderer->makeLink( $title, $revId, [], $query );
91 $pagelink = $this->linkRenderer->makeLink( $title, $title->getPrefixedText() );
92
93 return $this->msg( 'confirm-markpatrolled-top' )->params(
94 $title->getPrefixedText(),
95 // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
96 Message::rawParam( $pagelink ),
97 Message::rawParam( $revlink )
98 )->parse();
99 }
100
101 protected function alterForm( HTMLForm $form ) {
102 $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
103 $form->setTokenSalt( 'patrol' );
104 $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
105 }
106
111 public function onSubmit( $data ) {
112 $rc = $this->getRecentChange( $data );
113 $errors = $rc->doMarkPatrolled( $this->getAuthority() );
114
115 if ( in_array( [ 'rcpatroldisabled' ], $errors ) ) {
116 throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
117 }
118
119 // Guess where the user came from
120 // TODO: Would be nice to see where the user actually came from
121 if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) {
122 $returnTo = 'Newpages';
123 } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
124 $returnTo = 'Newfiles';
125 } else {
126 $returnTo = 'Recentchanges';
127 }
128 $return = SpecialPage::getTitleFor( $returnTo );
129
130 if ( in_array( [ 'markedaspatrollederror-noautopatrol' ], $errors ) ) {
131 $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrollederror' ) );
132 $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
133 $this->getOutput()->returnToMain( null, $return );
134 return true;
135 }
136
137 if ( $errors ) {
138 if ( !in_array( [ 'hookaborted' ], $errors ) ) {
139 throw new PermissionsError( 'patrol', $errors );
140 }
141 // The hook itself has handled any output
142 return $errors;
143 }
144
145 $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrolled' ) );
146 $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
147 $this->getOutput()->returnToMain( null, $return );
148 return true;
149 }
150
151 public function onSuccess() {
152 // Required by parent class. Redundant as our onSubmit handles output already.
153 }
154
155 public function doesWrites() {
156 return true;
157 }
158}
getAuthority()
const RC_NEW
Definition Defines.php:117
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:160
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:242
getRequest()
Get the WebRequest being used for this instance.
Definition Action.php:150
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.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:150
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
setTokenSalt( $salt)
Set the salt for the edit token.
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.
__construct(Page $page, IContextSource $context, LinkRenderer $linkRenderer)
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.
preText()
Add pre- or post-text to the form.
Class that generates HTML anchor link elements for pages.
static rawParam( $raw)
Definition Message.php:1134
Show an error when a user tries to do something they do not have the necessary permissions for.
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,...
Interface for objects which can provide a MediaWiki context on request.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition Page.php:29