MediaWiki  1.29.2
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 getRecentChange( $data = null ) {
46  $rc = null;
47  // Note: This works both on initial GET url and after submitting the form
48  $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
49  if ( $rcId ) {
50  $rc = RecentChange::newFromId( $rcId );
51  }
52  if ( !$rc ) {
53  throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
54  }
55  return $rc;
56  }
57 
58  protected function preText() {
59  $rc = $this->getRecentChange();
60  $title = $rc->getTitle();
61  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
62 
63  // Based on logentry-patrol-patrol (see PatrolLogFormatter)
64  $revId = $rc->getAttribute( 'rc_this_oldid' );
65  $query = [
66  'curid' => $rc->getAttribute( 'rc_cur_id' ),
67  'diff' => $revId,
68  'oldid' => $rc->getAttribute( 'rc_last_oldid' )
69  ];
70  $revlink = $linkRenderer->makeLink( $title, $revId, [], $query );
71  $pagelink = $linkRenderer->makeLink( $title, $title->getPrefixedText() );
72 
73  return $this->msg( 'confirm-markpatrolled-top' )->params(
74  $title->getPrefixedText(),
75  // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
76  Message::rawParam( $pagelink ),
77  Message::rawParam( $revlink )
78  )->parse();
79  }
80 
81  protected function alterForm( HTMLForm $form ) {
82  $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
83  $form->setTokenSalt( 'patrol' );
84  $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
85  }
86 
90  public function onSubmit( $data ) {
91  $user = $this->getUser();
92  $rc = $this->getRecentChange( $data );
93  $errors = $rc->doMarkPatrolled( $user );
94 
95  if ( in_array( [ 'rcpatroldisabled' ], $errors ) ) {
96  throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
97  }
98 
99  // Guess where the user came from
100  // TODO: Would be nice to see where the user actually came from
101  if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) {
102  $returnTo = 'Newpages';
103  } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
104  $returnTo = 'Newfiles';
105  } else {
106  $returnTo = 'Recentchanges';
107  }
108  $return = SpecialPage::getTitleFor( $returnTo );
109 
110  if ( in_array( [ 'markedaspatrollederror-noautopatrol' ], $errors ) ) {
111  $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrollederror' ) );
112  $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
113  $this->getOutput()->returnToMain( null, $return );
114  return true;
115  }
116 
117  if ( $errors ) {
118  if ( !in_array( [ 'hookaborted' ], $errors ) ) {
119  throw new PermissionsError( 'patrol', $errors );
120  }
121  // The hook itself has handled any output
122  return $errors;
123  }
124 
125  $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrolled' ) );
126  $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
127  $this->getOutput()->returnToMain( null, $return );
128  return true;
129  }
130 
131  public function onSuccess() {
132  // Required by parent class. Redundant as our onSubmit handles output already.
133  }
134 
135  public function doesWrites() {
136  return true;
137  }
138 }
Action\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:197
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
HTMLForm\setTokenSalt
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:991
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:246
FormAction
An action which shows a form and does something based on the input from the form.
Definition: FormAction.php:28
MarkpatrolledAction\preText
preText()
Add pre- or post-text to the form.
Definition: MarkpatrolledAction.php:58
MarkpatrolledAction\getDescription
getDescription()
Returns the description that goes below the <h1> tag.
Definition: MarkpatrolledAction.php:36
$linkRenderer
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:1956
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:82
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:28
php
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
MarkpatrolledAction\getName
getName()
Return the name of the action this object responds to.
Definition: MarkpatrolledAction.php:32
$query
null for the 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:1572
MarkpatrolledAction\alterForm
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
Definition: MarkpatrolledAction.php:81
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
HTMLForm\addHiddenField
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:901
MarkpatrolledAction\onSuccess
onSuccess()
Do something exciting on successful processing of the form.
Definition: MarkpatrolledAction.php:131
MarkpatrolledAction\getRestriction
getRestriction()
Get the permission required to perform this action.
Definition: MarkpatrolledAction.php:41
RecentChange\newFromId
static newFromId( $rcid)
Obtain the recent change with a given rc_id value.
Definition: RecentChange.php:172
Action\getUser
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:217
MarkpatrolledAction\onSubmit
onSubmit( $data)
Definition: MarkpatrolledAction.php:90
RC_NEW
const RC_NEW
Definition: Defines.php:141
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1359
Action\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:256
Action\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:207
$revId
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context $revId
Definition: hooks.txt:1049
MediaWikiServices
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
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
MarkpatrolledAction\doesWrites
doesWrites()
Indicates whether this action may perform database writes.
Definition: MarkpatrolledAction.php:135
MarkpatrolledAction
Mark a revision as patrolled on a page.
Definition: MarkpatrolledAction.php:30
MarkpatrolledAction\getRecentChange
getRecentChange( $data=null)
Definition: MarkpatrolledAction.php:45
$returnTo
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect & $returnTo
Definition: hooks.txt:2536
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:128