MediaWiki  master
MarkpatrolledAction.php
Go to the documentation of this file.
1 <?php
24 
31 
33  private $linkRenderer;
34 
40  public function __construct(
41  Page $page,
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  // @phan-suppress-next-line SecurityCheck-DoubleEscaped Triggered by RecentChange::getAttribute
91  $revlink = $this->linkRenderer->makeLink( $title, $revId, [], $query );
92  $pagelink = $this->linkRenderer->makeLink( $title, $title->getPrefixedText() );
93 
94  return $this->msg( 'confirm-markpatrolled-top' )->params(
95  $title->getPrefixedText(),
96  // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
97  Message::rawParam( $pagelink ),
98  Message::rawParam( $revlink )
99  )->parse();
100  }
101 
102  protected function alterForm( HTMLForm $form ) {
103  $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
104  $form->setTokenSalt( 'patrol' );
105  $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
106  }
107 
112  public function onSubmit( $data ) {
113  $user = $this->getUser();
114  $rc = $this->getRecentChange( $data );
115  $errors = $rc->doMarkPatrolled( $user );
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()->setPageTitle( $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()->setPageTitle( $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 }
Page
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition: Page.php:29
Action\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:146
MarkpatrolledAction\usesOOUI
usesOOUI()
Whether the form should use OOUI.
Definition: MarkpatrolledAction.php:62
MarkpatrolledAction\__construct
__construct(Page $page, IContextSource $context, LinkRenderer $linkRenderer)
Definition: MarkpatrolledAction.php:40
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition: LinkRenderer.php:43
HTMLForm\setTokenSalt
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1057
FormAction
An action which shows a form and does something based on the input from the form.
Definition: FormAction.php:30
MarkpatrolledAction\preText
preText()
Add pre- or post-text to the form.
Definition: MarkpatrolledAction.php:79
MarkpatrolledAction\getDescription
getDescription()
Returns the description that goes below the <h1> tag.
Definition: MarkpatrolledAction.php:53
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:107
MarkpatrolledAction\$linkRenderer
LinkRenderer $linkRenderer
Definition: MarkpatrolledAction.php:33
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:32
RC_NEW
const RC_NEW
Definition: Defines.php:116
MarkpatrolledAction\getName
getName()
Return the name of the action this object responds to.
Definition: MarkpatrolledAction.php:49
MarkpatrolledAction\alterForm
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
Definition: MarkpatrolledAction.php:102
HTMLForm\addHiddenField
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:968
$title
$title
Definition: testCompression.php:38
MarkpatrolledAction\onSuccess
onSuccess()
Do something exciting on successful processing of the form.
Definition: MarkpatrolledAction.php:153
MarkpatrolledAction\getRestriction
getRestriction()
Get the permission required to perform this action.
Definition: MarkpatrolledAction.php:58
RecentChange\newFromId
static newFromId( $rcid)
Obtain the recent change with a given rc_id value.
Definition: RecentChange.php:213
Action\getUser
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:166
Action\$context
IContextSource $context
IContextSource if specified; otherwise we'll use the Context from the Page.
Definition: Action.php:66
Message\rawParam
static rawParam( $raw)
Definition: Message.php:1116
MarkpatrolledAction\onSubmit
onSubmit( $data)
Definition: MarkpatrolledAction.php:112
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1420
Action\$page
WikiPage Article ImagePage CategoryPage Page $page
Page on which we're performing the action.
Definition: Action.php:53
Action\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:228
Action\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:156
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:30
MarkpatrolledAction\doesWrites
doesWrites()
Definition: MarkpatrolledAction.php:157
MarkpatrolledAction
Mark a revision as patrolled on a page.
Definition: MarkpatrolledAction.php:30
MarkpatrolledAction\getRecentChange
getRecentChange( $data=null)
Definition: MarkpatrolledAction.php:66
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:143