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
;
24 class ProtectedPagesPager
extends TablePager
{
27 private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect;
30 * @param SpecialPage $form
33 * @param string $level
34 * @param int $namespace
35 * @param string $sizetype
37 * @param bool $indefonly
38 * @param bool $cascadeonly
39 * @param bool $noredirect
40 * @param LinkRenderer $linkRenderer
42 public function __construct( $form, $conds, $type, $level, $namespace,
43 $sizetype, $size, $indefonly, $cascadeonly, $noredirect,
44 LinkRenderer
$linkRenderer
46 parent
::__construct( $form->getContext(), $linkRenderer );
47 $this->mConds
= $conds;
48 $this->type
= $type ?
: 'edit';
49 $this->level
= $level;
50 $this->namespace = $namespace;
51 $this->sizetype
= $sizetype;
52 $this->size
= intval( $size );
53 $this->indefonly
= (bool)$indefonly;
54 $this->cascadeonly
= (bool)$cascadeonly;
55 $this->noredirect
= (bool)$noredirect;
58 function preprocessResults( $result ) {
59 # Do a link batch query
63 foreach ( $result as $row ) {
64 $lb->add( $row->page_namespace
, $row->page_title
);
65 // field is nullable, maybe null on old protections
66 if ( $row->log_user
!== null ) {
67 $userids[] = $row->log_user
;
71 // fill LinkBatch with user page and user talk
72 if ( count( $userids ) ) {
73 $userCache = UserCache
::singleton();
74 $userCache->doQuery( $userids, [], __METHOD__
);
75 foreach ( $userids as $userid ) {
76 $name = $userCache->getProp( $userid, 'name' );
77 if ( $name !== false ) {
78 $lb->add( NS_USER
, $name );
79 $lb->add( NS_USER_TALK
, $name );
87 function getFieldNames() {
88 static $headers = null;
90 if ( $headers == [] ) {
92 'log_timestamp' => 'protectedpages-timestamp',
93 'pr_page' => 'protectedpages-page',
94 'pr_expiry' => 'protectedpages-expiry',
95 'log_user' => 'protectedpages-performer',
96 'pr_params' => 'protectedpages-params',
97 'log_comment' => 'protectedpages-reason',
99 foreach ( $headers as $key => $val ) {
100 $headers[$key] = $this->msg( $val )->text();
108 * @param string $field
109 * @param string $value
110 * @return string HTML
111 * @throws MWException
113 function formatValue( $field, $value ) {
114 /** @var object $row */
115 $row = $this->mCurrentRow
;
116 $linkRenderer = $this->getLinkRenderer();
119 case 'log_timestamp':
120 // when timestamp is null, this is a old protection row
121 if ( $value === null ) {
122 $formatted = Html
::rawElement(
124 [ 'class' => 'mw-protectedpages-unknown' ],
125 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
128 $formatted = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
129 $value, $this->getUser() ) );
134 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
136 $formatted = Html
::element(
138 [ 'class' => 'mw-invalidtitle' ],
139 Linker
::getInvalidTitleDescription(
141 $row->page_namespace
,
146 $formatted = $linkRenderer->makeLink( $title );
148 if ( !is_null( $row->page_len
) ) {
149 $formatted .= $this->getLanguage()->getDirMark() .
150 ' ' . Html
::rawElement(
152 [ 'class' => 'mw-protectedpages-length' ],
153 Linker
::formatRevisionSize( $row->page_len
)
159 $formatted = htmlspecialchars( $this->getLanguage()->formatExpiry(
160 $value, /* User preference timezone */true ) );
161 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
162 if ( $this->getUser()->isAllowed( 'protect' ) && $title ) {
163 $changeProtection = $linkRenderer->makeKnownLink(
165 $this->msg( 'protect_change' )->text(),
167 [ 'action' => 'unprotect' ]
169 $formatted .= ' ' . Html
::rawElement(
171 [ 'class' => 'mw-protectedpages-actions' ],
172 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
178 // when timestamp is null, this is a old protection row
179 if ( $row->log_timestamp
=== null ) {
180 $formatted = Html
::rawElement(
182 [ 'class' => 'mw-protectedpages-unknown' ],
183 $this->msg( 'protectedpages-unknown-performer' )->escaped()
186 $username = UserCache
::singleton()->getProp( $value, 'name' );
187 if ( LogEventsList
::userCanBitfield(
189 LogPage
::DELETED_USER
,
192 if ( $username === false ) {
193 $formatted = htmlspecialchars( $value );
195 $formatted = Linker
::userLink( $value, $username )
196 . Linker
::userToolLinks( $value, $username );
199 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
201 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
202 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
209 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
210 $params[] = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
211 if ( $row->pr_cascade
) {
212 $params[] = $this->msg( 'protect-summary-cascade' )->escaped();
214 $formatted = $this->getLanguage()->commaList( $params );
218 // when timestamp is null, this is an old protection row
219 if ( $row->log_timestamp
=== null ) {
220 $formatted = Html
::rawElement(
222 [ 'class' => 'mw-protectedpages-unknown' ],
223 $this->msg( 'protectedpages-unknown-reason' )->escaped()
226 if ( LogEventsList
::userCanBitfield(
228 LogPage
::DELETED_COMMENT
,
231 $value = CommentStore
::getStore()->getComment( 'log_comment', $row )->text
;
232 $formatted = Linker
::formatComment( $value ??
'' );
234 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
236 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
237 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
243 throw new MWException( "Unknown field '$field'" );
249 function getQueryInfo() {
250 $conds = $this->mConds
;
251 $conds[] = 'pr_expiry > ' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
252 ' OR pr_expiry IS NULL';
253 $conds[] = 'page_id=pr_page';
254 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
256 if ( $this->sizetype
== 'min' ) {
257 $conds[] = 'page_len>=' . $this->size
;
258 } elseif ( $this->sizetype
== 'max' ) {
259 $conds[] = 'page_len<=' . $this->size
;
262 if ( $this->indefonly
) {
263 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
264 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
266 if ( $this->cascadeonly
) {
267 $conds[] = 'pr_cascade = 1';
269 if ( $this->noredirect
) {
270 $conds[] = 'page_is_redirect = 0';
273 if ( $this->level
) {
274 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
276 if ( !is_null( $this->namespace ) ) {
277 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
280 $commentQuery = CommentStore
::getStore()->getJoin( 'log_comment' );
281 $actorQuery = ActorMigration
::newMigration()->getJoin( 'log_user' );
285 'page', 'page_restrictions', 'log_search',
286 'logparen' => [ 'logging' ] +
$commentQuery['tables'] +
$actorQuery['tables'],
299 ] +
$commentQuery['fields'] +
$actorQuery['fields'],
304 'ls_field' => 'pr_id', 'ls_value = ' . $this->mDb
->buildStringCast( 'pr_id' )
312 ] +
$commentQuery['joins'] +
$actorQuery['joins']
316 protected function getTableClass() {
317 return parent
::getTableClass() . ' mw-protectedpages';
320 function getIndexField() {
324 function getDefaultSort() {
328 function isFieldSortable( $field ) {
329 // no index for sorting exists