* Fixed magic quotes in $_REQUEST, in Setup.php
[lhc/web/wiklou.git] / includes / PageHistory.php
index d3fbff6..bfae24e 100644 (file)
@@ -7,7 +7,7 @@
 class PageHistory {
        var $mArticle, $mTitle, $mSkin;
        var $lastline, $lastdate;
-       
+       var $linesonpage;
        function PageHistory( $article ) {
                $this->mArticle =& $article;
                $this->mTitle =& $article->mTitle;
@@ -17,7 +17,7 @@ class PageHistory {
 
        function history()
        {
-               global $wgUser, $wgOut, $wgLang, $offset, $limit;
+               global $wgUser, $wgOut, $wgLang;
 
                # If page hasn't changed, client can cache this
                
@@ -31,6 +31,7 @@ class PageHistory {
                $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
                $wgOut->setSubtitle( wfMsg( "revhistory" ) );
                $wgOut->setArticleFlag( false );
+               $wgOut->setArticleRelated( true );
                $wgOut->setRobotpolicy( "noindex,nofollow" );
 
                if( $this->mTitle->getArticleID() == 0 ) {
@@ -39,9 +40,18 @@ class PageHistory {
                        return;
                }
                
-               $offset = (int)$offset;
-               $limit = (int)$limit;
-               if( $limit == 0 ) $limit = 50;
+               list( $limit, $offset ) = wfCheckLimits();
+               
+               /* We have to draw the latest revision from 'cur' */
+               $rawlimit = $limit;
+               $rawoffset = $offset - 1;
+               if( 0 == $offset ) {
+                       $rawlimit--;
+                       $rawoffset = 0;
+               }
+               /* Check one extra row to see whether we need to show 'next' and diff links */
+               $limitplus = $rawlimit + 1;
+               
                $namespace = $this->mTitle->getNamespace();
                $title = $this->mTitle->getText();
                $sql = "SELECT old_id,old_user," .
@@ -49,38 +59,43 @@ class PageHistory {
                  "FROM old USE INDEX (name_title_timestamp) " .
                  "WHERE old_namespace={$namespace} AND " .
                  "old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
-                 "ORDER BY inverse_timestamp LIMIT $offset, $limit";
+                 "ORDER BY inverse_timestamp LIMIT $rawoffset, $limitplus";
                $res = wfQuery( $sql, DB_READ, $fname );
 
                $revs = wfNumRows( $res );
-               if( $this->mTitle->getArticleID() == 0 ) {
-                       $wgOut->addHTML( wfMsg( "nohistory" ) );
-                       wfProfileOut( $fname );
-                       return;
-               }
+               
+               if( $revs < $limitplus ) // the sql above tries to fetch one extra
+                       $this->linesonpage = $revs;
+               else
+                       $this->linesonpage = $revs - 1;
+
+               $atend = ($revs < $limitplus);
                
                $this->mSkin = $wgUser->getSkin();
                $numbar = wfViewPrevNext(
                        $offset, $limit,
                        $this->mTitle->getPrefixedText(),
-                       "action=history" );
+                       "action=history", $atend );
                $s = $numbar;
                $s .= $this->beginHistoryList();
 
-               if($offset == 0 )
-               $s .= $this->historyLine( $this->mArticle->getTimestamp(), $this->mArticle->getUser(),
-                 $this->mArticle->getUserText(), $namespace,
-                 $title, 0, $this->mArticle->getComment(),
-                 ( $this->mArticle->getMinorEdit() > 0 ) );
-
-               $revs = wfNumRows( $res );
+               if( $offset == 0 ){
+                       $this->linesonpage++;
+                       $s .= $this->historyLine( 
+                               $this->mArticle->getTimestamp(), 
+                               $this->mArticle->getUser(),
+                               $this->mArticle->getUserText(), $namespace,
+                               $title, 0, $this->mArticle->getComment(),
+                               ( $this->mArticle->getMinorEdit() > 0 ) 
+                       );
+               }
                while ( $line = wfFetchObject( $res ) ) {
                        $s .= $this->historyLine( $line->old_timestamp, $line->old_user,
                          $line->old_user_text, $namespace,
                          $title, $line->old_id,
                          $line->old_comment, ( $line->old_minor_edit > 0 ) );
                }
-               $s .= $this->endHistoryList();
+               $s .= $this->endHistoryList( !$atend );
                $s .= $numbar;
                $wgOut->addHTML( $s );
                wfProfileOut( $fname );
@@ -88,16 +103,46 @@ class PageHistory {
 
        function beginHistoryList()
        {
+               global $wgTitle;
                $this->lastdate = $this->lastline = "";
                $s = "\n<p>" . wfMsg( "histlegend" ) . "\n<ul>";
+               $url = $wgTitle->getURL("-");
+               $s .= "<SCRIPT>
+                       var sel = -1;
+                       function anysel(oid){ 
+                               row = document.getElementById(\"ver\" + oid);
+                               if( row.selected ){
+                                       row.style.backgroundColor=row.oldbg; 
+                                       row.selected = 0;
+                                       sel = -1;
+                               } else {
+                                       row.oldbg = row.style.backgroundColor;
+                                       row.style.backgroundColor=\"lightgrey\"; 
+                                       row.selected = 1;
+                                       if( sel == -1){
+                                               sel = oid;
+                                       } else {
+                                               dodiff(sel, oid);
+                                       }
+                               }
+                               return false; 
+                       } 
+                       function dodiff(oldid, diff){
+                               if( (diff < oldid && diff != 0) || oldid == 0 ){ 
+                                       tmp = oldid; oldid = diff; diff = tmp; 
+                               }
+                               u = \"{$url}&diff=\" + diff + \"&oldid=\" + oldid;
+                               location.href=u;
+                       }
+               </SCRIPT>";
                return $s;
        }
 
-       function endHistoryList()
+       function endHistoryList( $skip = false )
        {
                $last = wfMsg( "last" );
 
-               $s = preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
+               $s = $skip ? "" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
                $s .= "</ul>\n";
                return $s;
        }
@@ -141,13 +186,15 @@ class PageHistory {
                } else {
                        $curlink = $cur;
                }
-               $s .= "({$curlink}) (!OLDID!{$oid}!) . .";
-
+               $arbitrary = "";
+               if( $this->linesonpage > 1)
+                       $arbitrary = "<INPUT TYPE=CHECKBOX onClick='anysel($oid)' TITLE='Select any two versions to diff them'>";
+               $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary . .";
                $M = wfMsg( "minoreditletter" );
                if ( $isminor ) {
                        $s .= " <strong>{$M}</strong>";
                }
-               $s .= " {$link} . . {$ul}";
+               $s .= " <span ID='ver$oid'>{$link} . . {$ul}</span>";
 
                if ( "" != $c && "*" != $c ) {
                        $s .= " <em>(" . wfEscapeHTML($c) . ")</em>";