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
;
27 class ProtectedPagesPager
extends TablePager
{
28 public $mForm, $mConds;
29 private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect;
34 private $linkRenderer;
37 * @param SpecialProtectedpages $form
40 * @param string $level
41 * @param int $namespace
42 * @param string $sizetype
44 * @param bool $indefonly
45 * @param bool $cascadeonly
46 * @param bool $noredirect
47 * @param LinkRenderer $linkRenderer
49 function __construct( $form, $conds = [], $type, $level, $namespace,
50 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false, $noredirect = false,
51 LinkRenderer
$linkRenderer
54 $this->mConds
= $conds;
55 $this->type
= ( $type ) ?
$type : 'edit';
56 $this->level
= $level;
57 $this->namespace = $namespace;
58 $this->sizetype
= $sizetype;
59 $this->size
= intval( $size );
60 $this->indefonly
= (bool)$indefonly;
61 $this->cascadeonly
= (bool)$cascadeonly;
62 $this->noredirect
= (bool)$noredirect;
63 $this->linkRenderer
= $linkRenderer;
64 parent
::__construct( $form->getContext() );
67 function preprocessResults( $result ) {
68 # Do a link batch query
72 foreach ( $result as $row ) {
73 $lb->add( $row->page_namespace
, $row->page_title
);
74 // field is nullable, maybe null on old protections
75 if ( $row->log_user
!== null ) {
76 $userids[] = $row->log_user
;
80 // fill LinkBatch with user page and user talk
81 if ( count( $userids ) ) {
82 $userCache = UserCache
::singleton();
83 $userCache->doQuery( $userids, [], __METHOD__
);
84 foreach ( $userids as $userid ) {
85 $name = $userCache->getProp( $userid, 'name' );
86 if ( $name !== false ) {
87 $lb->add( NS_USER
, $name );
88 $lb->add( NS_USER_TALK
, $name );
96 function getFieldNames() {
97 static $headers = null;
99 if ( $headers == [] ) {
101 'log_timestamp' => 'protectedpages-timestamp',
102 'pr_page' => 'protectedpages-page',
103 'pr_expiry' => 'protectedpages-expiry',
104 'log_user' => 'protectedpages-performer',
105 'pr_params' => 'protectedpages-params',
106 'log_comment' => 'protectedpages-reason',
108 foreach ( $headers as $key => $val ) {
109 $headers[$key] = $this->msg( $val )->text();
117 * @param string $field
118 * @param string $value
119 * @return string HTML
120 * @throws MWException
122 function formatValue( $field, $value ) {
123 /** @var $row object */
124 $row = $this->mCurrentRow
;
127 case 'log_timestamp':
128 // when timestamp is null, this is a old protection row
129 if ( $value === null ) {
130 $formatted = Html
::rawElement(
132 [ 'class' => 'mw-protectedpages-unknown' ],
133 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
136 $formatted = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
137 $value, $this->getUser() ) );
142 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
144 $formatted = Html
::element(
146 [ 'class' => 'mw-invalidtitle' ],
147 Linker
::getInvalidTitleDescription(
149 $row->page_namespace
,
154 $formatted = $this->linkRenderer
->makeLink( $title );
156 if ( !is_null( $row->page_len
) ) {
157 $formatted .= $this->getLanguage()->getDirMark() .
158 ' ' . Html
::rawElement(
160 [ 'class' => 'mw-protectedpages-length' ],
161 Linker
::formatRevisionSize( $row->page_len
)
167 $formatted = htmlspecialchars( $this->getLanguage()->formatExpiry(
168 $value, /* User preference timezone */true ) );
169 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
170 if ( $this->getUser()->isAllowed( 'protect' ) && $title ) {
171 $changeProtection = $this->linkRenderer
->makeKnownLink(
173 $this->msg( 'protect_change' )->text(),
175 [ 'action' => 'unprotect' ]
177 $formatted .= ' ' . Html
::rawElement(
179 [ 'class' => 'mw-protectedpages-actions' ],
180 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
186 // when timestamp is null, this is a old protection row
187 if ( $row->log_timestamp
=== null ) {
188 $formatted = Html
::rawElement(
190 [ 'class' => 'mw-protectedpages-unknown' ],
191 $this->msg( 'protectedpages-unknown-performer' )->escaped()
194 $username = UserCache
::singleton()->getProp( $value, 'name' );
195 if ( LogEventsList
::userCanBitfield(
197 LogPage
::DELETED_USER
,
200 if ( $username === false ) {
201 $formatted = htmlspecialchars( $value );
203 $formatted = Linker
::userLink( $value, $username )
204 . Linker
::userToolLinks( $value, $username );
207 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
209 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_USER
) ) {
210 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
217 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
218 $params[] = $this->msg( 'restriction-level-' . $row->pr_level
)->escaped();
219 if ( $row->pr_cascade
) {
220 $params[] = $this->msg( 'protect-summary-cascade' )->escaped();
222 $formatted = $this->getLanguage()->commaList( $params );
226 // when timestamp is null, this is an old protection row
227 if ( $row->log_timestamp
=== null ) {
228 $formatted = Html
::rawElement(
230 [ 'class' => 'mw-protectedpages-unknown' ],
231 $this->msg( 'protectedpages-unknown-reason' )->escaped()
234 if ( LogEventsList
::userCanBitfield(
236 LogPage
::DELETED_COMMENT
,
239 $formatted = Linker
::formatComment( $value !== null ?
$value : '' );
241 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
243 if ( LogEventsList
::isDeleted( $row, LogPage
::DELETED_COMMENT
) ) {
244 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
250 throw new MWException( "Unknown field '$field'" );
256 function getQueryInfo() {
257 $conds = $this->mConds
;
258 $conds[] = 'pr_expiry > ' . $this->mDb
->addQuotes( $this->mDb
->timestamp() ) .
259 ' OR pr_expiry IS NULL';
260 $conds[] = 'page_id=pr_page';
261 $conds[] = 'pr_type=' . $this->mDb
->addQuotes( $this->type
);
263 if ( $this->sizetype
== 'min' ) {
264 $conds[] = 'page_len>=' . $this->size
;
265 } elseif ( $this->sizetype
== 'max' ) {
266 $conds[] = 'page_len<=' . $this->size
;
269 if ( $this->indefonly
) {
270 $infinity = $this->mDb
->addQuotes( $this->mDb
->getInfinity() );
271 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
273 if ( $this->cascadeonly
) {
274 $conds[] = 'pr_cascade = 1';
276 if ( $this->noredirect
) {
277 $conds[] = 'page_is_redirect = 0';
280 if ( $this->level
) {
281 $conds[] = 'pr_level=' . $this->mDb
->addQuotes( $this->level
);
283 if ( !is_null( $this->namespace ) ) {
284 $conds[] = 'page_namespace=' . $this->mDb
->addQuotes( $this->namespace );
288 'tables' => [ 'page', 'page_restrictions', 'log_search', 'logging' ],
307 'ls_field' => 'pr_id', 'ls_value = ' . $this->mDb
->buildStringCast( 'pr_id' )
319 protected function getTableClass() {
320 return parent
::getTableClass() . ' mw-protectedpages';
323 function getIndexField() {
327 function getDefaultSort() {
331 function isFieldSortable( $field ) {
332 // no index for sorting exists