Fix NS_PROJECT_TALK (bug #7792)
[lhc/web/wiklou.git] / includes / SpecialLog.php
index 52b388b..7076d81 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
 
 /**
  */
 function wfSpecialLog( $par = '' ) {
        global $wgRequest;
-       $logReader =& new LogReader( $wgRequest );
+       $logReader = new LogReader( $wgRequest );
        if( $wgRequest->getVal( 'type' ) == '' && $par != '' ) {
                $logReader->limitType( $par );
        }
-       $logViewer =& new LogViewer( $logReader );
+       $logViewer = new LogViewer( $logReader );
        $logViewer->show();
 }
 
@@ -56,13 +56,15 @@ class LogReader {
        /**
         * Basic setup and applies the limiting factors from the WebRequest object.
         * @param WebRequest $request
-        * @access private
+        * @private
         */
        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' ) );
@@ -76,7 +78,7 @@ class LogReader {
        /**
         * Set the log reader to return only entries of the given type.
         * @param string $type A log type ('upload', 'delete', etc)
-        * @access private
+        * @private
         */
        function limitType( $type ) {
                if( empty( $type ) ) {
@@ -90,25 +92,31 @@ class LogReader {
        /**
         * Set the log reader to return only entries by the given user.
         * @param string $name (In)valid user name
-        * @access private
+        * @private
         */
        function limitUser( $name ) {
                if ( $name == '' )
                        return false;
-               $title = Title::makeTitle( NS_USER, $name );
-               if ( is_null( $title ) )
+               $usertitle = Title::makeTitleSafe( NS_USER, $name );
+               if ( is_null( $usertitle ) )
                        return false;
-               $this->user = $title->getText();
-               $safename = $this->db->strencode( $this->user );
-               $user = $this->db->tableName( 'user' );
-               $this->whereClauses[] = "user_name='$safename'";
+               $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";
        }
 
        /**
         * Set the log reader to return only entries affecting the given page.
         * (For the block and rights logs, this is a user page.)
         * @param string $page Title name as text
-        * @access private
+        * @private
         */
        function limitTitle( $page ) {
                $title = Title::newFromText( $page );
@@ -125,7 +133,7 @@ class LogReader {
         * Set the log reader to return only entries in a given time range.
         * @param string $time Timestamp of one endpoint
         * @param string $direction either ">=" or "<=" operators
-        * @access private
+        * @private
         */
        function limitTime( $time, $direction ) {
                # Direction should be a comparison operator
@@ -139,20 +147,16 @@ class LogReader {
        /**
         * Build an SQL query from all the set parameters.
         * @return string the SQL query
-        * @access private
+        * @private
         */
        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 ";
-               if ($this->type=="" && $this->db->indexExists('logging','times')) {
-                       $sql .= ' /*! FORCE INDEX (times) */ ';
-               }
+                       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 );
@@ -167,7 +171,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 );
        }
 
@@ -294,12 +298,11 @@ class LogViewer {
        /**
         * @param Object $s a single row from the result set
         * @return string Formatted HTML list item
-        * @access private
+        * @private
         */
        function logLine( $s ) {
                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,
@@ -311,12 +314,12 @@ class LogViewer {
                        $linkCache->addBadLinkObj( $title );
                }
 
-               $userLink = $this->skin->makeLinkObj( $user, htmlspecialchars( $s->user_name ) );
+               $userLink = $this->skin->userLink( $s->log_user, $s->user_name ) . $this->skin->userToolLinks( $s->log_user, $s->user_name );
                $comment = $this->skin->commentBlock( $s->log_comment );
                $paramArray = LogPage::extractParams( $s->log_params );
                $revert = '';
                if ( $s->log_type == 'move' && isset( $paramArray[0] ) ) {
-                       $specialTitle = Title::makeTitle( NS_SPECIAL, 'Movepage' );
+                       $specialTitle = SpecialPage::getTitleFor( 'Movepage' );
                        $destTitle = Title::newFromText( $paramArray[0] );
                        if ( $destTitle ) {
                                $revert = '(' . $this->skin->makeKnownLinkObj( $specialTitle, wfMsg( 'revertmove' ),
@@ -334,7 +337,7 @@ class LogViewer {
 
        /**
         * @param OutputPage &$out where to send output
-        * @access private
+        * @private
         */
        function showHeader( &$out ) {
                $type = $this->reader->queryType();
@@ -346,12 +349,12 @@ class LogViewer {
 
        /**
         * @param OutputPage &$out where to send output
-        * @access private
+        * @private
         */
        function showOptions( &$out ) {
                global $wgScript;
                $action = htmlspecialchars( $wgScript );
-               $title = Title::makeTitle( NS_SPECIAL, 'Log' );
+               $title = SpecialPage::getTitleFor( 'Log' );
                $special = htmlspecialchars( $title->getPrefixedDBkey() );
                $out->addHTML( "<form action=\"$action\" method=\"get\">\n" .
                        "<input type='hidden' name='title' value=\"$special\" />\n" .
@@ -364,7 +367,7 @@ class LogViewer {
 
        /**
         * @return string Formatted HTML
-        * @access private
+        * @private
         */
        function getTypeMenu() {
                $out = "<select name='type'>\n";
@@ -379,7 +382,7 @@ class LogViewer {
 
        /**
         * @return string Formatted HTML
-        * @access private
+        * @private
         */
        function getUserInput() {
                $user = htmlspecialchars( $this->reader->queryUser() );
@@ -388,7 +391,7 @@ class LogViewer {
 
        /**
         * @return string Formatted HTML
-        * @access private
+        * @private
         */
        function getTitleInput() {
                $title = htmlspecialchars( $this->reader->queryTitle() );
@@ -397,7 +400,7 @@ class LogViewer {
 
        /**
         * @param OutputPage &$out where to send output
-        * @access private
+        * @private
         */
        function showPrevNext( &$out ) {
                global $wgContLang,$wgRequest;