MediaWiki
master
MarkpatrolledAction.php
Go to the documentation of this file.
1
<?php
23
use
MediaWiki\Context\IContextSource
;
24
use
MediaWiki\Linker\LinkRenderer
;
25
use
MediaWiki\Message\Message
;
26
use
MediaWiki\SpecialPage\SpecialPage
;
27
33
class
MarkpatrolledAction
extends
FormAction
{
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
getRequest()
getAuthority
getAuthority()
RC_NEW
const RC_NEW
Definition
Defines.php:117
Action\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition
Action.php:141
Action\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition
Action.php:223
Article
Legacy class representing an editable page and handling UI for some page actions.
Definition
Article.php:67
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition
ErrorPageError.php:30
FormAction
An action which shows a form and does something based on the input from the form.
Definition
FormAction.php:32
MarkpatrolledAction
Mark a revision as patrolled on a page.
Definition
MarkpatrolledAction.php:33
MarkpatrolledAction\getName
getName()
Return the name of the action this object responds to.
Definition
MarkpatrolledAction.php:51
MarkpatrolledAction\alterForm
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
Definition
MarkpatrolledAction.php:103
MarkpatrolledAction\doesWrites
doesWrites()
Definition
MarkpatrolledAction.php:157
MarkpatrolledAction\usesOOUI
usesOOUI()
Whether the form should use OOUI.
Definition
MarkpatrolledAction.php:64
MarkpatrolledAction\getRecentChange
getRecentChange( $data=null)
Definition
MarkpatrolledAction.php:68
MarkpatrolledAction\getDescription
getDescription()
Returns the description that goes below the <h1> element.
Definition
MarkpatrolledAction.php:55
MarkpatrolledAction\getRestriction
getRestriction()
Get the permission required to perform this action.
Definition
MarkpatrolledAction.php:60
MarkpatrolledAction\onSuccess
onSuccess()
Do something exciting on successful processing of the form.
Definition
MarkpatrolledAction.php:153
MarkpatrolledAction\__construct
__construct(Article $article, IContextSource $context, LinkRenderer $linkRenderer)
Definition
MarkpatrolledAction.php:42
MarkpatrolledAction\onSubmit
onSubmit( $data)
Definition
MarkpatrolledAction.php:113
MarkpatrolledAction\preText
preText()
Add pre- or post-text to the form.
Definition
MarkpatrolledAction.php:81
MediaWiki\Linker\LinkRenderer
Class that generates HTML for internal links.
Definition
LinkRenderer.php:45
MediaWiki\Message\Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition
Message.php:158
MediaWiki\SpecialPage\SpecialPage
Parent class for all special pages.
Definition
SpecialPage.php:66
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition
PermissionsError.php:34
MediaWiki\Context\IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition
IContextSource.php:71
includes
actions
MarkpatrolledAction.php
Generated on Wed May 8 2024 00:22:53 for MediaWiki by
1.10.0