Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 57 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ProtectedTitlesPager | |
0.00% |
0 / 56 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
doBatchLookups | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
formatRow | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
20 | |||
getQueryInfo | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
getIndexField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | * @ingroup Pager |
20 | */ |
21 | |
22 | namespace MediaWiki\Pager; |
23 | |
24 | use MediaWiki\Cache\LinkBatchFactory; |
25 | use MediaWiki\Context\IContextSource; |
26 | use MediaWiki\Html\Html; |
27 | use MediaWiki\Linker\Linker; |
28 | use MediaWiki\Linker\LinkRenderer; |
29 | use MediaWiki\Title\Title; |
30 | use Wikimedia\Rdbms\IConnectionProvider; |
31 | |
32 | /** |
33 | * @ingroup Pager |
34 | */ |
35 | class ProtectedTitlesPager extends AlphabeticPager { |
36 | |
37 | /** @var string|null */ |
38 | private $level; |
39 | |
40 | /** @var int|null */ |
41 | private $namespace; |
42 | |
43 | private LinkBatchFactory $linkBatchFactory; |
44 | |
45 | /** |
46 | * @param IContextSource $context |
47 | * @param LinkRenderer $linkRenderer |
48 | * @param LinkBatchFactory $linkBatchFactory |
49 | * @param IConnectionProvider $dbProvider |
50 | * @param string|null $level |
51 | * @param int|null $namespace |
52 | */ |
53 | public function __construct( |
54 | IContextSource $context, |
55 | LinkRenderer $linkRenderer, |
56 | LinkBatchFactory $linkBatchFactory, |
57 | IConnectionProvider $dbProvider, |
58 | $level, |
59 | $namespace |
60 | ) { |
61 | // Set database before parent constructor to avoid setting it there |
62 | $this->mDb = $dbProvider->getReplicaDatabase(); |
63 | $this->level = $level; |
64 | $this->namespace = $namespace; |
65 | parent::__construct( $context, $linkRenderer ); |
66 | $this->linkBatchFactory = $linkBatchFactory; |
67 | } |
68 | |
69 | protected function doBatchLookups() { |
70 | $this->mResult->seek( 0 ); |
71 | $lb = $this->linkBatchFactory->newLinkBatch(); |
72 | |
73 | foreach ( $this->mResult as $row ) { |
74 | $lb->add( $row->pt_namespace, $row->pt_title ); |
75 | } |
76 | |
77 | $lb->execute(); |
78 | } |
79 | |
80 | public function formatRow( $row ) { |
81 | $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title ); |
82 | if ( !$title ) { |
83 | return Html::rawElement( |
84 | 'li', |
85 | [], |
86 | Html::element( |
87 | 'span', |
88 | [ 'class' => 'mw-invalidtitle' ], |
89 | Linker::getInvalidTitleDescription( |
90 | $this->getContext(), |
91 | $row->pt_namespace, |
92 | $row->pt_title |
93 | ) |
94 | ) |
95 | ) . "\n"; |
96 | } |
97 | |
98 | $link = $this->getLinkRenderer()->makeLink( $title ); |
99 | // Messages: restriction-level-sysop, restriction-level-autoconfirmed |
100 | $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped(); |
101 | $lang = $this->getLanguage(); |
102 | $expiry = strlen( $row->pt_expiry ) ? |
103 | $lang->formatExpiry( $row->pt_expiry, TS_MW ) : |
104 | 'infinity'; |
105 | |
106 | if ( $expiry !== 'infinity' ) { |
107 | $user = $this->getUser(); |
108 | $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg( |
109 | 'protect-expiring-local', |
110 | $lang->userTimeAndDate( $expiry, $user ), |
111 | $lang->userDate( $expiry, $user ), |
112 | $lang->userTime( $expiry, $user ) |
113 | )->escaped(); |
114 | } |
115 | |
116 | return '<li>' . $lang->specialList( $link, $description ) . "</li>\n"; |
117 | } |
118 | |
119 | /** |
120 | * @return array |
121 | */ |
122 | public function getQueryInfo() { |
123 | $dbr = $this->getDatabase(); |
124 | $conds = [ |
125 | $dbr->expr( 'pt_expiry', '>', $this->mDb->timestamp() ) |
126 | ->or( 'pt_expiry', '=', null ), |
127 | ]; |
128 | if ( $this->level ) { |
129 | $conds['pt_create_perm'] = $this->level; |
130 | } |
131 | |
132 | if ( $this->namespace !== null ) { |
133 | $conds[] = $dbr->expr( 'pt_namespace', '=', $this->namespace ); |
134 | } |
135 | |
136 | return [ |
137 | 'tables' => 'protected_titles', |
138 | 'fields' => [ 'pt_namespace', 'pt_title', 'pt_create_perm', |
139 | 'pt_expiry', 'pt_timestamp' ], |
140 | 'conds' => $conds |
141 | ]; |
142 | } |
143 | |
144 | public function getIndexField() { |
145 | return [ [ 'pt_timestamp', 'pt_namespace', 'pt_title' ] ]; |
146 | } |
147 | } |
148 | |
149 | /** |
150 | * Retain the old class name for backwards compatibility. |
151 | * @deprecated since 1.41 |
152 | */ |
153 | class_alias( ProtectedTitlesPager::class, 'ProtectedTitlesPager' ); |