r107945 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107944‎ | r107945 | r107946 >
Date:21:44, 3 January 2012
Author:brion
Status:ok (Comments)
Tags:
Comment:
Revert r107769, r107771, r107825, r107840, r107927, r107934

Title objects are meant to be dumb value objects; we shouldn't add to their internal state like this, but should be working to remove the bits already in there like the article ID.
Preloading information like this can make sense, but probably belongs in WikiPage, not Title.
Modified paths:
  • /trunk/phase3/includes/FakeTitle.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -43,27 +43,11 @@
4444
4545 /**
4646 * Used to be GAID_FOR_UPDATE define. Used with getArticleID() and friends
47 - * to SELECT FOR UPDATE
 47+ * to use the master DB
4848 */
4949 const GAID_FOR_UPDATE = 1;
5050
5151 /**
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 - /**
6852 * @name Private member variables
6953 * Please use the accessor functions instead.
7054 * @private
@@ -77,16 +61,12 @@
7862 var $mNamespace = NS_MAIN; // /< Namespace index, i.e. one of the NS_xxxx constants
7963 var $mInterwiki = ''; // /< Interwiki prefix (or null string)
8064 var $mFragment; // /< Title fragment (i.e. the bit after the #)
81 - private $mLoadedLevel = 0; // /<
82 - private $mLoadedFromMaster = false;
8365 var $mArticleID = -1; // /< Article ID, fetched from the link cache on demand
8466 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")
8868 private $mEstimateRevisions; // /< Estimated number of revisions; null of not loaded
8969 var $mRestrictions = array(); // /< Array of groups allowed to edit this article
90 - var $mOldRestrictions;
 70+ var $mOldRestrictions = false;
9171 var $mCascadeRestriction; ///< Cascade restrictions on this page to included templates and images?
9272 var $mCascadingRestrictions; // Caching the results of getCascadeProtectionSources
9373 var $mRestrictionsExpiry = array(); ///< When do the restrictions on this page expire?
@@ -222,11 +202,11 @@
223203 * Create a new Title from an article ID
224204 *
225205 * @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
227207 * @return Title the new object, or NULL on an error
228208 */
229209 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 );
231211 $row = $db->selectRow( 'page', '*', array( 'page_id' => $id ), __METHOD__ );
232212 if ( $row !== false ) {
233213 $title = Title::newFromRow( $row );
@@ -248,8 +228,15 @@
249229 }
250230 $dbr = wfGetDB( DB_SLAVE );
251231
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+ );
254241
255242 $titles = array();
256243 foreach ( $res as $row ) {
@@ -275,80 +262,27 @@
276263 * If false is given, the title will be treated as non-existing.
277264 *
278265 * @param $row Object|false database row
279 - * @param $wasFromMaster bool: whether the row was loaded from the master
280 - * database
281266 * @return void
282267 */
283 - public function loadFromRow( $row, $wasFromMaster = false ) {
 268+ public function loadFromRow( $row ) {
284269 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 ) )
315271 $this->mArticleID = (int)$row->page_id;
316 - } else {
317 - $cacheLevel = 0;
318 - }
319 - if ( isset( $row->page_len ) ) {
 272+ if ( isset( $row->page_len ) )
320273 $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 ) )
325275 $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 ) )
330277 $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;
340280 } else { // page not found
341281 $this->mArticleID = 0;
342282 $this->mLength = 0;
343283 $this->mRedirect = false;
344284 $this->mLatestID = 0;
345285 $this->mCounter = 0;
346 - $this->mTouched = false;
347 - $this->mIsNew = false;
348 - $this->mOldRestrictions = false;
349 - $this->mLoadedLevel = 2;
350 - LinkCache::singleton()->addBadLinkObj( $this );
351286 }
352 - $this->mLoadedFromMaster = $wasFromMaster;
353287 }
354288
355289 /**
@@ -537,27 +471,6 @@
538472 }
539473
540474 /**
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 - /**
562475 * Get a regex character class describing the legal characters in a link
563476 *
564477 * @return String the list of characters, not delimited
@@ -1578,82 +1491,6 @@
15791492 }
15801493
15811494 /**
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 - /**
16581495 * Is $wgUser watching this page?
16591496 *
16601497 * @return Bool
@@ -2656,15 +2493,17 @@
26572494 * Loads a string into mRestrictions array
26582495 *
26592496 * @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)
26602499 */
2661 - private function loadRestrictionsFromResultWrapper( $res ) {
 2500+ private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = null ) {
26622501 $rows = array();
26632502
26642503 foreach ( $res as $row ) {
26652504 $rows[] = $row;
26662505 }
26672506
2668 - $this->loadRestrictionsFromRows( $rows );
 2507+ $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
26692508 }
26702509
26712510 /**
@@ -2673,8 +2512,10 @@
26742513 * Public for usage by LiquidThreads.
26752514 *
26762515 * @param $rows array of db result objects
 2516+ * @param $oldFashionedRestrictions string comma-separated list of page
 2517+ * restrictions from page table (pre 1.10)
26772518 */
2678 - public function loadRestrictionsFromRows( $rows ) {
 2519+ public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
26792520 global $wgContLang;
26802521 $dbr = wfGetDB( DB_SLAVE );
26812522
@@ -2689,13 +2530,14 @@
26902531
26912532 # Backwards-compatibility: also load the restrictions from the page record (old format).
26922533
2693 - if ( $this->mOldRestrictions === null ) {
2694 - $this->mOldRestrictions = $dbr->selectField( 'page', 'page_restrictions',
 2534+ if ( $oldFashionedRestrictions === null ) {
 2535+ $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions',
26952536 array( 'page_id' => $this->getArticleId() ), __METHOD__ );
26962537 }
26972538
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 ) {
27002542 $temp = explode( '=', trim( $restrict ) );
27012543 if ( count( $temp ) == 1 ) {
27022544 // old old format should be treated as edit/move restriction
@@ -2705,6 +2547,9 @@
27062548 $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
27072549 }
27082550 }
 2551+
 2552+ $this->mOldRestrictions = true;
 2553+
27092554 }
27102555
27112556 if ( count( $rows ) ) {
@@ -2745,8 +2590,11 @@
27462591
27472592 /**
27482593 * 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)
27492597 */
2750 - public function loadRestrictions() {
 2598+ public function loadRestrictions( $oldFashionedRestrictions = null ) {
27512599 global $wgContLang;
27522600 if ( !$this->mRestrictionsLoaded ) {
27532601 if ( $this->exists() ) {
@@ -2759,7 +2607,7 @@
27602608 __METHOD__
27612609 );
27622610
2763 - $this->loadRestrictionsFromResultWrapper( $res );
 2611+ $this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions );
27642612 } else {
27652613 $title_protection = $this->getTitleProtection();
27662614
@@ -2919,83 +2767,86 @@
29202768 * @return int The view count for the page
29212769 */
29222770 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+ }
29252782 }
29262783
29272784 return $this->mCounter;
29282785 }
29292786
29302787 /**
2931 - * Get the last touched timestamp
 2788+ * Get the article ID for this Title from the link cache,
 2789+ * adding it if necessary
29322790 *
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
29622793 * @return Int the ID
29632794 */
29642795 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;
29672798 }
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+ }
29692810 return $this->mArticleID;
29702811 }
29712812
29722813 /**
29732814 * 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
29752816 *
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
29782818 * @return Bool
29792819 */
29802820 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;
29832823 }
 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' );
