MediaWiki  1.29.1
ProtectedPagesPager.php
Go to the documentation of this file.
1 <?php
22 use \MediaWiki\Linker\LinkRenderer;
23 
28  public $mForm, $mConds;
30 
34  private $linkRenderer;
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  $formatted = Linker::formatComment( $value !== null ? $value : '' );
240  } else {
241  $formatted = $this->msg( 'rev-deleted-comment' )->escaped();
242  }
244  $formatted = '<span class="history-deleted">' . $formatted . '</span>';
245  }
246  }
247  break;
248 
249  default:
250  throw new MWException( "Unknown field '$field'" );
251  }
252 
253  return $formatted;
254  }
255 
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 );
262 
263  if ( $this->sizetype == 'min' ) {
264  $conds[] = 'page_len>=' . $this->size;
265  } elseif ( $this->sizetype == 'max' ) {
266  $conds[] = 'page_len<=' . $this->size;
267  }
268 
269  if ( $this->indefonly ) {
270  $infinity = $this->mDb->addQuotes( $this->mDb->getInfinity() );
271  $conds[] = "pr_expiry = $infinity OR pr_expiry IS NULL";
272  }
273  if ( $this->cascadeonly ) {
274  $conds[] = 'pr_cascade = 1';
275  }
276  if ( $this->noredirect ) {
277  $conds[] = 'page_is_redirect = 0';
278  }
279 
280  if ( $this->level ) {
281  $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
282  }
283  if ( !is_null( $this->namespace ) ) {
284  $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
285  }
286 
287  return [
288  'tables' => [ 'page', 'page_restrictions', 'log_search', 'logging' ],
289  'fields' => [
290  'pr_id',
291  'page_namespace',
292  'page_title',
293  'page_len',
294  'pr_type',
295  'pr_level',
296  'pr_expiry',
297  'pr_cascade',
298  'log_timestamp',
299  'log_user',
300  'log_comment',
301  'log_deleted',
302  ],
303  'conds' => $conds,
304  'join_conds' => [
305  'log_search' => [
306  'LEFT JOIN', [
307  'ls_field' => 'pr_id', 'ls_value = ' . $this->mDb->buildStringCast( 'pr_id' )
308  ]
309  ],
310  'logging' => [
311  'LEFT JOIN', [
312  'ls_log_id = log_id'
313  ]
314  ]
315  ]
316  ];
317  }
318 
319  protected function getTableClass() {
320  return parent::getTableClass() . ' mw-protectedpages';
321  }
322 
323  function getIndexField() {
324  return 'pr_id';
325  }
326 
327  function getDefaultSort() {
328  return 'pr_id';
329  }
330 
331  function isFieldSortable( $field ) {
332  // no index for sorting exists
333  return false;
334  }
335 }
ProtectedPagesPager\$level
$level
Definition: ProtectedPagesPager.php:29
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:41
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:187
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
LinkBatch\add
add( $ns, $dbkey)
Definition: LinkBatch.php:81
Linker\userLink
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:888
TablePager\$mCurrentRow
$mCurrentRow
Definition: TablePager.php:31
ProtectedPagesPager\isFieldSortable
isFieldSortable( $field)
Return true if the named field should be sortable by the UI, false otherwise.
Definition: ProtectedPagesPager.php:331
captcha-old.count
count
Definition: captcha-old.py:225
text
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:12
ProtectedPagesPager\formatValue
formatValue( $field, $value)
Definition: ProtectedPagesPager.php:122
ProtectedPagesPager\getIndexField
getIndexField()
Definition: ProtectedPagesPager.php:323
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition: LinkRenderer.php:42
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1954
ProtectedPagesPager\__construct
__construct( $form, $conds=[], $type, $level, $namespace, $sizetype='', $size=0, $indefonly=false, $cascadeonly=false, $noredirect=false, LinkRenderer $linkRenderer)
Definition: ProtectedPagesPager.php:49
$params
$params
Definition: styleTest.css.php:40
ProtectedPagesPager\getQueryInfo
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
Definition: ProtectedPagesPager.php:256
ProtectedPagesPager\getDefaultSort
getDefaultSort()
The database field name used as a default sort order.
Definition: ProtectedPagesPager.php:327
ProtectedPagesPager\$type
$type
Definition: ProtectedPagesPager.php:29
ProtectedPagesPager\getTableClass
getTableClass()
Definition: ProtectedPagesPager.php:319
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
Linker\getInvalidTitleDescription
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:204
ProtectedPagesPager\$mForm
$mForm
Definition: ProtectedPagesPager.php:28
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:133
ProtectedPagesPager\$namespace
$namespace
Definition: ProtectedPagesPager.php:29
ProtectedPagesPager\$linkRenderer
LinkRenderer $linkRenderer
Definition: ProtectedPagesPager.php:34
ProtectedPagesPager\preprocessResults
preprocessResults( $result)
Pre-process results; useful for performing batch existence checks, etc.
Definition: ProtectedPagesPager.php:67
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ContextSource\getLanguage
getLanguage()
Get the Language object.
Definition: ContextSource.php:143
MWException
MediaWiki exception.
Definition: MWException.php:26
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
ProtectedPagesPager\$size
$size
Definition: ProtectedPagesPager.php:29
LogPage\DELETED_COMMENT
const DELETED_COMMENT
Definition: LogPage.php:33
ProtectedPagesPager\$cascadeonly
$cascadeonly
Definition: ProtectedPagesPager.php:29
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:34
TablePager
Table-based display with a user-selectable sort order.
Definition: TablePager.php:28
ProtectedPagesPager\$indefonly
$indefonly
Definition: ProtectedPagesPager.php:29
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:538
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:65
$value
$value
Definition: styleTest.css.php:45
Linker\userToolLinks
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:921
Linker\formatRevisionSize
static formatRevisionSize( $size)
Definition: Linker.php:1487
Linker\formatComment
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:1094
ProtectedPagesPager\getFieldNames
getFieldNames()
An array mapping database field names to a textual description of the field name, for use in the tabl...
Definition: ProtectedPagesPager.php:96
type
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:22
ProtectedPagesPager\$noredirect
$noredirect
Definition: ProtectedPagesPager.php:29
LogEventsList\userCanBitfield
static userCanBitfield( $bitfield, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this log row,...
Definition: LogEventsList.php:512
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
UserCache\singleton
static singleton()
Definition: UserCache.php:34
LogEventsList\isDeleted
static isDeleted( $row, $field)
Definition: LogEventsList.php:535
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
NS_USER
const NS_USER
Definition: Defines.php:64
ProtectedPagesPager\$mConds
$mConds
Definition: ProtectedPagesPager.php:28
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:783
ProtectedPagesPager
Definition: ProtectedPagesPager.php:27
ProtectedPagesPager\$sizetype
$sizetype
Definition: ProtectedPagesPager.php:29