* Support for table name prefixes throughout the code. No support yet for converting...
[lhc/web/wiklou.git] / includes / DifferenceEngine.php
index 1890ae4..df68822 100644 (file)
@@ -118,31 +118,33 @@ cellpadding='0' cellspacing='4px' class='diff'><tr>
        #
        function loadText()
        {
-               global $wgTitle, $wgOut, $wgLang, $wgIsMySQL;
+               global $wgTitle, $wgOut, $wgLang;
                $fname = "DifferenceEngine::loadText";
                
+               $dbr =& wfGetDB( DB_SLAVE );
                if ( 0 == $this->mNewid || 0 == $this->mOldid ) {
                        $wgOut->setArticleFlag( true );
                        $this->mNewtitle = wfMsg( "currentrev" );
                        $id = $wgTitle->getArticleID();
                        
-                       $sql = "SELECT cur_text, cur_user_text, cur_comment FROM cur WHERE cur_id={$id}";
-                       $res = wfQuery( $sql, DB_READ, $fname );
-                       if ( 0 == wfNumRows( $res ) ) { return false; }
+                       $s = $dbr->getArray( 'cur', array( 'cur_text', 'cur_user_text', 'cur_comment' ), 
+                               array( 'cur_id' => $id ), $fname );
+                       if ( $s === false ) { 
+                               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_namespace,old_title,old_timestamp,old_text,old_flags,old_user_text,old_comment FROM old WHERE " .
-                         "old_id={$this->mNewid}";
+                       $s = $dbr->getArray( 'old', array( 'old_namespace','old_title','old_timestamp', 'old_text',
+                               'old_flags','old_user_text','old_comment' ), array( 'old_id' => $this->mNewid ), $fname );
 
-                       $res = wfQuery( $sql, DB_READ, $fname );
-                       if ( 0 == wfNumRows( $res ) ) { return false; }
+                       if ( $s === false ) { 
+                               return false; 
+                       }
 
-                       $s = wfFetchObject( $res );
                        $this->mNewtext = Article::getRevisionText( $s );
 
                        $t = $wgLang->timeanddate( $s->old_timestamp, true );
@@ -152,21 +154,23 @@ cellpadding='0' cellspacing='4px' class='diff'><tr>
                        $this->mNewComment = $s->old_comment;
                }
                if ( 0 == $this->mOldid ) {
-                       $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 old $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 );
+                       $s = $dbr->getArray( 'old', 
+                               array( 'old_namespace','old_title','old_timestamp','old_text', 'old_flags','old_user_text','old_comment' ), 
+                               array( /* WHERE */
+                                       'old_namespace' => $this->mNewPage->getNamespace(), 
+                                       'old_title' => $this->mNewPage->getDBkey() 
+                               ), $fname, array( 'ORDER BY' => 'inverse_timestamp', 'USE INDEX' => 'name_title_timestamp' )
+                       );
                } else {
-                       $sql = "SELECT old_namespace,old_title,old_timestamp,old_text,old_flags,old_user_text,old_comment FROM old WHERE " .
-                         "old_id={$this->mOldid}";
-                       $res = wfQuery( $sql, DB_READ, $fname );
+                       $s = $dbr->getArray( 'old', 
+                               array( 'old_namespace','old_title','old_timestamp','old_text','old_flags','old_user_text','old_comment'),
+                               array( 'old_id' => $this->mOldid ), 
+                               $fname
+                       );
+               }
+               if ( $s === false ) { 
+                       return false; 
                }
-               if ( 0 == wfNumRows( $res ) ) { return false; }
-
-               $s = wfFetchObject( $res );
                $this->mOldPage = Title::MakeTitle( $s->old_namespace, $s->old_title );
                $this->mOldtext = Article::getRevisionText( $s );
 
@@ -1022,7 +1026,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;
        }
@@ -1123,8 +1127,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;
        }
 
@@ -1140,27 +1144,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" );
                }
        }
@@ -1168,7 +1172,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" );
                }
        }
@@ -1176,7 +1180,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" );
                }
        }
@@ -1189,7 +1193,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