Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 116 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
RenameQueueTablePager | |
0.00% |
0 / 116 |
|
0.00% |
0 / 12 |
1260 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
showOpenRequests | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
showClosedRequests | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfoConds | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
30 | |||
getIndexField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isFieldSortable | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
90 | |||
formatValue | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
56 | |||
formatDateTime | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
formatActionValue | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
getDefaultSort | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getFieldNames | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** |
3 | * @section LICENSE |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * http://www.gnu.org/copyleft/gpl.html |
18 | * |
19 | * @file |
20 | * @ingroup SpecialPage |
21 | */ |
22 | |
23 | namespace MediaWiki\Extension\CentralAuth\Special; |
24 | |
25 | use IContextSource; |
26 | use MediaWiki\Extension\CentralAuth\CentralAuthDatabaseManager; |
27 | use MediaWiki\Extension\CentralAuth\GlobalRename\GlobalRenameRequest; |
28 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
29 | use MediaWiki\Html\Html; |
30 | use MediaWiki\Linker\LinkRenderer; |
31 | use MediaWiki\Pager\TablePager; |
32 | use MediaWiki\SpecialPage\SpecialPage; |
33 | use MediaWiki\User\UserNameUtils; |
34 | use MediaWiki\WikiMap\WikiMap; |
35 | use stdClass; |
36 | |
37 | /** |
38 | * Paginated table of search results. |
39 | * @ingroup Pager |
40 | */ |
41 | class RenameQueueTablePager extends TablePager { |
42 | |
43 | /** @var UserNameUtils */ |
44 | private $userNameUtils; |
45 | |
46 | /** |
47 | * @var string |
48 | */ |
49 | protected $mPage; |
50 | |
51 | /** |
52 | * @var string[]|null |
53 | */ |
54 | protected $mFieldNames; |
55 | |
56 | /** |
57 | * @param IContextSource $context |
58 | * @param LinkRenderer $linkRenderer |
59 | * @param CentralAuthDatabaseManager $databaseManager |
60 | * @param UserNameUtils $userNameUtils |
61 | * @param string $page Subpage |
62 | */ |
63 | public function __construct( |
64 | IContextSource $context, |
65 | LinkRenderer $linkRenderer, |
66 | CentralAuthDatabaseManager $databaseManager, |
67 | UserNameUtils $userNameUtils, |
68 | string $page |
69 | ) { |
70 | $this->setContext( $context ); |
71 | $this->mPage = $page; |
72 | $this->mDb = $databaseManager->getCentralDB( DB_REPLICA ); |
73 | $this->userNameUtils = $userNameUtils; |
74 | |
75 | $limit = $this->getRequest()->getInt( 'limit', 25 ); |
76 | // Override default cap of 5000 |
77 | $this->setLimit( min( 100, $limit ) ); |
78 | |
79 | if ( $this->showOpenRequests() ) { |
80 | $this->mDefaultDirection = self::DIR_ASCENDING; |
81 | } else { |
82 | $this->mDefaultDirection = self::DIR_DESCENDING; |
83 | } |
84 | parent::__construct( null, $linkRenderer ); |
85 | } |
86 | |
87 | protected function showOpenRequests() { |
88 | return $this->mPage === SpecialGlobalRenameQueue::PAGE_OPEN_QUEUE; |
89 | } |
90 | |
91 | protected function showClosedRequests() { |
92 | return $this->mPage === SpecialGlobalRenameQueue::PAGE_CLOSED_QUEUE; |
93 | } |
94 | |
95 | /** @inheritDoc */ |
96 | public function getQueryInfo() { |
97 | return [ |
98 | 'tables' => 'renameuser_queue', |
99 | 'fields' => [ |
100 | 'rq_id', |
101 | 'rq_name', |
102 | 'rq_wiki', |
103 | 'rq_newname', |
104 | 'rq_reason', |
105 | 'rq_requested_ts', |
106 | 'rq_status', |
107 | 'rq_completed_ts', |
108 | # 'rq_deleted', not implemented yet |
109 | 'rq_performer', |
110 | 'rq_comments', |
111 | ], |
112 | 'conds' => $this->getQueryInfoConds(), |
113 | ]; |
114 | } |
115 | |
116 | /** @inheritDoc */ |
117 | protected function getQueryInfoConds() { |
118 | $conds = []; |
119 | |
120 | $username = $this->getRequest()->getText( 'username' ); |
121 | $username = $this->userNameUtils->getCanonical( $username ); |
122 | if ( $username ) { |
123 | $conds['rq_name'] = $username; |
124 | } |
125 | |
126 | $newname = $this->getRequest()->getText( 'newname' ); |
127 | $newname = $this->userNameUtils->getCanonical( $newname ); |
128 | if ( $newname ) { |
129 | $conds['rq_newname'] = $newname; |
130 | } |
131 | |
132 | if ( $this->showOpenRequests() ) { |
133 | $conds['rq_status'] = GlobalRenameRequest::PENDING; |
134 | } else { |
135 | $status = $this->getRequest()->getVal( 'status', 'all' ); |
136 | $closedStatuses = [ GlobalRenameRequest::APPROVED, GlobalRenameRequest::REJECTED ]; |
137 | if ( in_array( $status, $closedStatuses ) ) { |
138 | // User requested closed status - either approved or rejected |
139 | $conds['rq_status'] = $status; |
140 | } else { |
141 | // All closed requests |
142 | $conds[] = $this->mDb->expr( 'rq_status', '!=', GlobalRenameRequest::PENDING ); |
143 | } |
144 | } |
145 | |
146 | return $conds; |
147 | } |
148 | |
149 | /** |
150 | * @return array |
151 | */ |
152 | public function getIndexField() { |
153 | return [ [ parent::getIndexField(), 'rq_id' ] ]; |
154 | } |
155 | |
156 | /** |
157 | * @param string $field |
158 | * @return bool |
159 | */ |
160 | public function isFieldSortable( $field ) { |
161 | $sortable = false; |
162 | switch ( $field ) { |
163 | case 'rq_name': |
164 | case 'rq_wiki': |
165 | case 'rq_newname': |
166 | case 'rq_reason': |
167 | case 'rq_requested_ts': |
168 | case 'rq_status': |
169 | case 'rq_completed_ts': |
170 | case 'rq_performer': |
171 | $sortable = true; |
172 | } |
173 | return $sortable; |
174 | } |
175 | |
176 | /** |
177 | * @param string $name The database field name |
178 | * @param string|null $value The value retrieved from the database |
179 | * @return string HTML to place inside table cell |
180 | */ |
181 | public function formatValue( $name, $value ) { |
182 | $formatted = htmlspecialchars( $value ); |
183 | switch ( $name ) { |
184 | case 'rq_requested_ts': |
185 | case 'rq_completed_ts': |
186 | $formatted = $this->formatDateTime( $value ); |
187 | break; |
188 | case 'rq_name': |
189 | case 'rq_newname': |
190 | $title = SpecialPage::getTitleFor( 'CentralAuth', $value ); |
191 | $formatted = $this->getLinkRenderer()->makeLink( $title, $value ); |
192 | break; |
193 | case 'rq_performer': |
194 | $renamer = CentralAuthUser::newFromId( (int)$value ); |
195 | $formatted = '<span class="plainlinks">' . |
196 | WikiMap::foreignUserLink( |
197 | $renamer->getHomeWiki(), |
198 | $renamer->getName(), |
199 | $renamer->getName() |
200 | ) . '</span>'; |
201 | break; |
202 | case 'row_actions': |
203 | $formatted = $this->formatActionValue( $this->mCurrentRow ); |
204 | break; |
205 | } |
206 | return $formatted; |
207 | } |
208 | |
209 | /** |
210 | * @param string $value |
211 | * @return string Formatted table cell contents |
212 | */ |
213 | protected function formatDateTime( $value ) { |
214 | return htmlspecialchars( |
215 | $this->getLanguage()->userTimeAndDate( $value, $this->getUser() ) |
216 | ); |
217 | } |
218 | |
219 | /** |
220 | * @param stdClass $row |
221 | * @return string Formatted table cell contents |
222 | */ |
223 | protected function formatActionValue( $row ) { |
224 | $target = SpecialGlobalRenameQueue::PAGE_PROCESS_REQUEST . '/' . $row->rq_id; |
225 | if ( $this->showOpenRequests() ) { |
226 | $label = 'globalrenamequeue-action-address'; |
227 | } else { |
228 | $target .= '/' . SpecialGlobalRenameQueue::ACTION_VIEW; |
229 | $label = 'globalrenamequeue-action-view'; |
230 | } |
231 | return Html::element( 'a', |
232 | [ |
233 | 'href' => SpecialPage::getTitleFor( 'GlobalRenameQueue', $target )->getFullURL(), |
234 | ], |
235 | $this->msg( $label )->text() |
236 | ); |
237 | } |
238 | |
239 | /** |
240 | * @return string |
241 | */ |
242 | public function getDefaultSort() { |
243 | if ( $this->showOpenRequests() ) { |
244 | return 'rq_requested_ts'; |
245 | } else { |
246 | return 'rq_completed_ts'; |
247 | } |
248 | } |
249 | |
250 | /** |
251 | * @return string[] |
252 | */ |
253 | public function getFieldNames() { |
254 | if ( $this->mFieldNames === null ) { |
255 | $this->mFieldNames = [ |
256 | 'rq_name' => $this->msg( 'globalrenamequeue-column-rq-name' )->text(), |
257 | 'rq_newname' => $this->msg( 'globalrenamequeue-column-rq-newname' )->text(), |
258 | 'rq_wiki' => $this->msg( 'globalrenamequeue-column-rq-wiki' )->text(), |
259 | 'rq_requested_ts' => |
260 | $this->msg( 'globalrenamequeue-column-rq-requested-ts' )->text(), |
261 | 'row_actions' => $this->msg( 'globalrenamequeue-column-row-actions' )->text(), |
262 | ]; |
263 | |
264 | if ( $this->showClosedRequests() ) { |
265 | // Remove action column |
266 | array_pop( $this->mFieldNames ); |
267 | |
268 | $this->mFieldNames += [ |
269 | 'rq_completed_ts' => |
270 | $this->msg( 'globalrenamequeue-column-rq-completed-ts' )->text(), |
271 | 'rq_status' => $this->msg( 'globalrenamequeue-column-rq-status' )->text(), |
272 | 'rq_performer' => $this->msg( 'globalrenamequeue-column-rq-performer' )->text(), |
273 | 'row_actions' => $this->msg( 'globalrenamequeue-column-row-actions' )->text(), |
274 | ]; |
275 | } |
276 | } |
277 | return $this->mFieldNames; |
278 | } |
279 | } |