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  $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  $user = $this->getUser();
113  $rc = $this->getRecentChange( $data );
114  $errors = $rc->doMarkPatrolled( $user );
115 
116  if ( in_array( [ 'rcpatroldisabled' ], $errors ) ) {
117  throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
118  }
119 
120  // Guess where the user came from
121  // TODO: Would be nice to see where the user actually came from
122  if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) {
123  $returnTo = 'Newpages';
124  } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
125  $returnTo = 'Newfiles';
126  } else {
127  $returnTo = 'Recentchanges';
128  }
129  $return = SpecialPage::getTitleFor( $returnTo );
130 
131  if ( in_array( [ 'markedaspatrollederror-noautopatrol' ], $errors ) ) {
132  $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrollederror' ) );
133  $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
134  $this->getOutput()->returnToMain( null, $return );
135  return true;
136  }
137 
138  if ( $errors ) {
139  if ( !in_array( [ 'hookaborted' ], $errors ) ) {
140  throw new PermissionsError( 'patrol', $errors );
141  }
142  // The hook itself has handled any output
143  return $errors;
144  }
145 
146  $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrolled' ) );
147  $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
148  $this->getOutput()->returnToMain( null, $return );
149  return true;
150  }
151 
152  public function onSuccess() {
153  // Required by parent class. Redundant as our onSubmit handles output already.
154  }
155 
156  public function doesWrites() {
157  return true;
158  }
159 }
const RC_NEW
Definition: Defines.php:116
IContextSource null $context
IContextSource if specified; otherwise we'll use the Context from the Page.
Definition: Action.php:66
WikiPage Article ImagePage CategoryPage Page $page
Page on which we're performing the action.
Definition: Action.php:53
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:159
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:169
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:231
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:149
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.
Definition: FormAction.php:30
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.
Definition: HTMLForm.php:1578
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:1120
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1209
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:1155
Show an error when a user tries to do something they do not have the necessary permissions for.
static newFromId( $rcid)
Obtain the recent change with a given rc_id value.
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