MediaWiki  1.27.2
ApiPageSet.php
Go to the documentation of this file.
1 <?php
41 class ApiPageSet extends ApiBase {
46  const DISABLE_GENERATORS = 1;
47 
48  private $mDbSource;
49  private $mParams;
51  private $mConvertTitles;
53 
54  private $mAllPages = []; // [ns][dbkey] => page_id or negative when missing
55  private $mTitles = [];
56  private $mGoodAndMissingPages = []; // [ns][dbkey] => page_id or negative when missing
57  private $mGoodPages = []; // [ns][dbkey] => page_id
58  private $mGoodTitles = [];
59  private $mMissingPages = []; // [ns][dbkey] => fake page_id
60  private $mMissingTitles = [];
62  private $mInvalidTitles = [];
63  private $mMissingPageIDs = [];
64  private $mRedirectTitles = [];
65  private $mSpecialTitles = [];
66  private $mNormalizedTitles = [];
67  private $mInterwikiTitles = [];
69  private $mPendingRedirectIDs = [];
71  private $mConvertedTitles = [];
72  private $mGoodRevIDs = [];
73  private $mLiveRevIDs = [];
74  private $mDeletedRevIDs = [];
75  private $mMissingRevIDs = [];
76  private $mGeneratorData = []; // [ns][dbkey] => data array
77  private $mFakePageId = -1;
78  private $mCacheMode = 'public';
79  private $mRequestedPageFields = [];
84 
92  private static function addValues( array &$result, $values, $flag = null, $name = null ) {
93  foreach ( $values as $val ) {
94  if ( $val instanceof Title ) {
95  $v = [];
96  ApiQueryBase::addTitleInfo( $v, $val );
97  } elseif ( $name !== null ) {
98  $v = [ $name => $val ];
99  } else {
100  $v = $val;
101  }
102  if ( $flag !== null ) {
103  $v[$flag] = true;
104  }
105  $result[] = $v;
106  }
107  }
108 
116  public function __construct( ApiBase $dbSource, $flags = 0, $defaultNamespace = NS_MAIN ) {
117  parent::__construct( $dbSource->getMain(), $dbSource->getModuleName() );
118  $this->mDbSource = $dbSource;
119  $this->mAllowGenerator = ( $flags & ApiPageSet::DISABLE_GENERATORS ) == 0;
120  $this->mDefaultNamespace = $defaultNamespace;
121 
122  $this->mParams = $this->extractRequestParams();
123  $this->mResolveRedirects = $this->mParams['redirects'];
124  $this->mConvertTitles = $this->mParams['converttitles'];
125  }
126 
131  public function executeDryRun() {
132  $this->executeInternal( true );
133  }
134 
138  public function execute() {
139  $this->executeInternal( false );
140  }
141 
147  private function executeInternal( $isDryRun ) {
148  $generatorName = $this->mAllowGenerator ? $this->mParams['generator'] : null;
149  if ( isset( $generatorName ) ) {
150  $dbSource = $this->mDbSource;
151  if ( !$dbSource instanceof ApiQuery ) {
152  // If the parent container of this pageset is not ApiQuery, we must create it to run generator
153  $dbSource = $this->getMain()->getModuleManager()->getModule( 'query' );
154  }
155  $generator = $dbSource->getModuleManager()->getModule( $generatorName, null, true );
156  if ( $generator === null ) {
157  $this->dieUsage( 'Unknown generator=' . $generatorName, 'badgenerator' );
158  }
159  if ( !$generator instanceof ApiQueryGeneratorBase ) {
160  $this->dieUsage( "Module $generatorName cannot be used as a generator", 'badgenerator' );
161  }
162  // Create a temporary pageset to store generator's output,
163  // add any additional fields generator may need, and execute pageset to populate titles/pageids
164  $tmpPageSet = new ApiPageSet( $dbSource, ApiPageSet::DISABLE_GENERATORS );
165  $generator->setGeneratorMode( $tmpPageSet );
166  $this->mCacheMode = $generator->getCacheMode( $generator->extractRequestParams() );
167 
168  if ( !$isDryRun ) {
169  $generator->requestExtraData( $tmpPageSet );
170  }
171  $tmpPageSet->executeInternal( $isDryRun );
172 
173  // populate this pageset with the generator output
174  if ( !$isDryRun ) {
175  $generator->executeGenerator( $this );
176  Hooks::run( 'APIQueryGeneratorAfterExecute', [ &$generator, &$this ] );
177  } else {
178  // Prevent warnings from being reported on these parameters
179  $main = $this->getMain();
180  foreach ( $generator->extractRequestParams() as $paramName => $param ) {
181  $main->markParamsUsed( $generator->encodeParamName( $paramName ) );
182  }
183  }
184 
185  if ( !$isDryRun ) {
186  $this->resolvePendingRedirects();
187  }
188  } else {
189  // Only one of the titles/pageids/revids is allowed at the same time
190  $dataSource = null;
191  if ( isset( $this->mParams['titles'] ) ) {
192  $dataSource = 'titles';
193  }
194  if ( isset( $this->mParams['pageids'] ) ) {
195  if ( isset( $dataSource ) ) {
196  $this->dieUsage( "Cannot use 'pageids' at the same time as '$dataSource'", 'multisource' );
197  }
198  $dataSource = 'pageids';
199  }
200  if ( isset( $this->mParams['revids'] ) ) {
201  if ( isset( $dataSource ) ) {
202  $this->dieUsage( "Cannot use 'revids' at the same time as '$dataSource'", 'multisource' );
203  }
204  $dataSource = 'revids';
205  }
206 
207  if ( !$isDryRun ) {
208  // Populate page information with the original user input
209  switch ( $dataSource ) {
210  case 'titles':
211  $this->initFromTitles( $this->mParams['titles'] );
212  break;
213  case 'pageids':
214  $this->initFromPageIds( $this->mParams['pageids'] );
215  break;
216  case 'revids':
217  if ( $this->mResolveRedirects ) {
218  $this->setWarning( 'Redirect resolution cannot be used ' .
219  'together with the revids= parameter. Any redirects ' .
220  'the revids= point to have not been resolved.' );
221  }
222  $this->mResolveRedirects = false;
223  $this->initFromRevIDs( $this->mParams['revids'] );
224  break;
225  default:
226  // Do nothing - some queries do not need any of the data sources.
227  break;
228  }
229  }
230  }
231  }
232 
237  public function isResolvingRedirects() {
239  }
240 
249  public function getDataSource() {
250  if ( $this->mAllowGenerator && isset( $this->mParams['generator'] ) ) {
251  return 'generator';
252  }
253  if ( isset( $this->mParams['titles'] ) ) {
254  return 'titles';
255  }
256  if ( isset( $this->mParams['pageids'] ) ) {
257  return 'pageids';
258  }
259  if ( isset( $this->mParams['revids'] ) ) {
260  return 'revids';
261  }
262 
263  return null;
264  }
265 
271  public function requestField( $fieldName ) {
272  $this->mRequestedPageFields[$fieldName] = null;
273  }
274 
281  public function getCustomField( $fieldName ) {
282  return $this->mRequestedPageFields[$fieldName];
283  }
284 
291  public function getPageTableFields() {
292  // Ensure we get minimum required fields
293  // DON'T change this order
294  $pageFlds = [
295  'page_namespace' => null,
296  'page_title' => null,
297  'page_id' => null,
298  ];
299 
300  if ( $this->mResolveRedirects ) {
301  $pageFlds['page_is_redirect'] = null;
302  }
303 
304  if ( $this->getConfig()->get( 'ContentHandlerUseDB' ) ) {
305  $pageFlds['page_content_model'] = null;
306  }
307 
308  if ( $this->getConfig()->get( 'PageLanguageUseDB' ) ) {
309  $pageFlds['page_lang'] = null;
310  }
311 
312  // only store non-default fields
313  $this->mRequestedPageFields = array_diff_key( $this->mRequestedPageFields, $pageFlds );
314 
315  $pageFlds = array_merge( $pageFlds, $this->mRequestedPageFields );
316 
317  return array_keys( $pageFlds );
318  }
319 
326  public function getAllTitlesByNamespace() {
327  return $this->mAllPages;
328  }
329 
334  public function getTitles() {
335  return $this->mTitles;
336  }
337 
342  public function getTitleCount() {
343  return count( $this->mTitles );
344  }
345 
350  public function getGoodTitlesByNamespace() {
351  return $this->mGoodPages;
352  }
353 
358  public function getGoodTitles() {
359  return $this->mGoodTitles;
360  }
361 
366  public function getGoodTitleCount() {
367  return count( $this->mGoodTitles );
368  }
369 
375  public function getMissingTitlesByNamespace() {
376  return $this->mMissingPages;
377  }
378 
384  public function getMissingTitles() {
385  return $this->mMissingTitles;
386  }
387 
394  }
395 
400  public function getGoodAndMissingTitles() {
401  return $this->mGoodTitles + $this->mMissingTitles;
402  }
403 
410  public function getInvalidTitles() {
411  wfDeprecated( __METHOD__, '1.26' );
412  return array_map( function ( $t ) {
413  return $t['title'];
415  }
416 
422  public function getInvalidTitlesAndReasons() {
423  return $this->mInvalidTitles;
424  }
425 
430  public function getMissingPageIDs() {
431  return $this->mMissingPageIDs;
432  }
433 
439  public function getRedirectTitles() {
440  return $this->mRedirectTitles;
441  }
442 
450  public function getRedirectTitlesAsResult( $result = null ) {
451  $values = [];
452  foreach ( $this->getRedirectTitles() as $titleStrFrom => $titleTo ) {
453  $r = [
454  'from' => strval( $titleStrFrom ),
455  'to' => $titleTo->getPrefixedText(),
456  ];
457  if ( $titleTo->hasFragment() ) {
458  $r['tofragment'] = $titleTo->getFragment();
459  }
460  if ( $titleTo->isExternal() ) {
461  $r['tointerwiki'] = $titleTo->getInterwiki();
462  }
463  if ( isset( $this->mResolvedRedirectTitles[$titleStrFrom] ) ) {
464  $titleFrom = $this->mResolvedRedirectTitles[$titleStrFrom];
465  $ns = $titleFrom->getNamespace();
466  $dbkey = $titleFrom->getDBkey();
467  if ( isset( $this->mGeneratorData[$ns][$dbkey] ) ) {
468  $r = array_merge( $this->mGeneratorData[$ns][$dbkey], $r );
469  }
470  }
471 
472  $values[] = $r;
473  }
474  if ( !empty( $values ) && $result ) {
475  ApiResult::setIndexedTagName( $values, 'r' );
476  }
477 
478  return $values;
479  }
480 
486  public function getNormalizedTitles() {
488  }
489 
497  public function getNormalizedTitlesAsResult( $result = null ) {
498  $values = [];
499  foreach ( $this->getNormalizedTitles() as $rawTitleStr => $titleStr ) {
500  $values[] = [
501  'from' => $rawTitleStr,
502  'to' => $titleStr
503  ];
504  }
505  if ( !empty( $values ) && $result ) {
506  ApiResult::setIndexedTagName( $values, 'n' );
507  }
508 
509  return $values;
510  }
511 
517  public function getConvertedTitles() {
519  }
520 
528  public function getConvertedTitlesAsResult( $result = null ) {
529  $values = [];
530  foreach ( $this->getConvertedTitles() as $rawTitleStr => $titleStr ) {
531  $values[] = [
532  'from' => $rawTitleStr,
533  'to' => $titleStr
534  ];
535  }
536  if ( !empty( $values ) && $result ) {
537  ApiResult::setIndexedTagName( $values, 'c' );
538  }
539 
540  return $values;
541  }
542 
548  public function getInterwikiTitles() {
550  }
551 
560  public function getInterwikiTitlesAsResult( $result = null, $iwUrl = false ) {
561  $values = [];
562  foreach ( $this->getInterwikiTitles() as $rawTitleStr => $interwikiStr ) {
563  $item = [
564  'title' => $rawTitleStr,
565  'iw' => $interwikiStr,
566  ];
567  if ( $iwUrl ) {
568  $title = Title::newFromText( $rawTitleStr );
569  $item['url'] = $title->getFullURL( '', false, PROTO_CURRENT );
570  }
571  $values[] = $item;
572  }
573  if ( !empty( $values ) && $result ) {
574  ApiResult::setIndexedTagName( $values, 'i' );
575  }
576 
577  return $values;
578  }
579 
594  public function getInvalidTitlesAndRevisions( $invalidChecks = [ 'invalidTitles',
595  'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles' ]
596  ) {
597  $result = [];
598  if ( in_array( 'invalidTitles', $invalidChecks ) ) {
599  self::addValues( $result, $this->getInvalidTitlesAndReasons(), 'invalid' );
600  }
601  if ( in_array( 'special', $invalidChecks ) ) {
602  self::addValues( $result, $this->getSpecialTitles(), 'special', 'title' );
603  }
604  if ( in_array( 'missingIds', $invalidChecks ) ) {
605  self::addValues( $result, $this->getMissingPageIDs(), 'missing', 'pageid' );
606  }
607  if ( in_array( 'missingRevIds', $invalidChecks ) ) {
608  self::addValues( $result, $this->getMissingRevisionIDs(), 'missing', 'revid' );
609  }
610  if ( in_array( 'missingTitles', $invalidChecks ) ) {
611  self::addValues( $result, $this->getMissingTitles(), 'missing' );
612  }
613  if ( in_array( 'interwikiTitles', $invalidChecks ) ) {
614  self::addValues( $result, $this->getInterwikiTitlesAsResult() );
615  }
616 
617  return $result;
618  }
619 
624  public function getRevisionIDs() {
625  return $this->mGoodRevIDs;
626  }
627 
632  public function getLiveRevisionIDs() {
633  return $this->mLiveRevIDs;
634  }
635 
640  public function getDeletedRevisionIDs() {
641  return $this->mDeletedRevIDs;
642  }
643 
648  public function getMissingRevisionIDs() {
649  return $this->mMissingRevIDs;
650  }
651 
658  public function getMissingRevisionIDsAsResult( $result = null ) {
659  $values = [];
660  foreach ( $this->getMissingRevisionIDs() as $revid ) {
661  $values[$revid] = [
662  'revid' => $revid
663  ];
664  }
665  if ( !empty( $values ) && $result ) {
666  ApiResult::setIndexedTagName( $values, 'rev' );
667  }
668 
669  return $values;
670  }
671 
676  public function getSpecialTitles() {
677  return $this->mSpecialTitles;
678  }
679 
684  public function getRevisionCount() {
685  return count( $this->getRevisionIDs() );
686  }
687 
692  public function populateFromTitles( $titles ) {
693  $this->initFromTitles( $titles );
694  }
695 
700  public function populateFromPageIDs( $pageIDs ) {
701  $this->initFromPageIds( $pageIDs );
702  }
703 
713  public function populateFromQueryResult( $db, $queryResult ) {
714  $this->initFromQueryResult( $queryResult );
715  }
716 
721  public function populateFromRevisionIDs( $revIDs ) {
722  $this->initFromRevIDs( $revIDs );
723  }
724 
729  public function processDbRow( $row ) {
730  // Store Title object in various data structures
731  $title = Title::newFromRow( $row );
732 
733  $pageId = intval( $row->page_id );
734  $this->mAllPages[$row->page_namespace][$row->page_title] = $pageId;
735  $this->mTitles[] = $title;
736 
737  if ( $this->mResolveRedirects && $row->page_is_redirect == '1' ) {
738  $this->mPendingRedirectIDs[$pageId] = $title;
739  } else {
740  $this->mGoodPages[$row->page_namespace][$row->page_title] = $pageId;
741  $this->mGoodAndMissingPages[$row->page_namespace][$row->page_title] = $pageId;
742  $this->mGoodTitles[$pageId] = $title;
743  }
744 
745  foreach ( $this->mRequestedPageFields as $fieldName => &$fieldValues ) {
746  $fieldValues[$pageId] = $row->$fieldName;
747  }
748  }
749 
766  private function initFromTitles( $titles ) {
767  // Get validated and normalized title objects
768  $linkBatch = $this->processTitlesArray( $titles );
769  if ( $linkBatch->isEmpty() ) {
770  return;
771  }
772 
773  $db = $this->getDB();
774  $set = $linkBatch->constructSet( 'page', $db );
775 
776  // Get pageIDs data from the `page` table
777  $res = $db->select( 'page', $this->getPageTableFields(), $set,
778  __METHOD__ );
779 
780  // Hack: get the ns:titles stored in array(ns => array(titles)) format
781  $this->initFromQueryResult( $res, $linkBatch->data, true ); // process Titles
782 
783  // Resolve any found redirects
784  $this->resolvePendingRedirects();
785  }
786 
791  private function initFromPageIds( $pageids ) {
792  if ( !$pageids ) {
793  return;
794  }
795 
796  $pageids = array_map( 'intval', $pageids ); // paranoia
797  $remaining = array_flip( $pageids );
798 
799  $pageids = self::getPositiveIntegers( $pageids );
800 
801  $res = null;
802  if ( !empty( $pageids ) ) {
803  $set = [
804  'page_id' => $pageids
805  ];
806  $db = $this->getDB();
807 
808  // Get pageIDs data from the `page` table
809  $res = $db->select( 'page', $this->getPageTableFields(), $set,
810  __METHOD__ );
811  }
812 
813  $this->initFromQueryResult( $res, $remaining, false ); // process PageIDs
814 
815  // Resolve any found redirects
816  $this->resolvePendingRedirects();
817  }
818 
829  private function initFromQueryResult( $res, &$remaining = null, $processTitles = null ) {
830  if ( !is_null( $remaining ) && is_null( $processTitles ) ) {
831  ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
832  }
833 
834  $usernames = [];
835  if ( $res ) {
836  foreach ( $res as $row ) {
837  $pageId = intval( $row->page_id );
838 
839  // Remove found page from the list of remaining items
840  if ( isset( $remaining ) ) {
841  if ( $processTitles ) {
842  unset( $remaining[$row->page_namespace][$row->page_title] );
843  } else {
844  unset( $remaining[$pageId] );
845  }
846  }
847 
848  // Store any extra fields requested by modules
849  $this->processDbRow( $row );
850 
851  // Need gender information
852  if ( MWNamespace::hasGenderDistinction( $row->page_namespace ) ) {
853  $usernames[] = $row->page_title;
854  }
855  }
856  }
857 
858  if ( isset( $remaining ) ) {
859  // Any items left in the $remaining list are added as missing
860  if ( $processTitles ) {
861  // The remaining titles in $remaining are non-existent pages
862  foreach ( $remaining as $ns => $dbkeys ) {
863  foreach ( array_keys( $dbkeys ) as $dbkey ) {
864  $title = Title::makeTitle( $ns, $dbkey );
865  $this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
866  $this->mMissingPages[$ns][$dbkey] = $this->mFakePageId;
867  $this->mGoodAndMissingPages[$ns][$dbkey] = $this->mFakePageId;
868  $this->mMissingTitles[$this->mFakePageId] = $title;
869  $this->mFakePageId--;
870  $this->mTitles[] = $title;
871 
872  // need gender information
873  if ( MWNamespace::hasGenderDistinction( $ns ) ) {
874  $usernames[] = $dbkey;
875  }
876  }
877  }
878  } else {
879  // The remaining pageids do not exist
880  if ( !$this->mMissingPageIDs ) {
881  $this->mMissingPageIDs = array_keys( $remaining );
882  } else {
883  $this->mMissingPageIDs = array_merge( $this->mMissingPageIDs, array_keys( $remaining ) );
884  }
885  }
886  }
887 
888  // Get gender information
889  $genderCache = GenderCache::singleton();
890  $genderCache->doQuery( $usernames, __METHOD__ );
891  }
892 
898  private function initFromRevIDs( $revids ) {
899  if ( !$revids ) {
900  return;
901  }
902 
903  $revids = array_map( 'intval', $revids ); // paranoia
904  $db = $this->getDB();
905  $pageids = [];
906  $remaining = array_flip( $revids );
907 
908  $revids = self::getPositiveIntegers( $revids );
909 
910  if ( !empty( $revids ) ) {
911  $tables = [ 'revision', 'page' ];
912  $fields = [ 'rev_id', 'rev_page' ];
913  $where = [ 'rev_id' => $revids, 'rev_page = page_id' ];
914 
915  // Get pageIDs data from the `page` table
916  $res = $db->select( $tables, $fields, $where, __METHOD__ );
917  foreach ( $res as $row ) {
918  $revid = intval( $row->rev_id );
919  $pageid = intval( $row->rev_page );
920  $this->mGoodRevIDs[$revid] = $pageid;
921  $this->mLiveRevIDs[$revid] = $pageid;
922  $pageids[$pageid] = '';
923  unset( $remaining[$revid] );
924  }
925  }
926 
927  $this->mMissingRevIDs = array_keys( $remaining );
928 
929  // Populate all the page information
930  $this->initFromPageIds( array_keys( $pageids ) );
931 
932  // If the user can see deleted revisions, pull out the corresponding
933  // titles from the archive table and include them too. We ignore
934  // ar_page_id because deleted revisions are tied by title, not page_id.
935  if ( !empty( $this->mMissingRevIDs ) && $this->getUser()->isAllowed( 'deletedhistory' ) ) {
936  $remaining = array_flip( $this->mMissingRevIDs );
937  $tables = [ 'archive' ];
938  $fields = [ 'ar_rev_id', 'ar_namespace', 'ar_title' ];
939  $where = [ 'ar_rev_id' => $this->mMissingRevIDs ];
940 
941  $res = $db->select( $tables, $fields, $where, __METHOD__ );
942  $titles = [];
943  foreach ( $res as $row ) {
944  $revid = intval( $row->ar_rev_id );
945  $titles[$revid] = Title::makeTitle( $row->ar_namespace, $row->ar_title );
946  unset( $remaining[$revid] );
947  }
948 
949  $this->initFromTitles( $titles );
950 
951  foreach ( $titles as $revid => $title ) {
952  $ns = $title->getNamespace();
953  $dbkey = $title->getDBkey();
954 
955  // Handle converted titles
956  if ( !isset( $this->mAllPages[$ns][$dbkey] ) &&
957  isset( $this->mConvertedTitles[$title->getPrefixedText()] )
958  ) {
959  $title = Title::newFromText( $this->mConvertedTitles[$title->getPrefixedText()] );
960  $ns = $title->getNamespace();
961  $dbkey = $title->getDBkey();
962  }
963 
964  if ( isset( $this->mAllPages[$ns][$dbkey] ) ) {
965  $this->mGoodRevIDs[$revid] = $this->mAllPages[$ns][$dbkey];
966  $this->mDeletedRevIDs[$revid] = $this->mAllPages[$ns][$dbkey];
967  } else {
968  $remaining[$revid] = true;
969  }
970  }
971 
972  $this->mMissingRevIDs = array_keys( $remaining );
973  }
974  }
975 
981  private function resolvePendingRedirects() {
982  if ( $this->mResolveRedirects ) {
983  $db = $this->getDB();
984  $pageFlds = $this->getPageTableFields();
985 
986  // Repeat until all redirects have been resolved
987  // The infinite loop is prevented by keeping all known pages in $this->mAllPages
988  while ( $this->mPendingRedirectIDs ) {
989  // Resolve redirects by querying the pagelinks table, and repeat the process
990  // Create a new linkBatch object for the next pass
991  $linkBatch = $this->getRedirectTargets();
992 
993  if ( $linkBatch->isEmpty() ) {
994  break;
995  }
996 
997  $set = $linkBatch->constructSet( 'page', $db );
998  if ( $set === false ) {
999  break;
1000  }
1001 
1002  // Get pageIDs data from the `page` table
1003  $res = $db->select( 'page', $pageFlds, $set, __METHOD__ );
1004 
1005  // Hack: get the ns:titles stored in array(ns => array(titles)) format
1006  $this->initFromQueryResult( $res, $linkBatch->data, true );
1007  }
1008  }
1009  }
1010 
1018  private function getRedirectTargets() {
1019  $lb = new LinkBatch();
1020  $db = $this->getDB();
1021 
1022  $res = $db->select(
1023  'redirect',
1024  [
1025  'rd_from',
1026  'rd_namespace',
1027  'rd_fragment',
1028  'rd_interwiki',
1029  'rd_title'
1030  ], [ 'rd_from' => array_keys( $this->mPendingRedirectIDs ) ],
1031  __METHOD__
1032  );
1033  foreach ( $res as $row ) {
1034  $rdfrom = intval( $row->rd_from );
1035  $from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
1036  $to = Title::makeTitle(
1037  $row->rd_namespace,
1038  $row->rd_title,
1039  $row->rd_fragment,
1040  $row->rd_interwiki
1041  );
1042  $this->mResolvedRedirectTitles[$from] = $this->mPendingRedirectIDs[$rdfrom];
1043  unset( $this->mPendingRedirectIDs[$rdfrom] );
1044  if ( $to->isExternal() ) {
1045  $this->mInterwikiTitles[$to->getPrefixedText()] = $to->getInterwiki();
1046  } elseif ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) {
1047  $lb->add( $row->rd_namespace, $row->rd_title );
1048  }
1049  $this->mRedirectTitles[$from] = $to;
1050  }
1051 
1052  if ( $this->mPendingRedirectIDs ) {
1053  // We found pages that aren't in the redirect table
1054  // Add them
1055  foreach ( $this->mPendingRedirectIDs as $id => $title ) {
1057  $rt = $page->insertRedirect();
1058  if ( !$rt ) {
1059  // What the hell. Let's just ignore this
1060  continue;
1061  }
1062  $lb->addObj( $rt );
1063  $from = $title->getPrefixedText();
1064  $this->mResolvedRedirectTitles[$from] = $title;
1065  $this->mRedirectTitles[$from] = $rt;
1066  unset( $this->mPendingRedirectIDs[$id] );
1067  }
1068  }
1069 
1070  return $lb;
1071  }
1072 
1086  public function getCacheMode( $params = null ) {
1087  return $this->mCacheMode;
1088  }
1089 
1099  private function processTitlesArray( $titles ) {
1100  $usernames = [];
1101  $linkBatch = new LinkBatch();
1102 
1103  foreach ( $titles as $title ) {
1104  if ( is_string( $title ) ) {
1105  try {
1106  $titleObj = Title::newFromTextThrow( $title, $this->mDefaultNamespace );
1107  } catch ( MalformedTitleException $ex ) {
1108  // Handle invalid titles gracefully
1109  $this->mAllPages[0][$title] = $this->mFakePageId;
1110  $this->mInvalidTitles[$this->mFakePageId] = [
1111  'title' => $title,
1112  'invalidreason' => $ex->getMessage(),
1113  ];
1114  $this->mFakePageId--;
1115  continue; // There's nothing else we can do
1116  }
1117  } else {
1118  $titleObj = $title;
1119  }
1120  $unconvertedTitle = $titleObj->getPrefixedText();
1121  $titleWasConverted = false;
1122  if ( $titleObj->isExternal() ) {
1123  // This title is an interwiki link.
1124  $this->mInterwikiTitles[$unconvertedTitle] = $titleObj->getInterwiki();
1125  } else {
1126  // Variants checking
1128  if ( $this->mConvertTitles &&
1129  count( $wgContLang->getVariants() ) > 1 &&
1130  !$titleObj->exists()
1131  ) {
1132  // Language::findVariantLink will modify titleText and titleObj into
1133  // the canonical variant if possible
1134  $titleText = is_string( $title ) ? $title : $titleObj->getPrefixedText();
1135  $wgContLang->findVariantLink( $titleText, $titleObj );
1136  $titleWasConverted = $unconvertedTitle !== $titleObj->getPrefixedText();
1137  }
1138 
1139  if ( $titleObj->getNamespace() < 0 ) {
1140  // Handle Special and Media pages
1141  $titleObj = $titleObj->fixSpecialName();
1142  $this->mSpecialTitles[$this->mFakePageId] = $titleObj;
1143  $this->mFakePageId--;
1144  } else {
1145  // Regular page
1146  $linkBatch->addObj( $titleObj );
1147  }
1148  }
1149 
1150  // Make sure we remember the original title that was
1151  // given to us. This way the caller can correlate new
1152  // titles with the originally requested when e.g. the
1153  // namespace is localized or the capitalization is
1154  // different
1155  if ( $titleWasConverted ) {
1156  $this->mConvertedTitles[$unconvertedTitle] = $titleObj->getPrefixedText();
1157  // In this case the page can't be Special.
1158  if ( is_string( $title ) && $title !== $unconvertedTitle ) {
1159  $this->mNormalizedTitles[$title] = $unconvertedTitle;
1160  }
1161  } elseif ( is_string( $title ) && $title !== $titleObj->getPrefixedText() ) {
1162  $this->mNormalizedTitles[$title] = $titleObj->getPrefixedText();
1163  }
1164 
1165  // Need gender information
1166  if ( MWNamespace::hasGenderDistinction( $titleObj->getNamespace() ) ) {
1167  $usernames[] = $titleObj->getText();
1168  }
1169  }
1170  // Get gender information
1171  $genderCache = GenderCache::singleton();
1172  $genderCache->doQuery( $usernames, __METHOD__ );
1173 
1174  return $linkBatch;
1175  }
1176 
1192  public function setGeneratorData( Title $title, array $data ) {
1193  $ns = $title->getNamespace();
1194  $dbkey = $title->getDBkey();
1195  $this->mGeneratorData[$ns][$dbkey] = $data;
1196  }
1197 
1217  public function setRedirectMergePolicy( $callable ) {
1218  $this->mRedirectMergePolicy = $callable;
1219  }
1220 
1241  public function populateGeneratorData( &$result, array $path = [] ) {
1242  if ( $result instanceof ApiResult ) {
1243  $data = $result->getResultData( $path );
1244  if ( $data === null ) {
1245  return true;
1246  }
1247  } else {
1248  $data = &$result;
1249  foreach ( $path as $key ) {
1250  if ( !isset( $data[$key] ) ) {
1251  // Path isn't in $result, so nothing to add, so everything
1252  // "fits"
1253  return true;
1254  }
1255  $data = &$data[$key];
1256  }
1257  }
1258  foreach ( $this->mGeneratorData as $ns => $dbkeys ) {
1259  if ( $ns === -1 ) {
1260  $pages = [];
1261  foreach ( $this->mSpecialTitles as $id => $title ) {
1262  $pages[$title->getDBkey()] = $id;
1263  }
1264  } else {
1265  if ( !isset( $this->mAllPages[$ns] ) ) {
1266  // No known titles in the whole namespace. Skip it.
1267  continue;
1268  }
1269  $pages = $this->mAllPages[$ns];
1270  }
1271  foreach ( $dbkeys as $dbkey => $genData ) {
1272  if ( !isset( $pages[$dbkey] ) ) {
1273  // Unknown title. Forget it.
1274  continue;
1275  }
1276  $pageId = $pages[$dbkey];
1277  if ( !isset( $data[$pageId] ) ) {
1278  // $pageId didn't make it into the result. Ignore it.
1279  continue;
1280  }
1281 
1282  if ( $result instanceof ApiResult ) {
1283  $path2 = array_merge( $path, [ $pageId ] );
1284  foreach ( $genData as $key => $value ) {
1285  if ( !$result->addValue( $path2, $key, $value ) ) {
1286  return false;
1287  }
1288  }
1289  } else {
1290  $data[$pageId] = array_merge( $data[$pageId], $genData );
1291  }
1292  }
1293  }
1294 
1295  // Merge data generated about redirect titles into the redirect destination
1296  if ( $this->mRedirectMergePolicy ) {
1297  foreach ( $this->mResolvedRedirectTitles as $titleFrom ) {
1298  $dest = $titleFrom;
1299  while ( isset( $this->mRedirectTitles[$dest->getPrefixedText()] ) ) {
1300  $dest = $this->mRedirectTitles[$dest->getPrefixedText()];
1301  }
1302  $fromNs = $titleFrom->getNamespace();
1303  $fromDBkey = $titleFrom->getDBkey();
1304  $toPageId = $dest->getArticleID();
1305  if ( isset( $data[$toPageId] ) &&
1306  isset( $this->mGeneratorData[$fromNs][$fromDBkey] )
1307  ) {
1308  // It is necesary to set both $data and add to $result, if an ApiResult,
1309  // to ensure multiple redirects to the same destination are all merged.
1310  $data[$toPageId] = call_user_func(
1311  $this->mRedirectMergePolicy,
1312  $data[$toPageId],
1313  $this->mGeneratorData[$fromNs][$fromDBkey]
1314  );
1315  if ( $result instanceof ApiResult ) {
1316  if ( !$result->addValue( $path, $toPageId, $data[$toPageId], ApiResult::OVERRIDE ) ) {
1317  return false;
1318  }
1319  }
1320  }
1321  }
1322  }
1323 
1324  return true;
1325  }
1326 
1331  protected function getDB() {
1332  return $this->mDbSource->getDB();
1333  }
1334 
1341  private static function getPositiveIntegers( $array ) {
1342  // bug 25734 API: possible issue with revids validation
1343  // It seems with a load of revision rows, MySQL gets upset
1344  // Remove any < 0 integers, as they can't be valid
1345  foreach ( $array as $i => $int ) {
1346  if ( $int < 0 ) {
1347  unset( $array[$i] );
1348  }
1349  }
1350 
1351  return $array;
1352  }
1353 
1354  public function getAllowedParams( $flags = 0 ) {
1355  $result = [
1356  'titles' => [
1357  ApiBase::PARAM_ISMULTI => true,
1358  ApiBase::PARAM_HELP_MSG => 'api-pageset-param-titles',
1359  ],
1360  'pageids' => [
1361  ApiBase::PARAM_TYPE => 'integer',
1362  ApiBase::PARAM_ISMULTI => true,
1363  ApiBase::PARAM_HELP_MSG => 'api-pageset-param-pageids',
1364  ],
1365  'revids' => [
1366  ApiBase::PARAM_TYPE => 'integer',
1367  ApiBase::PARAM_ISMULTI => true,
1368  ApiBase::PARAM_HELP_MSG => 'api-pageset-param-revids',
1369  ],
1370  'generator' => [
1371  ApiBase::PARAM_TYPE => null,
1372  ApiBase::PARAM_HELP_MSG => 'api-pageset-param-generator',
1374  ],
1375  'redirects' => [
1376  ApiBase::PARAM_DFLT => false,
1377  ApiBase::PARAM_HELP_MSG => $this->mAllowGenerator
1378  ? 'api-pageset-param-redirects-generator'
1379  : 'api-pageset-param-redirects-nogenerator',
1380  ],
1381  'converttitles' => [
1382  ApiBase::PARAM_DFLT => false,
1383  ApiBase::PARAM_HELP_MSG => [
1384  'api-pageset-param-converttitles',
1385  new DeferredStringifier(
1386  function ( IContextSource $context ) {
1387  return $context->getLanguage()
1389  },
1390  $this
1391  )
1392  ],
1393  ],
1394  ];
1395 
1396  if ( !$this->mAllowGenerator ) {
1397  unset( $result['generator'] );
1398  } elseif ( $flags & ApiBase::GET_VALUES_FOR_HELP ) {
1399  $result['generator'][ApiBase::PARAM_TYPE] = 'submodule';
1400  $result['generator'][ApiBase::PARAM_SUBMODULE_MAP] = $this->getGenerators();
1401  }
1402 
1403  return $result;
1404  }
1405 
1406  private static $generators = null;
1407 
1412  private function getGenerators() {
1413  if ( self::$generators === null ) {
1415  if ( !( $query instanceof ApiQuery ) ) {
1416  // If the parent container of this pageset is not ApiQuery,
1417  // we must create it to get module manager
1418  $query = $this->getMain()->getModuleManager()->getModule( 'query' );
1419  }
1420  $gens = [];
1421  $prefix = $query->getModulePath() . '+';
1422  $mgr = $query->getModuleManager();
1423  foreach ( $mgr->getNamesWithClasses() as $name => $class ) {
1424  if ( is_subclass_of( $class, 'ApiQueryGeneratorBase' ) ) {
1425  $gens[$name] = $prefix . $name;
1426  }
1427  }
1428  ksort( $gens );
1429  self::$generators = $gens;
1430  }
1431 
1432  return self::$generators;
1433  }
1434 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:99
static $generators
static newFromRow($row)
Make a Title object from a DB row.
Definition: Title.php:465
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
Definition: ApiBase.php:88
Interface for objects which can provide a MediaWiki context on request.
static hasGenderDistinction($index)
Does the namespace (potentially) have different aliases for different genders.
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:439
the array() calling protocol came about after MediaWiki 1.4rc1.
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:1418
initFromRevIDs($revids)
Does the same as initFromTitles(), but is based on revision IDs instead.
Definition: ApiPageSet.php:898
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Definition: hooks.txt:2321
$mGoodAndMissingPages
Definition: ApiPageSet.php:56
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
getRedirectTitlesAsResult($result=null)
Get a list of redirect resolutions - maps a title to its redirect target.
Definition: ApiPageSet.php:450
getSpecialTitles()
Get the list of titles with negative namespace.
Definition: ApiPageSet.php:676
const NS_MAIN
Definition: Defines.php:69
getDataSource()
Return the parameter name that is the source of data for this PageSet.
Definition: ApiPageSet.php:249
This class contains a list of pages that the client has requested.
Definition: ApiPageSet.php:41
populateFromRevisionIDs($revIDs)
Populate this PageSet from a list of revision IDs.
Definition: ApiPageSet.php:721
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:50
getMain()
Get the main module.
Definition: ApiBase.php:480
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
Definition: ApiBase.php:197
static singleton()
Definition: GenderCache.php:39
getConvertedTitles()
Get a list of title conversions - maps a title to its converted version.
Definition: ApiPageSet.php:517
processDbRow($row)
Extract all requested fields from the row received from the database.
Definition: ApiPageSet.php:729
getMissingRevisionIDs()
Revision IDs that were not found in the database.
Definition: ApiPageSet.php:648
extractRequestParams($parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user...
Definition: ApiBase.php:685
$value
getConvertedTitlesAsResult($result=null)
Get a list of title conversions - maps a title to its converted version as a result array...
Definition: ApiPageSet.php:528
const PROTO_CURRENT
Definition: Defines.php:264
getInvalidTitles()
Titles that were deemed invalid by Title::newFromText() The array's index will be unique and negative...
Definition: ApiPageSet.php:410
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2548
getInvalidTitlesAndRevisions($invalidChecks=[ 'invalidTitles', 'special', 'missingIds', 'missingRevIds', 'missingTitles', 'interwikiTitles'])
Get an array of invalid/special/missing titles.
Definition: ApiPageSet.php:594
requestField($fieldName)
Request an additional field from the page table.
Definition: ApiPageSet.php:271
getMissingTitlesByNamespace()
Returns an array [ns][dbkey] => fake_page_id for all missing titles.
Definition: ApiPageSet.php:375
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
Represents a title within MediaWiki.
Definition: Title.php:34
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
getRevisionIDs()
Get the list of valid revision IDs (requested with the revids= parameter)
Definition: ApiPageSet.php:624
getTitleCount()
Returns the number of unique pages (not revisions) in the set.
Definition: ApiPageSet.php:342
IContextSource $context
getAllTitlesByNamespace()
Returns an array [ns][dbkey] => page_id for all requested titles.
Definition: ApiPageSet.php:326
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:618
populateFromTitles($titles)
Populate this PageSet from a list of Titles.
Definition: ApiPageSet.php:692
getPageTableFields()
Get the fields that have to be queried from the page table: the ones requested through requestField()...
Definition: ApiPageSet.php:291
getTitles()
All Title objects provided.
Definition: ApiPageSet.php:334
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:965
getLiveRevisionIDs()
Get the list of non-deleted revision IDs (requested with the revids= parameter)
Definition: ApiPageSet.php:632
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:Associative array mapping language codes to prefixed links of the form"language:title".&$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':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:1796
callable null $mRedirectMergePolicy
Definition: ApiPageSet.php:83
resolvePendingRedirects()
Resolve any redirects in the result if redirect resolution was requested.
Definition: ApiPageSet.php:981
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:31
getGoodAndMissingTitlesByNamespace()
Returns an array [ns][dbkey] => page_id for all good and missing titles.
Definition: ApiPageSet.php:392
populateFromQueryResult($db, $queryResult)
Populate this PageSet from a rowset returned from the database.
Definition: ApiPageSet.php:713
getGoodTitleCount()
Returns the number of found unique pages (not revisions) in the set.
Definition: ApiPageSet.php:366
const PARAM_SUBMODULE_PARAM_PREFIX
(string) When PARAM_TYPE is 'submodule', used to indicate the 'g' prefix added by ApiQueryGeneratorBa...
Definition: ApiBase.php:172
getInvalidTitlesAndReasons()
Titles that were deemed invalid by Title::newFromText() The array's index will be unique and negative...
Definition: ApiPageSet.php:422
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:400
getDBkey()
Get the main part with underscores.
Definition: Title.php:911
getGoodTitlesByNamespace()
Returns an array [ns][dbkey] => page_id for all good titles.
Definition: ApiPageSet.php:350
$res
Definition: database.txt:21
getGenerators()
Get an array of all available generators.
initFromPageIds($pageids)
Does the same as initFromTitles(), but is based on page IDs instead.
Definition: ApiPageSet.php:791
executeDryRun()
In case execute() is not called, call this method to mark all relevant parameters as used This preven...
Definition: ApiPageSet.php:131
getConfig()
Get the Config object.
getMissingRevisionIDsAsResult($result=null)
Revision IDs that were not found in the database as result array.
Definition: ApiPageSet.php:658
const PARAM_SUBMODULE_MAP
(string[]) When PARAM_TYPE is 'submodule', map parameter values to submodule paths.
Definition: ApiBase.php:165
getGoodTitles()
Title objects that were found in the database.
Definition: ApiPageSet.php:358
$params
static addValues(array &$result, $values, $flag=null, $name=null)
Add all items from $values into the result.
Definition: ApiPageSet.php:92
getMissingTitles()
Title objects that were NOT found in the database.
Definition: ApiPageSet.php:384
getDB()
Get the database connection (read-only)
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
populateFromPageIDs($pageIDs)
Populate this PageSet from a list of page IDs.
Definition: ApiPageSet.php:700
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:464
This class represents the result of the API operations.
Definition: ApiResult.php:33
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:934
initFromTitles($titles)
This method populates internal variables with page information based on the given array of title stri...
Definition: ApiPageSet.php:766
This is the main query class.
Definition: ApiQuery.php:38
setWarning($warning)
Set warning section for this module.
Definition: ApiBase.php:1495
getLanguage()
Get the Language object.
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
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
Definition: ApiBase.php:125
$mResolvedRedirectTitles
Definition: ApiPageSet.php:70
processTitlesArray($titles)
Given an array of title strings, convert them into Title objects.
getCacheMode($params=null)
Get the cache mode for the data generated by this module.
static newFromTextThrow($text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid, rather than returning null.
Definition: Title.php:307
int $mDefaultNamespace
Definition: ApiPageSet.php:81
executeInternal($isDryRun)
Populate the PageSet from the request parameters.
Definition: ApiPageSet.php:147
getMissingPageIDs()
Page IDs that were not found in the database.
Definition: ApiPageSet.php:430
getInterwikiTitles()
Get a list of interwiki titles - maps a title to its interwiki prefix.
Definition: ApiPageSet.php:548
$from
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
setRedirectMergePolicy($callable)
Controls how generator data about a redirect source is merged into the generator data for the redirec...
$mRequestedPageFields
Definition: ApiPageSet.php:79
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.
getInterwikiTitlesAsResult($result=null, $iwUrl=false)
Get a list of interwiki titles - maps a title to its interwiki prefix as result.
Definition: ApiPageSet.php:560
getAllowedParams($flags=0)
getNormalizedTitles()
Get a list of title normalizations - maps a title to its normalized version.
Definition: ApiPageSet.php:486
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:53
array $mInvalidTitles
[fake_page_id] => array( 'title' => $title, 'invalidreason' => $reason )
Definition: ApiPageSet.php:62
__construct(ApiBase $dbSource, $flags=0, $defaultNamespace=NS_MAIN)
Definition: ApiPageSet.php:116
dieUsage($description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
Definition: ApiBase.php:1526
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 local content language as $wgContLang
Definition: design.txt:56
This abstract class implements many basic API functions, and is the base of all API classes...
Definition: ApiBase.php:39
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:497
isResolvingRedirects()
Check whether this PageSet is resolving redirects.
Definition: ApiPageSet.php:237
getRevisionCount()
Returns the number of revisions (requested with revids= parameter).
Definition: ApiPageSet.php:684
initFromQueryResult($res, &$remaining=null, $processTitles=null)
Iterate through the result of the query on 'page' table, and for each row create and store title obje...
Definition: ApiPageSet.php:829
static dieDebug($method, $message)
Internal code errors should be reported with this method.
Definition: ApiBase.php:2230
const DISABLE_GENERATORS
Constructor flag: The new instance of ApiPageSet will ignore the 'generator=' parameter.
Definition: ApiPageSet.php:46
Title[] $mPendingRedirectIDs
Definition: ApiPageSet.php:69
static getPositiveIntegers($array)
Returns the input array of integers with all values < 0 removed.
static array $languagesWithVariants
languages supporting variants
const OVERRIDE
Override existing value in addValue(), setValue(), and similar functions.
Definition: ApiResult.php:39
static addTitleInfo(&$arr, $title, $prefix= '')
Add information (title and namespace) about a Title object to a result array.
execute()
Populate the PageSet from the request parameters.
Definition: ApiPageSet.php:138
getUser()
Get the User object.
static & makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:524
getDeletedRevisionIDs()
Get the list of revision IDs that were associated with deleted titles.
Definition: ApiPageSet.php:640
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2338
getCustomField($fieldName)
Get the value of a custom field previously requested through requestField()
Definition: ApiPageSet.php:281
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310