Apply changes made live on Wikimedia cluster related to preprocessor caching to subve...
[lhc/web/wiklou.git] / includes / Article.php
index 4f3125e..5c33c75 100644 (file)
@@ -103,8 +103,7 @@ class Article {
         * @return Title object
         */
        public function insertRedirect() {
-               // set noRecurse so that we always get an entry even if redirects are "disabled"
-               $retval = Title::newFromRedirect( $this->getContent(), false, true );
+               $retval = Title::newFromRedirect( $this->getContent() );
                if( !$retval ) {
                        return null;
                }
@@ -136,7 +135,7 @@ class Article {
         * @return mixed false, Title of in-wiki target, or string with URL
         */
        public function followRedirectText( $text ) {
-               $rt = Title::newFromRedirect( $text ); // only get the final target
+               $rt = Title::newFromRedirectRecurse( $text ); // recurse through to only get the final target
                # process if title object is valid and not special:userlogout
                if( $rt ) {
                        if( $rt->getInterwiki() != '' ) {
@@ -607,10 +606,9 @@ class Article {
                        }
                        // Apparently loadPageData was never called
                        $this->loadContent();
-                       // Only get the next target to reduce load times
-                       $titleObj = Title::newFromRedirect( $this->fetchContent(), false, true );
+                       $titleObj = Title::newFromRedirectRecurse( $this->fetchContent() );
                } else {
-                       $titleObj = Title::newFromRedirect( $text, false, true );
+                       $titleObj = Title::newFromRedirect( $text );
                }
                return $titleObj !== NULL;
        }
@@ -782,15 +780,17 @@ class Article {
                }
                $wgOut->setRobotPolicy( $policy );
 
+               # Allow admins to see deleted content if explicitly requested
+               $delId = $diff ? $diff : $oldid;
+               $unhide = $wgRequest->getInt('unhide') == 1 && $wgUser->matchEditToken( $wgRequest->getVal('token'), $delId );
                # If we got diff and oldid in the query, we want to see a
                # diff page instead of the article.
 
                if( !is_null( $diff ) ) {
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
 
-                       $diff = $wgRequest->getVal( 'diff' );
                        $htmldiff = $wgRequest->getVal( 'htmldiff' , false);
-                       $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge, $htmldiff);
+                       $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge, $htmldiff, $unhide );
                        // DifferenceEngine directly fetched the revision:
                        $this->mRevIdFetched = $de->mNewid;
                        $de->showDiffPage( $diffOnly );
@@ -915,8 +915,9 @@ class Article {
                                        // FIXME: This would be a nice place to load the 'no such page' text.
                                } else {
                                        $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
+                                       # Allow admins to see deleted content if explicitly requested
                                        if( $this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
-                                               if( !$this->mRevision->userCan( Revision::DELETED_TEXT ) ) {
+                                               if( !$unhide || !$this->mRevision->userCan(Revision::DELETED_TEXT) ) {
                                                        $wgOut->addWikiMsg( 'rev-deleted-text-permission' );
                                                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
                                                        wfProfileOut( __METHOD__ );
@@ -943,7 +944,7 @@ class Article {
                                        $wgOut->addHTML( htmlspecialchars( $this->mContent ) );
                                        $wgOut->addHTML( "\n</pre>\n" );
                                }
-                       } else if( $rt = Title::newFromRedirect( $text, true ) ) { # get an array of redirect targets
+                       } else if( $rt = Title::newFromRedirectArray( $text ) ) { # get an array of redirect targets
                                # Don't append the subtitle if this was an old revision
                                $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
                                $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
@@ -993,22 +994,9 @@ class Article {
                        $wgOut->addWikiMsg('anontalkpagetext');
                }
 
-               # Only diffs and new page links from RC give rcid params, so if
-               # we are just viewing the page normally with no rcid, try to find it. 
-               # This is more convenient for users.
-               if( $this->mTitle->exists() && $this->mTitle->userCan('patrol') ) {
-                       if( empty($rcid) ) {
-                               $firstRev = $this->mTitle->getFirstRevision();
-                               $rcid = $firstRev ? $firstRev->isUnpatrolled() : 0;
-                       } else {
-                               $rc = RecentChange::newFromId( $rcid );
-                               // Already patrolled?
-                               $rcid = is_object($rc) && !$rc->getAttribute('rc_patrolled') ? $rcid : 0;
-                       }
-               }
                # If we have been passed an &rcid= parameter, we want to give the user a
                # chance to mark this new article as patrolled.
-               if( !empty($rcid) && $this->mTitle->exists() && $this->mTitle->userCan('patrol') ) {
+               if( !empty($rcid) && $this->mTitle->exists() && $this->mTitle->quickUserCan('patrol') ) {
                        $wgOut->addHTML(
                                "<div class='patrollink'>" .
                                        wfMsgHtml( 'markaspatrolledlink',
@@ -1813,8 +1801,8 @@ class Article {
                }
 
                #It would be nice to see where the user had actually come from, but for now just guess
-               $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
-               $return = Title::makeTitle( NS_SPECIAL, $returnto );
+               $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'newpages' : 'recentchanges';
+               $return = SpecialPage::getTitleFor( $returnto );
 
                $dbw = wfGetDB( DB_MASTER );
                $errors = $rc->doMarkPatrolled();
@@ -2986,7 +2974,7 @@ class Article {
         * @param $oldid String: revision ID of this article revision
         */
        public function setOldSubtitle( $oldid = 0 ) {
-               global $wgLang, $wgOut, $wgUser;
+               global $wgLang, $wgOut, $wgUser, $wgRequest;
 
                if( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
                        return;
@@ -3037,16 +3025,17 @@ class Article {
                        }
                        $cdel = "(<small>$cdel</small>) ";
                }
-               # Show user links if allowed to see them. Normally they
-               # are hidden regardless, but since we can already see the text here...
-               $userlinks = $sk->revUserTools( $revision, false );
+               $unhide = $wgRequest->getInt('unhide') == 1 && $wgUser->matchEditToken( $wgRequest->getVal('token'), $oldid );
+               # Show user links if allowed to see them. If hidden, then show them only if requested...
+               $userlinks = $sk->revUserTools( $revision, !$unhide );
 
                $m = wfMsg( 'revision-info-current' );
                $infomsg = $current && !wfEmptyMsg( 'revision-info-current', $m ) && $m != '-'
                        ? 'revision-info-current'
                        : 'revision-info';
 
-               $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" . wfMsgExt( $infomsg, array( 'parseinline', 'replaceafter' ), $td, $userlinks, $revision->getID() ) . "</div>\n" .
+               $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" . wfMsgExt( $infomsg, array( 'parseinline', 'replaceafter' ), 
+                       $td, $userlinks, $revision->getID() ) . "</div>\n" .
 
                     "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgHtml( 'revision-nav', $prevdiff, 
                                $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
@@ -3475,9 +3464,9 @@ class Article {
        public static function getAutosummary( $oldtext, $newtext, $flags ) {
                # Decide what kind of autosummary is needed.
 
-               # Redirect autosummaries -- should only get the next target and not recurse
-               $ot = Title::newFromRedirect( $oldtext, false, true );
-               $rt = Title::newFromRedirect( $newtext, false, true );
+               # Redirect autosummaries
+               $ot = Title::newFromRedirect( $oldtext );
+               $rt = Title::newFromRedirect( $newtext );
                if( is_object( $rt ) && ( !is_object( $ot ) || !$rt->equals( $ot ) || $ot->getFragment() != $rt->getFragment() ) ) {
                        return wfMsgForContent( 'autoredircomment', $rt->getFullText() );
                }