Some cleanup to Article::view() and related:
[lhc/web/wiklou.git] / includes / WikiPage.php
index 11658c0..9b7a02c 100644 (file)
@@ -15,7 +15,6 @@ abstract class Page {}
 class WikiPage extends Page {
        /**
         * @var Title
-        * @protected
         */
        public $mTitle = null;
 
@@ -25,19 +24,22 @@ class WikiPage extends Page {
        public $mCounter = -1;               // !< Integer (-1 means "not loaded")
        public $mDataLoaded = false;         // !< Boolean
        public $mIsRedirect = false;         // !< Boolean
-       public $mLatest = false;             // !< Boolean
+       public $mLatest = false;             // !< Integer (false means "not loaded")
        public $mPreparedEdit = false;           // !< Array
-       public $mRedirectTarget = null;          // !< Title object
-       public $mLastRevision = null;            // !< Revision object
-       public $mTimestamp = '';             // !< String
-       public $mTouched = '19700101000000'; // !< String
-       /**@}}*/
 
        /**
-        * @protected
-        * @var ParserOptions: ParserOptions object for $wgUser articles
+        * @var Title
         */
-       public $mParserOptions;
+       protected $mRedirectTarget = null;
+
+       /**
+        * @var Revision
+        */
+       protected $mLastRevision = null;
+
+       protected $mTimestamp = '';             // !< String
+       protected $mTouched = '19700101000000'; // !< String
+       /**@}}*/
 
        /**
         * Constructor and clear the article
@@ -203,7 +205,7 @@ class WikiPage extends Page {
                                        return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
                                }
                        } else {
-                               if ( $rt->getNamespace() == NS_SPECIAL ) {
+                               if ( $rt->isSpecialPage() ) {
                                        // Gotta handle redirects to special pages differently:
                                        // Fill the HTTP response "Location" header and ignore
                                        // the rest of the page we're on.
@@ -707,6 +709,7 @@ class WikiPage extends Page {
         * Should the parser cache be used?
         *
         * @param $user User The relevant user
+        * @param $oldid int
         * @return boolean
         */
        public function isParserCacheUsed( User $user, $oldid ) {
@@ -715,7 +718,7 @@ class WikiPage extends Page {
                return $wgEnableParserCache
                        && $user->getStubThreshold() == 0
                        && $this->exists()
-                       && empty( $oldid )
+                       && ( $oldid === null || $oldid === 0 || $oldid === $this->getLatest() )
                        && $this->mTitle->isWikitextPage();
        }
 
@@ -763,7 +766,6 @@ class WikiPage extends Page {
         *
         * @param $dbw DatabaseBase
         * @return int The newly created page_id key, or false if the title already existed
-        * @private
         */
        public function insertOn( $dbw ) {
                wfProfileIn( __METHOD__ );
@@ -975,9 +977,11 @@ class WikiPage extends Page {
                        if ( $section == 'new' ) {
                                # Inserting a new section
                                $subject = $summary ? wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" : '';
-                               $text = strlen( trim( $oldtext ) ) > 0
+                               if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) {
+                                       $text = strlen( trim( $oldtext ) ) > 0
                                                ? "{$oldtext}\n\n{$subject}{$text}"
                                                : "{$subject}{$text}";
+                               }
                        } else {
                                # Replacing an existing section; roll out the big guns
                                global $wgParser;
@@ -1067,7 +1071,7 @@ class WikiPage extends Page {
                $status = Status::newGood( array() );
 
                # Load $this->mTitle->getArticleID() and $this->mLatest if it's not already
-               $this->loadPageData();
+               $this->loadPageData( 'fromdbmaster' );
 
                $flags = $this->checkFlags( $flags );
 
@@ -1527,10 +1531,6 @@ class WikiPage extends Page {
         */
        public function estimateRevisionCount() {
                $dbr = wfGetDB( DB_SLAVE );
-
-               // For an exact count...
-               // return $dbr->selectField( 'revision', 'COUNT(*)',
-               //      array( 'rev_page' => $this->getId() ), __METHOD__ );
                return $dbr->estimateRowCount( 'revision', '*',
                        array( 'rev_page' => $this->getId() ), __METHOD__ );
        }
@@ -1592,7 +1592,7 @@ class WikiPage extends Page {
         * Deletes the article with database consistency, writes logs, purges caches
         *
         * @param $reason string delete reason for deletion log
-        * @param suppress bitfield
+        * @param $suppress bitfield
         *      Revision::DELETED_TEXT
         *      Revision::DELETED_COMMENT
         *      Revision::DELETED_USER
@@ -1606,7 +1606,7 @@ class WikiPage extends Page {
        public function doDeleteArticle(
                $reason, $suppress = false, $id = 0, $commit = true, &$error = '', User $user = null
        ) {
-               global $wgUseTrackbacks, $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase, $wgUser;
+               global $wgUseTrackbacks, $wgUser;
                $user = is_null( $user ) ? $wgUser : $user;
 
                wfDebug( __METHOD__ . "\n" );
@@ -1665,7 +1665,8 @@ class WikiPage extends Page {
                                'ar_flags'      => '\'\'', // MySQL's "strict mode"...
                                'ar_len'        => 'rev_len',
                                'ar_page_id'    => 'page_id',
-                               'ar_deleted'    => $bitfield
+                               'ar_deleted'    => $bitfield,
+                               'ar_sha1'       => 'rev_sha1'
                        ), array(
                                'page_id' => $id,
                                'page_id = rev_page'
@@ -1712,14 +1713,6 @@ class WikiPage extends Page {
                        $dbw->delete( 'iwlinks', array( 'iwl_from' => $id ), __METHOD__ );
                        $dbw->delete( 'redirect', array( 'rd_from' => $id ), __METHOD__ );
                        $dbw->delete( 'page_props', array( 'pp_page' => $id ), __METHOD__ );
-
-                       if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
-                               $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
-                               $dbw2->delete( 'globaltemplatelinks',
-                                                       array(  'gtl_from_wiki' => wfGetID(),
-                                                                       'gtl_from_page' => $id )
-                                                       );
-                       }
                }
 
                # If using cleanup triggers, we can skip some manual deletes
@@ -1765,6 +1758,8 @@ class WikiPage extends Page {
         * roll back to, e.g. user is the sole contributor. This function
         * performs permissions checks on $user, then calls commitRollback()
         * to do the dirty work
+        * 
+        * @todo: seperate the business/permission stuff out from backend code
         *
         * @param $fromP String: Name of the user whose edits to rollback.
         * @param $summary String: Custom summary. Set to default summary if empty.
@@ -1965,7 +1960,7 @@ class WikiPage extends Page {
         * Returns a stdclass with source, pst and output members
         */
        public function prepareTextForEdit( $text, $revid = null, User $user = null ) {
-               global $wgParser, $wgUser;
+               global $wgParser, $wgContLang, $wgUser;
                $user = is_null( $user ) ? $wgUser : $user;
                // @TODO fixme: check $user->getId() here???
                if ( $this->mPreparedEdit
@@ -1976,7 +1971,7 @@ class WikiPage extends Page {
                        return $this->mPreparedEdit;
                }
 
-               $popts = ParserOptions::newFromUser( $user );
+               $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang );
                wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
 
                $edit = (object)array();
@@ -2240,9 +2235,6 @@ class WikiPage extends Page {
                $title->touchLinks();
                $title->purgeSquid();
                $title->deleteTitleProtection();
-
-               # Invalidate caches of distant articles which transclude this page
-               DeferredUpdates::addHTMLCacheUpdate( $title, 'globaltemplatelinks' );
        }
 
        /**
@@ -2286,9 +2278,6 @@ class WikiPage extends Page {
 
                # Image redirects
                RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $title );
-
-               # Invalidate caches of distant articles which transclude this page
-               DeferredUpdates::addHTMLCacheUpdate( $title, 'globaltemplatelinks' );
        }
 
        /**
@@ -2301,8 +2290,6 @@ class WikiPage extends Page {
                // Invalidate caches of articles which include this page
                DeferredUpdates::addHTMLCacheUpdate( $title, 'templatelinks' );
 
-               // Invalidate caches of distant articles which transclude this page
-               DeferredUpdates::addHTMLCacheUpdate( $title, 'globaltemplatelinks' );
 
                // Invalidate the caches of all pages which redirect here
                DeferredUpdates::addHTMLCacheUpdate( $title, 'redirect' );
@@ -2345,40 +2332,6 @@ class WikiPage extends Page {
                return $result;
        }
 
-       /**
-        * Return a list of distant templates used by this article.
-        * Uses the globaltemplatelinks table
-        *
-        * @return Array of Title objects
-        */
-       public function getUsedDistantTemplates() {
-               global $wgGlobalDatabase;
-
-               $result = array();
-
-               if ( $wgGlobalDatabase ) {
-                       $id = $this->mTitle->getArticleID();
-
-                       if ( $id == 0 ) {
-                               return array();
-                       }
-
-                       $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDatabase );
-                       $res = $dbr->select( 'globaltemplatelinks',
-                               array( 'gtl_to_prefix', 'gtl_to_namespace', 'gtl_to_title' ),
-                               array( 'gtl_from_wiki' => wfWikiID( ), 'gtl_from_page' => $id ),
-                               __METHOD__ );
-
-                       if ( $res !== false ) {
-                               foreach ( $res as $row ) {
-                                       $result[] = Title::makeTitle( $row->gtl_to_namespace, $row->gtl_to_title, null, $row->gtl_to_prefix );
-                               }
-                       }
-               }
-
-               return $result;
-       }
-
        /**
         * Returns a list of hidden categories this page is a member of.
         * Uses the page_props and categorylinks tables.
@@ -2564,12 +2517,11 @@ class WikiPage extends Page {
        * @return ParserOptions
        */
        public function makeParserOptions( $user ) {
-               global $wgLanguageCode;
+               global $wgContLang;
                if ( $user instanceof User ) { // settings per user (even anons)
                        $options = ParserOptions::newFromUser( $user );
                } else { // canonical settings
-                       $options = ParserOptions::newFromUser( new User );
-                       $options->setUserLang( $wgLanguageCode ); # Must be set explicitily
+                       $options = ParserOptions::newFromUserAndLang( new User, $wgContLang );
                }
                $options->enableLimitReport(); // show inclusion/loop reports
                $options->setTidy( true ); // fix bad HTML
@@ -2643,7 +2595,7 @@ class WikiPage extends Page {
         * Updates cascading protections
         *
         * @param $parserOutput ParserOutput object for the current version
-        **/
+        */
        public function doCascadeProtectionUpdates( ParserOutput $parserOutput ) {
                if ( wfReadOnly() || !$this->mTitle->areRestrictionsCascading() ) {
                        return;
@@ -2690,25 +2642,25 @@ class WikiPage extends Page {
                }
        }
 
-       /*
-       * @deprecated since 1.18
-       */
+       /**
+        * @deprecated since 1.18
+        */
        public function quickEdit( $text, $comment = '', $minor = 0 ) {
                global $wgUser;
                return $this->doQuickEdit( $text, $wgUser, $comment, $minor );
        }
 
-       /*
-       * @deprecated since 1.18
-       */
+       /**
+        * @deprecated since 1.18
+        */
        public function viewUpdates() {
                global $wgUser;
                return $this->doViewUpdates( $wgUser );
        }
 
-       /*
-       * @deprecated since 1.18
-       */
+       /**
+        * @deprecated since 1.18
+        */
        public function useParserCache( $oldid ) {
                global $wgUser;
                return $this->isParserCacheUsed( $wgUser, $oldid );