MediaWiki  master
ApiPageSet.php
Go to the documentation of this file.
1 <?php
25 
40 class ApiPageSet extends ApiBase {
45  const DISABLE_GENERATORS = 1;
46 
47  private $mDbSource;
48  private $mParams;
50  private $mConvertTitles;
52 
53  private $mAllPages = []; // [ns][dbkey] => page_id or negative when missing
54  private $mTitles = [];
55  private $mGoodAndMissingPages = []; // [ns][dbkey] => page_id or negative when missing
56  private $mGoodPages = []; // [ns][dbkey] => page_id
57  private $mGoodTitles = [];
58  private $mMissingPages = []; // [ns][dbkey] => fake page_id
59  private $mMissingTitles = [];
61  private $mInvalidTitles = [];
62  private $mMissingPageIDs = [];
63  private $mRedirectTitles = [];
64  private $mSpecialTitles = [];
65  private $mAllSpecials = []; // separate from mAllPages to avoid breaking getAllTitlesByNamespace()
66  private $mNormalizedTitles = [];
67  private $mInterwikiTitles = [];
69  private $mPendingRedirectIDs = [];
70  private $mPendingRedirectSpecialPages = []; // [dbkey] => [ Title $from, Title $to ]
72  private $mConvertedTitles = [];
73  private $mGoodRevIDs = [];
74  private $mLiveRevIDs = [];
75  private $mDeletedRevIDs = [];
76  private $mMissingRevIDs = [];
77  private $mGeneratorData = []; // [ns][dbkey] => data array
78  private $mFakePageId = -1;
79  private $mCacheMode = 'public';
80  private $mRequestedPageFields = [];
85 
93  private static function addValues( array &$result, $values, $flags = [], $name = null ) {
94  foreach ( $values as $val ) {
95  if ( $val instanceof Title ) {
96  $v = [];
97  ApiQueryBase::addTitleInfo( $v, $val );
98  } elseif ( $name !== null ) {
99  $v = [ $name => $val ];
100  } else {
101  $v = $val;
102  }
103  foreach ( $flags as $flag ) {
104  $v[$flag] = true;
105  }
106  $result[] = $v;
107  }
108  }
109 
117  public function __construct( ApiBase $dbSource, $flags = 0, $defaultNamespace = NS_MAIN ) {
118  parent::__construct( $dbSource->getMain(), $dbSource->getModuleName() );
119  $this->mDbSource = $dbSource;
120  $this->mAllowGenerator = ( $flags & self::DISABLE_GENERATORS ) == 0;
121  $this->mDefaultNamespace = $defaultNamespace;
122 
123  $this->mParams = $this->extractRequestParams();
124  $this->mResolveRedirects = $this->mParams['redirects'];
125  $this->mConvertTitles = $this->mParams['converttitles'];
126  }
127 
132  public function executeDryRun() {
133  $this->executeInternal( true );
134  }
135 
139  public function execute() {
140  $this->executeInternal( false );
141  }
142 
148  private function executeInternal( $isDryRun ) {
149  $generatorName = $this->mAllowGenerator ? $this->mParams['generator'] : null;
150  if ( isset( $generatorName ) ) {
151  $dbSource = $this->mDbSource;
152  if ( !$dbSource instanceof ApiQuery ) {
153  // If the parent container of this pageset is not ApiQuery, we must create it to run generator
154  $dbSource = $this->getMain()->getModuleManager()->getModule( 'query' );
155  }
156  $generator = $dbSource->getModuleManager()->getModule( $generatorName, null, true );
157  if ( $generator === null ) {
158  $this->dieWithError( [ 'apierror-badgenerator-unknown', $generatorName ], 'badgenerator' );
159  }
160  if ( !$generator instanceof ApiQueryGeneratorBase ) {
161  $this->dieWithError( [ 'apierror-badgenerator-notgenerator', $generatorName ], 'badgenerator' );
162  }
163  // Create a temporary pageset to store generator's output,
164  // add any additional fields generator may need, and execute pageset to populate titles/pageids
165  $tmpPageSet = new ApiPageSet( $dbSource, self::DISABLE_GENERATORS );
166  $generator->setGeneratorMode( $tmpPageSet );
167  $this->mCacheMode = $generator->getCacheMode( $generator->extractRequestParams() );
168 
169  if ( !$isDryRun ) {
170  $generator->requestExtraData( $tmpPageSet );
171  }
172  $tmpPageSet->executeInternal( $isDryRun );
173 
174  // populate this pageset with the generator output
175  if ( !$isDryRun ) {
176  $generator->executeGenerator( $this );
177 
178  // Avoid PHP 7.1 warning of passing $this by reference
179  $apiModule = $this;
180  Hooks::run( 'APIQueryGeneratorAfterExecute', [ &$generator, &$apiModule ] );
181  } else {
182  // Prevent warnings from being reported on these parameters
183  $main = $this->getMain();
184  foreach ( $generator->extractRequestParams() as $paramName => $param ) {
185  $main->markParamsUsed( $generator->encodeParamName( $paramName ) );
186  }
187  }
188 
189  if ( !$isDryRun ) {
190  $this->resolvePendingRedirects();
191  }
192  } else {
193  // Only one of the titles/pageids/revids is allowed at the same time
194  $dataSource = null;
195  if ( isset( $this->mParams['titles'] ) ) {
196  $dataSource = 'titles';
197  }
198  if ( isset( $this->mParams['pageids'] ) ) {
199  if ( isset( $dataSource ) ) {
200  $this->dieWithError(
201  [
202  'apierror-invalidparammix-cannotusewith',
203  $this->encodeParamName( 'pageids' ),
204  $this->encodeParamName( $dataSource )
205  ],
206  'multisource'
207  );
208  }
209  $dataSource = 'pageids';
210  }
211  if ( isset( $this->mParams['revids'] ) ) {
212  if ( isset( $dataSource ) ) {
213  $this->dieWithError(
214  [
215  'apierror-invalidparammix-cannotusewith',
216  $this->encodeParamName( 'revids' ),
217  $this->encodeParamName( $dataSource )
218  ],
219  'multisource'
220  );
221  }
222  $dataSource = 'revids';
223  }
224 
225  if ( !$isDryRun ) {
226  // Populate page information with the original user input
227  switch ( $dataSource ) {
228  case 'titles':
229  $this->initFromTitles( $this->mParams['titles'] );
230  break;
231  case 'pageids':
232  $this->initFromPageIds( $this->mParams['pageids'] );
233  break;
234  case 'revids':
235  if ( $this->mResolveRedirects ) {
236  $this->addWarning( 'apiwarn-redirectsandrevids' );
237  }
238  $this->mResolveRedirects = false;
239  $this->initFromRevIDs( $this->mParams['revids'] );
240  break;
241  default:
242  // Do nothing - some queries do not need any of the data sources.
243  break;
244  }
245  }
246  }
247  }
248 
253  public function isResolvingRedirects() {
255  }
256 
265  public function getDataSource() {
266  if ( $this->mAllowGenerator && isset( $this->mParams['generator'] ) ) {
267  return 'generator';
268  }
269  if ( isset( $this->mParams['titles'] ) ) {
270  return 'titles';
271  }
272  if ( isset( $this->mParams['pageids'] ) ) {
273  return 'pageids';
274  }
275  if ( isset( $this->mParams['revids'] ) ) {
276  return 'revids';
277  }
278 
279  return null;
280  }
281 
287  public function requestField( $fieldName ) {
288  $this->mRequestedPageFields[$fieldName] = null;
289  }
290 
297  public function getCustomField( $fieldName ) {
298  return $this->mRequestedPageFields[$fieldName];
299  }
300 
307  public function getPageTableFields() {
308  // Ensure we get minimum required fields
309  // DON'T change this order
310  $pageFlds = [
311  'page_namespace' => null,
312  'page_title' => null,
313  'page_id' => null,
314  ];
315 
316  if ( $this->mResolveRedirects ) {
317  $pageFlds['page_is_redirect'] = null;
318  }
319 
320  if ( $this->getConfig()->get( 'ContentHandlerUseDB' ) ) {
321  $pageFlds['page_content_model'] = null;
322  }
323 
324  if ( $this->getConfig()->get( 'PageLanguageUseDB' ) ) {
325  $pageFlds['page_lang'] = null;
326  }
327 
328  foreach ( LinkCache::getSelectFields() as $field ) {
329  $pageFlds[$field] = null;
330  }
331 
332  $pageFlds = array_merge( $pageFlds, $this->mRequestedPageFields );
333 
334  return array_keys( $pageFlds );
335  }
336 
343  public function getAllTitlesByNamespace() {
344  return $this->mAllPages;
345  }
346 
351  public function getTitles() {
352  return $this->mTitles;
353  }
354 
359  public function getTitleCount() {
360  return count( $this->mTitles );
361  }
362 
367  public function getGoodTitlesByNamespace() {
368  return $this->mGoodPages;
369  }
370 
375  public function getGoodTitles() {
376  return $this->mGoodTitles;
377  }
378 
383  public function getGoodTitleCount() {
384  return count( $this->mGoodTitles );
385  }
386 
392  public function getMissingTitlesByNamespace() {
393  return $this->mMissingPages;
394  }
395 
401  public function getMissingTitles() {
402  return $this->mMissingTitles;
403  }
404 
411  }
412 
417  public function getGoodAndMissingTitles() {
418  return $this->mGoodTitles + $this->mMissingTitles;
419  }
420 
426  public function getInvalidTitlesAndReasons() {
427  return $this->mInvalidTitles;
428  }
429 
434  public function getMissingPageIDs() {
435  return $this->mMissingPageIDs;
436  }
437 
443  public function getRedirectTitles() {
444  return $this->mRedirectTitles;
445  }
446 
454  public function getRedirectTitlesAsResult( $result = null ) {
455  $values = [];
456  foreach ( $this->getRedirectTitles() as $titleStrFrom => $titleTo ) {
457  $r = [
458  'from' => strval( $titleStrFrom ),
459  'to' => $titleTo->getPrefixedText(),
460  ];
461  if ( $titleTo->hasFragment() ) {
462  $r['tofragment'] = $titleTo->getFragment();
463  }
464  if ( $titleTo->isExternal() ) {
465  $r['tointerwiki'] = $titleTo->getInterwiki();
466  }
467  if ( isset( $this->mResolvedRedirectTitles[$titleStrFrom] ) ) {
468  $titleFrom = $this->mResolvedRedirectTitles[$titleStrFrom];
469  $ns = $titleFrom->getNamespace();
470  $dbkey = $titleFrom->getDBkey();
471  if ( isset( $this->mGeneratorData[$ns][$dbkey] ) ) {
472  $r = array_merge( $this->mGeneratorData[$ns][$dbkey], $r );
473  }
474  }
475 
476  $values[] = $r;
477  }
478  if ( !empty( $values ) && $result ) {
479  ApiResult::setIndexedTagName( $values, 'r' );
480  }
481 
482  return $values;
483  }
484 
490  public function getNormalizedTitles() {
492  }
493 
501  public function getNormalizedTitlesAsResult( $result = null ) {
502  $values = [];
503  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
504  foreach ( $this->getNormalizedTitles() as $rawTitleStr => $titleStr ) {
505  $encode = $contLang->normalize( $rawTitleStr ) !== $rawTitleStr;
506  $values[] = [
507  'fromencoded' => $encode,
508  'from' => $encode ? rawurlencode( $rawTitleStr ) : $rawTitleStr,
509  'to' => $titleStr
510  ];
511  }
512  if ( !empty( $values ) && $result ) {
513  ApiResult::setIndexedTagName( $values, 'n' );
514  }
515 
516  return $values;
517  }
518 
524  public function getConvertedTitles() {
526  }
527 
535  public function getConvertedTitlesAsResult( $result = null ) {
536  $values = [];
537  foreach ( $this->getConvertedTitles() as $rawTitleStr => $titleStr ) {
538  $values[] = [
539  'from' => $rawTitleStr,
540  'to' => $titleStr
541  ];
542  }
543  if ( !empty( $values ) && $result ) {
544  ApiResult::setIndexedTagName( $values, 'c' );
545  }
546 
547  return $values;
548  }
549 
555  public function getInterwikiTitles() {
557  }
558 
567  public function getInterwikiTitlesAsResult( $result = null, $iwUrl = false ) {
568  $values = [];
569  foreach ( $this->getInterwikiTitles() as $rawTitleStr => $interwikiStr ) {
570  $item = [
571  'title' => $rawTitleStr,
572  'iw' => $interwikiStr,
573  ];
574  if ( $iwUrl ) {
575  $title = Title::newFromText( $rawTitleStr );
576  $item['url'] = $title->getFullURL( '', false, PROTO_CURRENT );
577  }
578  $values[] = $item;
579  }
580  if ( !empty( $values ) && $result ) {
581  ApiResult::setIndexedTagName( $values, 'i' );
582  }
583 
584  return $values;
585  }
586 
601  public function getInvalidTitlesAndRevisions( $invalidChecks = [ 'invalidTitles',
602  'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles' ]
603  ) {
604  $result = [];
605  if ( in_array( 'invalidTitles', $invalidChecks ) ) {
606  self::addValues( $result, $this->getInvalidTitlesAndReasons(), [ 'invalid' ] );
607  }
608  if ( in_array( 'special', $invalidChecks ) ) {
609  $known = [];
610  $unknown = [];
611  foreach ( $this->getSpecialTitles() as $title ) {
612  if ( $title->isKnown() ) {
613  $known[] = $title;
614  } else {
615  $unknown[] = $title;
616  }
617  }
618  self::addValues( $result, $unknown, [ 'special', 'missing' ] );
619  self::addValues( $result, $known, [ 'special' ] );
620  }
621  if ( in_array( 'missingIds', $invalidChecks ) ) {
622  self::addValues( $result, $this->getMissingPageIDs(), [ 'missing' ], 'pageid' );
623  }
624  if ( in_array( 'missingRevIds', $invalidChecks ) ) {
625  self::addValues( $result, $this->getMissingRevisionIDs(), [ 'missing' ], 'revid' );
626  }
627  if ( in_array( 'missingTitles', $invalidChecks ) ) {
628  $known = [];
629  $unknown = [];
630  foreach ( $this->getMissingTitles() as $title ) {
631  if ( $title->isKnown() ) {
632  $known[] = $title;
633  } else {
634  $unknown[] = $title;
635  }
636  }
637  self::addValues( $result, $unknown, [ 'missing' ] );
638  self::addValues( $result, $known, [ 'missing', 'known' ] );
639  }
640  if ( in_array( 'interwikiTitles', $invalidChecks ) ) {
641  self::addValues( $result, $this->getInterwikiTitlesAsResult() );
642  }
643 
644  return $result;
645  }
646 
651  public function getRevisionIDs() {
652  return $this->mGoodRevIDs;
653  }
654 
659  public function getLiveRevisionIDs() {
660  return $this->mLiveRevIDs;
661  }
662 
667  public function getDeletedRevisionIDs() {
668  return $this->mDeletedRevIDs;
669  }
670 
675  public function getMissingRevisionIDs() {
676  return $this->mMissingRevIDs;
677  }
678 
686  $values = [];
687  foreach ( $this->getMissingRevisionIDs() as $revid ) {
688  $values[$revid] = [
689  'revid' => $revid
690  ];
691  }
692  if ( !empty( $values ) && $result ) {
693  ApiResult::setIndexedTagName( $values, 'rev' );
694  }
695 
696  return $values;
697  }
698 
703  public function getSpecialTitles() {
704  return $this->mSpecialTitles;
705  }
706 
711  public function getRevisionCount() {
712  return count( $this->getRevisionIDs() );
713  }
714 
719  public function populateFromTitles( $titles ) {
720  $this->initFromTitles( $titles );
721  }
722 
727  public function populateFromPageIDs( $pageIDs ) {
728  $this->initFromPageIds( $pageIDs );
729  }
730 
740  public function populateFromQueryResult( $db, $queryResult ) {
741  $this->initFromQueryResult( $queryResult );
742  }
743 
748  public function populateFromRevisionIDs( $revIDs ) {
749  $this->initFromRevIDs( $revIDs );
750  }
751 
756  public function processDbRow( $row ) {
757  // Store Title object in various data structures
758  $title = Title::newFromRow( $row );
759 
760  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
761  $linkCache->addGoodLinkObjFromRow( $title, $row );
762 
763  $pageId = (int)$row->page_id;
764  $this->mAllPages[$row->page_namespace][$row->page_title] = $pageId;
765  $this->mTitles[] = $title;
766 
767  if ( $this->mResolveRedirects && $row->page_is_redirect == '1' ) {
768  $this->mPendingRedirectIDs[$pageId] = $title;
769  } else {
770  $this->mGoodPages[$row->page_namespace][$row->page_title] = $pageId;
771  $this->mGoodAndMissingPages[$row->page_namespace][$row->page_title] = $pageId;
772  $this->mGoodTitles[$pageId] = $title;
773  }
774 
775  foreach ( $this->mRequestedPageFields as $fieldName => &$fieldValues ) {
776  $fieldValues[$pageId] = $row->$fieldName;
777  }
778  }
779 
796  private function initFromTitles( $titles ) {
797  // Get validated and normalized title objects
798  $linkBatch = $this->processTitlesArray( $titles );
799  if ( $linkBatch->isEmpty() ) {
800  // There might be special-page redirects
801  $this->resolvePendingRedirects();
802  return;
803  }
804 
805  $db = $this->getDB();
806  $set = $linkBatch->constructSet( 'page', $db );
807 
808  // Get pageIDs data from the `page` table
809  $res = $db->select( 'page', $this->getPageTableFields(), $set,
810  __METHOD__ );
811 
812  // Hack: get the ns:titles stored in [ ns => [ titles ] ] format
813  $this->initFromQueryResult( $res, $linkBatch->data, true ); // process Titles
814 
815  // Resolve any found redirects
816  $this->resolvePendingRedirects();
817  }
818 
824  private function initFromPageIds( $pageids, $filterIds = true ) {
825  if ( !$pageids ) {
826  return;
827  }
828 
829  $pageids = array_map( 'intval', $pageids ); // paranoia
830  $remaining = array_flip( $pageids );
831 
832  if ( $filterIds ) {
833  $pageids = $this->filterIDs( [ [ 'page', 'page_id' ] ], $pageids );
834  }
835 
836  $res = null;
837  if ( !empty( $pageids ) ) {
838  $set = [
839  'page_id' => $pageids
840  ];
841  $db = $this->getDB();
842 
843  // Get pageIDs data from the `page` table
844  $res = $db->select( 'page', $this->getPageTableFields(), $set,
845  __METHOD__ );
846  }
847 
848  $this->initFromQueryResult( $res, $remaining, false ); // process PageIDs
849 
850  // Resolve any found redirects
851  $this->resolvePendingRedirects();
852  }
853 
864  private function initFromQueryResult( $res, &$remaining = null, $processTitles = null ) {
865  if ( !is_null( $remaining ) && is_null( $processTitles ) ) {
866  ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
867  }
868 
869  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
870 
871  $usernames = [];
872  if ( $res ) {
873  foreach ( $res as $row ) {
874  $pageId = (int)$row->page_id;
875 
876  // Remove found page from the list of remaining items
877  if ( isset( $remaining ) ) {
878  if ( $processTitles ) {
879  unset( $remaining[$row->page_namespace][$row->page_title] );
880  } else {
881  unset( $remaining[$pageId] );
882  }
883  }
884 
885  // Store any extra fields requested by modules
886  $this->processDbRow( $row );
887 
888  // Need gender information
889  if ( $nsInfo->hasGenderDistinction( $row->page_namespace ) ) {
890  $usernames[] = $row->page_title;
891  }
892  }
893  }
894 
895  if ( isset( $remaining ) ) {
896  // Any items left in the $remaining list are added as missing
897  if ( $processTitles ) {
898  // The remaining titles in $remaining are non-existent pages
899  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
900  foreach ( $remaining as $ns => $dbkeys ) {
901  foreach ( array_keys( $dbkeys ) as $dbkey ) {
902  $title = Title::makeTitle( $ns, $dbkey );
903  $linkCache->addBadLinkObj( $title );
904  $this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
905  $this->mMissingPages[$ns][$dbkey] = $this->mFakePageId;
906  $this->mGoodAndMissingPages[$ns][$dbkey] = $this->mFakePageId;
907  $this->mMissingTitles[$this->mFakePageId] = $title;
908  $this->mFakePageId--;
909  $this->mTitles[] = $title;
910 
911  // need gender information
912  if ( $nsInfo->hasGenderDistinction( $ns ) ) {
913  $usernames[] = $dbkey;
914  }
915  }
916  }
917  } else {
918  // The remaining pageids do not exist
919  if ( !$this->mMissingPageIDs ) {
920  $this->mMissingPageIDs = array_keys( $remaining );
921  } else {
922  $this->mMissingPageIDs = array_merge( $this->mMissingPageIDs, array_keys( $remaining ) );
923  }
924  }
925  }
926 
927  // Get gender information
928  $genderCache = MediaWikiServices::getInstance()->getGenderCache();
929  $genderCache->doQuery( $usernames, __METHOD__ );
930  }
931 
937  private function initFromRevIDs( $revids ) {
938  if ( !$revids ) {
939  return;
940  }
941 
942  $revids = array_map( 'intval', $revids ); // paranoia
943  $db = $this->getDB();
944  $pageids = [];
945  $remaining = array_flip( $revids );
946 
947  $revids = $this->filterIDs( [ [ 'revision', 'rev_id' ], [ 'archive', 'ar_rev_id' ] ], $revids );
948  $goodRemaining = array_flip( $revids );
949 
950  if ( $revids ) {
951  $tables = [ 'revision', 'page' ];
952  $fields = [ 'rev_id', 'rev_page' ];
953  $where = [ 'rev_id' => $revids, 'rev_page = page_id' ];
954 
955  // Get pageIDs data from the `page` table
956  $res = $db->select( $tables, $fields, $where, __METHOD__ );
957  foreach ( $res as $row ) {
958  $revid = (int)$row->rev_id;
959  $pageid = (int)$row->rev_page;
960  $this->mGoodRevIDs[$revid] = $pageid;
961  $this->mLiveRevIDs[$revid] = $pageid;
962  $pageids[$pageid] = '';
963  unset( $remaining[$revid] );
964  unset( $goodRemaining[$revid] );
965  }
966  }
967 
968  // Populate all the page information
969  $this->initFromPageIds( array_keys( $pageids ), false );
970 
971  // If the user can see deleted revisions, pull out the corresponding
972  // titles from the archive table and include them too. We ignore
973  // ar_page_id because deleted revisions are tied by title, not page_id.
974  if ( $goodRemaining &&
975  $this->getPermissionManager()->userHasRight( $this->getUser(), 'deletedhistory' ) ) {
976  $tables = [ 'archive' ];
977  $fields = [ 'ar_rev_id', 'ar_namespace', 'ar_title' ];
978  $where = [ 'ar_rev_id' => array_keys( $goodRemaining ) ];
979 
980  $res = $db->select( $tables, $fields, $where, __METHOD__ );
981  $titles = [];
982  foreach ( $res as $row ) {
983  $revid = (int)$row->ar_rev_id;
984  $titles[$revid] = Title::makeTitle( $row->ar_namespace, $row->ar_title );
985  unset( $remaining[$revid] );
986  }
987 
988  $this->initFromTitles( $titles );
989 
990  foreach ( $titles as $revid => $title ) {
991  $ns = $title->getNamespace();
992  $dbkey = $title->getDBkey();
993 
994  // Handle converted titles
995  if ( !isset( $this->mAllPages[$ns][$dbkey] ) &&
996  isset( $this->mConvertedTitles[$title->getPrefixedText()] )
997  ) {
998  $title = Title::newFromText( $this->mConvertedTitles[$title->getPrefixedText()] );
999  $ns = $title->getNamespace();
1000  $dbkey = $title->getDBkey();
1001  }
1002 
1003  if ( isset( $this->mAllPages[$ns][$dbkey] ) ) {
1004  $this->mGoodRevIDs[$revid] = $this->mAllPages[$ns][$dbkey];
1005  $this->mDeletedRevIDs[$revid] = $this->mAllPages[$ns][$dbkey];
1006  } else {
1007  $remaining[$revid] = true;
1008  }
1009  }
1010  }
1011 
1012  $this->mMissingRevIDs = array_keys( $remaining );
1013  }
1014 
1020  private function resolvePendingRedirects() {
1021  if ( $this->mResolveRedirects ) {
1022  $db = $this->getDB();
1023  $pageFlds = $this->getPageTableFields();
1024 
1025  // Repeat until all redirects have been resolved
1026  // The infinite loop is prevented by keeping all known pages in $this->mAllPages
1027  while ( $this->mPendingRedirectIDs || $this->mPendingRedirectSpecialPages ) {
1028  // Resolve redirects by querying the pagelinks table, and repeat the process
1029  // Create a new linkBatch object for the next pass
1030  $linkBatch = $this->getRedirectTargets();
1031 
1032  if ( $linkBatch->isEmpty() ) {
1033  break;
1034  }
1035 
1036  $set = $linkBatch->constructSet( 'page', $db );
1037  if ( $set === false ) {
1038  break;
1039  }
1040 
1041  // Get pageIDs data from the `page` table
1042  $res = $db->select( 'page', $pageFlds, $set, __METHOD__ );
1043 
1044  // Hack: get the ns:titles stored in [ns => array(titles)] format
1045  $this->initFromQueryResult( $res, $linkBatch->data, true );
1046  }
1047  }
1048  }
1049 
1057  private function getRedirectTargets() {
1058  $titlesToResolve = [];
1059  $db = $this->getDB();
1060 
1061  if ( $this->mPendingRedirectIDs ) {
1062  $res = $db->select(
1063  'redirect',
1064  [
1065  'rd_from',
1066  'rd_namespace',
1067  'rd_fragment',
1068  'rd_interwiki',
1069  'rd_title'
1070  ], [ 'rd_from' => array_keys( $this->mPendingRedirectIDs ) ],
1071  __METHOD__
1072  );
1073  foreach ( $res as $row ) {
1074  $rdfrom = (int)$row->rd_from;
1075  $from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
1076  $to = Title::makeTitle(
1077  $row->rd_namespace,
1078  $row->rd_title,
1079  $row->rd_fragment,
1080  $row->rd_interwiki
1081  );
1082  $this->mResolvedRedirectTitles[$from] = $this->mPendingRedirectIDs[$rdfrom];
1083  unset( $this->mPendingRedirectIDs[$rdfrom] );
1084  if ( $to->isExternal() ) {
1085  $this->mInterwikiTitles[$to->getPrefixedText()] = $to->getInterwiki();
1086  } elseif ( !isset( $this->mAllPages[$to->getNamespace()][$to->getDBkey()] ) ) {
1087  $titlesToResolve[] = $to;
1088  }
1089  $this->mRedirectTitles[$from] = $to;
1090  }
1091 
1092  if ( $this->mPendingRedirectIDs ) {
1093  // We found pages that aren't in the redirect table
1094  // Add them
1095  foreach ( $this->mPendingRedirectIDs as $id => $title ) {
1096  $page = WikiPage::factory( $title );
1097  $rt = $page->insertRedirect();
1098  if ( !$rt ) {
1099  // What the hell. Let's just ignore this
1100  continue;
1101  }
1102  if ( $rt->isExternal() ) {
1103  $this->mInterwikiTitles[$rt->getPrefixedText()] = $rt->getInterwiki();
1104  } elseif ( !isset( $this->mAllPages[$rt->getNamespace()][$rt->getDBkey()] ) ) {
1105  $titlesToResolve[] = $rt;
1106  }
1107  $from = $title->getPrefixedText();
1108  $this->mResolvedRedirectTitles[$from] = $title;
1109  $this->mRedirectTitles[$from] = $rt;
1110  unset( $this->mPendingRedirectIDs[$id] );
1111  }
1112  }
1113  }
1114 
1115  if ( $this->mPendingRedirectSpecialPages ) {
1116  foreach ( $this->mPendingRedirectSpecialPages as $key => list( $from, $to ) ) {
1117  $fromKey = $from->getPrefixedText();
1118  $this->mResolvedRedirectTitles[$fromKey] = $from;
1119  $this->mRedirectTitles[$fromKey] = $to;
1120  if ( $to->isExternal() ) {
1121  $this->mInterwikiTitles[$to->getPrefixedText()] = $to->getInterwiki();
1122  } elseif ( !isset( $this->mAllPages[$to->getNamespace()][$to->getDBkey()] ) ) {
1123  $titlesToResolve[] = $to;
1124  }
1125  }
1126  $this->mPendingRedirectSpecialPages = [];
1127 
1128  // Set private caching since we don't know what criteria the
1129  // special pages used to decide on these redirects.
1130  $this->mCacheMode = 'private';
1131  }
1132 
1133  return $this->processTitlesArray( $titlesToResolve );
1134  }
1135 
1149  public function getCacheMode( $params = null ) {
1150  return $this->mCacheMode;
1151  }
1152 
1162  private function processTitlesArray( $titles ) {
1163  $usernames = [];
1164  $linkBatch = new LinkBatch();
1165  $services = MediaWikiServices::getInstance();
1166  $contLang = $services->getContentLanguage();
1167 
1168  foreach ( $titles as $title ) {
1169  if ( is_string( $title ) ) {
1170  try {
1171  $titleObj = Title::newFromTextThrow( $title, $this->mDefaultNamespace );
1172  } catch ( MalformedTitleException $ex ) {
1173  // Handle invalid titles gracefully
1174  if ( !isset( $this->mAllPages[0][$title] ) ) {
1175  $this->mAllPages[0][$title] = $this->mFakePageId;
1176  $this->mInvalidTitles[$this->mFakePageId] = [
1177  'title' => $title,
1178  'invalidreason' => $this->getErrorFormatter()->formatException( $ex, [ 'bc' => true ] ),
1179  ];
1180  $this->mFakePageId--;
1181  }
1182  continue; // There's nothing else we can do
1183  }
1184  } else {
1185  $titleObj = $title;
1186  }
1187  $unconvertedTitle = $titleObj->getPrefixedText();
1188  $titleWasConverted = false;
1189  if ( $titleObj->isExternal() ) {
1190  // This title is an interwiki link.
1191  $this->mInterwikiTitles[$unconvertedTitle] = $titleObj->getInterwiki();
1192  } else {
1193  // Variants checking
1194  if (
1195  $this->mConvertTitles && $contLang->hasVariants() && !$titleObj->exists()
1196  ) {
1197  // Language::findVariantLink will modify titleText and titleObj into
1198  // the canonical variant if possible
1199  $titleText = is_string( $title ) ? $title : $titleObj->getPrefixedText();
1200  $contLang->findVariantLink( $titleText, $titleObj );
1201  $titleWasConverted = $unconvertedTitle !== $titleObj->getPrefixedText();
1202  }
1203 
1204  if ( $titleObj->getNamespace() < 0 ) {
1205  // Handle Special and Media pages
1206  $titleObj = $titleObj->fixSpecialName();
1207  $ns = $titleObj->getNamespace();
1208  $dbkey = $titleObj->getDBkey();
1209  if ( !isset( $this->mAllSpecials[$ns][$dbkey] ) ) {
1210  $this->mAllSpecials[$ns][$dbkey] = $this->mFakePageId;
1211  $target = null;
1212  if ( $ns === NS_SPECIAL && $this->mResolveRedirects ) {
1213  $spFactory = $services->getSpecialPageFactory();
1214  $special = $spFactory->getPage( $dbkey );
1215  if ( $special instanceof RedirectSpecialArticle ) {
1216  // Only RedirectSpecialArticle is intended to redirect to an article, other kinds of
1217  // RedirectSpecialPage are probably applying weird URL parameters we don't want to handle.
1218  $context = new DerivativeContext( $this );
1219  $context->setTitle( $titleObj );
1220  $context->setRequest( new FauxRequest );
1221  $special->setContext( $context );
1222  list( /* $alias */, $subpage ) = $spFactory->resolveAlias( $dbkey );
1223  $target = $special->getRedirect( $subpage );
1224  }
1225  }
1226  if ( $target ) {
1227  $this->mPendingRedirectSpecialPages[$dbkey] = [ $titleObj, $target ];
1228  } else {
1229  $this->mSpecialTitles[$this->mFakePageId] = $titleObj;
1230  $this->mFakePageId--;
1231  }
1232  }
1233  } else {
1234  // Regular page
1235  $linkBatch->addObj( $titleObj );
1236  }
1237  }
1238 
1239  // Make sure we remember the original title that was
1240  // given to us. This way the caller can correlate new
1241  // titles with the originally requested when e.g. the
1242  // namespace is localized or the capitalization is
1243  // different
1244  if ( $titleWasConverted ) {
1245  $this->mConvertedTitles[$unconvertedTitle] = $titleObj->getPrefixedText();
1246  // In this case the page can't be Special.
1247  if ( is_string( $title ) && $title !== $unconvertedTitle ) {
1248  $this->mNormalizedTitles[$title] = $unconvertedTitle;
1249  }
1250  } elseif ( is_string( $title ) && $title !== $titleObj->getPrefixedText() ) {
1251  $this->mNormalizedTitles[$title] = $titleObj->getPrefixedText();
1252  }
1253 
1254  // Need gender information
1255  if (
1256  MediaWikiServices::getInstance()->getNamespaceInfo()->
1257  hasGenderDistinction( $titleObj->getNamespace() )
1258  ) {
1259  $usernames[] = $titleObj->getText();
1260  }
1261  }
1262  // Get gender information
1263  $genderCache = $services->getGenderCache();
1264  $genderCache->doQuery( $usernames, __METHOD__ );
1265 
1266  return $linkBatch;
1267  }
1268 
1284  public function setGeneratorData( Title $title, array $data ) {
1285  $ns = $title->getNamespace();
1286  $dbkey = $title->getDBkey();
1287  $this->mGeneratorData[$ns][$dbkey] = $data;
1288  }
1289 
1309  public function setRedirectMergePolicy( $callable ) {
1310  $this->mRedirectMergePolicy = $callable;
1311  }
1312 
1333  public function populateGeneratorData( &$result, array $path = [] ) {
1334  if ( $result instanceof ApiResult ) {
1335  $data = $result->getResultData( $path );
1336  if ( $data === null ) {
1337  return true;
1338  }
1339  } else {
1340  $data = &$result;
1341  foreach ( $path as $key ) {
1342  if ( !isset( $data[$key] ) ) {
1343  // Path isn't in $result, so nothing to add, so everything
1344  // "fits"
1345  return true;
1346  }
1347  $data = &$data[$key];
1348  }
1349  }
1350  foreach ( $this->mGeneratorData as $ns => $dbkeys ) {
1351  if ( $ns === NS_SPECIAL ) {
1352  $pages = [];
1353  foreach ( $this->mSpecialTitles as $id => $title ) {
1354  $pages[$title->getDBkey()] = $id;
1355  }
1356  } else {
1357  if ( !isset( $this->mAllPages[$ns] ) ) {
1358  // No known titles in the whole namespace. Skip it.
1359  continue;
1360  }
1361  $pages = $this->mAllPages[$ns];
1362  }
1363  foreach ( $dbkeys as $dbkey => $genData ) {
1364  if ( !isset( $pages[$dbkey] ) ) {
1365  // Unknown title. Forget it.
1366  continue;
1367  }
1368  $pageId = $pages[$dbkey];
1369  if ( !isset( $data[$pageId] ) ) {
1370  // $pageId didn't make it into the result. Ignore it.
1371  continue;
1372  }
1373 
1374  if ( $result instanceof ApiResult ) {
1375  $path2 = array_merge( $path, [ $pageId ] );
1376  foreach ( $genData as $key => $value ) {
1377  if ( !$result->addValue( $path2, $key, $value ) ) {
1378  return false;
1379  }
1380  }
1381  } else {
1382  $data[$pageId] = array_merge( $data[$pageId], $genData );
1383  }
1384  }
1385  }
1386 
1387  // Merge data generated about redirect titles into the redirect destination
1388  if ( $this->mRedirectMergePolicy ) {
1389  foreach ( $this->mResolvedRedirectTitles as $titleFrom ) {
1390  $dest = $titleFrom;
1391  while ( isset( $this->mRedirectTitles[$dest->getPrefixedText()] ) ) {
1392  $dest = $this->mRedirectTitles[$dest->getPrefixedText()];
1393  }
1394  $fromNs = $titleFrom->getNamespace();
1395  $fromDBkey = $titleFrom->getDBkey();
1396  $toPageId = $dest->getArticleID();
1397  if ( isset( $data[$toPageId] ) &&
1398  isset( $this->mGeneratorData[$fromNs][$fromDBkey] )
1399  ) {
1400  // It is necessary to set both $data and add to $result, if an ApiResult,
1401  // to ensure multiple redirects to the same destination are all merged.
1402  $data[$toPageId] = call_user_func(
1403  $this->mRedirectMergePolicy,
1404  $data[$toPageId],
1405  $this->mGeneratorData[$fromNs][$fromDBkey]
1406  );
1407  if ( $result instanceof ApiResult &&
1408  !$result->addValue( $path, $toPageId, $data[$toPageId], ApiResult::OVERRIDE )
1409  ) {
1410  return false;
1411  }
1412  }
1413  }
1414  }
1415 
1416  return true;
1417  }
1418 
1423  protected function getDB() {
1424  return $this->mDbSource->getDB();
1425  }
1426 
1427  public function getAllowedParams( $flags = 0 ) {
1428  $result = [
1429  'titles' => [
1430  ApiBase::PARAM_ISMULTI => true,
1431  ApiBase::PARAM_HELP_MSG => 'api-pageset-param-titles',
1432  ],
1433  'pageids' => [
1434  ApiBase::PARAM_TYPE => 'integer',
1435  ApiBase::PARAM_ISMULTI => true,
1436  ApiBase::PARAM_HELP_MSG => 'api-pageset-param-pageids',
1437  ],
1438  'revids' => [
1439  ApiBase::PARAM_TYPE => 'integer',
1440  ApiBase::PARAM_ISMULTI => true,
1441  ApiBase::PARAM_HELP_MSG => 'api-pageset-param-revids',
1442  ],
1443  'generator' => [
1445  ApiBase::PARAM_HELP_MSG => 'api-pageset-param-generator',
1447  ],
1448  'redirects' => [
1449  ApiBase::PARAM_DFLT => false,
1450  ApiBase::PARAM_HELP_MSG => $this->mAllowGenerator
1451  ? 'api-pageset-param-redirects-generator'
1452  : 'api-pageset-param-redirects-nogenerator',
1453  ],
1454  'converttitles' => [
1455  ApiBase::PARAM_DFLT => false,
1456  ApiBase::PARAM_HELP_MSG => [
1457  'api-pageset-param-converttitles',
1459  ],
1460  ],
1461  ];
1462 
1463  if ( !$this->mAllowGenerator ) {
1464  unset( $result['generator'] );
1465  } elseif ( $flags & ApiBase::GET_VALUES_FOR_HELP ) {
1466  $result['generator'][ApiBase::PARAM_TYPE] = 'submodule';
1467  $result['generator'][ApiBase::PARAM_SUBMODULE_MAP] = $this->getGenerators();
1468  }
1469 
1470  return $result;
1471  }
1472 
1473  protected function handleParamNormalization( $paramName, $value, $rawValue ) {
1474  parent::handleParamNormalization( $paramName, $value, $rawValue );
1475 
1476  if ( $paramName === 'titles' ) {
1477  // For the 'titles' parameter, we want to split it like ApiBase would
1478  // and add any changed titles to $this->mNormalizedTitles
1479  $value = $this->explodeMultiValue( $value, self::LIMIT_SML2 + 1 );
1480  $l = count( $value );
1481  $rawValue = $this->explodeMultiValue( $rawValue, $l );
1482  for ( $i = 0; $i < $l; $i++ ) {
1483  if ( $value[$i] !== $rawValue[$i] ) {
1484  $this->mNormalizedTitles[$rawValue[$i]] = $value[$i];
1485  }
1486  }
1487  }
1488  }
1489 
1490  private static $generators = null;
1491 
1496  private function getGenerators() {
1497  if ( self::$generators === null ) {
1499  if ( !( $query instanceof ApiQuery ) ) {
1500  // If the parent container of this pageset is not ApiQuery,
1501  // we must create it to get module manager
1502  $query = $this->getMain()->getModuleManager()->getModule( 'query' );
1503  }
1504  $gens = [];
1505  $prefix = $query->getModulePath() . '+';
1506  $mgr = $query->getModuleManager();
1507  foreach ( $mgr->getNamesWithClasses() as $name => $class ) {
1508  if ( is_subclass_of( $class, ApiQueryGeneratorBase::class ) ) {
1509  $gens[$name] = $prefix . $name;
1510  }
1511  }
1512  ksort( $gens );
1513  self::$generators = $gens;
1514  }
1515 
1516  return self::$generators;
1517  }
1518 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
static $generators
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
Definition: ApiBase.php:94
getErrorFormatter()
Get the error formatter.
Definition: ApiBase.php:654
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
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
setGeneratorData(Title $title, array $data)
Set data for a title.
getRedirectTitles()
Get a list of redirect resolutions - maps a title to its redirect target, as an array of output-ready...
Definition: ApiPageSet.php:443
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges use this to change the tables headers change it to an object instance and return false override the list derivative used $groups Array of ChangesListFilterGroup objects(added in 1.34) 'FileDeleteComplete' null for the local 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:1535
$mGoodAndMissingPages
Definition: ApiPageSet.php:55
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
$mPendingRedirectSpecialPages
Definition: ApiPageSet.php:70
getSpecialTitles()
Get the list of titles with negative namespace.
Definition: ApiPageSet.php:703
const NS_MAIN
Definition: Defines.php:60
getDataSource()
Return the parameter name that is the source of data for this PageSet.
Definition: ApiPageSet.php:265
This class contains a list of pages that the client has requested.
Definition: ApiPageSet.php:40
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:55
getMain()
Get the main module.
Definition: ApiBase.php:536
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
Definition: ApiBase.php:272
An IContextSource implementation which will inherit context from another source but allow individual ...
getConvertedTitles()
Get a list of title conversions - maps a title to its converted version.
Definition: ApiPageSet.php:524
getMissingRevisionIDs()
Revision IDs that were not found in the database.
Definition: ApiPageSet.php:675
$value
const NS_SPECIAL
Definition: Defines.php:49
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:2009
const PROTO_CURRENT
Definition: Defines.php:202
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user...
Definition: ApiBase.php:761
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 MediaWikiServices
Definition: injection.txt:23
getMissingTitlesByNamespace()
Returns an array [ns][dbkey] => fake_page_id for all missing titles.
Definition: ApiPageSet.php:392
populateFromRevisionIDs( $revIDs)
Populate this PageSet from a list of revision IDs.
Definition: ApiPageSet.php:748
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:522
getRevisionIDs()
Get the list of valid revision IDs (requested with the revids= parameter)
Definition: ApiPageSet.php:651
getTitleCount()
Returns the number of unique pages (not revisions) in the set.
Definition: ApiPageSet.php:359
IContextSource $context
getAllTitlesByNamespace()
Returns an array [ns][dbkey] => page_id for all requested titles.
Definition: ApiPageSet.php:343
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
getPageTableFields()
Get the fields that have to be queried from the page table: the ones requested through requestField()...
Definition: ApiPageSet.php:307
getTitles()
All Title objects provided.
Definition: ApiPageSet.php:351
this hook is for auditing only 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:966
getLiveRevisionIDs()
Get the list of non-deleted revision IDs (requested with the revids= parameter)
Definition: ApiPageSet.php:659
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. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\*-\*)") will be honored when streaming the file. '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:1976
callable null $mRedirectMergePolicy
Definition: ApiPageSet.php:84
initFromQueryResult( $res, &$remaining=null, $processTitles=null)
Iterate through the result of the query on &#39;page&#39; table, and for each row create and store title obje...
Definition: ApiPageSet.php:864
resolvePendingRedirects()
Resolve any redirects in the result if redirect resolution was requested.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
getGoodAndMissingTitlesByNamespace()
Returns an array [ns][dbkey] => page_id for all good and missing titles.
Definition: ApiPageSet.php:409
static addValues(array &$result, $values, $flags=[], $name=null)
Add all items from $values into the result.
Definition: ApiPageSet.php:93
getGoodTitleCount()
Returns the number of found unique pages (not revisions) in the set.
Definition: ApiPageSet.php:383
initFromPageIds( $pageids, $filterIds=true)
Does the same as initFromTitles(), but is based on page IDs instead.
Definition: ApiPageSet.php:824
const PARAM_SUBMODULE_PARAM_PREFIX
(string) When PARAM_TYPE is &#39;submodule&#39;, used to indicate the &#39;g&#39; prefix added by ApiQueryGeneratorBa...
Definition: ApiBase.php:179
getInvalidTitlesAndReasons()
Titles that were deemed invalid by Title::newFromText() The array&#39;s index will be unique and negative...
Definition: ApiPageSet.php:426
populateGeneratorData(&$result, array $path=[])
Populate the generator data for all titles in the result.
getGoodAndMissingTitles()
Title objects for good and missing titles.
Definition: ApiPageSet.php:417
populateFromTitles( $titles)
Populate this PageSet from a list of Titles.
Definition: ApiPageSet.php:719
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition: hooks.txt:2211
getDBkey()
Get the main part with underscores.
Definition: Title.php:1021
getGoodTitlesByNamespace()
Returns an array [ns][dbkey] => page_id for all good titles.
Definition: ApiPageSet.php:367
requestField( $fieldName)
Request an additional field from the page table.
Definition: ApiPageSet.php:287
$res
Definition: database.txt:21
getGenerators()
Get an array of all available generators.
executeDryRun()
In case execute() is not called, call this method to mark all relevant parameters as used This preven...
Definition: ApiPageSet.php:132
processTitlesArray( $titles)
Given an array of title strings, convert them into Title objects.
explodeMultiValue( $value, $limit)
Split a multi-valued parameter string, like explode()
Definition: ApiBase.php:1467
const PARAM_SUBMODULE_MAP
(string[]) When PARAM_TYPE is &#39;submodule&#39;, map parameter values to submodule paths.
Definition: ApiBase.php:172
getGoodTitles()
Title objects that were found in the database.
Definition: ApiPageSet.php:375
$params
getMissingTitles()
Title objects that were NOT found in the database.
Definition: ApiPageSet.php:401
getDB()
Get the database connection (read-only)
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:773
if(ini_get('mbstring.func_overload'))
Pre-config setup: Before loading LocalSettings.php.
Definition: Setup.php:51
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:918
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:520
This class represents the result of the API operations.
Definition: ApiResult.php:35
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1045
This is the main query class.
Definition: ApiQuery.php:36
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
getInvalidTitlesAndRevisions( $invalidChecks=[ 'invalidTitles', 'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles'])
Get an array of invalid/special/missing titles.
Definition: ApiPageSet.php:601
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
Definition: ApiBase.php:131
$mResolvedRedirectTitles
Definition: ApiPageSet.php:71
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid, rather than returning null.
Definition: Title.php:359
populateFromQueryResult( $db, $queryResult)
Populate this PageSet from a rowset returned from the database.
Definition: ApiPageSet.php:740
static getSelectFields()
Fields that LinkCache needs to select.
Definition: LinkCache.php:218
getAllowedParams( $flags=0)
int $mDefaultNamespace
Definition: ApiPageSet.php:82
getInterwikiTitlesAsResult( $result=null, $iwUrl=false)
Get a list of interwiki titles - maps a title to its interwiki prefix as result.
Definition: ApiPageSet.php:567
getMissingPageIDs()
Page IDs that were not found in the database.
Definition: ApiPageSet.php:434
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:592
getInterwikiTitles()
Get a list of interwiki titles - maps a title to its interwiki prefix.
Definition: ApiPageSet.php:555
executeInternal( $isDryRun)
Populate the PageSet from the request parameters.
Definition: ApiPageSet.php:148
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
Definition: ApiBase.php:739
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
getNormalizedTitlesAsResult( $result=null)
Get a list of title normalizations - maps a title to its normalized version in the form of result arr...
Definition: ApiPageSet.php:501
populateFromPageIDs( $pageIDs)
Populate this PageSet from a list of page IDs.
Definition: ApiPageSet.php:727
processDbRow( $row)
Extract all requested fields from the row received from the database.
Definition: ApiPageSet.php:756
filterIDs( $fields, array $ids)
Filter out-of-range values from a list of positive integer IDs.
Definition: ApiBase.php:1880
$mRequestedPageFields
Definition: ApiPageSet.php:80
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
getRedirectTargets()
Get the targets of the pending redirects from the database.
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
initFromRevIDs( $revids)
Does the same as initFromTitles(), but is based on revision IDs instead.
Definition: ApiPageSet.php:937
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1928
getCustomField( $fieldName)
Get the value of a custom field previously requested through requestField()
Definition: ApiPageSet.php:297
getNormalizedTitles()
Get a list of title normalizations - maps a title to its normalized version.
Definition: ApiPageSet.php:490
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:58
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks...
Definition: ApiBase.php:710
array $mInvalidTitles
[fake_page_id] => [ &#39;title&#39; => $title, &#39;invalidreason&#39; => $reason ]
Definition: ApiPageSet.php:61
__construct(ApiBase $dbSource, $flags=0, $defaultNamespace=NS_MAIN)
Definition: ApiPageSet.php:117
getMissingRevisionIDsAsResult( $result=null)
Revision IDs that were not found in the database as result array.
Definition: ApiPageSet.php:685
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
Definition: ApiBase.php:2212
getConvertedTitlesAsResult( $result=null)
Get a list of title conversions - maps a title to its converted version as a result array...
Definition: ApiPageSet.php:535
This abstract class implements many basic API functions, and is the base of all API classes...
Definition: ApiBase.php:42
setRedirectMergePolicy( $callable)
Controls how generator data about a redirect source is merged into the generator data for the redirec...
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:277
getCacheMode( $params=null)
Get the cache mode for the data generated by this module.
isResolvingRedirects()
Check whether this PageSet is resolving redirects.
Definition: ApiPageSet.php:253
getRevisionCount()
Returns the number of revisions (requested with revids= parameter).
Definition: ApiPageSet.php:711
initFromTitles( $titles)
This method populates internal variables with page information based on the given array of title stri...
Definition: ApiPageSet.php:796
const DISABLE_GENERATORS
Constructor flag: The new instance of ApiPageSet will ignore the &#39;generator=&#39; parameter.
Definition: ApiPageSet.php:45
Title [] $mPendingRedirectIDs
Definition: ApiPageSet.php:69
Superclass for any RedirectSpecialPage which redirects the user to a particular article (as opposed t...
static array $languagesWithVariants
languages supporting variants
const OVERRIDE
Override existing value in addValue(), setValue(), and similar functions.
Definition: ApiResult.php:41
handleParamNormalization( $paramName, $value, $rawValue)
execute()
Populate the PageSet from the request parameters.
Definition: ApiPageSet.php:139
static listParam(array $list, $type='text')
Definition: Message.php:1128
getDeletedRevisionIDs()
Get the list of revision IDs that were associated with deleted titles.
Definition: ApiPageSet.php:667
getRedirectTitlesAsResult( $result=null)
Get a list of redirect resolutions - maps a title to its redirect target.
Definition: ApiPageSet.php:454
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:322