Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProtectedTitlesPager
0.00% covered (danger)
0.00%
0 / 56
0.00% covered (danger)
0.00%
0 / 5
132
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 doBatchLookups
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 formatRow
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
20
 getQueryInfo
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
12
 getIndexField
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
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
22namespace MediaWiki\Pager;
23
24use MediaWiki\Cache\LinkBatchFactory;
25use MediaWiki\Context\IContextSource;
26use MediaWiki\Html\Html;
27use MediaWiki\Linker\Linker;
28use MediaWiki\Linker\LinkRenderer;
29use MediaWiki\Title\Title;
30use Wikimedia\Rdbms\IConnectionProvider;
31
32/**
33 * @ingroup Pager
34 */
35class ProtectedTitlesPager extends AlphabeticPager {
36
37    /**
38     * @var array
39     */
40    public $mConds;
41
42    /** @var string|null */
43    private $level;
44
45    /** @var int|null */
46    private $namespace;
47
48    private LinkBatchFactory $linkBatchFactory;
49
50    /**
51     * @param IContextSource $context
52     * @param LinkRenderer $linkRenderer
53     * @param LinkBatchFactory $linkBatchFactory
54     * @param IConnectionProvider $dbProvider
55     * @param array $conds
56     * @param string|null $type
57     * @param string|null $level
58     * @param int|null $namespace
59     * @param string|null $sizetype
60     * @param int|null $size
61     */
62    public function __construct(
63        IContextSource $context,
64        LinkRenderer $linkRenderer,
65        LinkBatchFactory $linkBatchFactory,
66        IConnectionProvider $dbProvider,
67        $conds,
68        $type,
69        $level,
70        $namespace,
71        $sizetype,
72        $size
73    ) {
74        // Set database before parent constructor to avoid setting it there
75        $this->mDb = $dbProvider->getReplicaDatabase();
76        $this->mConds = $conds;
77        $this->level = $level;
78        $this->namespace = $namespace;
79        parent::__construct( $context, $linkRenderer );
80        $this->linkBatchFactory = $linkBatchFactory;
81    }
82
83    protected function doBatchLookups() {
84        $this->mResult->seek( 0 );
85        $lb = $this->linkBatchFactory->newLinkBatch();
86
87        foreach ( $this->mResult as $row ) {
88            $lb->add( $row->pt_namespace, $row->pt_title );
89        }
90
91        $lb->execute();
92    }
93
94    public function formatRow( $row ) {
95        $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
96        if ( !$title ) {
97            return Html::rawElement(
98                'li',
99                [],
100                Html::element(
101                    'span',
102                    [ 'class' => 'mw-invalidtitle' ],
103                    Linker::getInvalidTitleDescription(
104                        $this->getContext(),
105                        $row->pt_namespace,
106                        $row->pt_title
107                    )
108                )
109            ) . "\n";
110        }
111
112        $link = $this->getLinkRenderer()->makeLink( $title );
113        // Messages: restriction-level-sysop, restriction-level-autoconfirmed
114        $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
115        $lang = $this->getLanguage();
116        $expiry = strlen( $row->pt_expiry ) ?
117            $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
118            'infinity';
119
120        if ( $expiry !== 'infinity' ) {
121            $user = $this->getUser();
122            $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
123                'protect-expiring-local',
124                $lang->userTimeAndDate( $expiry, $user ),
125                $lang->userDate( $expiry, $user ),
126                $lang->userTime( $expiry, $user )
127            )->escaped();
128        }
129
130        return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
131    }
132
133    /**
134     * @return array
135     */
136    public function getQueryInfo() {
137        $dbr = $this->getDatabase();
138        $conds = $this->mConds;
139        $conds[] = $dbr->expr( 'pt_expiry', '>', $this->mDb->timestamp() )
140            ->or( 'pt_expiry', '=', null );
141        if ( $this->level ) {
142            $conds['pt_create_perm'] = $this->level;
143        }
144
145        if ( $this->namespace !== null ) {
146            $conds[] = $dbr->expr( 'pt_namespace', '=', $this->namespace );
147        }
148
149        return [
150            'tables' => 'protected_titles',
151            'fields' => [ 'pt_namespace', 'pt_title', 'pt_create_perm',
152                'pt_expiry', 'pt_timestamp' ],
153            'conds' => $conds
154        ];
155    }
156
157    public function getIndexField() {
158        return [ [ 'pt_timestamp', 'pt_namespace', 'pt_title' ] ];
159    }
160}
161
162/**
163 * Retain the old class name for backwards compatibility.
164 * @deprecated since 1.41
165 */
166class_alias( ProtectedTitlesPager::class, 'ProtectedTitlesPager' );