MediaWiki  1.29.1
QueryPage.php
Go to the documentation of this file.
1 <?php
27 
34 abstract class QueryPage extends SpecialPage {
36  protected $listoutput = false;
37 
39  protected $offset = 0;
40 
42  protected $limit = 0;
43 
49  protected $numRows;
50 
51  protected $cachedTimestamp = null;
52 
56  protected $shownavigation = true;
57 
66  public static function getPages() {
67  static $qp = null;
68 
69  if ( $qp === null ) {
70  // QueryPage subclass, Special page name
71  $qp = [
72  [ 'AncientPagesPage', 'Ancientpages' ],
73  [ 'BrokenRedirectsPage', 'BrokenRedirects' ],
74  [ 'DeadendPagesPage', 'Deadendpages' ],
75  [ 'DoubleRedirectsPage', 'DoubleRedirects' ],
76  [ 'FileDuplicateSearchPage', 'FileDuplicateSearch' ],
77  [ 'ListDuplicatedFilesPage', 'ListDuplicatedFiles' ],
78  [ 'LinkSearchPage', 'LinkSearch' ],
79  [ 'ListredirectsPage', 'Listredirects' ],
80  [ 'LonelyPagesPage', 'Lonelypages' ],
81  [ 'LongPagesPage', 'Longpages' ],
82  [ 'MediaStatisticsPage', 'MediaStatistics' ],
83  [ 'MIMEsearchPage', 'MIMEsearch' ],
84  [ 'MostcategoriesPage', 'Mostcategories' ],
85  [ 'MostimagesPage', 'Mostimages' ],
86  [ 'MostinterwikisPage', 'Mostinterwikis' ],
87  [ 'MostlinkedCategoriesPage', 'Mostlinkedcategories' ],
88  [ 'MostlinkedTemplatesPage', 'Mostlinkedtemplates' ],
89  [ 'MostlinkedPage', 'Mostlinked' ],
90  [ 'MostrevisionsPage', 'Mostrevisions' ],
91  [ 'FewestrevisionsPage', 'Fewestrevisions' ],
92  [ 'ShortPagesPage', 'Shortpages' ],
93  [ 'UncategorizedCategoriesPage', 'Uncategorizedcategories' ],
94  [ 'UncategorizedPagesPage', 'Uncategorizedpages' ],
95  [ 'UncategorizedImagesPage', 'Uncategorizedimages' ],
96  [ 'UncategorizedTemplatesPage', 'Uncategorizedtemplates' ],
97  [ 'UnusedCategoriesPage', 'Unusedcategories' ],
98  [ 'UnusedimagesPage', 'Unusedimages' ],
99  [ 'WantedCategoriesPage', 'Wantedcategories' ],
100  [ 'WantedFilesPage', 'Wantedfiles' ],
101  [ 'WantedPagesPage', 'Wantedpages' ],
102  [ 'WantedTemplatesPage', 'Wantedtemplates' ],
103  [ 'UnwatchedpagesPage', 'Unwatchedpages' ],
104  [ 'UnusedtemplatesPage', 'Unusedtemplates' ],
105  [ 'WithoutInterwikiPage', 'Withoutinterwiki' ],
106  ];
107  Hooks::run( 'wgQueryPages', [ &$qp ] );
108  }
109 
110  return $qp;
111  }
112 
118  function setListoutput( $bool ) {
119  $this->listoutput = $bool;
120  }
121 
148  public function getQueryInfo() {
149  return null;
150  }
151 
158  function getSQL() {
159  /* Implement getQueryInfo() instead */
160  throw new MWException( "Bug in a QueryPage: doesn't implement getQueryInfo() nor "
161  . "getQuery() properly" );
162  }
163 
171  function getOrderFields() {
172  return [ 'value' ];
173  }
174 
185  public function usesTimestamps() {
186  return false;
187  }
188 
194  function sortDescending() {
195  return true;
196  }
197 
205  public function isExpensive() {
206  return $this->getConfig()->get( 'DisableQueryPages' );
207  }
208 
216  public function isCacheable() {
217  return true;
218  }
219 
226  public function isCached() {
227  return $this->isExpensive() && $this->getConfig()->get( 'MiserMode' );
228  }
229 
235  function isSyndicated() {
236  return true;
237  }
238 
248  abstract function formatResult( $skin, $result );
249 
255  function getPageHeader() {
256  return '';
257  }
258 
266  protected function showEmptyText() {
267  $this->getOutput()->addWikiMsg( 'specialpage-empty' );
268  }
269 
277  function linkParameters() {
278  return [];
279  }
280 
292  function tryLastResult() {
293  return false;
294  }
295 
304  public function recache( $limit, $ignoreErrors = true ) {
305  if ( !$this->isCacheable() ) {
306  return 0;
307  }
308 
309  $fname = static::class . '::recache';
310  $dbw = wfGetDB( DB_MASTER );
311  if ( !$dbw ) {
312  return false;
313  }
314 
315  try {
316  # Do query
317  $res = $this->reallyDoQuery( $limit, false );
318  $num = false;
319  if ( $res ) {
320  $num = $res->numRows();
321  # Fetch results
322  $vals = [];
323  foreach ( $res as $row ) {
324  if ( isset( $row->value ) ) {
325  if ( $this->usesTimestamps() ) {
326  $value = wfTimestamp( TS_UNIX,
327  $row->value );
328  } else {
329  $value = intval( $row->value ); // T16414
330  }
331  } else {
332  $value = 0;
333  }
334 
335  $vals[] = [
336  'qc_type' => $this->getName(),
337  'qc_namespace' => $row->namespace,
338  'qc_title' => $row->title,
339  'qc_value' => $value
340  ];
341  }
342 
343  $dbw->doAtomicSection(
344  __METHOD__,
345  function ( IDatabase $dbw, $fname ) use ( $vals ) {
346  # Clear out any old cached data
347  $dbw->delete( 'querycache',
348  [ 'qc_type' => $this->getName() ],
349  $fname
350  );
351  # Save results into the querycache table on the master
352  if ( count( $vals ) ) {
353  $dbw->insert( 'querycache', $vals, $fname );
354  }
355  # Update the querycache_info record for the page
356  $dbw->delete( 'querycache_info',
357  [ 'qci_type' => $this->getName() ],
358  $fname
359  );
360  $dbw->insert( 'querycache_info',
361  [ 'qci_type' => $this->getName(),
362  'qci_timestamp' => $dbw->timestamp() ],
363  $fname
364  );
365  }
366  );
367  }
368  } catch ( DBError $e ) {
369  if ( !$ignoreErrors ) {
370  throw $e; // report query error
371  }
372  $num = false; // set result to false to indicate error
373  }
374 
375  return $num;
376  }
377 
382  function getRecacheDB() {
383  return wfGetDB( DB_REPLICA, [ $this->getName(), 'QueryPage::recache', 'vslow' ] );
384  }
385 
393  public function reallyDoQuery( $limit, $offset = false ) {
394  $fname = static::class . '::reallyDoQuery';
395  $dbr = $this->getRecacheDB();
396  $query = $this->getQueryInfo();
397  $order = $this->getOrderFields();
398 
399  if ( $this->sortDescending() ) {
400  foreach ( $order as &$field ) {
401  $field .= ' DESC';
402  }
403  }
404 
405  if ( is_array( $query ) ) {
406  $tables = isset( $query['tables'] ) ? (array)$query['tables'] : [];
407  $fields = isset( $query['fields'] ) ? (array)$query['fields'] : [];
408  $conds = isset( $query['conds'] ) ? (array)$query['conds'] : [];
409  $options = isset( $query['options'] ) ? (array)$query['options'] : [];
410  $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : [];
411 
412  if ( $order ) {
413  $options['ORDER BY'] = $order;
414  }
415 
416  if ( $limit !== false ) {
417  $options['LIMIT'] = intval( $limit );
418  }
419 
420  if ( $offset !== false ) {
421  $options['OFFSET'] = intval( $offset );
422  }
423 
424  $res = $dbr->select( $tables, $fields, $conds, $fname,
425  $options, $join_conds
426  );
427  } else {
428  // Old-fashioned raw SQL style, deprecated
429  $sql = $this->getSQL();
430  $sql .= ' ORDER BY ' . implode( ', ', $order );
431  $sql = $dbr->limitResult( $sql, $limit, $offset );
432  $res = $dbr->query( $sql, $fname );
433  }
434 
435  return $res;
436  }
437 
444  public function doQuery( $offset = false, $limit = false ) {
445  if ( $this->isCached() && $this->isCacheable() ) {
446  return $this->fetchFromCache( $limit, $offset );
447  } else {
448  return $this->reallyDoQuery( $limit, $offset );
449  }
450  }
451 
459  public function fetchFromCache( $limit, $offset = false ) {
460  $dbr = wfGetDB( DB_REPLICA );
461  $options = [];
462 
463  if ( $limit !== false ) {
464  $options['LIMIT'] = intval( $limit );
465  }
466 
467  if ( $offset !== false ) {
468  $options['OFFSET'] = intval( $offset );
469  }
470 
471  $order = $this->getCacheOrderFields();
472  if ( $this->sortDescending() ) {
473  foreach ( $order as &$field ) {
474  $field .= " DESC";
475  }
476  }
477  if ( $order ) {
478  $options['ORDER BY'] = $order;
479  }
480 
481  return $dbr->select( 'querycache',
482  [ 'qc_type',
483  'namespace' => 'qc_namespace',
484  'title' => 'qc_title',
485  'value' => 'qc_value' ],
486  [ 'qc_type' => $this->getName() ],
487  __METHOD__,
488  $options
489  );
490  }
491 
498  function getCacheOrderFields() {
499  return [ 'value' ];
500  }
501 
502  public function getCachedTimestamp() {
503  if ( is_null( $this->cachedTimestamp ) ) {
504  $dbr = wfGetDB( DB_REPLICA );
505  $fname = static::class . '::getCachedTimestamp';
506  $this->cachedTimestamp = $dbr->selectField( 'querycache_info', 'qci_timestamp',
507  [ 'qci_type' => $this->getName() ], $fname );
508  }
509  return $this->cachedTimestamp;
510  }
511 
524  protected function getLimitOffset() {
525  list( $limit, $offset ) = $this->getRequest()->getLimitOffset();
526  if ( $this->getConfig()->get( 'MiserMode' ) ) {
527  $maxResults = $this->getMaxResults();
528  // Can't display more than max results on a page
529  $limit = min( $limit, $maxResults );
530  // Can't skip over more than the end of $maxResults
531  $offset = min( $offset, $maxResults + 1 );
532  }
533  return [ $limit, $offset ];
534  }
535 
544  protected function getDBLimit( $uiLimit, $uiOffset ) {
545  $maxResults = $this->getMaxResults();
546  if ( $this->getConfig()->get( 'MiserMode' ) ) {
547  $limit = min( $uiLimit + 1, $maxResults - $uiOffset );
548  return max( $limit, 0 );
549  } else {
550  return $uiLimit + 1;
551  }
552  }
553 
563  protected function getMaxResults() {
564  // Max of 10000, unless we store more than 10000 in query cache.
565  return max( $this->getConfig()->get( 'QueryCacheLimit' ), 10000 );
566  }
567 
573  public function execute( $par ) {
574  $user = $this->getUser();
575  if ( !$this->userCanExecute( $user ) ) {
576  $this->displayRestrictionError();
577  return;
578  }
579 
580  $this->setHeaders();
581  $this->outputHeader();
582 
583  $out = $this->getOutput();
584 
585  if ( $this->isCached() && !$this->isCacheable() ) {
586  $out->addWikiMsg( 'querypage-disabled' );
587  return;
588  }
589 
590  $out->setSyndicated( $this->isSyndicated() );
591 
592  if ( $this->limit == 0 && $this->offset == 0 ) {
593  list( $this->limit, $this->offset ) = $this->getLimitOffset();
594  }
595  $dbLimit = $this->getDBLimit( $this->limit, $this->offset );
596  // @todo Use doQuery()
597  if ( !$this->isCached() ) {
598  # select one extra row for navigation
599  $res = $this->reallyDoQuery( $dbLimit, $this->offset );
600  } else {
601  # Get the cached result, select one extra row for navigation
602  $res = $this->fetchFromCache( $dbLimit, $this->offset );
603  if ( !$this->listoutput ) {
604 
605  # Fetch the timestamp of this update
606  $ts = $this->getCachedTimestamp();
607  $lang = $this->getLanguage();
608  $maxResults = $lang->formatNum( $this->getConfig()->get( 'QueryCacheLimit' ) );
609 
610  if ( $ts ) {
611  $updated = $lang->userTimeAndDate( $ts, $user );
612  $updateddate = $lang->userDate( $ts, $user );
613  $updatedtime = $lang->userTime( $ts, $user );
614  $out->addMeta( 'Data-Cache-Time', $ts );
615  $out->addJsConfigVars( 'dataCacheTime', $ts );
616  $out->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime, $maxResults );
617  } else {
618  $out->addWikiMsg( 'perfcached', $maxResults );
619  }
620 
621  # If updates on this page have been disabled, let the user know
622  # that the data set won't be refreshed for now
623  if ( is_array( $this->getConfig()->get( 'DisableQueryPageUpdate' ) )
624  && in_array( $this->getName(), $this->getConfig()->get( 'DisableQueryPageUpdate' ) )
625  ) {
626  $out->wrapWikiMsg(
627  "<div class=\"mw-querypage-no-updates\">\n$1\n</div>",
628  'querypage-no-updates'
629  );
630  }
631  }
632  }
633 
634  $this->numRows = $res->numRows();
635 
636  $dbr = $this->getRecacheDB();
637  $this->preprocessResults( $dbr, $res );
638 
639  $out->addHTML( Xml::openElement( 'div', [ 'class' => 'mw-spcontent' ] ) );
640 
641  # Top header and navigation
642  if ( $this->shownavigation ) {
643  $out->addHTML( $this->getPageHeader() );
644  if ( $this->numRows > 0 ) {
645  $out->addHTML( $this->msg( 'showingresultsinrange' )->numParams(
646  min( $this->numRows, $this->limit ), # do not show the one extra row, if exist
647  $this->offset + 1, ( min( $this->numRows, $this->limit ) + $this->offset ) )->parseAsBlock() );
648  # Disable the "next" link when we reach the end
649  $miserMaxResults = $this->getConfig()->get( 'MiserMode' )
650  && ( $this->offset + $this->limit >= $this->getMaxResults() );
651  $atEnd = ( $this->numRows <= $this->limit ) || $miserMaxResults;
652  $paging = $this->getLanguage()->viewPrevNext( $this->getPageTitle( $par ), $this->offset,
653  $this->limit, $this->linkParameters(), $atEnd );
654  $out->addHTML( '<p>' . $paging . '</p>' );
655  } else {
656  # No results to show, so don't bother with "showing X of Y" etc.
657  # -- just let the user know and give up now
658  $this->showEmptyText();
659  $out->addHTML( Xml::closeElement( 'div' ) );
660  return;
661  }
662  }
663 
664  # The actual results; specialist subclasses will want to handle this
665  # with more than a straight list, so we hand them the info, plus
666  # an OutputPage, and let them get on with it
667  $this->outputResults( $out,
668  $this->getSkin(),
669  $dbr, # Should use a ResultWrapper for this
670  $res,
671  min( $this->numRows, $this->limit ), # do not format the one extra row, if exist
672  $this->offset );
673 
674  # Repeat the paging links at the bottom
675  if ( $this->shownavigation ) {
676  $out->addHTML( '<p>' . $paging . '</p>' );
677  }
678 
679  $out->addHTML( Xml::closeElement( 'div' ) );
680  }
681 
693  protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
695 
696  if ( $num > 0 ) {
697  $html = [];
698  if ( !$this->listoutput ) {
699  $html[] = $this->openList( $offset );
700  }
701 
702  # $res might contain the whole 1,000 rows, so we read up to
703  # $num [should update this to use a Pager]
704  // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
705  for ( $i = 0; $i < $num && $row = $res->fetchObject(); $i++ ) {
706  // @codingStandardsIgnoreEnd
707  $line = $this->formatResult( $skin, $row );
708  if ( $line ) {
709  $html[] = $this->listoutput
710  ? $line
711  : "<li>{$line}</li>\n";
712  }
713  }
714 
715  # Flush the final result
716  if ( $this->tryLastResult() ) {
717  $row = null;
718  $line = $this->formatResult( $skin, $row );
719  if ( $line ) {
720  $html[] = $this->listoutput
721  ? $line
722  : "<li>{$line}</li>\n";
723  }
724  }
725 
726  if ( !$this->listoutput ) {
727  $html[] = $this->closeList();
728  }
729 
730  $html = $this->listoutput
731  ? $wgContLang->listToText( $html )
732  : implode( '', $html );
733 
734  $out->addHTML( $html );
735  }
736  }
737 
742  function openList( $offset ) {
743  return "\n<ol start='" . ( $offset + 1 ) . "' class='special'>\n";
744  }
745 
749  function closeList() {
750  return "</ol>\n";
751  }
752 
758  function preprocessResults( $db, $res ) {
759  }
760 
767  function doFeed( $class = '', $limit = 50 ) {
768  if ( !$this->getConfig()->get( 'Feed' ) ) {
769  $this->getOutput()->addWikiMsg( 'feed-unavailable' );
770  return false;
771  }
772 
773  $limit = min( $limit, $this->getConfig()->get( 'FeedLimit' ) );
774 
775  $feedClasses = $this->getConfig()->get( 'FeedClasses' );
776  if ( isset( $feedClasses[$class] ) ) {
778  $feed = new $feedClasses[$class](
779  $this->feedTitle(),
780  $this->feedDesc(),
781  $this->feedUrl() );
782  $feed->outHeader();
783 
784  $res = $this->reallyDoQuery( $limit, 0 );
785  foreach ( $res as $obj ) {
786  $item = $this->feedResult( $obj );
787  if ( $item ) {
788  $feed->outItem( $item );
789  }
790  }
791 
792  $feed->outFooter();
793  return true;
794  } else {
795  return false;
796  }
797  }
798 
805  function feedResult( $row ) {
806  if ( !isset( $row->title ) ) {
807  return null;
808  }
809  $title = Title::makeTitle( intval( $row->namespace ), $row->title );
810  if ( $title ) {
811  $date = isset( $row->timestamp ) ? $row->timestamp : '';
812  $comments = '';
813  if ( $title ) {
814  $talkpage = $title->getTalkPage();
815  $comments = $talkpage->getFullURL();
816  }
817 
818  return new FeedItem(
819  $title->getPrefixedText(),
820  $this->feedItemDesc( $row ),
821  $title->getFullURL(),
822  $date,
823  $this->feedItemAuthor( $row ),
824  $comments );
825  } else {
826  return null;
827  }
828  }
829 
830  function feedItemDesc( $row ) {
831  return isset( $row->comment ) ? htmlspecialchars( $row->comment ) : '';
832  }
833 
834  function feedItemAuthor( $row ) {
835  return isset( $row->user_text ) ? $row->user_text : '';
836  }
837 
838  function feedTitle() {
839  $desc = $this->getDescription();
840  $code = $this->getConfig()->get( 'LanguageCode' );
841  $sitename = $this->getConfig()->get( 'Sitename' );
842  return "$sitename - $desc [$code]";
843  }
844 
845  function feedDesc() {
846  return $this->msg( 'tagline' )->text();
847  }
848 
849  function feedUrl() {
850  return $this->getPageTitle()->getFullURL();
851  }
852 
863  protected function executeLBFromResultWrapper( ResultWrapper $res, $ns = null ) {
864  if ( !$res->numRows() ) {
865  return;
866  }
867 
868  $batch = new LinkBatch;
869  foreach ( $res as $row ) {
870  $batch->add( $ns !== null ? $ns : $row->namespace, $row->title );
871  }
872  $batch->execute();
873 
874  $res->seek( 0 );
875  }
876 }
QueryPage\setListoutput
setListoutput( $bool)
A mutator for $this->listoutput;.
Definition: QueryPage.php:118
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:628
QueryPage\$listoutput
bool $listoutput
Whether or not we want plain listoutput rather than an ordered list.
Definition: QueryPage.php:36
FeedItem
A base class for basic support for outputting syndication feeds in RSS and other formats.
Definition: Feed.php:38
$tables
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition: hooks.txt:990
QueryPage\feedTitle
feedTitle()
Definition: QueryPage.php:838
QueryPage\getCacheOrderFields
getCacheOrderFields()
Return the order fields for fetchFromCache.
Definition: QueryPage.php:498
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:675
QueryPage\$cachedTimestamp
$cachedTimestamp
Definition: QueryPage.php:51
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
captcha-old.count
count
Definition: captcha-old.py:225
QueryPage\isCacheable
isCacheable()
Is the output of this query cacheable? Non-cacheable expensive pages will be disabled in miser mode a...
Definition: QueryPage.php:216
QueryPage\getPageHeader
getPageHeader()
The content returned by this function will be output before any result.
Definition: QueryPage.php:255
$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
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1994
QueryPage\linkParameters
linkParameters()
If using extra form wheely-dealies, return a set of parameters here as an associative array.
Definition: QueryPage.php:277
QueryPage\formatResult
formatResult( $skin, $result)
Formats the results of the query for display.
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
QueryPage\outputResults
outputResults( $out, $skin, $dbr, $res, $num, $offset)
Format and output report results using the given information plus OutputPage.
Definition: QueryPage.php:693
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:246
QueryPage\getLimitOffset
getLimitOffset()
Returns limit and offset, as returned by $this->getRequest()->getLimitOffset().
Definition: QueryPage.php:524
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:36
SpecialPage\displayRestrictionError
displayRestrictionError()
Output an error message telling the user what access level they have to have.
Definition: SpecialPage.php:295
QueryPage\openList
openList( $offset)
Definition: QueryPage.php:742
QueryPage\preprocessResults
preprocessResults( $db, $res)
Do any necessary preprocessing of the result object.
Definition: QueryPage.php:758
QueryPage\execute
execute( $par)
This is the actual workhorse.
Definition: QueryPage.php:573
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:695
$res
$res
Definition: database.txt:21
Wikimedia\Rdbms\ResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: ResultWrapper.php:24
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:705
SpecialPage\getName
getName()
Get the name of this Special Page.
Definition: SpecialPage.php:150
Wikimedia\Rdbms\DBError
Database error base class.
Definition: DBError.php:30
QueryPage\reallyDoQuery
reallyDoQuery( $limit, $offset=false)
Run the query and return the result.
Definition: QueryPage.php:393
QueryPage
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition: QueryPage.php:34
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
Wikimedia\Rdbms\IDatabase\insert
insert( $table, $a, $fname=__METHOD__, $options=[])
INSERT wrapper, inserts an array into a table.
QueryPage\$offset
int $offset
The offset and limit in use, as passed to the query() function.
Definition: QueryPage.php:39
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
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
QueryPage\$limit
int $limit
Definition: QueryPage.php:42
QueryPage\feedItemDesc
feedItemDesc( $row)
Definition: QueryPage.php:830
QueryPage\getCachedTimestamp
getCachedTimestamp()
Definition: QueryPage.php:502
SpecialPage\getDescription
getDescription()
Returns the name that goes in the <h1> in the special page itself, and also the name that will be l...
Definition: SpecialPage.php:606
QueryPage\closeList
closeList()
Definition: QueryPage.php:749
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1572
Wikimedia\Rdbms\IDatabase\timestamp
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1956
MWException
MediaWiki exception.
Definition: MWException.php:26
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:714
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
QueryPage\getMaxResults
getMaxResults()
Get max number of results we can return in miser mode.
Definition: QueryPage.php:563
a
</source > ! result< div class="mw-highlight mw-content-ltr" dir="ltr">< pre >< span ></span >< span class="kd"> var</span >< span class="nx"> a</span >< span class="p"></span ></pre ></div > ! end ! test Multiline< source/> in lists !input *< source > a b</source > *foo< source > a b</source > ! html< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! html tidy< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! end ! test Custom attributes !input< source lang="javascript" id="foo" class="bar" dir="rtl" style="font-size: larger;"> var a
Definition: parserTests.txt:89
QueryPage\isCached
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
Definition: QueryPage.php:226
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
not
if not
Definition: COPYING.txt:307
QueryPage\isExpensive
isExpensive()
Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.
Definition: QueryPage.php:205
QueryPage\recache
recache( $limit, $ignoreErrors=true)
Clear the cache and save new results.
Definition: QueryPage.php:304
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:484
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:685
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:514
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
QueryPage\doFeed
doFeed( $class='', $limit=50)
Similar to above, but packaging in a syndicated feed instead of a web page.
Definition: QueryPage.php:767
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
QueryPage\getRecacheDB
getRecacheDB()
Get a DB connection to be used for slow recache queries.
Definition: QueryPage.php:382
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
QueryPage\feedDesc
feedDesc()
Definition: QueryPage.php:845
QueryPage\feedUrl
feedUrl()
Definition: QueryPage.php:849
$line
$line
Definition: cdb.php:58
QueryPage\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: QueryPage.php:148
QueryPage\getOrderFields
getOrderFields()
Subclasses return an array of fields to order by here.
Definition: QueryPage.php:171
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
SpecialPage\userCanExecute
userCanExecute(User $user)
Checks if the given user (identified by an object) can execute this special page (as defined by $mRes...
Definition: SpecialPage.php:287
$value
$value
Definition: styleTest.css.php:45
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:746
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:36
QueryPage\doQuery
doQuery( $offset=false, $limit=false)
Somewhat deprecated, you probably want to be using execute()
Definition: QueryPage.php:444
QueryPage\fetchFromCache
fetchFromCache( $limit, $offset=false)
Fetch the query results from the query cache.
Definition: QueryPage.php:459
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:665
QueryPage\executeLBFromResultWrapper
executeLBFromResultWrapper(ResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed ResultWrapper (MUST include title and ...
Definition: QueryPage.php:863
QueryPage\feedItemAuthor
feedItemAuthor( $row)
Definition: QueryPage.php:834
QueryPage\showEmptyText
showEmptyText()
Outputs some kind of an informative message (via OutputPage) to let the user know that the query retu...
Definition: QueryPage.php:266
format
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1630
QueryPage\feedResult
feedResult( $row)
Override for custom handling.
Definition: QueryPage.php:805
QueryPage\isSyndicated
isSyndicated()
Sometime we don't want to build rss / atom feeds.
Definition: QueryPage.php:235
QueryPage\getSQL
getSQL()
For back-compat, subclasses may return a raw SQL query here, as a string.
Definition: QueryPage.php:158
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:118
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
$code
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition: hooks.txt:783
QueryPage\tryLastResult
tryLastResult()
Some special pages (for example SpecialListusers used to) might not return the current object formatt...
Definition: QueryPage.php:292
QueryPage\$shownavigation
$shownavigation
Whether to show prev/next links.
Definition: QueryPage.php:56
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
$skin
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition: hooks.txt:1956
QueryPage\usesTimestamps
usesTimestamps()
Does this query return timestamps rather than integers in its 'value' field? If true,...
Definition: QueryPage.php:185
$batch
$batch
Definition: linkcache.txt:23
QueryPage\getDBLimit
getDBLimit( $uiLimit, $uiOffset)
What is limit to fetch from DB.
Definition: QueryPage.php:544
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
QueryPage\sortDescending
sortDescending()
Override to sort by increasing values.
Definition: QueryPage.php:194
QueryPage\getPages
static getPages()
Get a list of query page classes and their associated special pages, for periodic updates.
Definition: QueryPage.php:66
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:583
$options
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049
Wikimedia\Rdbms\IDatabase\delete
delete( $table, $conds, $fname=__METHOD__)
DELETE query wrapper.
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
QueryPage\$numRows
$numRows
The number of rows returned by the query.
Definition: QueryPage.php:49
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:783