MediaWiki REL1_31
ProtectedPagesPager.php
Go to the documentation of this file.
1<?php
23
25
26 public $mForm, $mConds;
28
33
47 function __construct( $form, $conds = [], $type, $level, $namespace,
48 $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false, $noredirect = false,
50 ) {
51 $this->mForm = $form;
52 $this->mConds = $conds;
53 $this->type = ( $type ) ? $type : 'edit';
54 $this->level = $level;
55 $this->namespace = $namespace;
56 $this->sizetype = $sizetype;
57 $this->size = intval( $size );
58 $this->indefonly = (bool)$indefonly;
59 $this->cascadeonly = (bool)$cascadeonly;
60 $this->noredirect = (bool)$noredirect;
61 $this->linkRenderer = $linkRenderer;
62 parent::__construct( $form->getContext() );
63 }
64
65 function preprocessResults( $result ) {
66 # Do a link batch query
67 $lb = new LinkBatch;
68 $userids = [];
69
70 foreach ( $result as $row ) {
71 $lb->add( $row->page_namespace, $row->page_title );
72 // field is nullable, maybe null on old protections
73 if ( $row->log_user !== null ) {
74 $userids[] = $row->log_user;
75 }
76 }
77
78 // fill LinkBatch with user page and user talk
79 if ( count( $userids ) ) {
80 $userCache = UserCache::singleton();
81 $userCache->doQuery( $userids, [], __METHOD__ );
82 foreach ( $userids as $userid ) {
83 $name = $userCache->getProp( $userid, 'name' );
84 if ( $name !== false ) {
85 $lb->add( NS_USER, $name );
86 $lb->add( NS_USER_TALK, $name );
87 }
88 }
89 }
90
91 $lb->execute();
92 }
93
94 function getFieldNames() {
95 static $headers = null;
96
97 if ( $headers == [] ) {
98 $headers = [
99 'log_timestamp' => 'protectedpages-timestamp',
100 'pr_page' => 'protectedpages-page',
101 'pr_expiry' => 'protectedpages-expiry',
102 'log_user' => 'protectedpages-performer',
103 'pr_params' => 'protectedpages-params',
104 'log_comment' => 'protectedpages-reason',
105 ];
106 foreach ( $headers as $key => $val ) {
107 $headers[$key] = $this->msg( $val )->text();
108 }
109 }
110
111 return $headers;
112 }
113
120 function formatValue( $field, $value ) {
122 $row = $this->mCurrentRow;
123
124 switch ( $field ) {
125 case 'log_timestamp':
126 // when timestamp is null, this is a old protection row
127 if ( $value === null ) {
128 $formatted = Html::rawElement(
129 'span',
130 [ 'class' => 'mw-protectedpages-unknown' ],
131 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
132 );
133 } else {
134 $formatted = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
135 $value, $this->getUser() ) );
136 }
137 break;
138
139 case 'pr_page':
140 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
141 if ( !$title ) {
142 $formatted = Html::element(
143 'span',
144 [ 'class' => 'mw-invalidtitle' ],
146 $this->getContext(),
147 $row->page_namespace,
148 $row->page_title
149 )
150 );
151 } else {
152 $formatted = $this->linkRenderer->makeLink( $title );
153 }
154 if ( !is_null( $row->page_len ) ) {
155 $formatted .= $this->getLanguage()->getDirMark() .
156 ' ' . Html::rawElement(
157 'span',
158 [ 'class' => 'mw-protectedpages-length' ],
159 Linker::formatRevisionSize( $row->page_len )
160 );
161 }
162 break;
163
164 case 'pr_expiry':
165 $formatted = htmlspecialchars( $this->getLanguage()->formatExpiry(
166 $value, /* User preference timezone */true ) );
167 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
168 if ( $this->getUser()->isAllowed( 'protect' ) && $title ) {
169 $changeProtection = $this->linkRenderer->makeKnownLink(
170 $title,
171 $this->msg( 'protect_change' )->text(),
172 [],
173 [ 'action' => 'unprotect' ]
174 );
175 $formatted .= ' ' . Html::rawElement(
176 'span',
177 [ 'class' => 'mw-protectedpages-actions' ],
178 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
179 );
180 }
181 break;
182
183 case 'log_user':
184 // when timestamp is null, this is a old protection row
185 if ( $row->log_timestamp === null ) {
186 $formatted = Html::rawElement(
187 'span',
188 [ 'class' => 'mw-protectedpages-unknown' ],
189 $this->msg( 'protectedpages-unknown-performer' )->escaped()
190 );
191 } else {
192 $username = UserCache::singleton()->getProp( $value, 'name' );
194 $row->log_deleted,
196 $this->getUser()
197 ) ) {
198 if ( $username === false ) {
199 $formatted = htmlspecialchars( $value );
200 } else {
201 $formatted = Linker::userLink( $value, $username )
203 }
204 } else {
205 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
206 }
208 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
209 }
210 }
211 break;
212
213 case 'pr_params':
214 $params = [];
215 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
216 $params[] = $this->msg( 'restriction-level-' . $row->pr_level )->escaped();
217 if ( $row->pr_cascade ) {
218 $params[] = $this->msg( 'protect-summary-cascade' )->escaped();
219 }
220 $formatted = $this->getLanguage()->commaList( $params );
221 break;
222
223 case 'log_comment':
224 // when timestamp is null, this is an old protection row
225 if ( $row->log_timestamp === null ) {
226 $formatted = Html::rawElement(
227 'span',
228 [ 'class' => 'mw-protectedpages-unknown' ],
229 $this->msg( 'protectedpages-unknown-reason' )->escaped()
230 );
231 } else {
233 $row->log_deleted,
235 $this->getUser()
236 ) ) {
237 $value = CommentStore::getStore()->getComment( 'log_comment', $row )->text;
238 $formatted = Linker::formatComment( $value !== null ? $value : '' );
239 } else {
240 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
241 }
243 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
244 }
245 }
246 break;
247
248 default:
249 throw new MWException( "Unknown field '$field'" );
250 }
251
252 return $formatted;
253 }
254
255 function getQueryInfo() {
256 $conds = $this->mConds;
257 $conds[] = 'pr_expiry > ' . $this->mDb->addQuotes( $this->mDb->timestamp() ) .
258 ' OR pr_expiry IS NULL';
259 $conds[] = 'page_id=pr_page';
260 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
261
262 if ( $this->sizetype == 'min' ) {
263 $conds[] = 'page_len>=' . $this->size;
264 } elseif ( $this->sizetype == 'max' ) {
265 $conds[] = 'page_len<=' . $this->size;
266 }
267
268 if ( $this->indefonly ) {
269 $infinity = $this->mDb->addQuotes( $this->mDb->getInfinity() );
270 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
271 }
272 if ( $this->cascadeonly ) {
273 $conds[] = 'pr_cascade = 1';
274 }
275 if ( $this->noredirect ) {
276 $conds[] = 'page_is_redirect = 0';
277 }
278
279 if ( $this->level ) {
280 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
281 }
282 if ( !is_null( $this->namespace ) ) {
283 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
284 }
285
286 $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
287 $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
288
289 return [
290 'tables' => [
291 'page', 'page_restrictions', 'log_search',
292 'logparen' => [ 'logging' ] + $commentQuery['tables'] + $actorQuery['tables'],
293 ],
294 'fields' => [
295 'pr_id',
296 'page_namespace',
297 'page_title',
298 'page_len',
299 'pr_type',
300 'pr_level',
301 'pr_expiry',
302 'pr_cascade',
303 'log_timestamp',
304 'log_deleted',
305 ] + $commentQuery['fields'] + $actorQuery['fields'],
306 'conds' => $conds,
307 'join_conds' => [
308 'log_search' => [
309 'LEFT JOIN', [
310 'ls_field' => 'pr_id', 'ls_value = ' . $this->mDb->buildStringCast( 'pr_id' )
311 ]
312 ],
313 'logparen' => [
314 'LEFT JOIN', [
315 'ls_log_id = log_id'
316 ]
317 ]
318 ] + $commentQuery['joins'] + $actorQuery['joins']
319 ];
320 }
321
322 protected function getTableClass() {
323 return parent::getTableClass() . ' mw-protectedpages';
324 }
325
326 function getIndexField() {
327 return 'pr_id';
328 }
329
330 function getDefaultSort() {
331 return 'pr_id';
332 }
333
334 function isFieldSortable( $field ) {
335 // no index for sorting exists
336 return false;
337 }
338}
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
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:931
static formatRevisionSize( $size)
Definition Linker.php:1503
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:1109
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:785
const NS_USER_TALK
Definition Defines.php:77
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 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:30
$params