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.
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.
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
22 namespace MediaWiki\Pager
;
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
;
35 class ProtectedTitlesPager
extends AlphabeticPager
{
37 /** @var string|null */
43 private LinkBatchFactory
$linkBatchFactory;
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
53 public function __construct(
54 IContextSource
$context,
55 LinkRenderer
$linkRenderer,
56 LinkBatchFactory
$linkBatchFactory,
57 IConnectionProvider
$dbProvider,
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;
69 protected function doBatchLookups() {
70 $this->mResult
->seek( 0 );
71 $lb = $this->linkBatchFactory
->newLinkBatch();
73 foreach ( $this->mResult
as $row ) {
74 $lb->add( $row->pt_namespace
, $row->pt_title
);
80 public function formatRow( $row ) {
81 $title = Title
::makeTitleSafe( $row->pt_namespace
, $row->pt_title
);
83 return Html
::rawElement(
88 [ 'class' => 'mw-invalidtitle' ],
89 Linker
::getInvalidTitleDescription(
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
) :
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 )
116 return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
122 public function getQueryInfo() {
123 $dbr = $this->getDatabase();
125 $dbr->expr( 'pt_expiry', '>', $this->mDb
->timestamp() )
126 ->or( 'pt_expiry', '=', null ),
128 if ( $this->level
) {
129 $conds['pt_create_perm'] = $this->level
;
132 if ( $this->namespace !== null ) {
133 $conds[] = $dbr->expr( 'pt_namespace', '=', $this->namespace );
137 'tables' => 'protected_titles',
138 'fields' => [ 'pt_namespace', 'pt_title', 'pt_create_perm',
139 'pt_expiry', 'pt_timestamp' ],
144 public function getIndexField() {
145 return [ [ 'pt_timestamp', 'pt_namespace', 'pt_title' ] ];
150 * Retain the old class name for backwards compatibility.
151 * @deprecated since 1.41
153 class_alias( ProtectedTitlesPager
::class, 'ProtectedTitlesPager' );