Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 56 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
MarkpatrolledAction | |
0.00% |
0 / 56 |
|
0.00% |
0 / 11 |
420 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRestriction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
usesOOUI | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRecentChange | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
preText | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
2 | |||
alterForm | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
onSubmit | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
56 | |||
onSuccess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doesWrites | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Copyright © 2011 Alexandre Emsenhuber |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
18 | * |
19 | * @file |
20 | * @ingroup Actions |
21 | */ |
22 | |
23 | use MediaWiki\Context\IContextSource; |
24 | use MediaWiki\Linker\LinkRenderer; |
25 | use MediaWiki\Message\Message; |
26 | use MediaWiki\SpecialPage\SpecialPage; |
27 | |
28 | /** |
29 | * Mark a revision as patrolled on a page |
30 | * |
31 | * @ingroup Actions |
32 | */ |
33 | class MarkpatrolledAction extends FormAction { |
34 | |
35 | private LinkRenderer $linkRenderer; |
36 | |
37 | /** |
38 | * @param Article $article |
39 | * @param IContextSource $context |
40 | * @param LinkRenderer $linkRenderer |
41 | */ |
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 | |
109 | /** |
110 | * @param array $data |
111 | * @return bool|array True for success, false for didn't-try, array of errors on failure |
112 | */ |
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 | } |