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 use MediaWiki\Linker\LinkRenderer
;
23 use MediaWiki\MediaWikiServices
;
25 class ProtectedPagesPager
extends TablePager
{
28 private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect;
31 * @param SpecialPage $form
34 * @param string $level
35 * @param int $namespace
36 * @param string $sizetype
38 * @param bool $indefonly
39 * @param bool $cascadeonly
40 * @param bool $noredirect
41 * @param LinkRenderer $linkRenderer
43 public function __construct( $form, $conds, $type, $level, $namespace,
44 $sizetype, $size, $indefonly, $cascadeonly, $noredirect,
45 LinkRenderer
$linkRenderer
47 parent
::__construct( $form->getContext(), $linkRenderer );
48 $this->mConds
= $conds;
49 $this->type
= $type ?
: 'edit';
50 $this->level
= $level;
51 $this->namespace = $namespace;
52 $this->sizetype
= $sizetype;
53 $this->size
= intval( $size );
54 $this->indefonly
= (bool)$indefonly;
55 $this->cascadeonly
= (bool)$cascadeonly;
56 $this->noredirect
= (bool)$noredirect;
59 function preprocessResults( $result ) {
60 # Do a link batch query
64 foreach ( $result as $row ) {
65 $lb->add( $row->page_namespace
, $row->page_title
);
66 // field is nullable, maybe null on old protections
67 if ( $row->log_user
!== null ) {
68 $userids[] = $row->log_user
;
72 // fill LinkBatch with user page and user talk
73 if ( count( $userids ) ) {
74 $userCache = UserCache
::singleton();
75 $userCache->doQuery( $userids, [], __METHOD__
);
76 foreach ( $userids as $userid ) {
77 $name = $userCache->getProp( $userid, 'name' );
78 if ( $name !== false ) {
79 $lb->add( NS_USER
, $name );
80 $lb->add( NS_USER_TALK
, $name );
88 function getFieldNames() {
89 static $headers = null;
91 if ( $headers == [] ) {
93 'log_timestamp' => 'protectedpages-timestamp',
94 'pr_page' => 'protectedpages-page',
95 'pr_expiry' => 'protectedpages-expiry',
96 'log_user' => 'protectedpages-performer',
97 'pr_params' => 'protectedpages-params',
98 'log_comment' => 'protectedpages-reason',
100 foreach ( $headers as $key => $val ) {
101 $headers[$key] = $this->msg( $val )->text();
109 * @param string $field
110 * @param string $value
111 * @return string HTML
112 * @throws MWException
114 function formatValue( $field, $value ) {
115 /** @var object $row */
116 $row = $this->mCurrentRow
;
117 $linkRenderer = $this->getLinkRenderer();
120 case 'log_timestamp':
121 // when timestamp is null, this is a old protection row
122 if ( $value === null ) {
123 $formatted = Html
::rawElement(
125 [ 'class' => 'mw-protectedpages-unknown' ],
126 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
129 $formatted = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
130 $value, $this->getUser() ) );
135 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
137 $formatted = Html
::element(
139 [ 'class' => 'mw-invalidtitle' ],
140 Linker
::getInvalidTitleDescription(
142 $row->page_namespace
,
147 $formatted = $linkRenderer->makeLink( $title );
149 if ( !is_null( $row->page_len
) ) {
150 $formatted .= $this->getLanguage()->getDirMark() .
151 ' ' . Html
::rawElement(
153 [ 'class' => 'mw-protectedpages-length' ],
154 Linker
::formatRevisionSize( $row->page_len
)
160 $formatted = htmlspecialchars( $this->getLanguage()->formatExpiry(
161 $value, /* User preference timezone */true ) );
162 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
163 if ( $title && MediaWikiServices
::getInstance()
164 ->getPermissionManager()
165 ->userHasRight( $this->getUser(), 'protect' )
167 $changeProtection = $linkRenderer->makeKnownLink(
169 $this->msg( 'protect_change' )->text(),
171 [ 'action' => 'unprotect' ]
173 $formatted .= ' ' . Html
::rawElement(
175 [ 'class' => 'mw-protectedpages-actions' ],
176 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
182 // when timestamp is null, this is a old protection row
183 if ( $row->log_timestamp
=== null ) {
184 $formatted = Html
::rawElement(
186 [ 'class' => 'mw-protectedpages-unknown' ],
187 $this->msg( 'protectedpages-unknown-performer' )->escaped()
190 $username = UserCache
::singleton()->getProp( $value, 'name' );
191 if ( LogEventsList
::userCanBitfield(
193 LogPage
::DELETED_USER
,
196 if ( $username === false ) {
197 $formatted = htmlspecialchars( $value );
199 $formatted = Linker
::userLink( $value, $username )
200 . Linker
::userToolLinks( $value, $username );
203 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
205 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
206 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
213 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
214 $params[] = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
215 if ( $row->pr_cascade
) {
216 $params[] = $this->msg( 'protect-summary-cascade' )->escaped();
218 $formatted = $this->getLanguage()->commaList( $params );
222 // when timestamp is null, this is an old protection row
223 if ( $row->log_timestamp
=== null ) {
224 $formatted = Html
::rawElement(
226 [ 'class' => 'mw-protectedpages-unknown' ],
227 $this->msg( 'protectedpages-unknown-reason' )->escaped()
230 if ( LogEventsList
::userCanBitfield(
232 LogPage
::DELETED_COMMENT
,
235 $value = CommentStore
::getStore()->getComment( 'log_comment', $row )->text
;
236 $formatted = Linker
::formatComment( $value ??
'' );
238 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
240 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
241 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
247 throw new MWException( "Unknown field '$field'" );
253 function getQueryInfo() {
254 $conds = $this->mConds
;
255 $conds[] = 'pr_expiry > ' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
256 ' OR pr_expiry IS NULL';
257 $conds[] = 'page_id=pr_page';
258 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
260 if ( $this->sizetype
== 'min' ) {
261 $conds[] = 'page_len>=' . $this->size
;
262 } elseif ( $this->sizetype
== 'max' ) {
263 $conds[] = 'page_len<=' . $this->size
;
266 if ( $this->indefonly
) {
267 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
268 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
270 if ( $this->cascadeonly
) {
271 $conds[] = 'pr_cascade = 1';
273 if ( $this->noredirect
) {
274 $conds[] = 'page_is_redirect = 0';
277 if ( $this->level
) {
278 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
280 if ( !is_null( $this->namespace ) ) {
281 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
284 $commentQuery = CommentStore
::getStore()->getJoin( 'log_comment' );
285 $actorQuery = ActorMigration
::newMigration()->getJoin( 'log_user' );
289 'page', 'page_restrictions', 'log_search',
290 'logparen' => [ 'logging' ] +
$commentQuery['tables'] +
$actorQuery['tables'],
303 ] +
$commentQuery['fields'] +
$actorQuery['fields'],
308 'ls_field' => 'pr_id', 'ls_value = ' . $this->mDb
->buildStringCast( 'pr_id' )
316 ] +
$commentQuery['joins'] +
$actorQuery['joins']
320 protected function getTableClass() {
321 return parent
::getTableClass() . ' mw-protectedpages';
324 function getIndexField() {
328 function getDefaultSort() {
332 function isFieldSortable( $field ) {
333 // no index for sorting exists