29842830
29852831 return $this->mRedirect;
29862832 }
29872833
29882834 /**
29892835 * What is the length of this page?
2990 - * Uses link cache, adding it if necessary.
 2836+ * Uses link cache, adding it if necessary
29912837 *
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
29942839 * @return Int
29952840 */
29962841 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;
29992844 }
 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' ) );
30002851
30012852 return $this->mLength;
30022853 }
@@ -3003,14 +2854,19 @@
30042855 /**
30052856 * What is the page_latest field for this page?
30062857 *
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
30092859 * @return Int or 0 if the page doesn't exist
30102860 */
30112861 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 );
30142864 }
 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' ) );
30152871
30162872 return $this->mLatestID;
30172873 }
@@ -3026,29 +2882,21 @@
30272883 * @param $newid Int the new Article ID
30282884 */
30292885 public function resetArticleID( $newid ) {
3030 - LinkCache::singleton()->clearLink( $this );
 2886+ $linkCache = LinkCache::singleton();
 2887+ $linkCache->clearLink( $this );
30312888
3032 - if ( $newid === 0 ) {
3033 - $this->loadFromRow( false );
 2889+ if ( $newid === false ) {
 2890+ $this->mArticleID = -1;
30342891 } 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 );
30522893 }
 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;
30532901 }
30542902
30552903 /**
@@ -4144,6 +3992,16 @@
41453993 }
41463994
41473995 /**
 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+ /**
41484006 * Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit
41494007 *
41504008 * @return bool
@@ -4409,6 +4267,18 @@
44104268 }
44114269
44124270 /**
 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+ /**
44134283 * Get the timestamp when this page was updated since the user last saw it.
44144284 *
44154285 * @param $user User
Index: trunk/phase3/includes/WikiPage.php
@@ -355,12 +355,8 @@
356356 * @return void
357357 */
358358 public function loadPageData( $data = 'fromdb' ) {
359 - # If we get a DB row, God knows from where it comes
360 - $fromMaster = false;
361 -
362359 if ( $data === 'fromdbmaster' ) {
363360 $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle );
364 - $fromMaster = true;
365361 } elseif ( $data === 'fromdb' ) { // slave
366362 $data = $this->pageDataFromTitle( wfGetDB( DB_SLAVE ), $this->mTitle );
367363 # Use a "last rev inserted" timestamp key to dimish the issue of slave lag.
@@ -369,16 +365,26 @@
370366 if ( $touched ) { // key set
371367 if ( !$data || $touched > wfTimestamp( TS_MW, $data->page_touched ) ) {
372368 $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle );
373 - $fromMaster = true;
374369 }
375370 }
376371 }
377372
378 - $this->mTitle->loadFromRow( $data, $fromMaster );
 373+ $lc = LinkCache::singleton();
