MediaWiki  master
ProtectedPagesPager.php
Go to the documentation of this file.
1 <?php
23 
25 
26  public $mConds;
28 
32  private $linkRenderer;
33 
47  public function __construct( $form, $conds, $type, $level, $namespace,
48  $sizetype, $size, $indefonly, $cascadeonly, $noredirect,
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 }
stdClass $mCurrentRow
Definition: TablePager.php:33
Table-based display with a user-selectable sort order.
Definition: TablePager.php:28
add( $ns, $dbkey)
Definition: LinkBatch.php:83
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
static formatRevisionSize( $size)
Definition: Linker.php:1597
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
$value
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
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
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 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name '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. '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 '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 since 1.28! 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:1980
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
const DELETED_COMMENT
Definition: LogPage.php:35
__construct( $form, $conds, $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect, LinkRenderer $linkRenderer)
Class that generates HTML links for pages.
static newMigration()
Static constructor.
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:1160
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:945
static userCanBitfield( $bitfield, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this log row, if it&#39;s marked as deleted.
getContext()
Get the base IContextSource object.
$params
static isDeleted( $row, $field)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
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
formatValue( $field, $value)
const DELETED_USER
Definition: LogPage.php:36
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:900
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:617
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
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:780
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
static getStore()
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:192
const NS_USER_TALK
Definition: Defines.php:63
static singleton()
Definition: UserCache.php:34