Corrected spelling error
[lhc/web/wiklou.git] / includes / DifferenceEngine.php
index c676308..2e3937e 100644 (file)
@@ -7,6 +7,7 @@ class DifferenceEngine {
        /* private */ var $mOldtext, $mNewtext;
        /* private */ var $mOldUser, $mNewUser;
        /* private */ var $mOldComment, $mNewComment;
+       /* private */ var $mOldPage, $mNewPage;
        
        function DifferenceEngine( $old, $new )
        {
@@ -17,7 +18,9 @@ class DifferenceEngine {
        function showDiffPage()
        {
                global $wgUser, $wgTitle, $wgOut, $wgLang;
-
+               $fname = "DifferenceEngine::showDiffPage";
+               wfProfileIn( $fname );
+               
                $t = $wgTitle->getPrefixedText() . " (Diff: {$this->mOldid}, " .
                  "{$this->mNewid})";
                $mtext = wfMsg( "missingarticle", $t );
@@ -26,12 +29,28 @@ class DifferenceEngine {
                if ( ! $this->loadText() ) {
                        $wgOut->setPagetitle( wfMsg( "errorpagetitle" ) );
                        $wgOut->addHTML( $mtext );
+                       wfProfileOut( $fname );
                        return;
                }
                $wgOut->suppressQuickbar();
+               
+               $oldTitle = $this->mOldPage->getPrefixedText();
+               $newTitle = $this->mNewPage->getPrefixedText();
+               if( $oldTitle == $newTitle ) {
+                       $wgOut->setPageTitle( $newTitle );
+               } else {
+                       $wgOut->setPageTitle( $oldTitle . ", " . $newTitle );
+               }
                $wgOut->setSubtitle( wfMsg( "difference" ) );
                $wgOut->setRobotpolicy( "noindex,follow" );
                
+               if ( !( $this->mOldPage->userCanRead() && $this->mNewPage->userCanRead() ) ) {
+                       $wgOut->loginToUse();
+                       $wgOut->output();
+                       wfProfileOut( $fname );
+                       exit;
+               }
+
                $sk = $wgUser->getSkin();
                $talk = $wgLang->getNsText( NS_TALK );
                $contribs = wfMsg( "contribslink" );
@@ -65,6 +84,8 @@ class DifferenceEngine {
                  $oldHeader, $newHeader );
                $wgOut->addHTML( "<hr /><h2>{$this->mNewtitle}</h2>\n" );
                $wgOut->addWikiText( $this->mNewtext );
+               
+               wfProfileOut( $fname );
        }
 
        function showDiff( $otext, $ntext, $otitle, $ntitle )
@@ -97,9 +118,10 @@ cellpadding='0' cellspacing='4px' class='diff'><tr>
        #
        function loadText()
        {
-               global $wgTitle, $wgOut, $wgLang;
+               global $wgTitle, $wgOut, $wgLang, $wgIsMySQL, $wgIsPg;
                $fname = "DifferenceEngine::loadText";
                
+               $oldtable=$wgIsPg?'"old"':'old';
                if ( 0 == $this->mNewid || 0 == $this->mOldid ) {
                        $wgOut->setArticleFlag( true );
                        $this->mNewtitle = wfMsg( "currentrev" );
@@ -110,11 +132,12 @@ cellpadding='0' cellspacing='4px' class='diff'><tr>
                        if ( 0 == wfNumRows( $res ) ) { return false; }
 
                        $s = wfFetchObject( $res );
+                       $this->mNewPage = &$wgTitle;
                        $this->mNewtext = $s->cur_text;
                        $this->mNewUser = $s->cur_user_text;
                        $this->mNewComment = $s->cur_comment;
                } else {
-                       $sql = "SELECT old_timestamp,old_text,old_flags,old_user_text,old_comment FROM old WHERE " .
+                       $sql = "SELECT old_namespace,old_title,old_timestamp,old_text,old_flags,old_user_text,old_comment FROM $oldtable WHERE " .
                          "old_id={$this->mNewid}";
 
                        $res = wfQuery( $sql, DB_READ, $fname );
@@ -124,25 +147,28 @@ cellpadding='0' cellspacing='4px' class='diff'><tr>
                        $this->mNewtext = Article::getRevisionText( $s );
 
                        $t = $wgLang->timeanddate( $s->old_timestamp, true );
+                       $this->mNewPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
                        $this->mNewtitle = wfMsg( "revisionasof", $t );
                        $this->mNewUser = $s->old_user_text;
                        $this->mNewComment = $s->old_comment;
                }
                if ( 0 == $this->mOldid ) {
-                       $sql = "SELECT old_timestamp,old_text,old_flags,old_user_text,old_comment " .
-                         "FROM old USE INDEX (name_title_timestamp) WHERE " .
-                         "old_namespace=" . $wgTitle->getNamespace() . " AND " .
-                         "old_title='" . wfStrencode( $wgTitle->getDBkey() ) .
+                       $use_index=$wgIsMySQL?"USE INDEX (name_title_timestamp)":"";
+                       $sql = "SELECT old_namespace,old_title,old_timestamp,old_text,old_flags,old_user_text,old_comment " .
+                         "FROM $oldtable $use_index WHERE " .
+                         "old_namespace=" . $this->mNewPage->getNamespace() . " AND " .
+                         "old_title='" . wfStrencode( $this->mNewPage->getDBkey() ) .
                          "' ORDER BY inverse_timestamp LIMIT 1";
                        $res = wfQuery( $sql, DB_READ, $fname );
                } else {
-                       $sql = "SELECT old_timestamp,old_text,old_flags,old_user_text,old_comment FROM old WHERE " .
+                       $sql = "SELECT old_namespace,old_title,old_timestamp,old_text,old_flags,old_user_text,old_comment FROM $oldtable WHERE " .
                          "old_id={$this->mOldid}";
                        $res = wfQuery( $sql, DB_READ, $fname );
                }
                if ( 0 == wfNumRows( $res ) ) { return false; }
 
                $s = wfFetchObject( $res );
+               $this->mOldPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
                $this->mOldtext = Article::getRevisionText( $s );
 
                $t = $wgLang->timeanddate( $s->old_timestamp, true );
@@ -997,7 +1023,7 @@ class _HWLDF_WordAccumulator {
        function _flushGroup ($new_tag) {
                if ($this->_group !== '') {
          if ($this->_tag == 'mark') 
-                       $this->_line .= "<font color=\"red\">$this->_group</font>";
+                       $this->_line .= '<span class="diffchange">'.$this->_group.'</span>';
          else
                $this->_line .= $this->_group;
        }
@@ -1098,8 +1124,8 @@ class TableDiffFormatter extends DiffFormatter
                $l1 = wfMsg( "lineno", $xbeg );
                $l2 = wfMsg( "lineno", $ybeg );
 
-               $r = "<tr><td colspan='2' align='left'><strong>{$l1}</strong></td>\n" .
-                 "<td colspan='2' align='left'><strong>{$l2}</strong></td></tr>\n";
+               $r = '<tr><td colspan="2" align="left"><strong>'.$l1."</strong></td>\n" .
+                 '<td colspan="2" align="left"><strong>'.$l2."</strong></td></tr>\n";
                return $r;
        }
 
@@ -1115,27 +1141,27 @@ class TableDiffFormatter extends DiffFormatter
        }
 
        function addedLine( $line ) {
-               return "<td>+</td><td class='diff-addedline'>" .
-                 "<small>{$line}</small></td>";
+               return '<td>+</td><td class="diff-addedline">' .
+                 $line.'</td>';
        }
 
        function deletedLine( $line ) {
-               return "<td>-</td><td class='diff-deletedline'" .
-                 "<small>{$line}</small></td>";
+               return '<td>-</td><td class="diff-deletedline">' .
+                 $line.'</td>';
        }
 
        function emptyLine() {
-               return "<td colspan='2'>&nbsp;</td>";
+               return '<td colspan="2">&nbsp;</td>';
        }
 
        function contextLine( $line ) {
-               return "<td> </td><td class='diff-context'><small>{$line}</small></td>";
+               return '<td> </td><td class="diff-context">'.$line.'</td>';
        }
        
        function _added($lines) {
                global $wgOut;
                foreach ($lines as $line) {
-                       $wgOut->addHTML( "<tr>" . $this->emptyLine() .
+                       $wgOut->addHTML( '<tr>' . $this->emptyLine() .
                          $this->addedLine( $line ) . "</tr>\n" );
                }
        }
@@ -1143,7 +1169,7 @@ class TableDiffFormatter extends DiffFormatter
        function _deleted($lines) {
                global $wgOut;
                foreach ($lines as $line) {
-                       $wgOut->addHTML( "<tr>" . $this->deletedLine( $line ) .
+                       $wgOut->addHTML( '<tr>' . $this->deletedLine( $line ) .
                          $this->emptyLine() . "</tr>\n" );
                }
        }
@@ -1151,7 +1177,7 @@ class TableDiffFormatter extends DiffFormatter
        function _context( $lines ) {
                global $wgOut;
                foreach ($lines as $line) {
-                       $wgOut->addHTML( "<tr>" . $this->contextLine( $line ) .
+                       $wgOut->addHTML( '<tr>' . $this->contextLine( $line ) .
                          $this->contextLine( $line ) . "</tr>\n" );
                }
        }
@@ -1164,7 +1190,7 @@ class TableDiffFormatter extends DiffFormatter
 
                while ( $line = array_shift( $del ) ) {
                        $aline = array_shift( $add );
-                       $wgOut->addHTML( "<tr>" . $this->deletedLine( $line ) .
+                       $wgOut->addHTML( '<tr>' . $this->deletedLine( $line ) .
                          $this->addedLine( $aline ) . "</tr>\n" );
                }
                $this->_added( $add ); # If any leftovers