Moved constant values from initialiseFromUser() to class definition
[lhc/web/wiklou.git] / includes / Article.php
index 211a0da..a01f40c 100644 (file)
@@ -126,7 +126,7 @@ class Article {
                $this->insertRedirectEntry( $retval );
                return $retval;
        }
-       
+
        /**
         * Insert or update the redirect table entry for this page to indicate
         * it redirects to $rt .
@@ -166,7 +166,7 @@ class Article {
                // recurse through to only get the final target
                return $this->getRedirectURL( Title::newFromRedirectRecurse( $text ) );
        }
-       
+
        /**
         * Get the Title object or URL to use for a redirect. We use Title
         * objects for same-wiki, non-special redirects and URLs for everything
@@ -966,11 +966,11 @@ class Article {
                                                if ( $oldid === $this->getLatest() && $this->useParserCache( false ) ) {
                                                        $this->mParserOutput = $parserCache->get( $this, $parserOptions );
                                                        if ( $this->mParserOutput ) {
-                                                               wfDebug( __METHOD__ . ": showing parser cache for current rev permalink\n" );                                                           
+                                                               wfDebug( __METHOD__ . ": showing parser cache for current rev permalink\n" );
                                                                $wgOut->addParserOutput( $this->mParserOutput );
                                                                $wgOut->setRevisionId( $this->mLatest );
                                                                $outputDone = true;
-                                                               break;                                                          
+                                                               break;
                                                        }
                                                }
                                        }
@@ -984,25 +984,27 @@ class Article {
                                                wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
                                                $this->showCssOrJsPage();
                                                $outputDone = true;
-                                       } else if ( $rt = Title::newFromRedirectArray( $text ) ) {
-                                               wfDebug( __METHOD__ . ": showing redirect=no page\n" );
-                                               # Viewing a redirect page (e.g. with parameter redirect=no)
-                                               # Don't append the subtitle if this was an old revision
-                                               $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
-                                               # Parse just to get categories, displaytitle, etc.
-                                               $this->mParserOutput = $wgParser->parse( $text, $this->mTitle, $parserOptions );
-                                               $wgOut->addParserOutputNoText( $this->mParserOutput );
-                                               $outputDone = true;
+                                       } else {
+                                               $rt = Title::newFromRedirectArray( $text );
+                                               if ( $rt ) {
+                                                       wfDebug( __METHOD__ . ": showing redirect=no page\n" );
+                                                       # Viewing a redirect page (e.g. with parameter redirect=no)
+                                                       # Don't append the subtitle if this was an old revision
+                                                       $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
+                                                       # Parse just to get categories, displaytitle, etc.
+                                                       $this->mParserOutput = $wgParser->parse( $text, $this->mTitle, $parserOptions );
+                                                       $wgOut->addParserOutputNoText( $this->mParserOutput );
+                                                       $outputDone = true;
+                                               }
                                        }
                                        break;
                                case 4:
                                        # Run the parse, protected by a pool counter
                                        wfDebug( __METHOD__ . ": doing uncached parse\n" );
 
-                                       $this->checkTouched();
                                        $key = $parserCache->getKey( $this, $parserOptions );
                                        $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
-                                       
+
                                        if ( !$poolArticleView->execute() ) {
                                                # Connection or timeout error
                                                wfProfileOut( __METHOD__ );
@@ -1308,7 +1310,7 @@ class Article {
                }
 
                $sk = $wgUser->getSkin();
-               $token = $wgUser->editToken();
+               $token = $wgUser->editToken( $rcid );
 
                $wgOut->addHTML(
                        "<div class='patrollink'>" .
@@ -1470,7 +1472,6 @@ class Article {
                global $wgOut;
 
                $oldid = $this->getOldID();
-               $useParserCache = $this->useParserCache( $oldid );
                $parserOptions = $this->getParserOptions();
 
                # Render printable version, use printable version cache
@@ -1480,10 +1481,10 @@ class Article {
                if ( !$this->isCurrent() || $wgOut->isPrintable() ) {
                        $parserOptions->setEditSection( false );
                }
-               
+
                $useParserCache = $this->useParserCache( $oldid );
                $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
-               
+
                return true;
        }
 
@@ -1499,12 +1500,12 @@ class Article {
                global $wgOut;
                $parserCache = ParserCache::singleton();
                $options = clone $this->getParserOptions();
-               
+
                if ( $wgOut->isPrintable() ) {
                        $options->setIsPrintable( true );
                        $options->setEditSection( false );
                }
-               
+
                $output = $parserCache->getDirty( $this, $options );
 
                if ( $output ) {
@@ -1568,9 +1569,10 @@ class Article {
                        }
                }
 
-               $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';              
-               return Html::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
-                       '<span class="redirectText">' . $link . '</span>';
+               $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
+               return '<div class="redirectMsg">' .
+                       Html::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
+                       '<span class="redirectText">' . $link . '</span></div>';
        }
 
        /**
@@ -1590,7 +1592,7 @@ class Article {
                }
 
                $tbtext = "";
-               while ( $o = $dbr->fetchObject( $tbs ) ) {
+               foreach ( $tbs as $o ) {
                        $rmvtxt = "";
 
                        if ( $wgUser->isAllowed( 'trackback' ) ) {
@@ -1672,7 +1674,7 @@ class Article {
                        $form  = Html::openElement( 'form', $formParams );
                        $form .= Xml::submitButton( wfMsg( 'confirm_purge_button' ) );
                        $form .= Html::closeElement( 'form' );
-                       
+
                        $wgOut->addHTML( $form );
                        $wgOut->addWikiMsg( 'confirm-purge-bottom' );
 
@@ -1756,7 +1758,7 @@ class Article {
        /**
         * Update the page record to point to a newly saved revision.
         *
-        * @param $dbw Database object
+        * @param $dbw DatabaseBase: object
         * @param $revision Revision: For ID number, and text used to set
                            length and redirect status fields
         * @param $lastRevision Integer: if given, will not overwrite the page field
@@ -2125,8 +2127,6 @@ class Article {
                                $userAbort = ignore_user_abort( true );
                        }
 
-                       $revisionId = 0;
-
                        $changed = ( strcmp( $text, $oldtext ) != 0 );
 
                        if ( $changed ) {
@@ -2151,6 +2151,7 @@ class Article {
                                        'parent_id'  => $this->mLatest,
                                        'user'       => $user->getId(),
                                        'user_text'  => $user->getName(),
+                                       'timestamp'  => $now
                                ) );
 
                                $dbw->begin();
@@ -2182,7 +2183,8 @@ class Article {
                                        # Update recentchanges
                                        if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
                                                # Mark as patrolled if the user can do so
-                                               $patrolled = $wgUseRCPatrol && $this->mTitle->userCan( 'autopatrol' );
+                                               $patrolled = $wgUseRCPatrol && !count(
+                                                       $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
                                                # Add RC row to the DB
                                                $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
                                                        $this->mLatest, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
@@ -2254,7 +2256,8 @@ class Article {
                                'text'       => $text,
                                'user'       => $user->getId(),
                                'user_text'  => $user->getName(),
-                               ) );
+                               'timestamp'  => $now
+                       ) );
                        $revisionId = $revision->insertOn( $dbw );
 
                        $this->mTitle->resetArticleID( $newid );
@@ -2269,7 +2272,8 @@ class Article {
                                global $wgUseRCPatrol, $wgUseNPPatrol;
 
                                # Mark as patrolled if the user can do so
-                               $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) && $this->mTitle->userCan( 'autopatrol' );
+                               $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) && !count(
+                                       $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
                                # Add RC row to the DB
                                $rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot,
                                        '', strlen( $text ), $revisionId, $patrolled );
@@ -2348,7 +2352,7 @@ class Article {
                # If we haven't been given an rc_id value, we can't do anything
                $rcid = (int) $wgRequest->getVal( 'rcid' );
 
-               if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
+               if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
                        $wgOut->showErrorPage( 'sessionfailure-title', 'sessionfailure' );
                        return;
                }
@@ -2517,7 +2521,7 @@ class Article {
                $id = $this->mTitle->getArticleID();
 
                if ( $id <= 0 ) {
-                       wfDebug( "updateRestrictions failed: $id <= 0\n" );
+                       wfDebug( "updateRestrictions failed: article id $id <= 0\n" );
                        return false;
                }
 
@@ -2992,7 +2996,7 @@ class Article {
 
                $authors = array( $row->rev_user_text );
 
-               while ( $row = $db->fetchObject( $res ) ) {
+               foreach ( $res as $row ) {
                        $authors[] = $row->rev_user_text;
                }
 
@@ -3083,7 +3087,7 @@ class Article {
                        </tr>" .
                        Xml::closeElement( 'table' ) .
                        Xml::closeElement( 'fieldset' ) .
-                       Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
+                       Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
                        Xml::closeElement( 'form' );
 
                        if ( $wgUser->isAllowed( 'editinterface' ) ) {
@@ -3609,12 +3613,12 @@ class Article {
         * Every 100th edit, prune the recent changes table.
         *
         * @private
-        * @param $text New text of the article
-        * @param $summary Edit summary
-        * @param $minoredit Minor edit
+        * @param $text String: New text of the article
+        * @param $summary String: Edit summary
+        * @param $minoredit Boolean: Minor edit
         * @param $timestamp_of_pagechange Timestamp associated with the page change
-        * @param $newid rev_id value of the new revision
-        * @param $changed Whether or not the content actually changed
+        * @param $newid Integer: rev_id value of the new revision
+        * @param $changed Boolean: Whether or not the content actually changed
         */
        public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true ) {
                global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgEnableParserCache;
@@ -3919,7 +3923,7 @@ class Article {
                $cacheable = false;
 
                if ( HTMLFileCache::useFileCache() ) {
-                       $cacheable = $this->getID() && !$this->mRedirectedFrom;
+                       $cacheable = $this->getID() && !$this->mRedirectedFrom && !$this->mTitle->isRedirect();
                        // Extension may have reason to disable file caching on some pages.
                        if ( $cacheable ) {
                                $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
@@ -4331,7 +4335,7 @@ class Article {
        */
        public static function getAutosummary( $oldtext, $newtext, $flags ) {
                global $wgContLang;
-               
+
                # Decide what kind of autosummary is needed.
 
                # Redirect autosummaries
@@ -4445,7 +4449,7 @@ class Article {
                        $this->mParserOptions->enableLimitReport();
                }
 
-               // Clone to allow modifications of the return value without affecting 
+               // Clone to allow modifications of the return value without affecting
                // the cache
                return clone $this->mParserOptions;
        }
@@ -4570,7 +4574,7 @@ class Article {
         * consider, so it's not appropriate to use there.
         *
         * @since 1.16 (r52326) for LiquidThreads
-        * 
+        *
         * @param $oldid mixed integer Revision ID or null
         */
        public function getParserOutput( $oldid = null ) {
@@ -4619,21 +4623,21 @@ class Article {
 
 class PoolWorkArticleView extends PoolCounterWork {
        private $mArticle;
-       
+
        function __construct( $article, $key, $useParserCache, $parserOptions ) {
                parent::__construct( 'ArticleView', $key );
                $this->mArticle = $article;
                $this->cacheable = $useParserCache;
                $this->parserOptions = $parserOptions;
        }
-       
+
        function doWork() {
                return $this->mArticle->doViewParse();
        }
-       
+
        function getCachedWork() {
                global $wgOut;
-               
+
                $parserCache = ParserCache::singleton();
                $this->mArticle->mParserOutput = $parserCache->get( $this->mArticle, $this->parserOptions );
 
@@ -4647,21 +4651,21 @@ class PoolWorkArticleView extends PoolCounterWork {
                }
                return false;
        }
-       
+
        function fallback() {
                return $this->mArticle->tryDirtyCache();
        }
-       
+
        function error( $status ) {
                global $wgOut;
 
                $wgOut->clearHTML(); // for release() errors
                $wgOut->enableClientCache( false );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
-               
+
                $errortext = $status->getWikiText( false, 'view-pool-error' );
                $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
-               
+
                return false;
        }
 }