MediaWiki  master
MarkpatrolledAction.php
Go to the documentation of this file.
1 <?php
24 
31 
32  public function getName() {
33  return 'markpatrolled';
34  }
35 
36  protected function getDescription() {
37  // Disable default header "subtitle"
38  return '';
39  }
40 
41  public function getRestriction() {
42  return 'patrol';
43  }
44 
45  protected function usesOOUI() {
46  return true;
47  }
48 
49  protected function getRecentChange( $data = null ) {
50  $rc = null;
51  // Note: This works both on initial GET url and after submitting the form
52  $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
53  if ( $rcId ) {
54  $rc = RecentChange::newFromId( $rcId );
55  }
56  if ( !$rc ) {
57  throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
58  }
59  return $rc;
60  }
61 
62  protected function preText() {
63  $rc = $this->getRecentChange();
64  $title = $rc->getTitle();
65  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
66 
67  // Based on logentry-patrol-patrol (see PatrolLogFormatter)
68  $revId = $rc->getAttribute( 'rc_this_oldid' );
69  $query = [
70  'curid' => $rc->getAttribute( 'rc_cur_id' ),
71  'diff' => $revId,
72  'oldid' => $rc->getAttribute( 'rc_last_oldid' )
73  ];
74  $revlink = $linkRenderer->makeLink( $title, $revId, [], $query );
75  $pagelink = $linkRenderer->makeLink( $title, $title->getPrefixedText() );
76 
77  return $this->msg( 'confirm-markpatrolled-top' )->params(
78  $title->getPrefixedText(),
79  // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
80  Message::rawParam( $pagelink ),
81  Message::rawParam( $revlink )
82  )->parse();
83  }
84 
85  protected function alterForm( HTMLForm $form ) {
86  $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
87  $form->setTokenSalt( 'patrol' );
88  $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
89  }
90 
95  public function onSubmit( $data ) {
96  $user = $this->getUser();
97  $rc = $this->getRecentChange( $data );
98  $errors = $rc->doMarkPatrolled( $user );
99 
100  if ( in_array( [ 'rcpatroldisabled' ], $errors ) ) {
101  throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
102  }
103 
104  // Guess where the user came from
105  // TODO: Would be nice to see where the user actually came from
106  if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) {
107  $returnTo = 'Newpages';
108  } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
109  $returnTo = 'Newfiles';
110  } else {
111  $returnTo = 'Recentchanges';
112  }
113  $return = SpecialPage::getTitleFor( $returnTo );
114 
115  if ( in_array( [ 'markedaspatrollederror-noautopatrol' ], $errors ) ) {
116  $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrollederror' ) );
117  $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
118  $this->getOutput()->returnToMain( null, $return );
119  return true;
120  }
121 
122  if ( $errors ) {
123  if ( !in_array( [ 'hookaborted' ], $errors ) ) {
124  throw new PermissionsError( 'patrol', $errors );
125  }
126  // The hook itself has handled any output
127  return $errors;
128  }
129 
130  $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrolled' ) );
131  $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
132  $this->getOutput()->returnToMain( null, $return );
133  return true;
134  }
135 
136  public function onSuccess() {
137  // Required by parent class. Redundant as our onSubmit handles output already.
138  }
139 
140  public function doesWrites() {
141  return true;
142  }
143 }
static rawParam( $raw)
Definition: Message.php:1040
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:208
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges use this to change the tables headers change it to an object instance and return false override the list derivative used $groups Array of ChangesListFilterGroup objects(added in 1.34) 'FileDeleteComplete' null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1535
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1983
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1028
static newFromId( $rcid)
Obtain the recent change with a given rc_id value.
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:218
Mark a revision as patrolled on a page.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
An action which shows a form and does something based on the input from the form. ...
Definition: FormAction.php:28
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:938
An error page which can definitely be safely rendered using the OutputPage.
alterForm(HTMLForm $form)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:773
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:918
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Show an error when a user tries to do something they do not have the necessary permissions for...
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1384
const RC_NEW
Definition: Defines.php:123
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:257
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:198
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1460