From 8444069f2be884b7d8574ecdd49a1c80e93835e9 Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Sun, 29 Aug 2004 18:13:23 +0000 Subject: [PATCH] Fix handling of oldest revision with diff-links from the user contributions. ENH#228 Have next/previous links in diffs. --- includes/DifferenceEngine.php | 106 +++++++++++++++++++++++++++++++++- languages/Language.php | 4 ++ 2 files changed, 107 insertions(+), 3 deletions(-) diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 5241c4b75f..3bc8269938 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -14,14 +14,35 @@ class DifferenceEngine { { global $wgTitle; if ( 'prev' == $new ) { + # Show diff between revision $old and the previous one. + # Get previous one from DB. + # $this->mNewid = intval($old); $dbr =& wfGetDB( DB_SLAVE ); $this->mOldid = $dbr->selectField( 'old', 'old_id', "old_title='" . $wgTitle->getDBkey() . "'" . ' AND old_namespace=' . $wgTitle->getNamespace() . - " AND old_id<{$this->mNewid} order by old_id desc" ); + " AND old_id<{$this->mNewid} ORDER BY old_id DESC" ); + + } elseif ( 'next' == $new ) { + + # Show diff between revision $old and the previous one. + # Get previous one from DB. + # + $this->mOldid = intval($old); + $dbr =& wfGetDB( DB_SLAVE ); + $this->mNewid = $dbr->selectField( 'old', 'old_id', + "old_title='" . $wgTitle->getDBkey() . "'" . + ' AND old_namespace=' . $wgTitle->getNamespace() . + " AND old_id>{$this->mOldid} ORDER BY old_id " ); + if ( false === $this->mNewid ) { + # if no result, NewId points to the newest old revision. The only newer + # revision is cur, which is "0". + $this->mNewid = 0; + } } else { + $this->mOldid = intval($old); $this->mNewid = intval($new); } @@ -34,6 +55,15 @@ class DifferenceEngine { $fname = 'DifferenceEngine::showDiffPage'; wfProfileIn( $fname ); + # mOldid is false if the difference engine is called with a "vague" query for + # a diff between a version V and its previous version V' AND the version V + # is the first version of that article. In that case, V' does not exist. + if ( $this->mOldid === false ) { + $this->showFirstRevision(); + wfProfileOut( $fname ); + return; + } + $t = $wgTitle->getPrefixedText() . " (Diff: {$this->mOldid}, " . "{$this->mNewid})"; $mtext = wfMsg( 'missingarticle', $t ); @@ -94,10 +124,19 @@ class DifferenceEngine { $patrol = ''; } + $prevlink = $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'previousdiff' ), 'diff=prev&oldid='.$this->mOldid ); + if ( $this->mNewid == 0 ) { + $nextlink = ''; + } else { + $nextlink = $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'nextdiff' ), 'diff=next&oldid='.$this->mNewid ); + } + $oldHeader = "{$this->mOldtitle}
$oldUserLink " . - "($oldUTLink | $oldContribs)
" . $this->mOldComment; + "($oldUTLink | $oldContribs)
" . $this->mOldComment . + '
' . $prevlink; $newHeader = "{$this->mNewtitle}
$newUserLink " . - "($newUTLink | $newContribs) $rollback
" . $this->mNewComment . $patrol; + "($newUTLink | $newContribs) $rollback
" . $this->mNewComment . + '
' . $nextlink . $patrol; DifferenceEngine::showDiff( $this->mOldtext, $this->mNewtext, $oldHeader, $newHeader ); @@ -107,6 +146,67 @@ class DifferenceEngine { wfProfileOut( $fname ); } + # Show the first revision of an article. Uses normal diff headers in contrast to normal + # "old revision" display style. + # + function showFirstRevision() + { + global $wgOut, $wgTitle, $wgUser, $wgLang; + + $fname = 'DifferenceEngine::showFirstRevision'; + wfProfileIn( $fname ); + + + $this->mOldid = $this->mNewid; # hack to make loadText() work. + + # Get article text from the DB + # + if ( ! $this->loadText() ) { + $t = $wgTitle->getPrefixedText() . " (Diff: {$this->mOldid}, " . + "{$this->mNewid})"; + $mtext = wfMsg( 'missingarticle', $t ); + $wgOut->setPagetitle( wfMsg( 'errorpagetitle' ) ); + $wgOut->addHTML( $mtext ); + wfProfileOut( $fname ); + return; + } + + # Check if user is allowed to look at this page. If not, bail out. + # + if ( !( $this->mOldPage->userCanRead() ) ) { + $wgOut->loginToUse(); + $wgOut->output(); + wfProfileOut( $fname ); + exit; + } + + # Prepare the header box + # + $sk = $wgUser->getSkin(); + + $uTLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER_TALK, $this->mOldUser ), $wgLang->getNsText( NS_TALK ) ); + $userLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER, $this->mOldUser ), $this->mOldUser ); + $contribs = $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), wfMsg( 'contribslink' ), + 'target=' . urlencode($this->mOldUser) ); + $nextlink = $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'nextdiff' ), 'diff=next&oldid='.$this->mNewid ); + $header = "
{$this->mOldtitle}
$userLink " . + "($uTLink | $contribs)
" . $this->mOldComment . + '
' . $nextlink. "
\n"; + + $wgOut->addHTML( $header ); + + $wgOut->setSubtitle( wfMsg( 'difference' ) ); + $wgOut->setRobotpolicy( 'noindex,follow' ); + + + # Show current revision + # + $wgOut->addHTML( "

{$this->mPagetitle}

\n" ); + $wgOut->addWikiText( $this->mNewtext ); + + wfProfileOut( $fname ); + } + function showDiff( $otext, $ntext, $otitle, $ntitle ) { global $wgOut, $wgUseExternalDiffEngine; diff --git a/languages/Language.php b/languages/Language.php index 5c0c3ff378..79eb1501f8 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1525,6 +1525,10 @@ ta[\'ca-nstab-category\'] = new Array(\'c\',\'View the category page\'); # image deletion 'deletedrevision' => 'Deleted old revision $1.', +# browsing diffs +'previousdiff' => '← Go to previous diff', +'nextdiff' => 'Go to next diff →', + ); -- 2.20.1