MediaWiki REL1_30
ProtectedPagesPager.php
Go to the documentation of this file.
1<?php
22use \MediaWiki\Linker\LinkRenderer;
23
28 public $mForm, $mConds;
30
35
49 function __construct( $form, $conds = [], $type, $level, $namespace,
50 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false, $noredirect = false,
52 ) {
53 $this->mForm = $form;
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() );
65 }
66
67 function preprocessResults( $result ) {
68 # Do a link batch query
69 $lb = new LinkBatch;
70 $userids = [];
71
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;
77 }
78 }
79
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 );
89 }
90 }
91 }
92
93 $lb->execute();
94 }
95
96 function getFieldNames() {
97 static $headers = null;
98
99 if ( $headers == [] ) {
100 $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',
107 ];
108 foreach ( $headers as $key => $val ) {
109 $headers[$key] = $this->msg( $val )->text();
110 }
111 }
112
113 return $headers;
114 }
115
122 function formatValue( $field, $value ) {
124 $row = $this->mCurrentRow;
125
126 switch ( $field ) {
127 case 'log_timestamp':
128 // when timestamp is null, this is a old protection row
129 if ( $value === null ) {
130 $formatted = Html::rawElement(
131 'span',
132 [ 'class' => 'mw-protectedpages-unknown' ],
133 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
134 );
135 } else {
136 $formatted = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
137 $value, $this->getUser() ) );
138 }
139 break;
140
141 case 'pr_page':
142 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
143 if ( !$title ) {
144 $formatted = Html::element(
145 'span',
146 [ 'class' => 'mw-invalidtitle' ],
148 $this->getContext(),
149 $row->page_namespace,
150 $row->page_title
151 )
152 );
153 } else {
154 $formatted = $this->linkRenderer->makeLink( $title );
155 }
156 if ( !is_null( $row->page_len ) ) {
157 $formatted .= $this->getLanguage()->getDirMark() .
158 ' ' . Html::rawElement(
159 'span',
160 [ 'class' => 'mw-protectedpages-length' ],
161 Linker::formatRevisionSize( $row->page_len )
162 );
163 }
164 break;
165
166 case 'pr_expiry':
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(
172 $title,
173 $this->msg( 'protect_change' )->text(),
174 [],
175 [ 'action' => 'unprotect' ]
176 );
177 $formatted .= ' ' . Html::rawElement(
178 'span',
179 [ 'class' => 'mw-protectedpages-actions' ],
180 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
181 );
182 }
183 break;
184
185 case 'log_user':
186 // when timestamp is null, this is a old protection row
187 if ( $row->log_timestamp === null ) {
188 $formatted = Html::rawElement(
189 'span',
190 [ 'class' => 'mw-protectedpages-unknown' ],
191 $this->msg( 'protectedpages-unknown-performer' )->escaped()
192 );
193 } else {
194 $username = UserCache::singleton()->getProp( $value, 'name' );
196 $row->log_deleted,
198 $this->getUser()
199 ) ) {
200 if ( $username === false ) {
201 $formatted = htmlspecialchars( $value );
202 } else {
203 $formatted = Linker::userLink( $value, $username )
205 }
206 } else {
207 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
208 }
210 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
211 }
212 }
213 break;
214
215 case 'pr_params':
216 $params = [];
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();
221 }
222 $formatted = $this->getLanguage()->commaList( $params );
223 break;
224
225 case 'log_comment':
226 // when timestamp is null, this is an old protection row
227 if ( $row->log_timestamp === null ) {
228 $formatted = Html::rawElement(
229 'span',
230 [ 'class' => 'mw-protectedpages-unknown' ],
231 $this->msg( 'protectedpages-unknown-reason' )->escaped()
232 );
233 } else {
235 $row->log_deleted,
237 $this->getUser()
238 ) ) {
239 $value = CommentStore::newKey( 'log_comment' )->getComment( $row )->text;
240 $formatted = Linker::formatComment( $value !== null ? $value : '' );
241 } else {
242 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
243 }
245 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
246 }
247 }
248 break;
249
250 default:
251 throw new MWException( "Unknown field '$field'" );
252 }
253
254 return $formatted;
255 }
256
257 function getQueryInfo() {
258 $conds = $this->mConds;
259 $conds[] = 'pr_expiry > ' . $this->mDb->addQuotes( $this->mDb->timestamp() ) .
260 ' OR pr_expiry IS NULL';
261 $conds[] = 'page_id=pr_page';
262 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
263
264 if ( $this->sizetype == 'min' ) {
265 $conds[] = 'page_len>=' . $this->size;
266 } elseif ( $this->sizetype == 'max' ) {
267 $conds[] = 'page_len<=' . $this->size;
268 }
269
270 if ( $this->indefonly ) {
271 $infinity = $this->mDb->addQuotes( $this->mDb->getInfinity() );
272 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
273 }
274 if ( $this->cascadeonly ) {
275 $conds[] = 'pr_cascade = 1';
276 }
277 if ( $this->noredirect ) {
278 $conds[] = 'page_is_redirect = 0';
279 }
280
281 if ( $this->level ) {
282 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
283 }
284 if ( !is_null( $this->namespace ) ) {
285 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
286 }
287
288 $commentQuery = CommentStore::newKey( 'log_comment' )->getJoin();
289
290 return [
291 'tables' => [ 'page', 'page_restrictions', 'log_search', 'logging' ] + $commentQuery['tables'],
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_user',
303 'log_deleted',
304 ] + $commentQuery['fields'],
305 'conds' => $conds,
306 'join_conds' => [
307 'log_search' => [
308 'LEFT JOIN', [
309 'ls_field' => 'pr_id', 'ls_value = ' . $this->mDb->buildStringCast( 'pr_id' )
310 ]
311 ],
312 'logging' => [
313 'LEFT JOIN', [
314 'ls_log_id = log_id'
315 ]
316 ]
317 ] + $commentQuery['joins']
318 ];
319 }
320
321 protected function getTableClass() {
322 return parent::getTableClass() . ' mw-protectedpages';
323 }
324
325 function getIndexField() {
326 return 'pr_id';
327 }
328
329 function getDefaultSort() {
330 return 'pr_id';
331 }
332
333 function isFieldSortable( $field ) {
334 // no index for sorting exists
335 return false;
336 }
337}
static newKey( $key)
Static constructor for easier chaining.
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
getUser()
Get the User object.
getLanguage()
Get the Language object.
getContext()
Get the base IContextSource object.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
add( $ns, $dbkey)
Definition LinkBatch.php:80
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition Linker.php:893
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition Linker.php:209
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition Linker.php:926
static formatRevisionSize( $size)
Definition Linker.php:1493
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:1099
static userCanBitfield( $bitfield, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this log row,...
static isDeleted( $row, $field)
const DELETED_USER
Definition LogPage.php:34
const DELETED_COMMENT
Definition LogPage.php:33
MediaWiki exception.
Class that generates HTML links for pages.
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.
__construct( $form, $conds=[], $type, $level, $namespace, $sizetype='', $size=0, $indefonly=false, $cascadeonly=false, $noredirect=false, LinkRenderer $linkRenderer)
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
formatValue( $field, $value)
getDefaultSort()
The database field name used as a default sort order.
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.
static singleton()
Definition UserCache.php:34
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:783
const NS_USER_TALK
Definition Defines.php:68
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:36
$params