MediaWiki  master
LinksUpdate.php
Go to the documentation of this file.
1 <?php
31  // @todo make members protected, but make sure extensions don't break
32 
34  public $mId;
35 
37  public $mTitle;
38 
41 
43  public $mLinks;
44 
46  public $mImages;
47 
49  public $mTemplates;
50 
52  public $mExternals;
53 
55  public $mCategories;
56 
58  public $mInterlangs;
59 
61  public $mInterwikis;
62 
64  public $mProperties;
65 
67  public $mRecursive;
68 
70  private $mRevision;
71 
75  private $linkInsertions = null;
76 
80  private $linkDeletions = null;
81 
85  private $user;
86 
95  function __construct( Title $title, ParserOutput $parserOutput, $recursive = true ) {
96  // Implicit transactions are disabled as they interfere with batching
97  parent::__construct( false );
98 
99  $this->mTitle = $title;
100  $this->mId = $title->getArticleID( Title::GAID_FOR_UPDATE );
101 
102  if ( !$this->mId ) {
103  throw new InvalidArgumentException(
104  "The Title object yields no ID. Perhaps the page doesn't exist?"
105  );
106  }
107 
108  $this->mParserOutput = $parserOutput;
109 
110  $this->mLinks = $parserOutput->getLinks();
111  $this->mImages = $parserOutput->getImages();
112  $this->mTemplates = $parserOutput->getTemplates();
113  $this->mExternals = $parserOutput->getExternalLinks();
114  $this->mCategories = $parserOutput->getCategories();
115  $this->mProperties = $parserOutput->getProperties();
116  $this->mInterwikis = $parserOutput->getInterwikiLinks();
117 
118  # Convert the format of the interlanguage links
119  # I didn't want to change it in the ParserOutput, because that array is passed all
120  # the way back to the skin, so either a skin API break would be required, or an
121  # inefficient back-conversion.
122  $ill = $parserOutput->getLanguageLinks();
123  $this->mInterlangs = [];
124  foreach ( $ill as $link ) {
125  list( $key, $title ) = explode( ':', $link, 2 );
126  $this->mInterlangs[$key] = $title;
127  }
128 
129  foreach ( $this->mCategories as &$sortkey ) {
130  # If the sortkey is longer then 255 bytes,
131  # it truncated by DB, and then doesn't get
132  # matched when comparing existing vs current
133  # categories, causing bug 25254.
134  # Also. substr behaves weird when given "".
135  if ( $sortkey !== '' ) {
136  $sortkey = substr( $sortkey, 0, 255 );
137  }
138  }
139 
140  $this->mRecursive = $recursive;
141 
142  Hooks::run( 'LinksUpdateConstructed', [ &$this ] );
143  }
144 
150  public function doUpdate() {
151  // Make sure all links update threads see the changes of each other.
152  // This handles the case when updates have to batched into several COMMITs.
153  $scopedLock = self::acquirePageLock( $this->mDb, $this->mId );
154 
155  Hooks::run( 'LinksUpdate', [ &$this ] );
156  $this->doIncrementalUpdate();
157 
158  // Commit and release the lock
159  ScopedCallback::consume( $scopedLock );
160  // Run post-commit hooks without DBO_TRX
161  $this->mDb->onTransactionIdle( function() {
162  Hooks::run( 'LinksUpdateComplete', [ &$this ] );
163  } );
164  }
165 
176  public static function acquirePageLock( IDatabase $dbw, $pageId, $why = 'atomicity' ) {
177  $key = "LinksUpdate:$why:pageid:$pageId";
178  $scopedLock = $dbw->getScopedLockAndFlush( $key, __METHOD__, 15 );
179  if ( !$scopedLock ) {
180  throw new RuntimeException( "Could not acquire lock '$key'." );
181  }
182 
183  return $scopedLock;
184  }
185 
186  protected function doIncrementalUpdate() {
187  # Page links
188  $existing = $this->getExistingLinks();
189  $this->linkDeletions = $this->getLinkDeletions( $existing );
190  $this->linkInsertions = $this->getLinkInsertions( $existing );
191  $this->incrTableUpdate( 'pagelinks', 'pl', $this->linkDeletions, $this->linkInsertions );
192 
193  # Image links
194  $existing = $this->getExistingImages();
195  $imageDeletes = $this->getImageDeletions( $existing );
196  $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes,
197  $this->getImageInsertions( $existing ) );
198 
199  # Invalidate all image description pages which had links added or removed
200  $imageUpdates = $imageDeletes + array_diff_key( $this->mImages, $existing );
201  $this->invalidateImageDescriptions( $imageUpdates );
202 
203  # External links
204  $existing = $this->getExistingExternals();
205  $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
206  $this->getExternalInsertions( $existing ) );
207 
208  # Language links
209  $existing = $this->getExistingInterlangs();
210  $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
211  $this->getInterlangInsertions( $existing ) );
212 
213  # Inline interwiki links
214  $existing = $this->getExistingInterwikis();
215  $this->incrTableUpdate( 'iwlinks', 'iwl', $this->getInterwikiDeletions( $existing ),
216  $this->getInterwikiInsertions( $existing ) );
217 
218  # Template links
219  $existing = $this->getExistingTemplates();
220  $this->incrTableUpdate( 'templatelinks', 'tl', $this->getTemplateDeletions( $existing ),
221  $this->getTemplateInsertions( $existing ) );
222 
223  # Category links
224  $existing = $this->getExistingCategories();
225  $categoryDeletes = $this->getCategoryDeletions( $existing );
226  $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes,
227  $this->getCategoryInsertions( $existing ) );
228 
229  # Invalidate all categories which were added, deleted or changed (set symmetric difference)
230  $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
231  $categoryUpdates = $categoryInserts + $categoryDeletes;
232  $this->invalidateCategories( $categoryUpdates );
233  $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
234 
235  # Page properties
236  $existing = $this->getExistingProperties();
237  $propertiesDeletes = $this->getPropertyDeletions( $existing );
238  $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes,
239  $this->getPropertyInsertions( $existing ) );
240 
241  # Invalidate the necessary pages
242  $changed = $propertiesDeletes + array_diff_assoc( $this->mProperties, $existing );
243  $this->invalidateProperties( $changed );
244 
245  # Refresh links of all pages including this page
246  # This will be in a separate transaction
247  if ( $this->mRecursive ) {
248  $this->queueRecursiveJobs();
249  }
250 
251  # Update the links table freshness for this title
252  $this->updateLinksTimestamp();
253  }
254 
261  protected function queueRecursiveJobs() {
262  self::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' );
263  if ( $this->mTitle->getNamespace() == NS_FILE ) {
264  // Process imagelinks in case the title is or was a redirect
265  self::queueRecursiveJobsForTable( $this->mTitle, 'imagelinks' );
266  }
267 
268  $bc = $this->mTitle->getBacklinkCache();
269  // Get jobs for cascade-protected backlinks for a high priority queue.
270  // If meta-templates change to using a new template, the new template
271  // should be implicitly protected as soon as possible, if applicable.
272  // These jobs duplicate a subset of the above ones, but can run sooner.
273  // Which ever runs first generally no-ops the other one.
274  $jobs = [];
275  foreach ( $bc->getCascadeProtectedLinks() as $title ) {
276  $jobs[] = RefreshLinksJob::newPrioritized( $title, [] );
277  }
278  JobQueueGroup::singleton()->push( $jobs );
279  }
280 
287  public static function queueRecursiveJobsForTable( Title $title, $table ) {
288  if ( $title->getBacklinkCache()->hasLinks( $table ) ) {
289  $job = new RefreshLinksJob(
290  $title,
291  [
292  'table' => $table,
293  'recursive' => true,
294  ] + Job::newRootJobParams( // "overall" refresh links job info
295  "refreshlinks:{$table}:{$title->getPrefixedText()}"
296  )
297  );
298 
299  JobQueueGroup::singleton()->push( $job );
300  }
301  }
302 
306  function invalidateCategories( $cats ) {
307  $this->invalidatePages( NS_CATEGORY, array_keys( $cats ) );
308  }
309 
315  function updateCategoryCounts( $added, $deleted ) {
316  $a = WikiPage::factory( $this->mTitle );
317  $a->updateCategoryCounts(
318  array_keys( $added ), array_keys( $deleted )
319  );
320  }
321 
325  function invalidateImageDescriptions( $images ) {
326  $this->invalidatePages( NS_FILE, array_keys( $images ) );
327  }
328 
336  private function incrTableUpdate( $table, $prefix, $deletions, $insertions ) {
337  $bSize = RequestContext::getMain()->getConfig()->get( 'UpdateRowsPerQuery' );
338 
339  if ( $table === 'page_props' ) {
340  $fromField = 'pp_page';
341  } else {
342  $fromField = "{$prefix}_from";
343  }
344 
345  $deleteWheres = []; // list of WHERE clause arrays for each DB delete() call
346  if ( $table === 'pagelinks' || $table === 'templatelinks' || $table === 'iwlinks' ) {
347  $baseKey = ( $table === 'iwlinks' ) ? 'iwl_prefix' : "{$prefix}_namespace";
348 
349  $curBatchSize = 0;
350  $curDeletionBatch = [];
351  $deletionBatches = [];
352  foreach ( $deletions as $ns => $dbKeys ) {
353  foreach ( $dbKeys as $dbKey => $unused ) {
354  $curDeletionBatch[$ns][$dbKey] = 1;
355  if ( ++$curBatchSize >= $bSize ) {
356  $deletionBatches[] = $curDeletionBatch;
357  $curDeletionBatch = [];
358  $curBatchSize = 0;
359  }
360  }
361  }
362  if ( $curDeletionBatch ) {
363  $deletionBatches[] = $curDeletionBatch;
364  }
365 
366  foreach ( $deletionBatches as $deletionBatch ) {
367  $deleteWheres[] = [
368  $fromField => $this->mId,
369  $this->mDb->makeWhereFrom2d( $deletionBatch, $baseKey, "{$prefix}_title" )
370  ];
371  }
372  } else {
373  if ( $table === 'langlinks' ) {
374  $toField = 'll_lang';
375  } elseif ( $table === 'page_props' ) {
376  $toField = 'pp_propname';
377  } else {
378  $toField = $prefix . '_to';
379  }
380 
381  $deletionBatches = array_chunk( array_keys( $deletions ), $bSize );
382  foreach ( $deletionBatches as $deletionBatch ) {
383  $deleteWheres[] = [ $fromField => $this->mId, $toField => $deletionBatch ];
384  }
385  }
386 
387  foreach ( $deleteWheres as $deleteWhere ) {
388  $this->mDb->delete( $table, $deleteWhere, __METHOD__ );
389  $this->mDb->commit( __METHOD__, 'flush' );
390  wfGetLBFactory()->waitForReplication( [ 'wiki' => $this->mDb->getWikiID() ] );
391  }
392 
393  $insertBatches = array_chunk( $insertions, $bSize );
394  foreach ( $insertBatches as $insertBatch ) {
395  $this->mDb->insert( $table, $insertBatch, __METHOD__, 'IGNORE' );
396  $this->mDb->commit( __METHOD__, 'flush' );
397  wfGetLBFactory()->waitForReplication( [ 'wiki' => $this->mDb->getWikiID() ] );
398  }
399 
400  if ( count( $insertions ) ) {
401  Hooks::run( 'LinksUpdateAfterInsert', [ $this, $table, $insertions ] );
402  }
403  }
404 
411  private function getLinkInsertions( $existing = [] ) {
412  $arr = [];
413  foreach ( $this->mLinks as $ns => $dbkeys ) {
414  $diffs = isset( $existing[$ns] )
415  ? array_diff_key( $dbkeys, $existing[$ns] )
416  : $dbkeys;
417  foreach ( $diffs as $dbk => $id ) {
418  $arr[] = [
419  'pl_from' => $this->mId,
420  'pl_from_namespace' => $this->mTitle->getNamespace(),
421  'pl_namespace' => $ns,
422  'pl_title' => $dbk
423  ];
424  }
425  }
426 
427  return $arr;
428  }
429 
435  private function getTemplateInsertions( $existing = [] ) {
436  $arr = [];
437  foreach ( $this->mTemplates as $ns => $dbkeys ) {
438  $diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
439  foreach ( $diffs as $dbk => $id ) {
440  $arr[] = [
441  'tl_from' => $this->mId,
442  'tl_from_namespace' => $this->mTitle->getNamespace(),
443  'tl_namespace' => $ns,
444  'tl_title' => $dbk
445  ];
446  }
447  }
448 
449  return $arr;
450  }
451 
458  private function getImageInsertions( $existing = [] ) {
459  $arr = [];
460  $diffs = array_diff_key( $this->mImages, $existing );
461  foreach ( $diffs as $iname => $dummy ) {
462  $arr[] = [
463  'il_from' => $this->mId,
464  'il_from_namespace' => $this->mTitle->getNamespace(),
465  'il_to' => $iname
466  ];
467  }
468 
469  return $arr;
470  }
471 
477  private function getExternalInsertions( $existing = [] ) {
478  $arr = [];
479  $diffs = array_diff_key( $this->mExternals, $existing );
480  foreach ( $diffs as $url => $dummy ) {
481  foreach ( wfMakeUrlIndexes( $url ) as $index ) {
482  $arr[] = [
483  'el_id' => $this->mDb->nextSequenceValue( 'externallinks_el_id_seq' ),
484  'el_from' => $this->mId,
485  'el_to' => $url,
486  'el_index' => $index,
487  ];
488  }
489  }
490 
491  return $arr;
492  }
493 
502  private function getCategoryInsertions( $existing = [] ) {
504  $diffs = array_diff_assoc( $this->mCategories, $existing );
505  $arr = [];
506  foreach ( $diffs as $name => $prefix ) {
508  $wgContLang->findVariantLink( $name, $nt, true );
509 
510  if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
511  $type = 'subcat';
512  } elseif ( $this->mTitle->getNamespace() == NS_FILE ) {
513  $type = 'file';
514  } else {
515  $type = 'page';
516  }
517 
518  # Treat custom sortkeys as a prefix, so that if multiple
519  # things are forced to sort as '*' or something, they'll
520  # sort properly in the category rather than in page_id
521  # order or such.
522  $sortkey = Collation::singleton()->getSortKey(
523  $this->mTitle->getCategorySortkey( $prefix ) );
524 
525  $arr[] = [
526  'cl_from' => $this->mId,
527  'cl_to' => $name,
528  'cl_sortkey' => $sortkey,
529  'cl_timestamp' => $this->mDb->timestamp(),
530  'cl_sortkey_prefix' => $prefix,
531  'cl_collation' => $wgCategoryCollation,
532  'cl_type' => $type,
533  ];
534  }
535 
536  return $arr;
537  }
538 
546  private function getInterlangInsertions( $existing = [] ) {
547  $diffs = array_diff_assoc( $this->mInterlangs, $existing );
548  $arr = [];
549  foreach ( $diffs as $lang => $title ) {
550  $arr[] = [
551  'll_from' => $this->mId,
552  'll_lang' => $lang,
553  'll_title' => $title
554  ];
555  }
556 
557  return $arr;
558  }
559 
565  function getPropertyInsertions( $existing = [] ) {
566  $diffs = array_diff_assoc( $this->mProperties, $existing );
567 
568  $arr = [];
569  foreach ( array_keys( $diffs ) as $name ) {
570  $arr[] = $this->getPagePropRowData( $name );
571  }
572 
573  return $arr;
574  }
575 
592  private function getPagePropRowData( $prop ) {
594 
595  $value = $this->mProperties[$prop];
596 
597  $row = [
598  'pp_page' => $this->mId,
599  'pp_propname' => $prop,
600  'pp_value' => $value,
601  ];
602 
603  if ( $wgPagePropsHaveSortkey ) {
604  $row['pp_sortkey'] = $this->getPropertySortKeyValue( $value );
605  }
606 
607  return $row;
608  }
609 
622  private function getPropertySortKeyValue( $value ) {
623  if ( is_int( $value ) || is_float( $value ) || is_bool( $value ) ) {
624  return floatval( $value );
625  }
626 
627  return null;
628  }
629 
636  private function getInterwikiInsertions( $existing = [] ) {
637  $arr = [];
638  foreach ( $this->mInterwikis as $prefix => $dbkeys ) {
639  $diffs = isset( $existing[$prefix] )
640  ? array_diff_key( $dbkeys, $existing[$prefix] )
641  : $dbkeys;
642 
643  foreach ( $diffs as $dbk => $id ) {
644  $arr[] = [
645  'iwl_from' => $this->mId,
646  'iwl_prefix' => $prefix,
647  'iwl_title' => $dbk
648  ];
649  }
650  }
651 
652  return $arr;
653  }
654 
661  private function getLinkDeletions( $existing ) {
662  $del = [];
663  foreach ( $existing as $ns => $dbkeys ) {
664  if ( isset( $this->mLinks[$ns] ) ) {
665  $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks[$ns] );
666  } else {
667  $del[$ns] = $existing[$ns];
668  }
669  }
670 
671  return $del;
672  }
673 
680  private function getTemplateDeletions( $existing ) {
681  $del = [];
682  foreach ( $existing as $ns => $dbkeys ) {
683  if ( isset( $this->mTemplates[$ns] ) ) {
684  $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates[$ns] );
685  } else {
686  $del[$ns] = $existing[$ns];
687  }
688  }
689 
690  return $del;
691  }
692 
699  private function getImageDeletions( $existing ) {
700  return array_diff_key( $existing, $this->mImages );
701  }
702 
709  private function getExternalDeletions( $existing ) {
710  return array_diff_key( $existing, $this->mExternals );
711  }
712 
719  private function getCategoryDeletions( $existing ) {
720  return array_diff_assoc( $existing, $this->mCategories );
721  }
722 
729  private function getInterlangDeletions( $existing ) {
730  return array_diff_assoc( $existing, $this->mInterlangs );
731  }
732 
738  function getPropertyDeletions( $existing ) {
739  return array_diff_assoc( $existing, $this->mProperties );
740  }
741 
748  private function getInterwikiDeletions( $existing ) {
749  $del = [];
750  foreach ( $existing as $prefix => $dbkeys ) {
751  if ( isset( $this->mInterwikis[$prefix] ) ) {
752  $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis[$prefix] );
753  } else {
754  $del[$prefix] = $existing[$prefix];
755  }
756  }
757 
758  return $del;
759  }
760 
766  private function getExistingLinks() {
767  $res = $this->mDb->select( 'pagelinks', [ 'pl_namespace', 'pl_title' ],
768  [ 'pl_from' => $this->mId ], __METHOD__, $this->mOptions );
769  $arr = [];
770  foreach ( $res as $row ) {
771  if ( !isset( $arr[$row->pl_namespace] ) ) {
772  $arr[$row->pl_namespace] = [];
773  }
774  $arr[$row->pl_namespace][$row->pl_title] = 1;
775  }
776 
777  return $arr;
778  }
779 
785  private function getExistingTemplates() {
786  $res = $this->mDb->select( 'templatelinks', [ 'tl_namespace', 'tl_title' ],
787  [ 'tl_from' => $this->mId ], __METHOD__, $this->mOptions );
788  $arr = [];
789  foreach ( $res as $row ) {
790  if ( !isset( $arr[$row->tl_namespace] ) ) {
791  $arr[$row->tl_namespace] = [];
792  }
793  $arr[$row->tl_namespace][$row->tl_title] = 1;
794  }
795 
796  return $arr;
797  }
798 
804  private function getExistingImages() {
805  $res = $this->mDb->select( 'imagelinks', [ 'il_to' ],
806  [ 'il_from' => $this->mId ], __METHOD__, $this->mOptions );
807  $arr = [];
808  foreach ( $res as $row ) {
809  $arr[$row->il_to] = 1;
810  }
811 
812  return $arr;
813  }
814 
820  private function getExistingExternals() {
821  $res = $this->mDb->select( 'externallinks', [ 'el_to' ],
822  [ 'el_from' => $this->mId ], __METHOD__, $this->mOptions );
823  $arr = [];
824  foreach ( $res as $row ) {
825  $arr[$row->el_to] = 1;
826  }
827 
828  return $arr;
829  }
830 
836  private function getExistingCategories() {
837  $res = $this->mDb->select( 'categorylinks', [ 'cl_to', 'cl_sortkey_prefix' ],
838  [ 'cl_from' => $this->mId ], __METHOD__, $this->mOptions );
839  $arr = [];
840  foreach ( $res as $row ) {
841  $arr[$row->cl_to] = $row->cl_sortkey_prefix;
842  }
843 
844  return $arr;
845  }
846 
853  private function getExistingInterlangs() {
854  $res = $this->mDb->select( 'langlinks', [ 'll_lang', 'll_title' ],
855  [ 'll_from' => $this->mId ], __METHOD__, $this->mOptions );
856  $arr = [];
857  foreach ( $res as $row ) {
858  $arr[$row->ll_lang] = $row->ll_title;
859  }
860 
861  return $arr;
862  }
863 
868  protected function getExistingInterwikis() {
869  $res = $this->mDb->select( 'iwlinks', [ 'iwl_prefix', 'iwl_title' ],
870  [ 'iwl_from' => $this->mId ], __METHOD__, $this->mOptions );
871  $arr = [];
872  foreach ( $res as $row ) {
873  if ( !isset( $arr[$row->iwl_prefix] ) ) {
874  $arr[$row->iwl_prefix] = [];
875  }
876  $arr[$row->iwl_prefix][$row->iwl_title] = 1;
877  }
878 
879  return $arr;
880  }
881 
887  private function getExistingProperties() {
888  $res = $this->mDb->select( 'page_props', [ 'pp_propname', 'pp_value' ],
889  [ 'pp_page' => $this->mId ], __METHOD__, $this->mOptions );
890  $arr = [];
891  foreach ( $res as $row ) {
892  $arr[$row->pp_propname] = $row->pp_value;
893  }
894 
895  return $arr;
896  }
897 
902  public function getTitle() {
903  return $this->mTitle;
904  }
905 
911  public function getParserOutput() {
912  return $this->mParserOutput;
913  }
914 
919  public function getImages() {
920  return $this->mImages;
921  }
922 
930  public function setRevision( Revision $revision ) {
931  $this->mRevision = $revision;
932  }
933 
938  public function getRevision() {
939  return $this->mRevision;
940  }
941 
948  public function setTriggeringUser( User $user ) {
949  $this->user = $user;
950  }
951 
956  public function getTriggeringUser() {
957  return $this->user;
958  }
959 
964  private function invalidateProperties( $changed ) {
966 
967  foreach ( $changed as $name => $value ) {
968  if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
969  $inv = $wgPagePropLinkInvalidations[$name];
970  if ( !is_array( $inv ) ) {
971  $inv = [ $inv ];
972  }
973  foreach ( $inv as $table ) {
974  DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->mTitle, $table ) );
975  }
976  }
977  }
978  }
979 
985  public function getAddedLinks() {
986  if ( $this->linkInsertions === null ) {
987  return null;
988  }
989  $result = [];
990  foreach ( $this->linkInsertions as $insertion ) {
991  $result[] = Title::makeTitle( $insertion['pl_namespace'], $insertion['pl_title'] );
992  }
993 
994  return $result;
995  }
996 
1002  public function getRemovedLinks() {
1003  if ( $this->linkDeletions === null ) {
1004  return null;
1005  }
1006  $result = [];
1007  foreach ( $this->linkDeletions as $ns => $titles ) {
1008  foreach ( $titles as $title => $unused ) {
1009  $result[] = Title::makeTitle( $ns, $title );
1010  }
1011  }
1012 
1013  return $result;
1014  }
1015 
1019  protected function updateLinksTimestamp() {
1020  if ( $this->mId ) {
1021  // The link updates made here only reflect the freshness of the parser output
1022  $timestamp = $this->mParserOutput->getCacheTime();
1023  $this->mDb->update( 'page',
1024  [ 'page_links_updated' => $this->mDb->timestamp( $timestamp ) ],
1025  [ 'page_id' => $this->mId ],
1026  __METHOD__
1027  );
1028  }
1029  }
1030 
1031  public function getAsJobSpecification() {
1032  if ( $this->user ) {
1033  $userInfo = [
1034  'userId' => $this->user->getId(),
1035  'userName' => $this->user->getName(),
1036  ];
1037  } else {
1038  $userInfo = false;
1039  }
1040 
1041  if ( $this->mRevision ) {
1042  $triggeringRevisionId = $this->mRevision->getId();
1043  } else {
1044  $triggeringRevisionId = false;
1045  }
1046 
1047  return [
1048  'wiki' => $this->mDb->getWikiID(),
1049  'job' => new JobSpecification(
1050  'refreshLinksPrioritized',
1051  [
1052  // Reuse the parser cache if it was saved
1053  'rootJobTimestamp' => $this->mParserOutput->getCacheTime(),
1054  'useRecursiveLinksUpdate' => $this->mRecursive,
1055  'triggeringUser' => $userInfo,
1056  'triggeringRevisionId' => $triggeringRevisionId,
1057  ],
1058  [ 'removeDuplicates' => true ],
1059  $this->getTitle()
1060  )
1061  ];
1062  }
1063 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:101
setRevision(Revision $revision)
Set the revision corresponding to this LinksUpdate.
invalidateProperties($changed)
Invalidate any necessary link lists related to page property changes.
updateLinksTimestamp()
Update links table freshness.
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
$wgPagePropsHaveSortkey
Whether the page_props table has a pp_sortkey column.
queueRecursiveJobs()
Queue recursive jobs for this page.
getImageDeletions($existing)
Given an array of existing images, returns those images which are not in $this and thus should be del...
bool $mRecursive
Whether to queue jobs for recursive updates.
Definition: LinksUpdate.php:67
getArticleID($flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:3141
getPropertySortKeyValue($value)
Determines the sort key for the given property value.
Class the manages updates of *_link tables as well as similar extension-managed tables.
Definition: LinksUpdate.php:30
getCategoryInsertions($existing=[])
Get an array of category insertions.
getExistingInterwikis()
Get an array of existing inline interwiki links, as a 2-D array.
array $mProperties
Map of arbitrary name to value.
Definition: LinksUpdate.php:64
static singleton()
Definition: Collation.php:34
if(!isset($args[0])) $lang
Interface that marks a DataUpdate as enqueuable via the JobQueue.
Definition: DataUpdate.php:156
$value
static newRootJobParams($key)
Get "root job" parameters for a task.
Definition: Job.php:261
wfMakeUrlIndexes($url)
Make URL indexes, appropriate for the el_index field of externallinks.
Revision $mRevision
Revision for which this update has been triggered.
Definition: LinksUpdate.php:70
null array $linkInsertions
Added links if calculated.
Definition: LinksUpdate.php:75
Represents a title within MediaWiki.
Definition: Title.php:36
updateCategoryCounts($added, $deleted)
Update all the appropriate counts in the category table.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
getExistingProperties()
Get an array of existing categories, with the name in the key and sort key in the value...
Title $mTitle
Title object of the article linked from.
Definition: LinksUpdate.php:37
getBacklinkCache()
Get a backlink cache object.
Definition: Title.php:4552
$wgCategoryCollation
Specify how category names should be sorted, when listed on a category page.
__construct(Title $title, ParserOutput $parserOutput, $recursive=true)
Constructor.
Definition: LinksUpdate.php:95
getPagePropRowData($prop)
Returns an associative array to be used for inserting a row into the page_props table.
getExistingInterlangs()
Get an array of existing interlanguage links, with the language code in the key and the title in the ...
static queueRecursiveJobsForTable(Title $title, $table)
Queue a RefreshLinks job for any table.
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':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1814
ParserOutput $mParserOutput
Definition: LinksUpdate.php:40
the value to return A Title object or null for latest to be modified or replaced by the hook handler or if authentication is not possible after cache objects are set for highlighting & $link
Definition: hooks.txt:2621
getTemplateDeletions($existing)
Given an array of existing templates, returns those templates which are not in $this and thus should ...
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:47
$wgPagePropLinkInvalidations
Page property link table invalidation lists.
getLinkInsertions($existing=[])
Get an array of pagelinks insertions for passing to the DB Skips the titles specified by the 2-D arra...
getInterlangDeletions($existing)
Given an array of existing interlanguage links, returns those links which are not in $this and thus s...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1816
getPropertyInsertions($existing=[])
Get an array of page property insertions.
getTitle()
Return the title object of the page being updated.
getExistingCategories()
Get an array of existing categories, with the name in the key and sort key in the value...
array $mImages
DB keys of the images used, in the array key only.
Definition: LinksUpdate.php:46
static getMain()
Static methods.
invalidatePages($namespace, array $dbkeys)
Invalidate the cache of a list of pages from a single namespace.
getExistingExternals()
Get an array of existing external links, URLs in the keys.
getParserOutput()
Returns parser output.
getCategoryDeletions($existing)
Given an array of existing categories, returns those categories which are not in $this and thus shoul...
Class to invalidate the HTML cache of all the pages linking to a given title.
getAddedLinks()
Fetch page links added by this LinksUpdate.
if($limit) $timestamp
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context $parserOutput
Definition: hooks.txt:1020
$res
Definition: database.txt:21
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define.
Definition: Title.php:51
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Wikitext formatted, in the key only.
Definition: distributors.txt:9
setTriggeringUser(User $user)
Set the User who triggered this LinksUpdate.
getRemovedLinks()
Fetch page links removed by this LinksUpdate.
const NS_CATEGORY
Definition: Defines.php:83
incrTableUpdate($table, $prefix, $deletions, $insertions)
Update a table by doing a delete query then an insert query.
array $mExternals
URLs of external links, array key only.
Definition: LinksUpdate.php:52
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:527
array $mTemplates
Map of title strings to IDs for the template references, including broken ones.
Definition: LinksUpdate.php:49
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks conditions will AND in the final query as a Content object as a Content object $title
Definition: hooks.txt:312
static addUpdate(DeferrableUpdate $update, $type=self::POSTSEND)
Add an update to the deferred list.
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
invalidateCategories($cats)
getExistingImages()
Get an array of existing images, image names in the keys.
const NS_FILE
Definition: Defines.php:75
getInterlangInsertions($existing=[])
Get an array of interlanguage link insertions.
getTemplateInsertions($existing=[])
Get an array of template insertions.
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
Abstract base class for update jobs that put some secondary data extracted from article content into ...
getExistingTemplates()
Get an array of existing templates, as a 2-D array.
getExternalInsertions($existing=[])
Get an array of externallinks insertions.
getExistingLinks()
Get an array of existing links, as a 2-D array.
invalidateImageDescriptions($images)
static singleton($wiki=false)
Job to update link tables for pages.
User null $user
Definition: LinksUpdate.php:85
array $mLinks
Map of title strings to IDs for the links in the document.
Definition: LinksUpdate.php:43
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
getExternalDeletions($existing)
Given an array of existing external links, returns those links which are not in $this and thus should...
wfGetLBFactory()
Get the load balancer factory object.
getInterwikiDeletions($existing)
Given an array of existing interwiki links, returns those links which are not in $this and thus shoul...
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
if(count($args)< 1) $job
static newPrioritized(Title $title, array $params)
getPropertyDeletions($existing)
Get array of properties which should be deleted.
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
getInterwikiInsertions($existing=[])
Get an array of interwiki insertions for passing to the DB Skips the titles specified by the 2-D arra...
getLinkDeletions($existing)
Given an array of existing links, returns those links which are not in $this and thus should be delet...
doUpdate()
Update link tables with outgoing links from an updated article.
static consume(ScopedCallback &$sc=null)
Trigger a scoped callback and destroy it.
null array $linkDeletions
Deleted links if calculated.
Definition: LinksUpdate.php:80
getImages()
Return the list of images used as generated by the parser.
array $mInterlangs
Map of language codes to titles.
Definition: LinksUpdate.php:58
static acquirePageLock(IDatabase $dbw, $pageId, $why= 'atomicity')
Acquire a lock for performing link table updates for a page on a DB.
int $mId
Page ID of the article linked from.
Definition: LinksUpdate.php:34
getImageInsertions($existing=[])
Get an array of image insertions Skips the names specified in $existing.
array $mCategories
Map of category names to sort keys.
Definition: LinksUpdate.php:55
Job queue task description base code.
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 one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2376
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:503
getScopedLockAndFlush($lockKey, $fname, $timeout)
Acquire a named lock, flush any transaction, and return an RAII style unlocker object.
Basic database interface for live and lazy-loaded DB handles.
Definition: IDatabase.php:35
array $mInterwikis
2-D map of (prefix => DBK => 1)
Definition: LinksUpdate.php:61
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310