379374
380375 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+
381383 $this->mIsRedirect = intval( $data->page_is_redirect );
382384 $this->mLatest = intval( $data->page_latest );
 385+ } else {
 386+ $lc->addBadLinkObj( $this->mTitle );
 387+
 388+ $this->mTitle->loadFromRow( false );
383389 }
384390
385391 $this->mDataLoaded = true;
@@ -499,11 +505,7 @@
500506 if ( !$this->mDataLoaded ) {
501507 $this->loadPageData();
502508 }
503 - $timestamp = $this->mTitle->getTouched();
504 - if ( $timestamp === false ) {
505 - $timestamp = '19700101000000';
506 - }
507 - return $timestamp;
 509+ return $this->mTitle->getTouched();
508510 }
509511
510512 /**
Index: trunk/phase3/includes/FakeTitle.php
@@ -65,8 +65,8 @@
6666 function isCascadeProtected() { $this->error(); }
6767 function getCascadeProtectionSources( $get_pages = true ) { $this->error(); }
6868 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(); }
7171 function getRestrictions( $action ) { $this->error(); }
7272 function getRestrictionExpiry( $action ) { $this->error(); }
7373 function isDeleted() { $this->error(); }
@@ -109,7 +109,7 @@
110110 function isKnown() { $this->error(); }
111111 function canExist() { $this->error(); }
112112 function touchLinks() { $this->error(); }
113 - function getTouched() { $this->error(); }
 113+ function getTouched( $db = null ) { $this->error(); }
114114 function getNotificationTimestamp( $user = null ) { $this->error(); }
115115 function getNamespaceKey( $prepend = 'nstab-' ) { $this->error(); }
116116 function isSpecialPage() { $this->error(); }

Follow-up revisions

RevisionCommit summaryAuthorDate
r107992Fix for r107945: also partially revert r107842ialex08:24, 4 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107769Turn Title::isNewPage() into something useful by caching its result and prelo...ialex12:23, 1 January 2012
r107771Follow-up r107769:...ialex12:44, 1 January 2012
r107825* Store the value of the page.page_restrictions field in Title::loadFromRow()...ialex12:49, 2 January 2012
r107840Fix for r107825: forgot to change one instance of $oldFashionedRestrictions t...ialex17:22, 2 January 2012
r107927Give Title a decent loading mechanism:...ialex19:28, 3 January 2012
r107934Per Aaron, fix for r107771: Title::getTouched() should return false on non-ex...ialex20:15, 3 January 2012

Comments

#Comment by Aaron Schulz (talk | contribs)   21:47, 3 January 2012

This approach makes sense.

Status & tagging log