Moved view count from WikiPage to Title; avoids an extra DB query when showing the...
[lhc/web/wiklou.git] / includes / WikiPage.php
index fff85ce..e5dbb0a 100644 (file)
@@ -21,7 +21,6 @@ class WikiPage extends Page {
        /**@{{
         * @protected
         */
-       public $mCounter = -1;               // !< Integer (-1 means "not loaded")
        public $mDataLoaded = false;         // !< Boolean
        public $mIsRedirect = false;         // !< Boolean
        public $mLatest = false;             // !< Integer (false means "not loaded")
@@ -240,7 +239,6 @@ class WikiPage extends Page {
        public function clear() {
                $this->mDataLoaded = false;
 
-               $this->mCounter = -1; # Not loaded
                $this->mRedirectTarget = null; # Title object if set
                $this->mLastRevision = null; # Latest revision
                $this->mTimestamp = '';
@@ -380,7 +378,6 @@ class WikiPage extends Page {
                        # Old-fashioned restrictions
                        $this->mTitle->loadRestrictions( $data->page_restrictions );
 
-                       $this->mCounter     = intval( $data->page_counter );
                        $this->mTouched     = wfTimestamp( TS_MW, $data->page_touched );
                        $this->mIsRedirect  = intval( $data->page_is_redirect );
                        $this->mLatest      = intval( $data->page_latest );
@@ -404,7 +401,7 @@ class WikiPage extends Page {
         * @return bool Whether or not the page exists in the database
         */
        public function exists() {
-               return $this->getId() > 0;
+               return $this->mTitle->exists();
        }
 
        /**
@@ -416,29 +413,16 @@ class WikiPage extends Page {
         * @return bool
         */
        public function hasViewableContent() {
-               return $this->exists() || $this->mTitle->isAlwaysKnown();
+               return $this->mTitle->exists() || $this->mTitle->isAlwaysKnown();
        }
 
        /**
+        * Get the number of views of this page
+        *
         * @return int The view count for the page
         */
        public function getCount() {
-               if ( -1 == $this->mCounter ) {
-                       $id = $this->getId();
-
-                       if ( $id == 0 ) {
-                               $this->mCounter = 0;
-                       } else {
-                               $dbr = wfGetDB( DB_SLAVE );
-                               $this->mCounter = $dbr->selectField( 'page',
-                                       'page_counter',
-                                       array( 'page_id' => $id ),
-                                       __METHOD__
-                               );
-                       }
-               }
-
-               return $this->mCounter;
+               return $this->mTitle->getCount();
        }
 
        /**
@@ -717,14 +701,14 @@ class WikiPage extends Page {
 
                return $wgEnableParserCache
                        && $parserOptions->getStubThreshold() == 0
-                       && $this->exists()
+                       && $this->mTitle->exists()
                        && ( $oldid === null || $oldid === 0 || $oldid === $this->getLatest() )
                        && $this->mTitle->isWikitextPage();
        }
 
        /**
         * Get a ParserOutput for the given ParserOptions and revision ID.
-        * The the parser cache will be used if possible.
+        * The parser cache will be used if possible.
         *
         * @since 1.19
         * @param $parserOptions ParserOptions to use for the parse operation
@@ -733,8 +717,6 @@ class WikiPage extends Page {
         * @return ParserOutput or false if the revision was not found
         */
        public function getParserOutput( ParserOptions $parserOptions, $oldid = null ) {
-               global $wgParser;
-
                wfProfileIn( __METHOD__ );
 
                $useParserCache = $this->isParserCacheUsed( $parserOptions, $oldid );
@@ -788,10 +770,10 @@ class WikiPage extends Page {
                }
 
                if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
-                       if ( $this->getId() == 0 ) {
-                               $text = false;
-                       } else {
+                       if ( $this->mTitle->exists() ) {
                                $text = $this->getRawText();
+                       } else {
+                               $text = false;
                        }
 
                        MessageCache::singleton()->replace( $this->mTitle->getDBkey(), $text );
@@ -1651,7 +1633,7 @@ class WikiPage extends Page {
        public function doDeleteArticle(
                $reason, $suppress = false, $id = 0, $commit = true, &$error = '', User $user = null
        ) {
-               global $wgUseTrackbacks, $wgUser;
+               global $wgUser;
                $user = is_null( $user ) ? $wgUser : $user;
 
                wfDebug( __METHOD__ . "\n" );
@@ -1744,10 +1726,6 @@ class WikiPage extends Page {
                if ( !$dbw->cascadingDeletes() ) {
                        $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
 
-                       if ( $wgUseTrackbacks ) {
-                               $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ );
-                       }
-
                        # Delete outgoing links
                        $dbw->delete( 'pagelinks', array( 'pl_from' => $id ), __METHOD__ );
                        $dbw->delete( 'imagelinks', array( 'il_from' => $id ), __METHOD__ );
@@ -1991,7 +1969,7 @@ class WikiPage extends Page {
                }
 
                # Don't update page view counters on views from bot users (bug 14044)
-               if ( !$wgDisableCounters && !$user->isAllowed( 'bot' ) && $this->getId() ) {
+               if ( !$wgDisableCounters && !$user->isAllowed( 'bot' ) && $this->mTitle->exists() ) {
                        DeferredUpdates::addUpdate( new ViewCountUpdate( $this->getId() ) );
                        DeferredUpdates::addUpdate( new SiteStatsUpdate( 1, 0, 0 ) );
                }
@@ -2024,7 +2002,18 @@ class WikiPage extends Page {
                $edit->newText = $text;
                $edit->pst = $wgParser->preSaveTransform( $text, $this->mTitle, $user, $popts );
                $edit->popts = $this->makeParserOptions( 'canonical' );
-               $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
+
+               // Bug 32858: For a CSS/JS page, put a blank parser output into the 
+               // prepared edit, so that links etc. won't be registered in the 
+               // database. We could have set $edit->output to false or something if 
+               // we thought of this bug earlier, but now that would break the 
+               // interface with AbuseFilter etc.
+               if ( $this->mTitle->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) {
+                       $input = '';
+               } else {
+                       $input = $edit->pst;
+               }
+               $edit->output = $wgParser->parse( $input, $this->mTitle, $edit->popts, true, true, $revid );
                $edit->oldText = $this->getRawText();
 
                $this->mPreparedEdit = $edit;
@@ -2095,15 +2084,15 @@ class WikiPage extends Page {
                        }
                }
 
-               $id = $this->getId();
-               $title = $this->mTitle->getPrefixedDBkey();
-               $shortTitle = $this->mTitle->getDBkey();
-
-               if ( 0 == $id ) {
+               if ( !$this->mTitle->exists() ) {
                        wfProfileOut( __METHOD__ );
                        return;
                }
 
+               $id = $this->getId();
+               $title = $this->mTitle->getPrefixedDBkey();
+               $shortTitle = $this->mTitle->getDBkey();
+
                if ( !$options['changed'] ) {
                        $good = 0;
                        $total = 0;
@@ -2322,7 +2311,9 @@ class WikiPage extends Page {
                # User talk pages
                if ( $title->getNamespace() == NS_USER_TALK ) {
                        $user = User::newFromName( $title->getText(), false );
-                       $user->setNewtalk( false );
+                       if ( $user ) {
+                               $user->setNewtalk( false );
+                       }
                }
 
                # Image redirects