ENH#59 Provide a (diff) link in Special:Contributions
authorJens Frank <jeluf@users.mediawiki.org>
Sat, 28 Aug 2004 23:00:04 +0000 (23:00 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Sat, 28 Aug 2004 23:00:04 +0000 (23:00 +0000)
Does not look up the next old revision for every change but links to pseudo-revision 'prev'.
DifferenceEngine looks up the previous revision if user requests a specific diff.

includes/Article.php
includes/Database.php
includes/DifferenceEngine.php
includes/SpecialContributions.php

index 3bde806..9530bd0 100644 (file)
@@ -663,7 +663,7 @@ class Article {
                if ( !is_null( $diff ) ) {
                        require_once( 'DifferenceEngine.php' );
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
-                       $de = new DifferenceEngine( intval($oldid), intval($diff), intval($rcid) );
+                       $de = new DifferenceEngine( $oldid, $diff, $rcid );
                        $de->showDiffPage();
                        wfProfileOut( $fname );
                        if( $diff == 0 ) {
index ac3f06e..acfab2b 100644 (file)
@@ -326,7 +326,7 @@ class Database {
                return !!$this->query( $sql, DB_MASTER, $fname );
        }
        
-       function getField( $table, $var, $cond='', $fname = 'Database::get', $options = array() ) {
+       function getField( $table, $var, $cond='', $fname = 'Database::getField', $options = array() ) {
                return $this->selectField( $table, $var, $cond, $fname = 'Database::get', $options = array() );
        }
 
index 94a3102..5241c4b 100644 (file)
@@ -12,8 +12,19 @@ class DifferenceEngine {
 
        function DifferenceEngine( $old, $new, $rcid = 0 )
        {
-               $this->mOldid = $old;
-               $this->mNewid = $new;
+               global $wgTitle;
+               if ( 'prev' == $new ) {
+                       $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" );
+
+               } else {
+                       $this->mOldid = intval($old);
+                       $this->mNewid = intval($new);
+               }
                $this->mRcidMarkPatrolled = intval($rcid);  # force it to be an integer
        }
 
index ca909f9..78bd35c 100644 (file)
@@ -75,7 +75,7 @@ function wfSpecialContributions( $par = "" )
                  "ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res1 = $dbr->query( $sql, $fname );
 
-               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text FROM $old " .
+               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
                  "WHERE old_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$omq} " .
                  "ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res2 = $dbr->query( $sql, $fname );
@@ -84,7 +84,7 @@ function wfSpecialContributions( $par = "" )
                  "WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res1 = $dbr->query( $sql, $fname );
 
-               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text FROM $old " .
+               $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
                  "WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
                $res2 = $dbr->query( $sql, $fname );
        }
@@ -127,6 +127,7 @@ function wfSpecialContributions( $par = "" )
 
                        $obj1 = $dbr->fetchObject( $res1 );
                        $topmark = true;
+                       $oldid = false;
                        --$nCur;
                } else {
                        $ns = $obj2->old_namespace;
@@ -135,6 +136,7 @@ function wfSpecialContributions( $par = "" )
                        $comment =$obj2->old_comment;
                        $me = $obj2->old_minor_edit;
                        $usertext = $obj2->old_user_text;
+                       $oldid = $obj2->old_id;
 
                        $obj2 = $dbr->fetchObject( $res2 );
                        $topmark = false;
@@ -142,7 +144,7 @@ function wfSpecialContributions( $par = "" )
                        --$nOld;
                }
                if( $n >= $offset )
-                       ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext );
+                       ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext, $oldid );
        }
        $wgOut->addHTML( "</ul>\n" );
 
@@ -175,7 +177,7 @@ other users.
 TODO: This would probably look a lot nicer in a table.
 
 */
-function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target )
+function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid )
 {
        global $wgLang, $wgOut, $wgUser, $wgRequest;
        $page = Title::makeName( $ns, $t );
@@ -197,6 +199,9 @@ function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $t
                }
 
        }
+       if ( $oldid ) {
+               $oldtext= $sk->makeKnownLink( $page, '('.wfMsg('diff').')', 'diff=prev&oldid='.$oldid );
+       } else { $oldtext=''; }
        $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
 
        if($comment) {
@@ -212,7 +217,7 @@ function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $t
                $mflag = "";
        }
 
-       $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}</li>\n" );
+       $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}{$oldtext}</li>\n" );
 }
 
 function ucCountLink( $lim, $d )