MediaWiki REL1_33
ProtectedPagesPager.php
Go to the documentation of this file.
1<?php
23
25
26 public $mConds;
28
33
47 public function __construct( $form, $conds, $type, $level, $namespace,
50 ) {
51 $this->mConds = $conds;
52 $this->type = $type ?: 'edit';
53 $this->level = $level;
54 $this->namespace = $namespace;
55 $this->sizetype = $sizetype;
56 $this->size = intval( $size );
57 $this->indefonly = (bool)$indefonly;
58 $this->cascadeonly = (bool)$cascadeonly;
59 $this->noredirect = (bool)$noredirect;
60 $this->linkRenderer = $linkRenderer;
61 parent::__construct( $form->getContext() );
62 }
63
64 function preprocessResults( $result ) {
65 # Do a link batch query
66 $lb = new LinkBatch;
67 $userids = [];
68
69 foreach ( $result as $row ) {
70 $lb->add( $row->page_namespace, $row->page_title );
71 // field is nullable, maybe null on old protections
72 if ( $row->log_user !== null ) {
73 $userids[] = $row->log_user;
74 }
75 }
76
77 // fill LinkBatch with user page and user talk
78 if ( count( $userids ) ) {
79 $userCache = UserCache::singleton();
80 $userCache->doQuery( $userids, [], __METHOD__ );
81 foreach ( $userids as $userid ) {
82 $name = $userCache->getProp( $userid, 'name' );
83 if ( $name !== false ) {
84 $lb->add( NS_USER, $name );
85 $lb->add( NS_USER_TALK, $name );
86 }
87 }
88 }
89
90 $lb->execute();
91 }
92
93 function getFieldNames() {
94 static $headers = null;
95
96 if ( $headers == [] ) {
97 $headers = [
98 'log_timestamp' => 'protectedpages-timestamp',
99 'pr_page' => 'protectedpages-page',
100 'pr_expiry' => 'protectedpages-expiry',
101 'log_user' => 'protectedpages-performer',
102 'pr_params' => 'protectedpages-params',
103 'log_comment' => 'protectedpages-reason',
104 ];
105 foreach ( $headers as $key => $val ) {
106 $headers[$key] = $this->msg( $val )->text();
107 }
108 }
109
110 return $headers;
111 }
112
119 function formatValue( $field, $value ) {
121 $row = $this->mCurrentRow;
122
123 switch ( $field ) {
124 case 'log_timestamp':
125 // when timestamp is null, this is a old protection row
126 if ( $value === null ) {
127 $formatted = Html::rawElement(
128 'span',
129 [ 'class' => 'mw-protectedpages-unknown' ],
130 $this->msg( 'protectedpages-unknown-timestamp' )->escaped()
131 );
132 } else {
133 $formatted = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
134 $value, $this->getUser() ) );
135 }
136 break;
137
138 case 'pr_page':
139 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
140 if ( !$title ) {
141 $formatted = Html::element(
142 'span',
143 [ 'class' => 'mw-invalidtitle' ],
145 $this->getContext(),
146 $row->page_namespace,
147 $row->page_title
148 )
149 );
150 } else {
151 $formatted = $this->linkRenderer->makeLink( $title );
152 }
153 if ( !is_null( $row->page_len ) ) {
154 $formatted .= $this->getLanguage()->getDirMark() .
155 ' ' . Html::rawElement(
156 'span',
157 [ 'class' => 'mw-protectedpages-length' ],
158 Linker::formatRevisionSize( $row->page_len )
159 );
160 }
161 break;
162
163 case 'pr_expiry':
164 $formatted = htmlspecialchars( $this->getLanguage()->formatExpiry(
165 $value, /* User preference timezone */true ) );
166 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
167 if ( $this->getUser()->isAllowed( 'protect' ) && $title ) {
168 $changeProtection = $this->linkRenderer->makeKnownLink(
169 $title,
170 $this->msg( 'protect_change' )->text(),
171 [],
172 [ 'action' => 'unprotect' ]
173 );
174 $formatted .= ' ' . Html::rawElement(
175 'span',
176 [ 'class' => 'mw-protectedpages-actions' ],
177 $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped()
178 );
179 }
180 break;
181
182 case 'log_user':
183 // when timestamp is null, this is a old protection row
184 if ( $row->log_timestamp === null ) {
185 $formatted = Html::rawElement(
186 'span',
187 [ 'class' => 'mw-protectedpages-unknown' ],
188 $this->msg( 'protectedpages-unknown-performer' )->escaped()
189 );
190 } else {
191 $username = UserCache::singleton()->getProp( $value, 'name' );
193 $row->log_deleted,
195 $this->getUser()
196 ) ) {
197 if ( $username === false ) {
198 $formatted = htmlspecialchars( $value );
199 } else {
200 $formatted = Linker::userLink( $value, $username )
202 }
203 } else {
204 $formatted = $this->msg( 'rev-deleted-user' )->escaped();
205 }
207 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
208 }
209 }
210 break;
211
212 case 'pr_params':
213 $params = [];
214 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
215 $params[] = $this->msg( 'restriction-level-' . $row->pr_level )->escaped();
216 if ( $row->pr_cascade ) {
217 $params[] = $this->msg( 'protect-summary-cascade' )->escaped();
218 }
219 $formatted = $this->getLanguage()->commaList( $params );
220 break;
221
222 case 'log_comment':
223 // when timestamp is null, this is an old protection row
224 if ( $row->log_timestamp === null ) {
225 $formatted = Html::rawElement(
226 'span',
227 [ 'class' => 'mw-protectedpages-unknown' ],
228 $this->msg( 'protectedpages-unknown-reason' )->escaped()
229 );
230 } else {
232 $row->log_deleted,
234 $this->getUser()
235 ) ) {
236 $value = CommentStore::getStore()->getComment( 'log_comment', $row )->text;
237 $formatted = Linker::formatComment( $value ?? '' );
238 } else {
239 $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
240 }
242 $formatted = '<span class="history-deleted">' . $formatted . '</span>';
243 }
244 }
245 break;
246
247 default:
248 throw new MWException( "Unknown field '$field'" );
249 }
250
251 return $formatted;
252 }
253
254 function getQueryInfo() {
255 $conds = $this->mConds;
256 $conds[] = 'pr_expiry > ' . $this->mDb->addQuotes( $this->mDb->timestamp() ) .
257 ' OR pr_expiry IS NULL';
258 $conds[] = 'page_id=pr_page';
259 $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
260
261 if ( $this->sizetype == 'min' ) {
262 $conds[] = 'page_len>=' . $this->size;
263 } elseif ( $this->sizetype == 'max' ) {
264 $conds[] = 'page_len<=' . $this->size;
265 }
266
267 if ( $this->indefonly ) {
268 $infinity = $this->mDb->addQuotes( $this->mDb->getInfinity() );
269 $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
270 }
271 if ( $this->cascadeonly ) {
272 $conds[] = 'pr_cascade = 1';
273 }
274 if ( $this->noredirect ) {
275 $conds[] = 'page_is_redirect = 0';
276 }
277
278 if ( $this->level ) {
279 $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
280 }
281 if ( !is_null( $this->namespace ) ) {
282 $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
283 }
284
285 $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
286 $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
287
288 return [
289 'tables' => [
290 'page', 'page_restrictions', 'log_search',
291 'logparen' => [ 'logging' ] + $commentQuery['tables'] + $actorQuery['tables'],
292 ],
293 'fields' => [
294 'pr_id',
295 'page_namespace',
296 'page_title',
297 'page_len',
298 'pr_type',
299 'pr_level',
300 'pr_expiry',
301 'pr_cascade',
302 'log_timestamp',
303 'log_deleted',
304 ] + $commentQuery['fields'] + $actorQuery['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 'logparen' => [
313 'LEFT JOIN', [
314 'ls_log_id = log_id'
315 ]
316 ]
317 ] + $commentQuery['joins'] + $actorQuery['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}
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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:83
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition Linker.php:892
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition Linker.php:191
static formatRevisionSize( $size)
Definition Linker.php:1535
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:931
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:1122
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:36
const DELETED_COMMENT
Definition LogPage.php:35
MediaWiki exception.
Class that generates HTML links for pages.
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()
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.
__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.
stdClass $mCurrentRow
static singleton()
Definition UserCache.php:34
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:782
const NS_USER_TALK
Definition Defines.php:76
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