* (bug 21279, bug 28820) Workaround for standard diff links to deleted revs; Special...
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 10 May 2011 01:17:01 +0000 (01:17 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 10 May 2011 01:17:01 +0000 (01:17 +0000)
Adds links to Special:Undelete to view the requested revisions onto the 'revision data not found' error message, if they can be found via ar_rev_id and the user has permission to deletedhistory.

Follow-up to r87804; allows the 'diff' links on log entries for Special:RevisionDelete actions on deleted revs referenced by rev-id to continue to go someplace semi-sane.
Could benefit a more transparent forwarding -> bug 28820.

includes/diff/DifferenceEngine.php

index 5ada4e7..1dda3da 100644 (file)
@@ -119,6 +119,47 @@ class DifferenceEngine {
                return $this->mNewid;
        }
 
+       /**
+        * Look up a special:Undelete link to the given deleted revision id,
+        * as a workaround for being unable to load deleted diffs in currently.
+        *
+        * @param int $id revision ID
+        * @return mixed URL or false
+        */
+       function deletedLink( $id ) {
+               global $wgUser;
+               if ( $wgUser->isAllowed( 'deletedhistory' ) ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $row = $dbr->selectRow('archive', '*',
+                               array( 'ar_rev_id' => $id ),
+                               __METHOD__ );
+                       if ( $row ) {
+                               $rev = Revision::newFromArchiveRow( $row );
+                               $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
+                               return SpecialPage::getTitleFor( 'Undelete' )->getFullURL( array(
+                                       'target' => $title->getPrefixedText(),
+                                       'timestamp' => $rev->getTimestamp()
+                               ));
+                       }
+               }
+               return false;
+       }
+
+       /**
+        * Build a wikitext link toward a deleted revision, if viewable.
+        *
+        * @param int $id revision ID
+        * @return string wikitext fragment
+        */
+       function deletedIdMarker( $id ) {
+               $link = $this->deletedLink( $id );
+               if ( $link ) {
+                       return "[$link $id]";
+               } else {
+                       return $id;
+               }
+       }
+
        function showDiffPage( $diffOnly = false ) {
                global $wgUser, $wgOut, $wgUseExternalEditor, $wgUseRCPatrol;
                wfProfileIn( __METHOD__ );
@@ -165,10 +206,15 @@ CONTROL;
 
                $wgOut->setArticleFlag( false );
                if ( !$this->loadRevisionData() ) {
+                       // Sounds like a deleted revision... Let's see what we can do.
+                       $deletedLink = $this->deletedLink( $this->mNewid );
+
                        $t = $this->mTitle->getPrefixedText();
-                       $d = wfMsgExt( 'missingarticle-diff', array( 'escape' ), $this->mOldid, $this->mNewid );
+                       $d = wfMsgExt( 'missingarticle-diff', array( 'escape' ),
+                                       $this->deletedIdMarker( $this->mOldid ),
+                                       $this->deletedIdMarker( $this->mNewid ) );
                        $wgOut->setPagetitle( wfMsg( 'errorpagetitle' ) );
-                       $wgOut->addWikiMsg( 'missing-article', "<nowiki>$t</nowiki>", $d );
+                       $wgOut->addWikiMsg( 'missing-article', "<nowiki>$t</nowiki>", "<span class='plainlinks'>$d</span>" );
                        wfProfileOut( __METHOD__ );
                        return;
                }
@@ -520,9 +566,11 @@ CONTROL;
                #
                if ( ! $this->loadNewText() ) {
                        $t = $this->mTitle->getPrefixedText();
-                       $d = wfMsgExt( 'missingarticle-diff', array( 'escape' ), $this->mOldid, $this->mNewid );
+                       $d = wfMsgExt( 'missingarticle-diff', array( 'escape' ),
+                                       $this->deletedIdMarker( $this->mOldid ),
+                                       $this->deletedIdMarker( $this->mNewid ) );
                        $wgOut->setPagetitle( wfMsg( 'errorpagetitle' ) );
-                       $wgOut->addWikiMsg( 'missing-article', "<nowiki>$t</nowiki>", $d );
+                       $wgOut->addWikiMsg( 'missing-article', "<nowiki>$t</nowiki>", "<span class='plainlinks'>$d</span>" );
                        wfProfileOut( __METHOD__ );
                        return;
                }