Cripple the wiki text stuff for now. It doesn't SEEM dangerous but I haven't tested...
[lhc/web/wiklou.git] / includes / SpecialLog.php
index a981310..dae0ce7 100644 (file)
@@ -14,7 +14,7 @@
 #
 # You should have received a copy of the GNU General Public License along
 # with this program; if not, write to the Free Software Foundation, Inc.,
-# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 # http://www.gnu.org/copyleft/gpl.html
 
 /**
@@ -29,7 +29,7 @@
 function wfSpecialLog( $par = '' ) {
        global $wgRequest;
        $logReader =& new LogReader( $wgRequest );
-       if( '' == $wgRequest->getVal( 'type' ) && !empty( $par ) ) {
+       if( $wgRequest->getVal( 'type' ) == '' && $par != '' ) {
                $logReader->limitType( $par );
        }
        $logViewer =& new LogViewer( $logReader );
@@ -61,8 +61,10 @@ class LogReader {
        function setupQuery( $request ) {
                $page = $this->db->tableName( 'page' );
                $user = $this->db->tableName( 'user' );
-               $this->joinClauses = array( "LEFT OUTER JOIN $page ON log_namespace=page_namespace AND log_title=page_title" );
-               $this->whereClauses = array( 'user_id=log_user' );
+               $this->joinClauses = array( 
+                       "LEFT OUTER JOIN $page ON log_namespace=page_namespace AND log_title=page_title",
+                       "INNER JOIN $user ON user_id=log_user" );
+               $this->whereClauses = array();
 
                $this->limitType( $request->getVal( 'type' ) );
                $this->limitUser( $request->getText( 'user' ) );
@@ -89,18 +91,25 @@ class LogReader {
 
        /**
         * Set the log reader to return only entries by the given user.
-        * @param string $name Valid user name
+        * @param string $name (In)valid user name
         * @private
         */
        function limitUser( $name ) {
-               $title = Title::makeTitle( NS_USER, $name );
-               if( empty( $name ) || is_null( $title ) ) {
+               if ( $name == '' )
                        return false;
-               }
-               $this->user = str_replace( '_', ' ', $title->getDBkey() );
-               $safename = $this->db->strencode( $this->user );
-               $user = $this->db->tableName( 'user' );
-               $this->whereClauses[] = "user_name='$safename'";
+               $usertitle = Title::makeTitle( NS_USER, $name );
+               if ( is_null( $usertitle ) )
+                       return false;
+               $this->user = $usertitle->getText();
+               
+               /* Fetch userid at first, if known, provides awesome query plan afterwards */
+               $userid = $this->db->selectField('user','user_id',array('user_name'=>$this->user));
+               if (!$userid)
+                       /* It should be nicer to abort query at all, 
+                          but for now it won't pass anywhere behind the optimizer */
+                       $this->whereClauses[] = "NULL";
+               else
+                       $this->whereClauses[] = "log_user=$userid";
        }
 
        /**
@@ -143,12 +152,12 @@ class LogReader {
        function getQuery() {
                $logging = $this->db->tableName( "logging" );
                $user = $this->db->tableName( 'user' );
-               $sql = "SELECT log_type, log_action, log_timestamp,
+               $sql = "SELECT /*! STRAIGHT_JOIN */ log_type, log_action, log_timestamp,
                        log_user, user_name,
                        log_namespace, log_title, page_id,
-                       log_comment, log_params FROM $user, $logging ";
+                       log_comment, log_params FROM $logging ";
                if( !empty( $this->joinClauses ) ) {
-                       $sql .= implode( ',', $this->joinClauses );
+                       $sql .= implode( ' ', $this->joinClauses );
                }
                if( !empty( $this->whereClauses ) ) {
                        $sql .= " WHERE " . implode( ' AND ', $this->whereClauses );
@@ -163,7 +172,7 @@ class LogReader {
         * @return ResultWrapper result object to return the relevant rows
         */
        function getRows() {
-               $res = $this->db->query( $this->getQuery() );
+               $res = $this->db->query( $this->getQuery(), 'LogReader::getRows' );
                return $this->db->resultObject( $res );
        }
 
@@ -237,7 +246,6 @@ class LogViewer {
         * @return object database result set
         */
        function getLogRows() {
-               global $wgLinkCache;
                $result = $this->reader->getRows();
                $this->numResults = 0;
 
@@ -254,9 +262,9 @@ class LogViewer {
                                $title = Title::newFromText( $paramArray[0] );
                                $batch->addObj( $title );
                        }
-                       $this->numResults++;
+                       ++$this->numResults;
                }
-               $batch->execute( $wgLinkCache );
+               $batch->execute();
 
                return $result;
        }
@@ -274,7 +282,6 @@ class LogViewer {
 
        function doShowList( &$out, $result ) {
                // Rewind result pointer and go through it again, making the HTML
-               $html='';
                if ($this->numResults > 0) {
                        $html = "\n<ul>\n";
                        $result->seek( 0 );
@@ -282,9 +289,11 @@ class LogViewer {
                                $html .= $this->logLine( $s );
                        }
                        $html .= "\n</ul>\n";
+                       $out->addHTML( $html );
+               } else {
+                       $out->addWikiText( wfMsg( 'logempty' ) );
                }
                $result->free();
-               $out->addHTML( $html );
        }
 
        /**
@@ -293,17 +302,18 @@ class LogViewer {
         * @private
         */
        function logLine( $s ) {
-               global $wgLang, $wgLinkCache;
+               global $wgLang;
                $title = Title::makeTitle( $s->log_namespace, $s->log_title );
                $user = Title::makeTitleSafe( NS_USER, $s->user_name );
                $time = $wgLang->timeanddate( wfTimestamp(TS_MW, $s->log_timestamp), true );
 
                // Enter the existence or non-existence of this page into the link cache,
                // for faster makeLinkObj() in LogPage::actionText()
+               $linkCache =& LinkCache::singleton();
                if( $s->page_id ) {
-                       $wgLinkCache->addGoodLinkObj( $s->page_id, $title );
+                       $linkCache->addGoodLinkObj( $s->page_id, $title );
                } else {
-                       $wgLinkCache->addBadLinkObj( $title );
+                       $linkCache->addBadLinkObj( $title );
                }
 
                $userLink = $this->skin->makeLinkObj( $user, htmlspecialchars( $s->user_name ) );