MediaWiki master
MarkpatrolledAction.php
Go to the documentation of this file.
1<?php
27
34
35 private LinkRenderer $linkRenderer;
36
42 public function __construct(
43 Article $article,
44 IContextSource $context,
45 LinkRenderer $linkRenderer
46 ) {
47 parent::__construct( $article, $context );
48 $this->linkRenderer = $linkRenderer;
49 }
50
51 public function getName() {
52 return 'markpatrolled';
53 }
54
55 protected function getDescription() {
56 // Disable default header "subtitle"
57 return '';
58 }
59
60 public function getRestriction() {
61 return 'patrol';
62 }
63
64 protected function usesOOUI() {
65 return true;
66 }
67
68 protected function getRecentChange( $data = null ) {
69 $rc = null;
70 // Note: This works both on initial GET url and after submitting the form
71 $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
72 if ( $rcId ) {
73 $rc = RecentChange::newFromId( $rcId );
74 }
75 if ( !$rc ) {
76 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
77 }
78 return $rc;
79 }
80
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 $errors = $rc->doMarkPatrolled( $this->getAuthority() );
116
117 if ( in_array( [ 'rcpatroldisabled' ], $errors ) ) {
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_type' ) == RC_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 ( in_array( [ 'markedaspatrollederror-noautopatrol' ], $errors ) ) {
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 ( $errors ) {
140 if ( !in_array( [ 'hookaborted' ], $errors ) ) {
141 throw new PermissionsError( 'patrol', $errors );
142 }
143 // The hook itself has handled any output
144 return $errors;
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
153 public function onSuccess() {
154 // Required by parent class. Redundant as our onSubmit handles output already.
155 }
156
157 public function doesWrites() {
158 return true;
159 }
160}
getRequest()
getAuthority()
const RC_NEW
Definition Defines.php:117
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:67
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.
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.