MediaWiki REL1_35
ProtectedPagesPager.php
Go to the documentation of this file.
1<?php
24
26
27 public $mConds;
29
43 public function __construct( $form, $conds, $type, $level, $namespace,
46 ) {
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;
57 }
58
59 public function preprocessResults( $result ) {
60 # Do a link batch query
61 $lb = new LinkBatch;
62 $userids = [];
63
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;
69 }
70 }
71
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 );
81 }
82 }
83 }
84
85 $lb->execute();
86 }
87
88 protected function getFieldNames() {
89 static $headers = null;
90
91 if ( $headers == [] ) {
92 $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',
99 ];
100 foreach ( $headers as $key => $val ) {
101 $headers[$key] = $this->msg( $val )->text();
102 }
103 }
104
105 return $headers;
106 }
107
114 public function formatValue( $field, $value ) {
116 $row = $this->mCurrentRow;
118
119 switch ( $field ) {
120 case 'log_timestamp':
121 // when timestamp is null, this is a old protection row
122 if ( $value === null ) {
123 $formatted = Html::rawElement(
124 'span',
125 [ 'class' => 'mw-protectedpages-unknown' ],
126 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
127 );
128 } else {
129 $formatted = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
130 $value, $this->getUser() ) );
131 }
132 break;
133
134 case 'pr_page':
135 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
136 if ( !$title ) {
137 $formatted = Html::element(
138 'span',
139 [ 'class' => 'mw-invalidtitle' ],
141 $this->getContext(),
142 $row->page_namespace,
143 $row->page_title
144 )
145 );
146 } else {
147 $formatted = $linkRenderer->makeLink( $title );
148 }
149 if ( $row->page_len !== null ) {
150 $formatted .= $this->getLanguage()->getDirMark() .
151 ' ' . Html::rawElement(
152 'span',
153 [ 'class' => 'mw-protectedpages-length' ],
154 Linker::formatRevisionSize( $row->page_len )
155 );
156 }
157 break;
158
159 case 'pr_expiry':
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()
165 ->userHasRight( $this->getUser(), 'protect' )
166 ) {
167 $changeProtection = $linkRenderer->makeKnownLink(
168 $title,
169 $this->msg( 'protect_change' )->text(),
170 [],
171 [ 'action' => 'unprotect' ]
172 );
173 $formatted .= ' ' . Html::rawElement(
174 'span',
175 [ 'class' => 'mw-protectedpages-actions' ],
176 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
177 );
178 }
179 break;
180
181 case 'log_user':
182 // when timestamp is null, this is a old protection row
183 if ( $row->log_timestamp === null ) {
184 $formatted = Html::rawElement(
185 'span',
186 [ 'class' => 'mw-protectedpages-unknown' ],
187 $this->msg( 'protectedpages-unknown-performer' )->escaped()
188 );
189 } else {
190 $username = UserCache::singleton()->getProp( $value, 'name' );
191 if ( LogEventsList::userCanBitfield(
192 $row->log_deleted,
194 $this->getUser()
195 ) ) {
196 if ( $username === false ) {
197 $formatted = htmlspecialchars( $value );
198 } else {
199 $formatted = Linker::userLink( $value, $username )
200 . Linker::userToolLinks( $value, $username );
201 }
202 } else {
203 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
204 }
205 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_USER ) ) {
206 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
207 }
208 }
209 break;
210
211 case 'pr_params':
212 $params = [];
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();
217 }
218 $formatted = $this->getLanguage()->commaList( $params );
219 break;
220
221 case 'log_comment':
222 // when timestamp is null, this is an old protection row
223 if ( $row->log_timestamp === null ) {
224 $formatted = Html::rawElement(
225 'span',
226 [ 'class' => 'mw-protectedpages-unknown' ],
227 $this->msg( 'protectedpages-unknown-reason' )->escaped()
228 );
229 } else {
230 if ( LogEventsList::userCanBitfield(
231 $row->log_deleted,
233 $this->getUser()
234 ) ) {
235 $value = CommentStore::getStore()->getComment( 'log_comment', $row )->text;
236 $formatted = Linker::formatComment( $value ?? '' );
237 } else {
238 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
239 }
240 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) {
241 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
242 }
243 }
244 break;
245
246 default:
247 throw new MWException( "Unknown field '$field'" );
248 }
249
250 return $formatted;
251 }
252
253 public 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 );
259
260 if ( $this->sizetype == 'min' ) {
261 $conds[] = 'page_len>=' . $this->size;
262 } elseif ( $this->sizetype == 'max' ) {
263 $conds[] = 'page_len<=' . $this->size;
264 }
265
266 if ( $this->indefonly ) {
267 $infinity = $this->mDb->addQuotes( $this->mDb->getInfinity() );
268 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
269 }
270 if ( $this->cascadeonly ) {
271 $conds[] = 'pr_cascade = 1';
272 }
273 if ( $this->noredirect ) {
274 $conds[] = 'page_is_redirect = 0';
275 }
276
277 if ( $this->level ) {
278 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
279 }
280 if ( $this->namespace !== null ) {
281 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
282 }
283
284 $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
285 $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
286
287 return [
288 'tables' => [
289 'page', 'page_restrictions', 'log_search',
290 'logparen' => [ 'logging' ] + $commentQuery['tables'] + $actorQuery['tables'],
291 ],
292 'fields' => [
293 'pr_id',
294 'page_namespace',
295 'page_title',
296 'page_len',
297 'pr_type',
298 'pr_level',
299 'pr_expiry',
300 'pr_cascade',
301 'log_timestamp',
302 'log_deleted',
303 ] + $commentQuery['fields'] + $actorQuery['fields'],
304 'conds' => $conds,
305 'join_conds' => [
306 'log_search' => [
307 'LEFT JOIN', [
308 'ls_field' => 'pr_id', 'ls_value = ' . $this->mDb->buildStringCast( 'pr_id' )
309 ]
310 ],
311 'logparen' => [
312 'LEFT JOIN', [
313 'ls_log_id = log_id'
314 ]
315 ]
316 ] + $commentQuery['joins'] + $actorQuery['joins']
317 ];
318 }
319
320 protected function getTableClass() {
321 return parent::getTableClass() . ' mw-protectedpages';
322 }
323
324 public function getIndexField() {
325 return 'pr_id';
326 }
327
328 public function getDefaultSort() {
329 return 'pr_id';
330 }
331
332 protected function isFieldSortable( $field ) {
333 // no index for sorting exists
334 return false;
335 }
336}
getPermissionManager()
getUser()
Stable to override.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
LinkRenderer $linkRenderer
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:35
add( $ns, $dbkey)
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition Linker.php:906
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition Linker.php:188
static formatRevisionSize( $size)
Definition Linker.php:1660
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null, $useParentheses=true)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition Linker.php:951
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition Linker.php:1209
const DELETED_USER
Definition LogPage.php:40
const DELETED_COMMENT
Definition LogPage.php:39
MediaWiki exception.
Class that generates HTML links for pages.
makeKnownLink(LinkTarget $target, $text=null, array $extraAttribs=[], array $query=[])
makeLink(LinkTarget $target, $text=null, array $extraAttribs=[], array $query=[])
MediaWikiServices is the service locator for the application scope of MediaWiki.
getTableClass()
TablePager relies on mw-datatable for styling, see T214208.
getFieldNames()
An array mapping database field names to a textual description of the field name, for use in the tabl...
preprocessResults( $result)
Pre-process results; useful for performing batch existence checks, etc.
getQueryInfo()
Provides all parameters needed for the main paged query.
formatValue( $field, $value)
getDefaultSort()
The database field name used as a default sort order.
getIndexField()
Returns the name of the index field.If the pager supports multiple orders, it may return an array of ...
__construct( $form, $conds, $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect, LinkRenderer $linkRenderer)
isFieldSortable( $field)
Return true if the named field should be sortable by the UI, false otherwise.
Table-based display with a user-selectable sort order Stable to extend.
stdClass $mCurrentRow
static singleton()
Definition UserCache.php:34
const NS_USER
Definition Defines.php:72
const NS_USER_TALK
Definition Defines.php:73