3 * Updater for link tracking tables after a page edit.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * See docs/deferred.txt
26 * @todo document (e.g. one-sentence top-level class description).
28 class LinksUpdate
extends SqlDataUpdate
{
30 // @todo make members protected, but make sure extensions don't break
32 public $mId, //!< Page ID of the article linked from
33 $mTitle, //!< Title object of the article linked from
34 $mParserOutput, //!< Parser output
35 $mLinks, //!< Map of title strings to IDs for the links in the document
36 $mImages, //!< DB keys of the images used, in the array key only
37 $mTemplates, //!< Map of title strings to IDs for the template references, including broken ones
38 $mExternals, //!< URLs of external links, array key only
39 $mCategories, //!< Map of category names to sort keys
40 $mInterlangs, //!< Map of language codes to titles
41 $mProperties, //!< Map of arbitrary name to value
42 $mDb, //!< Database connection reference
43 $mOptions, //!< SELECT options to be used (array)
44 $mRecursive; //!< Whether to queue jobs for recursive updates
49 * @param $title Title of the page we're updating
50 * @param $parserOutput ParserOutput: output from a full parse of this page
51 * @param $recursive Boolean: queue jobs for recursive updates?
54 function __construct( $title, $parserOutput, $recursive = true ) {
55 parent
::__construct( false ); // no implicit transaction
57 if ( !( $title instanceof Title
) ) {
58 throw new MWException( "The calling convention to LinksUpdate::LinksUpdate() has changed. " .
59 "Please see Article::editUpdates() for an invocation example.\n" );
62 if ( !( $parserOutput instanceof ParserOutput
) ) {
63 throw new MWException( "The calling convention to LinksUpdate::__construct() has changed. " .
64 "Please see WikiPage::doEditUpdates() for an invocation example.\n" );
67 $this->mTitle
= $title;
68 $this->mId
= $title->getArticleID();
71 throw new MWException( "The Title object did not provide an article ID. Perhaps the page doesn't exist?" );
74 $this->mParserOutput
= $parserOutput;
76 $this->mLinks
= $parserOutput->getLinks();
77 $this->mImages
= $parserOutput->getImages();
78 $this->mTemplates
= $parserOutput->getTemplates();
79 $this->mExternals
= $parserOutput->getExternalLinks();
80 $this->mCategories
= $parserOutput->getCategories();
81 $this->mProperties
= $parserOutput->getProperties();
82 $this->mInterwikis
= $parserOutput->getInterwikiLinks();
84 # Convert the format of the interlanguage links
85 # I didn't want to change it in the ParserOutput, because that array is passed all
86 # the way back to the skin, so either a skin API break would be required, or an
87 # inefficient back-conversion.
88 $ill = $parserOutput->getLanguageLinks();
89 $this->mInterlangs
= array();
90 foreach ( $ill as $link ) {
91 list( $key, $title ) = explode( ':', $link, 2 );
92 $this->mInterlangs
[$key] = $title;
95 foreach ( $this->mCategories
as &$sortkey ) {
96 # If the sortkey is longer then 255 bytes,
97 # it truncated by DB, and then doesn't get
98 # matched when comparing existing vs current
99 # categories, causing bug 25254.
100 # Also. substr behaves weird when given "".
101 if ( $sortkey !== '' ) {
102 $sortkey = substr( $sortkey, 0, 255 );
106 $this->mRecursive
= $recursive;
108 wfRunHooks( 'LinksUpdateConstructed', array( &$this ) );
112 * Update link tables with outgoing links from an updated article
114 public function doUpdate() {
115 global $wgUseDumbLinkUpdate;
117 wfRunHooks( 'LinksUpdate', array( &$this ) );
118 if ( $wgUseDumbLinkUpdate ) {
119 $this->doDumbUpdate();
121 $this->doIncrementalUpdate();
123 wfRunHooks( 'LinksUpdateComplete', array( &$this ) );
126 protected function doIncrementalUpdate() {
127 wfProfileIn( __METHOD__
);
130 $existing = $this->getExistingLinks();
131 $this->incrTableUpdate( 'pagelinks', 'pl', $this->getLinkDeletions( $existing ),
132 $this->getLinkInsertions( $existing ) );
135 $existing = $this->getExistingImages();
137 $imageDeletes = $this->getImageDeletions( $existing );
138 $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes,
139 $this->getImageInsertions( $existing ) );
141 # Invalidate all image description pages which had links added or removed
142 $imageUpdates = $imageDeletes +
array_diff_key( $this->mImages
, $existing );
143 $this->invalidateImageDescriptions( $imageUpdates );
146 $existing = $this->getExistingExternals();
147 $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
148 $this->getExternalInsertions( $existing ) );
151 $existing = $this->getExistingInterlangs();
152 $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
153 $this->getInterlangInsertions( $existing ) );
155 # Inline interwiki links
156 $existing = $this->getExistingInterwikis();
157 $this->incrTableUpdate( 'iwlinks', 'iwl', $this->getInterwikiDeletions( $existing ),
158 $this->getInterwikiInsertions( $existing ) );
161 $existing = $this->getExistingTemplates();
162 $this->incrTableUpdate( 'templatelinks', 'tl', $this->getTemplateDeletions( $existing ),
163 $this->getTemplateInsertions( $existing ) );
166 $existing = $this->getExistingCategories();
168 $categoryDeletes = $this->getCategoryDeletions( $existing );
170 $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes,
171 $this->getCategoryInsertions( $existing ) );
173 # Invalidate all categories which were added, deleted or changed (set symmetric difference)
174 $categoryInserts = array_diff_assoc( $this->mCategories
, $existing );
175 $categoryUpdates = $categoryInserts +
$categoryDeletes;
176 $this->invalidateCategories( $categoryUpdates );
177 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
180 $existing = $this->getExistingProperties();
182 $propertiesDeletes = $this->getPropertyDeletions( $existing );
184 $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes,
185 $this->getPropertyInsertions( $existing ) );
187 # Invalidate the necessary pages
188 $changed = $propertiesDeletes +
array_diff_assoc( $this->mProperties
, $existing );
189 $this->invalidateProperties( $changed );
191 # Refresh links of all pages including this page
192 # This will be in a separate transaction
193 if ( $this->mRecursive
) {
194 $this->queueRecursiveJobs();
197 wfProfileOut( __METHOD__
);
201 * Link update which clears the previous entries and inserts new ones
202 * May be slower or faster depending on level of lock contention and write speed of DB
203 * Also useful where link table corruption needs to be repaired, e.g. in refreshLinks.php
205 protected function doDumbUpdate() {
206 wfProfileIn( __METHOD__
);
208 # Refresh category pages and image description pages
209 $existing = $this->getExistingCategories();
210 $categoryInserts = array_diff_assoc( $this->mCategories
, $existing );
211 $categoryDeletes = array_diff_assoc( $existing, $this->mCategories
);
212 $categoryUpdates = $categoryInserts +
$categoryDeletes;
213 $existing = $this->getExistingImages();
214 $imageUpdates = array_diff_key( $existing, $this->mImages
) +
array_diff_key( $this->mImages
, $existing );
216 $this->dumbTableUpdate( 'pagelinks', $this->getLinkInsertions(), 'pl_from' );
217 $this->dumbTableUpdate( 'imagelinks', $this->getImageInsertions(), 'il_from' );
218 $this->dumbTableUpdate( 'categorylinks', $this->getCategoryInsertions(), 'cl_from' );
219 $this->dumbTableUpdate( 'templatelinks', $this->getTemplateInsertions(), 'tl_from' );
220 $this->dumbTableUpdate( 'externallinks', $this->getExternalInsertions(), 'el_from' );
221 $this->dumbTableUpdate( 'langlinks', $this->getInterlangInsertions(), 'll_from' );
222 $this->dumbTableUpdate( 'iwlinks', $this->getInterwikiInsertions(), 'iwl_from' );
223 $this->dumbTableUpdate( 'page_props', $this->getPropertyInsertions(), 'pp_page' );
225 # Update the cache of all the category pages and image description
226 # pages which were changed, and fix the category table count
227 $this->invalidateCategories( $categoryUpdates );
228 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
229 $this->invalidateImageDescriptions( $imageUpdates );
231 # Refresh links of all pages including this page
232 # This will be in a separate transaction
233 if ( $this->mRecursive
) {
234 $this->queueRecursiveJobs();
237 wfProfileOut( __METHOD__
);
241 * Queue recursive jobs for this page
243 * Which means do LinksUpdate on all templates
244 * that include the current page, using the job queue.
246 function queueRecursiveJobs() {
247 self
::queueRecursiveJobsForTable( $this->mTitle
, 'templatelinks' );
251 * Queue a RefreshLinks job for any table.
253 * @param Title $title Title to do job for
254 * @param String $table Table to use (e.g. 'templatelinks')
256 public static function queueRecursiveJobsForTable( Title
$title, $table ) {
257 wfProfileIn( __METHOD__
);
258 if ( $title->getBacklinkCache()->hasLinks( $table ) ) {
259 $job = new RefreshLinksJob2(
263 ) + Job
::newRootJobParams( // "overall" refresh links job info
264 "refreshlinks:{$table}:{$title->getPrefixedText()}"
267 JobQueueGroup
::singleton()->push( $job );
268 JobQueueGroup
::singleton()->deduplicateRootJob( $job );
270 wfProfileOut( __METHOD__
);
276 function invalidateCategories( $cats ) {
277 $this->invalidatePages( NS_CATEGORY
, array_keys( $cats ) );
281 * Update all the appropriate counts in the category table.
282 * @param array $added associative array of category name => sort key
283 * @param array $deleted associative array of category name => sort key
285 function updateCategoryCounts( $added, $deleted ) {
286 $a = WikiPage
::factory( $this->mTitle
);
287 $a->updateCategoryCounts(
288 array_keys( $added ), array_keys( $deleted )
295 function invalidateImageDescriptions( $images ) {
296 $this->invalidatePages( NS_FILE
, array_keys( $images ) );
304 private function dumbTableUpdate( $table, $insertions, $fromField ) {
305 $this->mDb
->delete( $table, array( $fromField => $this->mId
), __METHOD__
);
306 if ( count( $insertions ) ) {
307 # The link array was constructed without FOR UPDATE, so there may
308 # be collisions. This may cause minor link table inconsistencies,
309 # which is better than crippling the site with lock contention.
310 $this->mDb
->insert( $table, $insertions, __METHOD__
, array( 'IGNORE' ) );
315 * Update a table by doing a delete query then an insert query
321 function incrTableUpdate( $table, $prefix, $deletions, $insertions ) {
322 if ( $table == 'page_props' ) {
323 $fromField = 'pp_page';
325 $fromField = "{$prefix}_from";
327 $where = array( $fromField => $this->mId
);
328 if ( $table == 'pagelinks' ||
$table == 'templatelinks' ||
$table == 'iwlinks' ) {
329 if ( $table == 'iwlinks' ) {
330 $baseKey = 'iwl_prefix';
332 $baseKey = "{$prefix}_namespace";
334 $clause = $this->mDb
->makeWhereFrom2d( $deletions, $baseKey, "{$prefix}_title" );
341 if ( $table == 'langlinks' ) {
342 $toField = 'll_lang';
343 } elseif ( $table == 'page_props' ) {
344 $toField = 'pp_propname';
346 $toField = $prefix . '_to';
348 if ( count( $deletions ) ) {
349 $where[] = "$toField IN (" . $this->mDb
->makeList( array_keys( $deletions ) ) . ')';
355 $this->mDb
->delete( $table, $where, __METHOD__
);
357 if ( count( $insertions ) ) {
358 $this->mDb
->insert( $table, $insertions, __METHOD__
, 'IGNORE' );
359 wfRunHooks( 'LinksUpdateAfterInsert', array( $this, $table, $insertions ) );
364 * Get an array of pagelinks insertions for passing to the DB
365 * Skips the titles specified by the 2-D array $existing
366 * @param $existing array
369 private function getLinkInsertions( $existing = array() ) {
371 foreach ( $this->mLinks
as $ns => $dbkeys ) {
372 $diffs = isset( $existing[$ns] )
373 ?
array_diff_key( $dbkeys, $existing[$ns] )
375 foreach ( $diffs as $dbk => $id ) {
377 'pl_from' => $this->mId
,
378 'pl_namespace' => $ns,
387 * Get an array of template insertions. Like getLinkInsertions()
388 * @param $existing array
391 private function getTemplateInsertions( $existing = array() ) {
393 foreach ( $this->mTemplates
as $ns => $dbkeys ) {
394 $diffs = isset( $existing[$ns] ) ?
array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
395 foreach ( $diffs as $dbk => $id ) {
397 'tl_from' => $this->mId
,
398 'tl_namespace' => $ns,
407 * Get an array of image insertions
408 * Skips the names specified in $existing
409 * @param $existing array
412 private function getImageInsertions( $existing = array() ) {
414 $diffs = array_diff_key( $this->mImages
, $existing );
415 foreach ( $diffs as $iname => $dummy ) {
417 'il_from' => $this->mId
,
425 * Get an array of externallinks insertions. Skips the names specified in $existing
426 * @param $existing array
429 private function getExternalInsertions( $existing = array() ) {
431 $diffs = array_diff_key( $this->mExternals
, $existing );
432 foreach ( $diffs as $url => $dummy ) {
433 foreach ( wfMakeUrlIndexes( $url ) as $index ) {
435 'el_from' => $this->mId
,
437 'el_index' => $index,
445 * Get an array of category insertions
447 * @param array $existing mapping existing category names to sort keys. If both
448 * match a link in $this, the link will be omitted from the output
452 private function getCategoryInsertions( $existing = array() ) {
453 global $wgContLang, $wgCategoryCollation;
454 $diffs = array_diff_assoc( $this->mCategories
, $existing );
456 foreach ( $diffs as $name => $prefix ) {
457 $nt = Title
::makeTitleSafe( NS_CATEGORY
, $name );
458 $wgContLang->findVariantLink( $name, $nt, true );
460 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
462 } elseif ( $this->mTitle
->getNamespace() == NS_FILE
) {
468 # Treat custom sortkeys as a prefix, so that if multiple
469 # things are forced to sort as '*' or something, they'll
470 # sort properly in the category rather than in page_id
472 $sortkey = Collation
::singleton()->getSortKey(
473 $this->mTitle
->getCategorySortkey( $prefix ) );
476 'cl_from' => $this->mId
,
478 'cl_sortkey' => $sortkey,
479 'cl_timestamp' => $this->mDb
->timestamp(),
480 'cl_sortkey_prefix' => $prefix,
481 'cl_collation' => $wgCategoryCollation,
489 * Get an array of interlanguage link insertions
491 * @param array $existing mapping existing language codes to titles
495 private function getInterlangInsertions( $existing = array() ) {
496 $diffs = array_diff_assoc( $this->mInterlangs
, $existing );
498 foreach ( $diffs as $lang => $title ) {
500 'll_from' => $this->mId
,
509 * Get an array of page property insertions
510 * @param $existing array
513 function getPropertyInsertions( $existing = array() ) {
514 $diffs = array_diff_assoc( $this->mProperties
, $existing );
516 foreach ( $diffs as $name => $value ) {
518 'pp_page' => $this->mId
,
519 'pp_propname' => $name,
520 'pp_value' => $value,
527 * Get an array of interwiki insertions for passing to the DB
528 * Skips the titles specified by the 2-D array $existing
529 * @param $existing array
532 private function getInterwikiInsertions( $existing = array() ) {
534 foreach ( $this->mInterwikis
as $prefix => $dbkeys ) {
535 $diffs = isset( $existing[$prefix] ) ?
array_diff_key( $dbkeys, $existing[$prefix] ) : $dbkeys;
536 foreach ( $diffs as $dbk => $id ) {
538 'iwl_from' => $this->mId
,
539 'iwl_prefix' => $prefix,
548 * Given an array of existing links, returns those links which are not in $this
549 * and thus should be deleted.
550 * @param $existing array
553 private function getLinkDeletions( $existing ) {
555 foreach ( $existing as $ns => $dbkeys ) {
556 if ( isset( $this->mLinks
[$ns] ) ) {
557 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks
[$ns] );
559 $del[$ns] = $existing[$ns];
566 * Given an array of existing templates, returns those templates which are not in $this
567 * and thus should be deleted.
568 * @param $existing array
571 private function getTemplateDeletions( $existing ) {
573 foreach ( $existing as $ns => $dbkeys ) {
574 if ( isset( $this->mTemplates
[$ns] ) ) {
575 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates
[$ns] );
577 $del[$ns] = $existing[$ns];
584 * Given an array of existing images, returns those images which are not in $this
585 * and thus should be deleted.
586 * @param $existing array
589 private function getImageDeletions( $existing ) {
590 return array_diff_key( $existing, $this->mImages
);
594 * Given an array of existing external links, returns those links which are not
595 * in $this and thus should be deleted.
596 * @param $existing array
599 private function getExternalDeletions( $existing ) {
600 return array_diff_key( $existing, $this->mExternals
);
604 * Given an array of existing categories, returns those categories which are not in $this
605 * and thus should be deleted.
606 * @param $existing array
609 private function getCategoryDeletions( $existing ) {
610 return array_diff_assoc( $existing, $this->mCategories
);
614 * Given an array of existing interlanguage links, returns those links which are not
615 * in $this and thus should be deleted.
616 * @param $existing array
619 private function getInterlangDeletions( $existing ) {
620 return array_diff_assoc( $existing, $this->mInterlangs
);
624 * Get array of properties which should be deleted.
625 * @param $existing array
628 function getPropertyDeletions( $existing ) {
629 return array_diff_assoc( $existing, $this->mProperties
);
633 * Given an array of existing interwiki links, returns those links which are not in $this
634 * and thus should be deleted.
635 * @param $existing array
638 private function getInterwikiDeletions( $existing ) {
640 foreach ( $existing as $prefix => $dbkeys ) {
641 if ( isset( $this->mInterwikis
[$prefix] ) ) {
642 $del[$prefix] = array_diff_key( $existing[$prefix], $this->mInterwikis
[$prefix] );
644 $del[$prefix] = $existing[$prefix];
651 * Get an array of existing links, as a 2-D array
655 private function getExistingLinks() {
656 $res = $this->mDb
->select( 'pagelinks', array( 'pl_namespace', 'pl_title' ),
657 array( 'pl_from' => $this->mId
), __METHOD__
, $this->mOptions
);
659 foreach ( $res as $row ) {
660 if ( !isset( $arr[$row->pl_namespace
] ) ) {
661 $arr[$row->pl_namespace
] = array();
663 $arr[$row->pl_namespace
][$row->pl_title
] = 1;
669 * Get an array of existing templates, as a 2-D array
673 private function getExistingTemplates() {
674 $res = $this->mDb
->select( 'templatelinks', array( 'tl_namespace', 'tl_title' ),
675 array( 'tl_from' => $this->mId
), __METHOD__
, $this->mOptions
);
677 foreach ( $res as $row ) {
678 if ( !isset( $arr[$row->tl_namespace
] ) ) {
679 $arr[$row->tl_namespace
] = array();
681 $arr[$row->tl_namespace
][$row->tl_title
] = 1;
687 * Get an array of existing images, image names in the keys
691 private function getExistingImages() {
692 $res = $this->mDb
->select( 'imagelinks', array( 'il_to' ),
693 array( 'il_from' => $this->mId
), __METHOD__
, $this->mOptions
);
695 foreach ( $res as $row ) {
696 $arr[$row->il_to
] = 1;
702 * Get an array of existing external links, URLs in the keys
706 private function getExistingExternals() {
707 $res = $this->mDb
->select( 'externallinks', array( 'el_to' ),
708 array( 'el_from' => $this->mId
), __METHOD__
, $this->mOptions
);
710 foreach ( $res as $row ) {
711 $arr[$row->el_to
] = 1;
717 * Get an array of existing categories, with the name in the key and sort key in the value.
721 private function getExistingCategories() {
722 $res = $this->mDb
->select( 'categorylinks', array( 'cl_to', 'cl_sortkey_prefix' ),
723 array( 'cl_from' => $this->mId
), __METHOD__
, $this->mOptions
);
725 foreach ( $res as $row ) {
726 $arr[$row->cl_to
] = $row->cl_sortkey_prefix
;
732 * Get an array of existing interlanguage links, with the language code in the key and the
733 * title in the value.
737 private function getExistingInterlangs() {
738 $res = $this->mDb
->select( 'langlinks', array( 'll_lang', 'll_title' ),
739 array( 'll_from' => $this->mId
), __METHOD__
, $this->mOptions
);
741 foreach ( $res as $row ) {
742 $arr[$row->ll_lang
] = $row->ll_title
;
748 * Get an array of existing inline interwiki links, as a 2-D array
749 * @return array (prefix => array(dbkey => 1))
751 protected function getExistingInterwikis() {
752 $res = $this->mDb
->select( 'iwlinks', array( 'iwl_prefix', 'iwl_title' ),
753 array( 'iwl_from' => $this->mId
), __METHOD__
, $this->mOptions
);
755 foreach ( $res as $row ) {
756 if ( !isset( $arr[$row->iwl_prefix
] ) ) {
757 $arr[$row->iwl_prefix
] = array();
759 $arr[$row->iwl_prefix
][$row->iwl_title
] = 1;
765 * Get an array of existing categories, with the name in the key and sort key in the value.
769 private function getExistingProperties() {
770 $res = $this->mDb
->select( 'page_props', array( 'pp_propname', 'pp_value' ),
771 array( 'pp_page' => $this->mId
), __METHOD__
, $this->mOptions
);
773 foreach ( $res as $row ) {
774 $arr[$row->pp_propname
] = $row->pp_value
;
780 * Return the title object of the page being updated
783 public function getTitle() {
784 return $this->mTitle
;
788 * Returns parser output
790 * @return ParserOutput
792 public function getParserOutput() {
793 return $this->mParserOutput
;
797 * Return the list of images used as generated by the parser
800 public function getImages() {
801 return $this->mImages
;
805 * Invalidate any necessary link lists related to page property changes
808 private function invalidateProperties( $changed ) {
809 global $wgPagePropLinkInvalidations;
811 foreach ( $changed as $name => $value ) {
812 if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
813 $inv = $wgPagePropLinkInvalidations[$name];
814 if ( !is_array( $inv ) ) {
815 $inv = array( $inv );
817 foreach ( $inv as $table ) {
818 $update = new HTMLCacheUpdate( $this->mTitle
, $table );
827 * Update object handling the cleanup of links tables after a page was deleted.
829 class LinksDeletionUpdate
extends SqlDataUpdate
{
831 protected $mPage; //!< WikiPage the wikipage that was deleted
836 * @param $page WikiPage Page we are updating
837 * @throws MWException
839 function __construct( WikiPage
$page ) {
840 parent
::__construct( false ); // no implicit transaction
842 $this->mPage
= $page;
844 if ( !$page->exists() ) {
845 throw new MWException( "Page ID not known, perhaps the page doesn't exist?" );
850 * Do some database updates after deletion
852 public function doUpdate() {
853 $title = $this->mPage
->getTitle();
854 $id = $this->mPage
->getId();
856 # Delete restrictions for it
857 $this->mDb
->delete( 'page_restrictions', array( 'pr_page' => $id ), __METHOD__
);
859 # Fix category table counts
861 $res = $this->mDb
->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__
);
863 foreach ( $res as $row ) {
864 $cats[] = $row->cl_to
;
867 $this->mPage
->updateCategoryCounts( array(), $cats );
869 # If using cascading deletes, we can skip some explicit deletes
870 if ( !$this->mDb
->cascadingDeletes() ) {
871 $this->mDb
->delete( 'revision', array( 'rev_page' => $id ), __METHOD__
);
873 # Delete outgoing links
874 $this->mDb
->delete( 'pagelinks', array( 'pl_from' => $id ), __METHOD__
);
875 $this->mDb
->delete( 'imagelinks', array( 'il_from' => $id ), __METHOD__
);
876 $this->mDb
->delete( 'categorylinks', array( 'cl_from' => $id ), __METHOD__
);
877 $this->mDb
->delete( 'templatelinks', array( 'tl_from' => $id ), __METHOD__
);
878 $this->mDb
->delete( 'externallinks', array( 'el_from' => $id ), __METHOD__
);
879 $this->mDb
->delete( 'langlinks', array( 'll_from' => $id ), __METHOD__
);
880 $this->mDb
->delete( 'iwlinks', array( 'iwl_from' => $id ), __METHOD__
);
881 $this->mDb
->delete( 'redirect', array( 'rd_from' => $id ), __METHOD__
);
882 $this->mDb
->delete( 'page_props', array( 'pp_page' => $id ), __METHOD__
);
885 # If using cleanup triggers, we can skip some manual deletes
886 if ( !$this->mDb
->cleanupTriggers() ) {
887 # Clean up recentchanges entries...
888 $this->mDb
->delete( 'recentchanges',
889 array( 'rc_type != ' . RC_LOG
,
890 'rc_namespace' => $title->getNamespace(),
891 'rc_title' => $title->getDBkey() ),
893 $this->mDb
->delete( 'recentchanges',
894 array( 'rc_type != ' . RC_LOG
, 'rc_cur_id' => $id ),
900 * Update all the appropriate counts in the category table.
901 * @param array $added associative array of category name => sort key
902 * @param array $deleted associative array of category name => sort key
904 function updateCategoryCounts( $added, $deleted ) {
905 $a = WikiPage
::factory( $this->mTitle
);
906 $a->updateCategoryCounts(
907 array_keys( $added ), array_keys( $deleted )