Don't require an existence check before calling loadPageData(). Added an accessor...
authorTim Starling <tstarling@users.mediawiki.org>
Thu, 16 Mar 2006 02:32:30 +0000 (02:32 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Thu, 16 Mar 2006 02:32:30 +0000 (02:32 +0000)
includes/Article.php
includes/Wiki.php

index cd7ff01..18e5f8d 100644 (file)
@@ -37,6 +37,7 @@ class Article {
        var $mRevIdFetched;
        var $mRevision;
        var $mRedirectUrl;
+       var $mLatest;
        /**#@-*/
 
        /**
@@ -125,6 +126,7 @@ class Article {
                $this->mIsRedirect = false;
                $this->mRevIdFetched = 0;
                $this->mRedirectUrl = false;
+               $this->mLatest = false;
        }
 
        /**
@@ -416,15 +418,28 @@ class Article {
         * @param object $data
         * @access private
         */
-       function loadPageData( $data ) {
-               $this->mTitle->mArticleID = $data->page_id;
-               $this->mTitle->loadRestrictions( $data->page_restrictions );
-               $this->mTitle->mRestrictionsLoaded = true;
+       function loadPageData( $data = 'fromdb' ) {
+               if ( $data === 'fromdb' ) {
+                       $dbr =& $this->getDB();
+                       $data = $this->pageDataFromId( $dbr, $this->getId() );
+               }
+                       
+               $lc =& LinkCache::singleton();
+               if ( $data ) {
+                       $lc->addGoodLinkObj( $data->page_id, $this->mTitle );
 
-               $this->mCounter     = $data->page_counter;
-               $this->mTouched     = wfTimestamp( TS_MW, $data->page_touched );
-               $this->mIsRedirect  = $data->page_is_redirect;
-               $this->mLatest      = $data->page_latest;
+                       $this->mTitle->mArticleID = $data->page_id;
+                       $this->mTitle->loadRestrictions( $data->page_restrictions );
+                       $this->mTitle->mRestrictionsLoaded = true;
+
+                       $this->mCounter     = $data->page_counter;
+                       $this->mTouched     = wfTimestamp( TS_MW, $data->page_touched );
+                       $this->mIsRedirect  = $data->page_is_redirect;
+                       $this->mLatest      = $data->page_latest;
+               } else {
+                       $lc->addBadLinkObj( $this->mTitle );
+                       $this->mTitle->mArticleID = 0;
+               }
 
                $this->mDataLoaded  = true;
        }
@@ -557,9 +572,13 @@ class Article {
        function getCount() {
                if ( -1 == $this->mCounter ) {
                        $id = $this->getID();
-                       $dbr =& wfGetDB( DB_SLAVE );
-                       $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
-                               'Article::getCount', $this->getSelectOptions() );
+                       if ( $id == 0 ) {
+                               $this->mCounter = 0;
+                       } else {
+                               $dbr =& wfGetDB( DB_SLAVE );
+                               $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
+                                       'Article::getCount', $this->getSelectOptions() );
+                       }
                }
                return $this->mCounter;
        }
@@ -633,7 +652,10 @@ class Article {
        }
 
        function getTimestamp() {
-               $this->loadLastEdit();
+               // Check if the field has been filled by ParserCache::get()
+               if ( !$this->mTimestamp ) {
+                       $this->loadLastEdit();
+               }
                return wfTimestamp(TS_MW, $this->mTimestamp);
        }
 
@@ -2363,11 +2385,7 @@ class Article {
        function checkTouched() {
                $fname = 'Article::checkTouched';
                if( !$this->mDataLoaded ) {
-                       $dbr =& $this->getDB();
-                       $data = $this->pageDataFromId( $dbr, $this->getId() );
-                       if( $data ) {
-                               $this->loadPageData( $data );
-                       }
+                       $this->loadPageData();
                }
                return !$this->mIsRedirect;
        }
@@ -2378,15 +2396,21 @@ class Article {
        function getTouched() {
                # Ensure that page data has been loaded
                if( !$this->mDataLoaded ) {
-                       $dbr =& $this->getDB();
-                       $data = $this->pageDataFromId( $dbr, $this->getId() );
-                       if( $data ) {
-                               $this->loadPageData( $data );
-                       }
+                       $this->loadPageData();
                }
                return $this->mTouched;
        }
 
+       /**
+        * Get the page_latest field
+        */
+       function getLatest() {
+               if ( !$this->mDataLoaded ) {
+                       $this->loadPageData();
+               }
+               return $this->mLatest;
+       }
+
        /**
         * Edit an article without doing all that other stuff
         * The article must already exist; link tables etc
index 0a0bd42..be3a8b4 100644 (file)
@@ -204,15 +204,10 @@ class MediaWiki {
                // Namespace might change when using redirects
                if( $action == 'view' && !$request->getVal( 'oldid' ) &&
                                                $request->getVal( 'redirect' ) != 'no' ) {
-                       $dbr=&wfGetDB(DB_SLAVE);
-                       
-                       // If we don't check for existance we'll get "Trying to get
-                       // property of non-object" E_NOTICE in Article::loadPageData() when
-                       // viewing a page that does not exist
-                       if ( $article->exists() ) {
-                               $article->loadPageData($article->pageDataFromTitle($dbr,$title));
-                       }
-                       
+                                                       
+                       $dbr =& wfGetDB(DB_SLAVE);
+                       $article->loadPageData($article->pageDataFromTitle($dbr, $title));
+               
                        /* Follow redirects only for... redirects */
                        if ($article->mIsRedirect) {
                                $target = $article->followRedirect();