Index: trunk/phase3/includes/Title.php |
— | — | @@ -43,27 +43,11 @@ |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Used to be GAID_FOR_UPDATE define. Used with getArticleID() and friends |
47 | | - * to SELECT FOR UPDATE |
| 47 | + * to use the master DB |
48 | 48 | */ |
49 | 49 | const GAID_FOR_UPDATE = 1; |
50 | 50 | |
51 | 51 | /** |
52 | | - * Used with getArticleID() and friends to load the object from the master |
53 | | - * database |
54 | | - */ |
55 | | - const GAID_USE_MASTER = 2; |
56 | | - |
57 | | - /** |
58 | | - * For use in load(). Field is available in LinkCache. |
59 | | - */ |
60 | | - const FIELD_IN_LINKCACHE = 1; |
61 | | - |
62 | | - /** |
63 | | - * For use in load(). Field is not available in LinkCache. |
64 | | - */ |
65 | | - const FIELD_NOT_IN_LINKCACHE = 2; |
66 | | - |
67 | | - /** |
68 | 52 | * @name Private member variables |
69 | 53 | * Please use the accessor functions instead. |
70 | 54 | * @private |
— | — | @@ -77,16 +61,12 @@ |
78 | 62 | var $mNamespace = NS_MAIN; // /< Namespace index, i.e. one of the NS_xxxx constants |
79 | 63 | var $mInterwiki = ''; // /< Interwiki prefix (or null string) |
80 | 64 | var $mFragment; // /< Title fragment (i.e. the bit after the #) |
81 | | - private $mLoadedLevel = 0; // /< |
82 | | - private $mLoadedFromMaster = false; |
83 | 65 | var $mArticleID = -1; // /< Article ID, fetched from the link cache on demand |
84 | 66 | var $mLatestID = false; // /< ID of most recent revision |
85 | | - private $mCounter = false; // /< Number of times this page has been viewed (-1 means "not loaded") |
86 | | - private $mTouched; // /< Timestamp of the last time this page was touched |
87 | | - private $mIsNew; // /< Whether this is a "new page" (i.e. it has only one revision) |
| 67 | + var $mCounter = -1; // /< Number of times this page has been viewed (-1 means "not loaded") |
88 | 68 | private $mEstimateRevisions; // /< Estimated number of revisions; null of not loaded |
89 | 69 | var $mRestrictions = array(); // /< Array of groups allowed to edit this article |
90 | | - var $mOldRestrictions; |
| 70 | + var $mOldRestrictions = false; |
91 | 71 | var $mCascadeRestriction; ///< Cascade restrictions on this page to included templates and images? |
92 | 72 | var $mCascadingRestrictions; // Caching the results of getCascadeProtectionSources |
93 | 73 | var $mRestrictionsExpiry = array(); ///< When do the restrictions on this page expire? |
— | — | @@ -222,11 +202,11 @@ |
223 | 203 | * Create a new Title from an article ID |
224 | 204 | * |
225 | 205 | * @param $id Int the page_id corresponding to the Title to create |
226 | | - * @param $flags Int use Title::GAID_USE_MASTER to use master |
| 206 | + * @param $flags Int use Title::GAID_FOR_UPDATE to use master |
227 | 207 | * @return Title the new object, or NULL on an error |
228 | 208 | */ |
229 | 209 | public static function newFromID( $id, $flags = 0 ) { |
230 | | - $db = $flags ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
| 210 | + $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
231 | 211 | $row = $db->selectRow( 'page', '*', array( 'page_id' => $id ), __METHOD__ ); |
232 | 212 | if ( $row !== false ) { |
233 | 213 | $title = Title::newFromRow( $row ); |
— | — | @@ -248,8 +228,15 @@ |
249 | 229 | } |
250 | 230 | $dbr = wfGetDB( DB_SLAVE ); |
251 | 231 | |
252 | | - $res = $dbr->select( 'page', self::selectFields(), |
253 | | - array( 'page_id' => $ids ), __METHOD__ ); |
| 232 | + $res = $dbr->select( |
| 233 | + 'page', |
| 234 | + array( |
| 235 | + 'page_namespace', 'page_title', 'page_id', |
| 236 | + 'page_len', 'page_is_redirect', 'page_latest', |
| 237 | + ), |
| 238 | + array( 'page_id' => $ids ), |
| 239 | + __METHOD__ |
| 240 | + ); |
254 | 241 | |
255 | 242 | $titles = array(); |
256 | 243 | foreach ( $res as $row ) { |
— | — | @@ -275,80 +262,27 @@ |
276 | 263 | * If false is given, the title will be treated as non-existing. |
277 | 264 | * |
278 | 265 | * @param $row Object|false database row |
279 | | - * @param $wasFromMaster bool: whether the row was loaded from the master |
280 | | - * database |
281 | 266 | * @return void |
282 | 267 | */ |
283 | | - public function loadFromRow( $row, $wasFromMaster = false ) { |
| 268 | + public function loadFromRow( $row ) { |
284 | 269 | if ( $row ) { // page found |
285 | | - $cacheLevel = self::FIELD_NOT_IN_LINKCACHE; |
286 | | - |
287 | | - # Items that cannot be stored in LinkCache |
288 | | - # If one (or more) of these field is missing, the row can still |
289 | | - # be stored in LinkCache |
290 | | - if ( isset( $row->page_counter ) ) { |
291 | | - $this->mCounter = (int)$row->page_counter; |
292 | | - } else { |
293 | | - $cacheLevel = self::FIELD_IN_LINKCACHE; |
294 | | - } |
295 | | - if ( isset( $row->page_touched ) ) { |
296 | | - $this->mTouched = $row->page_touched; |
297 | | - } else { |
298 | | - $cacheLevel = self::FIELD_IN_LINKCACHE; |
299 | | - } |
300 | | - if ( isset( $row->page_is_new ) ) { |
301 | | - $this->mIsNew = (bool)$row->page_is_new; |
302 | | - } else { |
303 | | - $cacheLevel = self::FIELD_IN_LINKCACHE; |
304 | | - } |
305 | | - if ( isset( $row->page_restrictions ) ) { |
306 | | - $this->mOldRestrictions = $row->page_restrictions; |
307 | | - } else { |
308 | | - $cacheLevel = self::FIELD_IN_LINKCACHE; |
309 | | - } |
310 | | - |
311 | | - # Items that can be stored in LinkCache |
312 | | - # If one (or more) of these field is missing, the row cannot |
313 | | - # be stored in LinkCache |
314 | | - if ( isset( $row->page_id ) ) { |
| 270 | + if ( isset( $row->page_id ) ) |
315 | 271 | $this->mArticleID = (int)$row->page_id; |
316 | | - } else { |
317 | | - $cacheLevel = 0; |
318 | | - } |
319 | | - if ( isset( $row->page_len ) ) { |
| 272 | + if ( isset( $row->page_len ) ) |
320 | 273 | $this->mLength = (int)$row->page_len; |
321 | | - } else { |
322 | | - $cacheLevel = 0; |
323 | | - } |
324 | | - if ( isset( $row->page_is_redirect ) ) { |
| 274 | + if ( isset( $row->page_is_redirect ) ) |
325 | 275 | $this->mRedirect = (bool)$row->page_is_redirect; |
326 | | - } else { |
327 | | - $cacheLevel = 0; |
328 | | - } |
329 | | - if ( isset( $row->page_latest ) ) { |
| 276 | + if ( isset( $row->page_latest ) ) |
330 | 277 | $this->mLatestID = (int)$row->page_latest; |
331 | | - } else { |
332 | | - $cacheLevel = 0; |
333 | | - } |
334 | | - |
335 | | - $this->mLoadedLevel = $cacheLevel; |
336 | | - if ( $cacheLevel > 0 ) { |
337 | | - # We have all fields required by LinkCache |
338 | | - LinkCache::singleton()->addGoodLinkObjFromRow( $this, $row ); |
339 | | - } |
| 278 | + if ( isset( $row->page_counter ) ) |
| 279 | + $this->mCounter = (int)$row->page_counter; |
340 | 280 | } else { // page not found |
341 | 281 | $this->mArticleID = 0; |
342 | 282 | $this->mLength = 0; |
343 | 283 | $this->mRedirect = false; |
344 | 284 | $this->mLatestID = 0; |
345 | 285 | $this->mCounter = 0; |
346 | | - $this->mTouched = false; |
347 | | - $this->mIsNew = false; |
348 | | - $this->mOldRestrictions = false; |
349 | | - $this->mLoadedLevel = 2; |
350 | | - LinkCache::singleton()->addBadLinkObj( $this ); |
351 | 286 | } |
352 | | - $this->mLoadedFromMaster = $wasFromMaster; |
353 | 287 | } |
354 | 288 | |
355 | 289 | /** |
— | — | @@ -537,27 +471,6 @@ |
538 | 472 | } |
539 | 473 | |
540 | 474 | /** |
541 | | - * Get the fields of the `page` table that have to be select if you want |
542 | | - * to give a complete row to loadFromRow() |
543 | | - * |
544 | | - * @return array |
545 | | - */ |
546 | | - public static function selectFields() { |
547 | | - return array( |
548 | | - 'page_namespace', |
549 | | - 'page_title', |
550 | | - 'page_id', |
551 | | - 'page_len', |
552 | | - 'page_is_redirect', |
553 | | - 'page_latest', |
554 | | - 'page_counter', |
555 | | - 'page_touched', |
556 | | - 'page_is_new', |
557 | | - 'page_restrictions', |
558 | | - ); |
559 | | - } |
560 | | - |
561 | | - /** |
562 | 475 | * Get a regex character class describing the legal characters in a link |
563 | 476 | * |
564 | 477 | * @return String the list of characters, not delimited |
— | — | @@ -1578,82 +1491,6 @@ |
1579 | 1492 | } |
1580 | 1493 | |
1581 | 1494 | /** |
1582 | | - * Load field from database into this object |
1583 | | - * |
1584 | | - * @param $level int, may be on of the following values: |
1585 | | - * - self::FIELD_IN_LINKCACHE: the field can be retrived from the LinkCache |
1586 | | - * - self::FIELD_NOT_IN_LINKCACHE: the field is not stored in LinkCache and |
1587 | | - * must be loaded from the database |
1588 | | - * @param $flags int, may be on of the following values: |
1589 | | - * - 0: to use a slave connection |
1590 | | - * - self::GAID_USE_MASTER to use a master connection |
1591 | | - * - self::GAID_FOR_UPDATE to SELECT FROM UPDATE from a master connection |
1592 | | - */ |
1593 | | - private function load( $level, $flags = 0 ) { |
1594 | | - global $wgAntiLockFlags; |
1595 | | - |
1596 | | - if ( !$this->canExist() ) { |
1597 | | - return; |
1598 | | - } |
1599 | | - |
1600 | | - // Check whether the wanted item is already loaded |
1601 | | - // and from where it is requested. |
1602 | | - // If $flags is self::GAID_FOR_UPDATE, it will always be reloaded. |
1603 | | - if ( $level <= $this->mLoadedLevel && ( $flags === 0 || |
1604 | | - ( $flags === self::GAID_USE_MASTER && $this->mLoadedFromMaster ) ) ) |
1605 | | - { |
1606 | | - return; |
1607 | | - } |
1608 | | - |
1609 | | - $linkCache = LinkCache::singleton(); |
1610 | | - |
1611 | | - # Only use the LinkCache if we can load from a slave database |
1612 | | - if ( $flags === 0 ) { |
1613 | | - |
1614 | | - # If the LinkCache says the page doesn't exist; we can load all fields |
1615 | | - if ( $linkCache->isBadLink( $this->getPrefixedDBkey() ) ) { |
1616 | | - $this->loadFromRow( false ); |
1617 | | - return; |
1618 | | - } |
1619 | | - |
1620 | | - # For existing pages we can only load some fields |
1621 | | - if ( $level === self::FIELD_IN_LINKCACHE ) { |
1622 | | - $id = $linkCache->getGoodLinkID( $this->getPrefixedDBkey() ); |
1623 | | - if ( $id ) { |
1624 | | - $this->mArticleID = $id; |
1625 | | - $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' ); |
1626 | | - $this->mLength = (int)$linkCache->getGoodLinkFieldObj( $this, 'length' ); |
1627 | | - $this->mLatestID = (int)$linkCache->getGoodLinkFieldObj( $this, 'revision' ); |
1628 | | - $this->mLoadedLevel = 1; |
1629 | | - $this->mLoadedFromMaster = false; |
1630 | | - return; |
1631 | | - } |
1632 | | - } |
1633 | | - } |
1634 | | - |
1635 | | - # Just in case it's already loaded from a slave database |
1636 | | - $linkCache->clearLink( $this ); |
1637 | | - |
1638 | | - # No success using LinkCache, we need to use the database |
1639 | | - # In this case we load the complete row regardless of $level |
1640 | | - $options = array(); |
1641 | | - if ( $flags === 0 ) { |
1642 | | - $db = wfGetDB( DB_SLAVE ); |
1643 | | - $this->mLoadedFromMaster = false; |
1644 | | - } else { |
1645 | | - $db = wfGetDB( DB_MASTER ); |
1646 | | - if ( $flags == self::GAID_FOR_UPDATE && !( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) ) { |
1647 | | - $options[] = 'FOR UPDATE'; |
1648 | | - } |
1649 | | - $this->mLoadedFromMaster = true; |
1650 | | - } |
1651 | | - |
1652 | | - $row = $db->selectRow( 'page', self::selectFields(), |
1653 | | - $this->pageCond(), __METHOD__, $options ); |
1654 | | - $this->loadFromRow( $row ); |
1655 | | - } |
1656 | | - |
1657 | | - /** |
1658 | 1495 | * Is $wgUser watching this page? |
1659 | 1496 | * |
1660 | 1497 | * @return Bool |
— | — | @@ -2656,15 +2493,17 @@ |
2657 | 2494 | * Loads a string into mRestrictions array |
2658 | 2495 | * |
2659 | 2496 | * @param $res Resource restrictions as an SQL result. |
| 2497 | + * @param $oldFashionedRestrictions String comma-separated list of page |
| 2498 | + * restrictions from page table (pre 1.10) |
2660 | 2499 | */ |
2661 | | - private function loadRestrictionsFromResultWrapper( $res ) { |
| 2500 | + private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = null ) { |
2662 | 2501 | $rows = array(); |
2663 | 2502 | |
2664 | 2503 | foreach ( $res as $row ) { |
2665 | 2504 | $rows[] = $row; |
2666 | 2505 | } |
2667 | 2506 | |
2668 | | - $this->loadRestrictionsFromRows( $rows ); |
| 2507 | + $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions ); |
2669 | 2508 | } |
2670 | 2509 | |
2671 | 2510 | /** |
— | — | @@ -2673,8 +2512,10 @@ |
2674 | 2513 | * Public for usage by LiquidThreads. |
2675 | 2514 | * |
2676 | 2515 | * @param $rows array of db result objects |
| 2516 | + * @param $oldFashionedRestrictions string comma-separated list of page |
| 2517 | + * restrictions from page table (pre 1.10) |
2677 | 2518 | */ |
2678 | | - public function loadRestrictionsFromRows( $rows ) { |
| 2519 | + public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) { |
2679 | 2520 | global $wgContLang; |
2680 | 2521 | $dbr = wfGetDB( DB_SLAVE ); |
2681 | 2522 | |
— | — | @@ -2689,13 +2530,14 @@ |
2690 | 2531 | |
2691 | 2532 | # Backwards-compatibility: also load the restrictions from the page record (old format). |
2692 | 2533 | |
2693 | | - if ( $this->mOldRestrictions === null ) { |
2694 | | - $this->mOldRestrictions = $dbr->selectField( 'page', 'page_restrictions', |
| 2534 | + if ( $oldFashionedRestrictions === null ) { |
| 2535 | + $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', |
2695 | 2536 | array( 'page_id' => $this->getArticleId() ), __METHOD__ ); |
2696 | 2537 | } |
2697 | 2538 | |
2698 | | - if ( $this->mOldRestrictions !== false && $this->mOldRestrictions !== '' ) { |
2699 | | - foreach ( explode( ':', trim( $this->mOldRestrictions ) ) as $restrict ) { |
| 2539 | + if ( $oldFashionedRestrictions != '' ) { |
| 2540 | + |
| 2541 | + foreach ( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) { |
2700 | 2542 | $temp = explode( '=', trim( $restrict ) ); |
2701 | 2543 | if ( count( $temp ) == 1 ) { |
2702 | 2544 | // old old format should be treated as edit/move restriction |
— | — | @@ -2705,6 +2547,9 @@ |
2706 | 2548 | $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) ); |
2707 | 2549 | } |
2708 | 2550 | } |
| 2551 | + |
| 2552 | + $this->mOldRestrictions = true; |
| 2553 | + |
2709 | 2554 | } |
2710 | 2555 | |
2711 | 2556 | if ( count( $rows ) ) { |
— | — | @@ -2745,8 +2590,11 @@ |
2746 | 2591 | |
2747 | 2592 | /** |
2748 | 2593 | * Load restrictions from the page_restrictions table |
| 2594 | + * |
| 2595 | + * @param $oldFashionedRestrictions String comma-separated list of page |
| 2596 | + * restrictions from page table (pre 1.10) |
2749 | 2597 | */ |
2750 | | - public function loadRestrictions() { |
| 2598 | + public function loadRestrictions( $oldFashionedRestrictions = null ) { |
2751 | 2599 | global $wgContLang; |
2752 | 2600 | if ( !$this->mRestrictionsLoaded ) { |
2753 | 2601 | if ( $this->exists() ) { |
— | — | @@ -2759,7 +2607,7 @@ |
2760 | 2608 | __METHOD__ |
2761 | 2609 | ); |
2762 | 2610 | |
2763 | | - $this->loadRestrictionsFromResultWrapper( $res ); |
| 2611 | + $this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions ); |
2764 | 2612 | } else { |
2765 | 2613 | $title_protection = $this->getTitleProtection(); |
2766 | 2614 | |
— | — | @@ -2919,83 +2767,86 @@ |
2920 | 2768 | * @return int The view count for the page |
2921 | 2769 | */ |
2922 | 2770 | public function getCount() { |
2923 | | - if ( $this->mCounter == false ) { |
2924 | | - $this->load( self::FIELD_NOT_IN_LINKCACHE ); |
| 2771 | + if ( $this->mCounter == -1 ) { |
| 2772 | + if ( $this->exists() ) { |
| 2773 | + $dbr = wfGetDB( DB_SLAVE ); |
| 2774 | + $this->mCounter = $dbr->selectField( 'page', |
| 2775 | + 'page_counter', |
| 2776 | + array( 'page_id' => $this->getArticleID() ), |
| 2777 | + __METHOD__ |
| 2778 | + ); |
| 2779 | + } else { |
| 2780 | + $this->mCounter = 0; |
| 2781 | + } |
2925 | 2782 | } |
2926 | 2783 | |
2927 | 2784 | return $this->mCounter; |
2928 | 2785 | } |
2929 | 2786 | |
2930 | 2787 | /** |
2931 | | - * Get the last touched timestamp |
| 2788 | + * Get the article ID for this Title from the link cache, |
| 2789 | + * adding it if necessary |
2932 | 2790 | * |
2933 | | - * @return String last-touched timestamp |
2934 | | - */ |
2935 | | - public function getTouched() { |
2936 | | - if ( $this->mTouched == null ) { |
2937 | | - $this->load( self::FIELD_NOT_IN_LINKCACHE ); |
2938 | | - } |
2939 | | - |
2940 | | - return $this->mTouched; |
2941 | | - } |
2942 | | - |
2943 | | - /** |
2944 | | - * Check if this is a new page (i.e. it has only one revision) |
2945 | | - * |
2946 | | - * @return bool |
2947 | | - */ |
2948 | | - public function isNewPage() { |
2949 | | - if ( $this->mIsNew === null ) { |
2950 | | - $this->load( self::FIELD_NOT_IN_LINKCACHE ); |
2951 | | - } |
2952 | | - |
2953 | | - return $this->mIsNew; |
2954 | | - } |
2955 | | - |
2956 | | - /** |
2957 | | - * Get the article ID for this page. |
2958 | | - * Uses link cache, adding it if necessary. |
2959 | | - * |
2960 | | - * @param $flags Int a bit field; may be Title::GAID_USE_MASTER to select |
2961 | | - * from the master database or Title::GAID_FOR_UPDATE to select for update. |
| 2791 | + * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select |
| 2792 | + * for update |
2962 | 2793 | * @return Int the ID |
2963 | 2794 | */ |
2964 | 2795 | public function getArticleID( $flags = 0 ) { |
2965 | | - if ( $this->mArticleID === -1 || $flags ) { |
2966 | | - $this->load( self::FIELD_IN_LINKCACHE, $flags ); |
| 2796 | + if ( $this->getNamespace() < 0 ) { |
| 2797 | + return $this->mArticleID = 0; |
2967 | 2798 | } |
2968 | | - |
| 2799 | + $linkCache = LinkCache::singleton(); |
| 2800 | + if ( $flags & self::GAID_FOR_UPDATE ) { |
| 2801 | + $oldUpdate = $linkCache->forUpdate( true ); |
| 2802 | + $linkCache->clearLink( $this ); |
| 2803 | + $this->mArticleID = $linkCache->addLinkObj( $this ); |
| 2804 | + $linkCache->forUpdate( $oldUpdate ); |
| 2805 | + } else { |
| 2806 | + if ( -1 == $this->mArticleID ) { |
| 2807 | + $this->mArticleID = $linkCache->addLinkObj( $this ); |
| 2808 | + } |
| 2809 | + } |
2969 | 2810 | return $this->mArticleID; |
2970 | 2811 | } |
2971 | 2812 | |
2972 | 2813 | /** |
2973 | 2814 | * Is this an article that is a redirect page? |
2974 | | - * Uses link cache, adding it if necessary. |
| 2815 | + * Uses link cache, adding it if necessary |
2975 | 2816 | * |
2976 | | - * @param $flags Int a bit field; may be Title::GAID_USE_MASTER to select |
2977 | | - * from the master database or Title::GAID_FOR_UPDATE to select for update. |
| 2817 | + * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select for update |
2978 | 2818 | * @return Bool |
2979 | 2819 | */ |
2980 | 2820 | public function isRedirect( $flags = 0 ) { |
2981 | | - if ( $this->mRedirect === null || $flags ) { |
2982 | | - $this->load( self::FIELD_IN_LINKCACHE, $flags ); |
| 2821 | + if ( !is_null( $this->mRedirect ) ) { |
| 2822 | + return $this->mRedirect; |
2983 | 2823 | } |
| 2824 | + # Calling getArticleID() loads the field from cache as needed |
| 2825 | + if ( !$this->getArticleID( $flags ) ) { |
| 2826 | + return $this->mRedirect = false; |
| 2827 | + } |
| 2828 | + $linkCache = LinkCache::singleton(); |
| 2829 | + $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' ); |
2984 | 2830 | |
2985 | 2831 | return $this->mRedirect; |
2986 | 2832 | } |
2987 | 2833 | |
2988 | 2834 | /** |
2989 | 2835 | * What is the length of this page? |
2990 | | - * Uses link cache, adding it if necessary. |
| 2836 | + * Uses link cache, adding it if necessary |
2991 | 2837 | * |
2992 | | - * @param $flags Int a bit field; may be Title::GAID_USE_MASTER to select |
2993 | | - * from the master database or Title::GAID_FOR_UPDATE to select for update. |
| 2838 | + * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select for update |
2994 | 2839 | * @return Int |
2995 | 2840 | */ |
2996 | 2841 | public function getLength( $flags = 0 ) { |
2997 | | - if ( $this->mLength === -1 || $flags ) { |
2998 | | - $this->load( self::FIELD_IN_LINKCACHE, $flags ); |
| 2842 | + if ( $this->mLength != -1 ) { |
| 2843 | + return $this->mLength; |
2999 | 2844 | } |
| 2845 | + # Calling getArticleID() loads the field from cache as needed |
| 2846 | + if ( !$this->getArticleID( $flags ) ) { |
| 2847 | + return $this->mLength = 0; |
| 2848 | + } |
| 2849 | + $linkCache = LinkCache::singleton(); |
| 2850 | + $this->mLength = intval( $linkCache->getGoodLinkFieldObj( $this, 'length' ) ); |
3000 | 2851 | |
3001 | 2852 | return $this->mLength; |
3002 | 2853 | } |
— | — | @@ -3003,14 +2854,19 @@ |
3004 | 2855 | /** |
3005 | 2856 | * What is the page_latest field for this page? |
3006 | 2857 | * |
3007 | | - * @param $flags Int a bit field; may be Title::GAID_USE_MASTER to select |
3008 | | - * from the master database or Title::GAID_FOR_UPDATE to select for update. |
| 2858 | + * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select for update |
3009 | 2859 | * @return Int or 0 if the page doesn't exist |
3010 | 2860 | */ |
3011 | 2861 | public function getLatestRevID( $flags = 0 ) { |
3012 | | - if ( $this->mLatestID === false || $flags ) { |
3013 | | - $this->load( self::FIELD_IN_LINKCACHE, $flags ); |
| 2862 | + if ( $this->mLatestID !== false ) { |
| 2863 | + return intval( $this->mLatestID ); |
3014 | 2864 | } |
| 2865 | + # Calling getArticleID() loads the field from cache as needed |
| 2866 | + if ( !$this->getArticleID( $flags ) ) { |
| 2867 | + return $this->mLatestID = 0; |
| 2868 | + } |
| 2869 | + $linkCache = LinkCache::singleton(); |
| 2870 | + $this->mLatestID = intval( $linkCache->getGoodLinkFieldObj( $this, 'revision' ) ); |
3015 | 2871 | |
3016 | 2872 | return $this->mLatestID; |
3017 | 2873 | } |
— | — | @@ -3026,29 +2882,21 @@ |
3027 | 2883 | * @param $newid Int the new Article ID |
3028 | 2884 | */ |
3029 | 2885 | public function resetArticleID( $newid ) { |
3030 | | - LinkCache::singleton()->clearLink( $this ); |
| 2886 | + $linkCache = LinkCache::singleton(); |
| 2887 | + $linkCache->clearLink( $this ); |
3031 | 2888 | |
3032 | | - if ( $newid === 0 ) { |
3033 | | - $this->loadFromRow( false ); |
| 2889 | + if ( $newid === false ) { |
| 2890 | + $this->mArticleID = -1; |
3034 | 2891 | } else { |
3035 | | - if ( $newid === false ) { |
3036 | | - $this->mArticleID = -1; |
3037 | | - } else { |
3038 | | - $this->mArticleID = intval( $newid ); |
3039 | | - } |
3040 | | - $this->mRestrictionsLoaded = false; |
3041 | | - $this->mRestrictions = array(); |
3042 | | - $this->mOldRestrictions = null; |
3043 | | - $this->mRedirect = null; |
3044 | | - $this->mLength = -1; |
3045 | | - $this->mLatestID = false; |
3046 | | - $this->mCounter = false; |
3047 | | - $this->mTouched = null; |
3048 | | - $this->mIsNew = null; |
3049 | | - $this->mEstimateRevisions = null; |
3050 | | - $this->mLoadedLevel = 0; |
3051 | | - $this->mLoadedFromMaster = false; |
| 2892 | + $this->mArticleID = intval( $newid ); |
3052 | 2893 | } |
| 2894 | + $this->mRestrictionsLoaded = false; |
| 2895 | + $this->mRestrictions = array(); |
| 2896 | + $this->mRedirect = null; |
| 2897 | + $this->mLength = -1; |
| 2898 | + $this->mLatestID = false; |
| 2899 | + $this->mCounter = -1; |
| 2900 | + $this->mEstimateRevisions = null; |
3053 | 2901 | } |
3054 | 2902 | |
3055 | 2903 | /** |
— | — | @@ -4144,6 +3992,16 @@ |
4145 | 3993 | } |
4146 | 3994 | |
4147 | 3995 | /** |
| 3996 | + * Check if this is a new page |
| 3997 | + * |
| 3998 | + * @return bool |
| 3999 | + */ |
| 4000 | + public function isNewPage() { |
| 4001 | + $dbr = wfGetDB( DB_SLAVE ); |
| 4002 | + return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ ); |
| 4003 | + } |
| 4004 | + |
| 4005 | + /** |
4148 | 4006 | * Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit |
4149 | 4007 | * |
4150 | 4008 | * @return bool |
— | — | @@ -4409,6 +4267,18 @@ |
4410 | 4268 | } |
4411 | 4269 | |
4412 | 4270 | /** |
| 4271 | + * Get the last touched timestamp |
| 4272 | + * |
| 4273 | + * @param $db DatabaseBase: optional db |
| 4274 | + * @return String last-touched timestamp |
| 4275 | + */ |
| 4276 | + public function getTouched( $db = null ) { |
| 4277 | + $db = isset( $db ) ? $db : wfGetDB( DB_SLAVE ); |
| 4278 | + $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ ); |
| 4279 | + return $touched; |
| 4280 | + } |
| 4281 | + |
| 4282 | + /** |
4413 | 4283 | * Get the timestamp when this page was updated since the user last saw it. |
4414 | 4284 | * |
4415 | 4285 | * @param $user User |
Index: trunk/phase3/includes/WikiPage.php |
— | — | @@ -355,12 +355,8 @@ |
356 | 356 | * @return void |
357 | 357 | */ |
358 | 358 | public function loadPageData( $data = 'fromdb' ) { |
359 | | - # If we get a DB row, God knows from where it comes |
360 | | - $fromMaster = false; |
361 | | - |
362 | 359 | if ( $data === 'fromdbmaster' ) { |
363 | 360 | $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle ); |
364 | | - $fromMaster = true; |
365 | 361 | } elseif ( $data === 'fromdb' ) { // slave |
366 | 362 | $data = $this->pageDataFromTitle( wfGetDB( DB_SLAVE ), $this->mTitle ); |
367 | 363 | # Use a "last rev inserted" timestamp key to dimish the issue of slave lag. |
— | — | @@ -369,16 +365,26 @@ |
370 | 366 | if ( $touched ) { // key set |
371 | 367 | if ( !$data || $touched > wfTimestamp( TS_MW, $data->page_touched ) ) { |
372 | 368 | $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle ); |
373 | | - $fromMaster = true; |
374 | 369 | } |
375 | 370 | } |
376 | 371 | } |
377 | 372 | |
378 | | - $this->mTitle->loadFromRow( $data, $fromMaster ); |
| 373 | + $lc = LinkCache::singleton(); |
379 | 374 | |
380 | 375 | if ( $data ) { |
| 376 | + $lc->addGoodLinkObjFromRow( $this->mTitle, $data ); |
| 377 | + |
| 378 | + $this->mTitle->loadFromRow( $data ); |
| 379 | + |
| 380 | + # Old-fashioned restrictions |
| 381 | + $this->mTitle->loadRestrictions( $data->page_restrictions ); |
| 382 | + |
381 | 383 | $this->mIsRedirect = intval( $data->page_is_redirect ); |
382 | 384 | $this->mLatest = intval( $data->page_latest ); |
| 385 | + } else { |
| 386 | + $lc->addBadLinkObj( $this->mTitle ); |
| 387 | + |
| 388 | + $this->mTitle->loadFromRow( false ); |
383 | 389 | } |
384 | 390 | |
385 | 391 | $this->mDataLoaded = true; |
— | — | @@ -499,11 +505,7 @@ |
500 | 506 | if ( !$this->mDataLoaded ) { |
501 | 507 | $this->loadPageData(); |
502 | 508 | } |
503 | | - $timestamp = $this->mTitle->getTouched(); |
504 | | - if ( $timestamp === false ) { |
505 | | - $timestamp = '19700101000000'; |
506 | | - } |
507 | | - return $timestamp; |
| 509 | + return $this->mTitle->getTouched(); |
508 | 510 | } |
509 | 511 | |
510 | 512 | /** |
Index: trunk/phase3/includes/FakeTitle.php |
— | — | @@ -65,8 +65,8 @@ |
66 | 66 | function isCascadeProtected() { $this->error(); } |
67 | 67 | function getCascadeProtectionSources( $get_pages = true ) { $this->error(); } |
68 | 68 | function areRestrictionsCascading() { $this->error(); } |
69 | | - function loadRestrictionsFromRows( $rows ) { $this->error(); } |
70 | | - function loadRestrictions() { $this->error(); } |
| 69 | + function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) { $this->error(); } |
| 70 | + function loadRestrictions( $res = null ) { $this->error(); } |
71 | 71 | function getRestrictions( $action ) { $this->error(); } |
72 | 72 | function getRestrictionExpiry( $action ) { $this->error(); } |
73 | 73 | function isDeleted() { $this->error(); } |
— | — | @@ -109,7 +109,7 @@ |
110 | 110 | function isKnown() { $this->error(); } |
111 | 111 | function canExist() { $this->error(); } |
112 | 112 | function touchLinks() { $this->error(); } |
113 | | - function getTouched() { $this->error(); } |
| 113 | + function getTouched( $db = null ) { $this->error(); } |
114 | 114 | function getNotificationTimestamp( $user = null ) { $this->error(); } |
115 | 115 | function getNamespaceKey( $prepend = 'nstab-' ) { $this->error(); } |
116 | 116 | function isSpecialPage() { $this->error(); } |