* API: Add documentation to important API classes
[lhc/web/wiklou.git] / includes / LinksUpdate.php
1 <?php
2 /**
3 * See docs/deferred.txt
4 *
5 * @todo document (e.g. one-sentence top-level class description).
6 */
7 class LinksUpdate {
8
9 /**@{{
10 * @private
11 */
12 var $mId, //!< Page ID of the article linked from
13 $mTitle, //!< Title object of the article linked from
14 $mLinks, //!< Map of title strings to IDs for the links in the document
15 $mImages, //!< DB keys of the images used, in the array key only
16 $mTemplates, //!< Map of title strings to IDs for the template references, including broken ones
17 $mExternals, //!< URLs of external links, array key only
18 $mCategories, //!< Map of category names to sort keys
19 $mInterlangs, //!< Map of language codes to titles
20 $mProperties, //!< Map of arbitrary name to value
21 $mDb, //!< Database connection reference
22 $mOptions, //!< SELECT options to be used (array)
23 $mRecursive, //!< Whether to queue jobs for recursive updates
24 $mTouchTmplLinks; //!< Whether to queue HTMLCacheUpdate jobs IF recursive
25 /**@}}*/
26
27 /**
28 * Constructor
29 *
30 * @param Title $title Title of the page we're updating
31 * @param ParserOutput $parserOutput Output from a full parse of this page
32 * @param bool $recursive Queue jobs for recursive updates?
33 */
34 function LinksUpdate( $title, $parserOutput, $recursive = true ) {
35 global $wgAntiLockFlags;
36
37 if ( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) {
38 $this->mOptions = array();
39 } else {
40 $this->mOptions = array( 'FOR UPDATE' );
41 }
42 $this->mDb = wfGetDB( DB_MASTER );
43
44 if ( !is_object( $title ) ) {
45 throw new MWException( "The calling convention to LinksUpdate::LinksUpdate() has changed. " .
46 "Please see Article::editUpdates() for an invocation example.\n" );
47 }
48 $this->mTitle = $title;
49 $this->mId = $title->getArticleID();
50
51 $this->mParserOutput = $parserOutput;
52 $this->mLinks = $parserOutput->getLinks();
53 $this->mImages = $parserOutput->getImages();
54 $this->mTemplates = $parserOutput->getTemplates();
55 $this->mExternals = $parserOutput->getExternalLinks();
56 $this->mCategories = $parserOutput->getCategories();
57 $this->mProperties = $parserOutput->getProperties();
58
59 # Convert the format of the interlanguage links
60 # I didn't want to change it in the ParserOutput, because that array is passed all
61 # the way back to the skin, so either a skin API break would be required, or an
62 # inefficient back-conversion.
63 $ill = $parserOutput->getLanguageLinks();
64 $this->mInterlangs = array();
65 foreach ( $ill as $link ) {
66 list( $key, $title ) = explode( ':', $link, 2 );
67 $this->mInterlangs[$key] = $title;
68 }
69
70 $this->mRecursive = $recursive;
71 $this->mTouchTmplLinks = false;
72
73 wfRunHooks( 'LinksUpdateConstructed', array( &$this ) );
74 }
75
76 /**
77 * Invalidate HTML cache of pages that include this page?
78 */
79 public function setRecursiveTouch( $val ) {
80 $this->mTouchTmplLinks = (bool)$val;
81 if( $val ) // Cannot invalidate without queueRecursiveJobs()
82 $this->mRecursive = true;
83 }
84
85 /**
86 * Update link tables with outgoing links from an updated article
87 */
88 public function doUpdate() {
89 global $wgUseDumbLinkUpdate;
90
91 wfRunHooks( 'LinksUpdate', array( &$this ) );
92 if ( $wgUseDumbLinkUpdate ) {
93 $this->doDumbUpdate();
94 } else {
95 $this->doIncrementalUpdate();
96 }
97 wfRunHooks( 'LinksUpdateComplete', array( &$this ) );
98
99 }
100
101 protected function doIncrementalUpdate() {
102 wfProfileIn( __METHOD__ );
103
104 # Page links
105 $existing = $this->getExistingLinks();
106 $this->incrTableUpdate( 'pagelinks', 'pl', $this->getLinkDeletions( $existing ),
107 $this->getLinkInsertions( $existing ) );
108
109 # Image links
110 $existing = $this->getExistingImages();
111
112 $imageDeletes = $this->getImageDeletions( $existing );
113 $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes, $this->getImageInsertions( $existing ) );
114
115 # Invalidate all image description pages which had links added or removed
116 $imageUpdates = $imageDeletes + array_diff_key( $this->mImages, $existing );
117 $this->invalidateImageDescriptions( $imageUpdates );
118
119 # External links
120 $existing = $this->getExistingExternals();
121 $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
122 $this->getExternalInsertions( $existing ) );
123
124 # Language links
125 $existing = $this->getExistingInterlangs();
126 $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
127 $this->getInterlangInsertions( $existing ) );
128
129 # Template links
130 $existing = $this->getExistingTemplates();
131 $this->incrTableUpdate( 'templatelinks', 'tl', $this->getTemplateDeletions( $existing ),
132 $this->getTemplateInsertions( $existing ) );
133
134 # Category links
135 $existing = $this->getExistingCategories();
136
137 $categoryDeletes = $this->getCategoryDeletions( $existing );
138
139 $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes, $this->getCategoryInsertions( $existing ) );
140
141 # Invalidate all categories which were added, deleted or changed (set symmetric difference)
142 $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
143 $categoryUpdates = $categoryInserts + $categoryDeletes;
144 $this->invalidateCategories( $categoryUpdates );
145 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
146
147 # Page properties
148 $existing = $this->getExistingProperties();
149
150 $propertiesDeletes = $this->getPropertyDeletions( $existing );
151
152 $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes, $this->getPropertyInsertions( $existing ) );
153
154 # Invalidate the necessary pages
155 $changed = $propertiesDeletes + array_diff_assoc( $this->mProperties, $existing );
156 $this->invalidateProperties( $changed );
157
158 # Refresh links of all pages including this page
159 # This will be in a separate transaction
160 if ( $this->mRecursive ) {
161 $this->queueRecursiveJobs();
162 }
163
164 wfProfileOut( __METHOD__ );
165 }
166
167 /**
168 * Link update which clears the previous entries and inserts new ones
169 * May be slower or faster depending on level of lock contention and write speed of DB
170 * Also useful where link table corruption needs to be repaired, e.g. in refreshLinks.php
171 */
172 protected function doDumbUpdate() {
173 wfProfileIn( __METHOD__ );
174
175 # Refresh category pages and image description pages
176 $existing = $this->getExistingCategories();
177 $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
178 $categoryDeletes = array_diff_assoc( $existing, $this->mCategories );
179 $categoryUpdates = $categoryInserts + $categoryDeletes;
180 $existing = $this->getExistingImages();
181 $imageUpdates = array_diff_key( $existing, $this->mImages ) + array_diff_key( $this->mImages, $existing );
182
183 $this->dumbTableUpdate( 'pagelinks', $this->getLinkInsertions(), 'pl_from' );
184 $this->dumbTableUpdate( 'imagelinks', $this->getImageInsertions(), 'il_from' );
185 $this->dumbTableUpdate( 'categorylinks', $this->getCategoryInsertions(), 'cl_from' );
186 $this->dumbTableUpdate( 'templatelinks', $this->getTemplateInsertions(), 'tl_from' );
187 $this->dumbTableUpdate( 'externallinks', $this->getExternalInsertions(), 'el_from' );
188 $this->dumbTableUpdate( 'langlinks', $this->getInterlangInsertions(),'ll_from' );
189 $this->dumbTableUpdate( 'page_props', $this->getPropertyInsertions(), 'pp_page' );
190
191 # Update the cache of all the category pages and image description
192 # pages which were changed, and fix the category table count
193 $this->invalidateCategories( $categoryUpdates );
194 $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
195 $this->invalidateImageDescriptions( $imageUpdates );
196
197 # Refresh links of all pages including this page
198 # This will be in a separate transaction
199 if ( $this->mRecursive ) {
200 $this->queueRecursiveJobs();
201 }
202
203 wfProfileOut( __METHOD__ );
204 }
205
206 function queueRecursiveJobs() {
207 global $wgUpdateRowsPerJob;
208 wfProfileIn( __METHOD__ );
209
210 $dbr = wfGetDB( DB_SLAVE );
211 $res = $dbr->select( 'templatelinks',
212 array( 'tl_from' ),
213 array(
214 'tl_namespace' => $this->mTitle->getNamespace(),
215 'tl_title' => $this->mTitle->getDBkey()
216 ), __METHOD__
217 );
218
219 $numRows = $res->numRows();
220 if( !$numRows ) {
221 wfProfileOut( __METHOD__ );
222 return; // nothing to do
223 }
224 $numBatches = ceil( $numRows / $wgUpdateRowsPerJob );
225 $realBatchSize = $numRows / $numBatches;
226 $start = false;
227 $jobs = array();
228 do {
229 for( $i = 0; $i <= $realBatchSize - 1; $i++ ) {
230 $row = $res->fetchRow();
231 if( $row ) {
232 $id = $row[0];
233 } else {
234 $id = false;
235 break;
236 }
237 }
238 $params = array(
239 'start' => $start,
240 'end' => ( $id !== false ? $id - 1 : false ),
241 );
242 $jobs[] = new RefreshLinksJob2( $this->mTitle, $params );
243 # Hit page caches while we're at it if set to do so...
244 if( $this->mTouchTmplLinks ) {
245 $params['table'] = 'templatelinks';
246 $jobs[] = new HTMLCacheUpdateJob( $this->mTitle, $params );
247 }
248 $start = $id;
249 } while ( $start );
250
251 $dbr->freeResult( $res );
252
253 Job::batchInsert( $jobs );
254
255 wfProfileOut( __METHOD__ );
256 }
257
258 /**
259 * Invalidate the cache of a list of pages from a single namespace
260 *
261 * @param integer $namespace
262 * @param array $dbkeys
263 */
264 function invalidatePages( $namespace, $dbkeys ) {
265 if ( !count( $dbkeys ) ) {
266 return;
267 }
268
269 /**
270 * Determine which pages need to be updated
271 * This is necessary to prevent the job queue from smashing the DB with
272 * large numbers of concurrent invalidations of the same page
273 */
274 $now = $this->mDb->timestamp();
275 $ids = array();
276 $res = $this->mDb->select( 'page', array( 'page_id' ),
277 array(
278 'page_namespace' => $namespace,
279 'page_title IN (' . $this->mDb->makeList( $dbkeys ) . ')',
280 'page_touched < ' . $this->mDb->addQuotes( $now )
281 ), __METHOD__
282 );
283 while ( $row = $this->mDb->fetchObject( $res ) ) {
284 $ids[] = $row->page_id;
285 }
286 if ( !count( $ids ) ) {
287 return;
288 }
289
290 /**
291 * Do the update
292 * We still need the page_touched condition, in case the row has changed since
293 * the non-locking select above.
294 */
295 $this->mDb->update( 'page', array( 'page_touched' => $now ),
296 array(
297 'page_id IN (' . $this->mDb->makeList( $ids ) . ')',
298 'page_touched < ' . $this->mDb->addQuotes( $now )
299 ), __METHOD__
300 );
301 }
302
303 function invalidateCategories( $cats ) {
304 $this->invalidatePages( NS_CATEGORY, array_keys( $cats ) );
305 }
306
307 /**
308 * Update all the appropriate counts in the category table.
309 * @param $added associative array of category name => sort key
310 * @param $deleted associative array of category name => sort key
311 */
312 function updateCategoryCounts( $added, $deleted ) {
313 $a = new Article($this->mTitle);
314 $a->updateCategoryCounts(
315 array_keys( $added ), array_keys( $deleted )
316 );
317 }
318
319 function invalidateImageDescriptions( $images ) {
320 $this->invalidatePages( NS_FILE, array_keys( $images ) );
321 }
322
323 function dumbTableUpdate( $table, $insertions, $fromField ) {
324 $this->mDb->delete( $table, array( $fromField => $this->mId ), __METHOD__ );
325 if ( count( $insertions ) ) {
326 # The link array was constructed without FOR UPDATE, so there may
327 # be collisions. This may cause minor link table inconsistencies,
328 # which is better than crippling the site with lock contention.
329 $this->mDb->insert( $table, $insertions, __METHOD__, array( 'IGNORE' ) );
330 }
331 }
332
333 /**
334 * Make a WHERE clause from a 2-d NS/dbkey array
335 *
336 * @param array $arr 2-d array indexed by namespace and DB key
337 * @param string $prefix Field name prefix, without the underscore
338 */
339 function makeWhereFrom2d( &$arr, $prefix ) {
340 $lb = new LinkBatch;
341 $lb->setArray( $arr );
342 return $lb->constructSet( $prefix, $this->mDb );
343 }
344
345 /**
346 * Update a table by doing a delete query then an insert query
347 * @private
348 */
349 function incrTableUpdate( $table, $prefix, $deletions, $insertions ) {
350 if ( $table == 'page_props' ) {
351 $fromField = 'pp_page';
352 } else {
353 $fromField = "{$prefix}_from";
354 }
355 $where = array( $fromField => $this->mId );
356 if ( $table == 'pagelinks' || $table == 'templatelinks' ) {
357 $clause = $this->makeWhereFrom2d( $deletions, $prefix );
358 if ( $clause ) {
359 $where[] = $clause;
360 } else {
361 $where = false;
362 }
363 } else {
364 if ( $table == 'langlinks' ) {
365 $toField = 'll_lang';
366 } elseif ( $table == 'page_props' ) {
367 $toField = 'pp_propname';
368 } else {
369 $toField = $prefix . '_to';
370 }
371 if ( count( $deletions ) ) {
372 $where[] = "$toField IN (" . $this->mDb->makeList( array_keys( $deletions ) ) . ')';
373 } else {
374 $where = false;
375 }
376 }
377 if ( $where ) {
378 $this->mDb->delete( $table, $where, __METHOD__ );
379 }
380 if ( count( $insertions ) ) {
381 $this->mDb->insert( $table, $insertions, __METHOD__, 'IGNORE' );
382 }
383 }
384
385
386 /**
387 * Get an array of pagelinks insertions for passing to the DB
388 * Skips the titles specified by the 2-D array $existing
389 * @private
390 */
391 function getLinkInsertions( $existing = array() ) {
392 $arr = array();
393 foreach( $this->mLinks as $ns => $dbkeys ) {
394 # array_diff_key() was introduced in PHP 5.1, there is a compatibility function
395 # in GlobalFunctions.php
396 $diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
397 foreach ( $diffs as $dbk => $id ) {
398 $arr[] = array(
399 'pl_from' => $this->mId,
400 'pl_namespace' => $ns,
401 'pl_title' => $dbk
402 );
403 }
404 }
405 return $arr;
406 }
407
408 /**
409 * Get an array of template insertions. Like getLinkInsertions()
410 * @private
411 */
412 function getTemplateInsertions( $existing = array() ) {
413 $arr = array();
414 foreach( $this->mTemplates as $ns => $dbkeys ) {
415 $diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;
416 foreach ( $diffs as $dbk => $id ) {
417 $arr[] = array(
418 'tl_from' => $this->mId,
419 'tl_namespace' => $ns,
420 'tl_title' => $dbk
421 );
422 }
423 }
424 return $arr;
425 }
426
427 /**
428 * Get an array of image insertions
429 * Skips the names specified in $existing
430 * @private
431 */
432 function getImageInsertions( $existing = array() ) {
433 $arr = array();
434 $diffs = array_diff_key( $this->mImages, $existing );
435 foreach( $diffs as $iname => $dummy ) {
436 $arr[] = array(
437 'il_from' => $this->mId,
438 'il_to' => $iname
439 );
440 }
441 return $arr;
442 }
443
444 /**
445 * Get an array of externallinks insertions. Skips the names specified in $existing
446 * @private
447 */
448 function getExternalInsertions( $existing = array() ) {
449 $arr = array();
450 $diffs = array_diff_key( $this->mExternals, $existing );
451 foreach( $diffs as $url => $dummy ) {
452 $arr[] = array(
453 'el_from' => $this->mId,
454 'el_to' => $url,
455 'el_index' => wfMakeUrlIndex( $url ),
456 );
457 }
458 return $arr;
459 }
460
461 /**
462 * Get an array of category insertions
463 * @param array $existing Array mapping existing category names to sort keys. If both
464 * match a link in $this, the link will be omitted from the output
465 * @private
466 */
467 function getCategoryInsertions( $existing = array() ) {
468 global $wgContLang;
469 $diffs = array_diff_assoc( $this->mCategories, $existing );
470 $arr = array();
471 foreach ( $diffs as $name => $sortkey ) {
472 $nt = Title::makeTitleSafe( NS_CATEGORY, $name );
473 $wgContLang->findVariantLink( $name, $nt, true );
474 // for category redirection
475 if ( $nt->isRedirect() ) {
476 $at = new Article( $nt );
477 $nt = $at->getRedirectTarget();
478 // we only redirect a category to another category
479 if ( $nt->getNamespace() == NS_CATEGORY )
480 $name = $nt->getText();
481 }
482 $arr[] = array(
483 'cl_from' => $this->mId,
484 'cl_to' => $name,
485 'cl_sortkey' => $sortkey,
486 'cl_timestamp' => $this->mDb->timestamp()
487 );
488 }
489 return $arr;
490 }
491
492 /**
493 * Get an array of interlanguage link insertions
494 * @param array $existing Array mapping existing language codes to titles
495 * @private
496 */
497 function getInterlangInsertions( $existing = array() ) {
498 $diffs = array_diff_assoc( $this->mInterlangs, $existing );
499 $arr = array();
500 foreach( $diffs as $lang => $title ) {
501 $arr[] = array(
502 'll_from' => $this->mId,
503 'll_lang' => $lang,
504 'll_title' => $title
505 );
506 }
507 return $arr;
508 }
509
510 /**
511 * Get an array of page property insertions
512 */
513 function getPropertyInsertions( $existing = array() ) {
514 $diffs = array_diff_assoc( $this->mProperties, $existing );
515 $arr = array();
516 foreach ( $diffs as $name => $value ) {
517 $arr[] = array(
518 'pp_page' => $this->mId,
519 'pp_propname' => $name,
520 'pp_value' => $value,
521 );
522 }
523 return $arr;
524 }
525
526
527 /**
528 * Given an array of existing links, returns those links which are not in $this
529 * and thus should be deleted.
530 * @private
531 */
532 function getLinkDeletions( $existing ) {
533 $del = array();
534 foreach ( $existing as $ns => $dbkeys ) {
535 if ( isset( $this->mLinks[$ns] ) ) {
536 $del[$ns] = array_diff_key( $existing[$ns], $this->mLinks[$ns] );
537 } else {
538 $del[$ns] = $existing[$ns];
539 }
540 }
541 return $del;
542 }
543
544 /**
545 * Given an array of existing templates, returns those templates which are not in $this
546 * and thus should be deleted.
547 * @private
548 */
549 function getTemplateDeletions( $existing ) {
550 $del = array();
551 foreach ( $existing as $ns => $dbkeys ) {
552 if ( isset( $this->mTemplates[$ns] ) ) {
553 $del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates[$ns] );
554 } else {
555 $del[$ns] = $existing[$ns];
556 }
557 }
558 return $del;
559 }
560
561 /**
562 * Given an array of existing images, returns those images which are not in $this
563 * and thus should be deleted.
564 * @private
565 */
566 function getImageDeletions( $existing ) {
567 return array_diff_key( $existing, $this->mImages );
568 }
569
570 /**
571 * Given an array of existing external links, returns those links which are not
572 * in $this and thus should be deleted.
573 * @private
574 */
575 function getExternalDeletions( $existing ) {
576 return array_diff_key( $existing, $this->mExternals );
577 }
578
579 /**
580 * Given an array of existing categories, returns those categories which are not in $this
581 * and thus should be deleted.
582 * @private
583 */
584 function getCategoryDeletions( $existing ) {
585 return array_diff_assoc( $existing, $this->mCategories );
586 }
587
588 /**
589 * Given an array of existing interlanguage links, returns those links which are not
590 * in $this and thus should be deleted.
591 * @private
592 */
593 function getInterlangDeletions( $existing ) {
594 return array_diff_assoc( $existing, $this->mInterlangs );
595 }
596
597 /**
598 * Get array of properties which should be deleted.
599 * @private
600 */
601 function getPropertyDeletions( $existing ) {
602 return array_diff_assoc( $existing, $this->mProperties );
603 }
604
605 /**
606 * Get an array of existing links, as a 2-D array
607 * @private
608 */
609 function getExistingLinks() {
610 $res = $this->mDb->select( 'pagelinks', array( 'pl_namespace', 'pl_title' ),
611 array( 'pl_from' => $this->mId ), __METHOD__, $this->mOptions );
612 $arr = array();
613 while ( $row = $this->mDb->fetchObject( $res ) ) {
614 if ( !isset( $arr[$row->pl_namespace] ) ) {
615 $arr[$row->pl_namespace] = array();
616 }
617 $arr[$row->pl_namespace][$row->pl_title] = 1;
618 }
619 $this->mDb->freeResult( $res );
620 return $arr;
621 }
622
623 /**
624 * Get an array of existing templates, as a 2-D array
625 * @private
626 */
627 function getExistingTemplates() {
628 $res = $this->mDb->select( 'templatelinks', array( 'tl_namespace', 'tl_title' ),
629 array( 'tl_from' => $this->mId ), __METHOD__, $this->mOptions );
630 $arr = array();
631 while ( $row = $this->mDb->fetchObject( $res ) ) {
632 if ( !isset( $arr[$row->tl_namespace] ) ) {
633 $arr[$row->tl_namespace] = array();
634 }
635 $arr[$row->tl_namespace][$row->tl_title] = 1;
636 }
637 $this->mDb->freeResult( $res );
638 return $arr;
639 }
640
641 /**
642 * Get an array of existing images, image names in the keys
643 * @private
644 */
645 function getExistingImages() {
646 $res = $this->mDb->select( 'imagelinks', array( 'il_to' ),
647 array( 'il_from' => $this->mId ), __METHOD__, $this->mOptions );
648 $arr = array();
649 while ( $row = $this->mDb->fetchObject( $res ) ) {
650 $arr[$row->il_to] = 1;
651 }
652 $this->mDb->freeResult( $res );
653 return $arr;
654 }
655
656 /**
657 * Get an array of existing external links, URLs in the keys
658 * @private
659 */
660 function getExistingExternals() {
661 $res = $this->mDb->select( 'externallinks', array( 'el_to' ),
662 array( 'el_from' => $this->mId ), __METHOD__, $this->mOptions );
663 $arr = array();
664 while ( $row = $this->mDb->fetchObject( $res ) ) {
665 $arr[$row->el_to] = 1;
666 }
667 $this->mDb->freeResult( $res );
668 return $arr;
669 }
670
671 /**
672 * Get an array of existing categories, with the name in the key and sort key in the value.
673 * @private
674 */
675 function getExistingCategories() {
676 $res = $this->mDb->select( 'categorylinks', array( 'cl_to', 'cl_sortkey' ),
677 array( 'cl_from' => $this->mId ), __METHOD__, $this->mOptions );
678 $arr = array();
679 while ( $row = $this->mDb->fetchObject( $res ) ) {
680 $arr[$row->cl_to] = $row->cl_sortkey;
681 }
682 $this->mDb->freeResult( $res );
683 return $arr;
684 }
685
686 /**
687 * Get an array of existing interlanguage links, with the language code in the key and the
688 * title in the value.
689 * @private
690 */
691 function getExistingInterlangs() {
692 $res = $this->mDb->select( 'langlinks', array( 'll_lang', 'll_title' ),
693 array( 'll_from' => $this->mId ), __METHOD__, $this->mOptions );
694 $arr = array();
695 while ( $row = $this->mDb->fetchObject( $res ) ) {
696 $arr[$row->ll_lang] = $row->ll_title;
697 }
698 return $arr;
699 }
700
701 /**
702 * Get an array of existing categories, with the name in the key and sort key in the value.
703 * @private
704 */
705 function getExistingProperties() {
706 $res = $this->mDb->select( 'page_props', array( 'pp_propname', 'pp_value' ),
707 array( 'pp_page' => $this->mId ), __METHOD__, $this->mOptions );
708 $arr = array();
709 while ( $row = $this->mDb->fetchObject( $res ) ) {
710 $arr[$row->pp_propname] = $row->pp_value;
711 }
712 $this->mDb->freeResult( $res );
713 return $arr;
714 }
715
716
717 /**
718 * Return the title object of the page being updated
719 */
720 function getTitle() {
721 return $this->mTitle;
722 }
723
724 /**
725 * Invalidate any necessary link lists related to page property changes
726 */
727 function invalidateProperties( $changed ) {
728 global $wgPagePropLinkInvalidations;
729
730 foreach ( $changed as $name => $value ) {
731 if ( isset( $wgPagePropLinkInvalidations[$name] ) ) {
732 $inv = $wgPagePropLinkInvalidations[$name];
733 if ( !is_array( $inv ) ) {
734 $inv = array( $inv );
735 }
736 foreach ( $inv as $table ) {
737 $update = new HTMLCacheUpdate( $this->mTitle, $table );
738 $update->doUpdate();
739 }
740 }
741 }
742 }
743 }