Changed LogPage::actionText() calling convention to allow for 1.4-style move page...
authorTim Starling <tstarling@users.mediawiki.org>
Sun, 3 Apr 2005 07:36:50 +0000 (07:36 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sun, 3 Apr 2005 07:36:50 +0000 (07:36 +0000)
includes/LogPage.php
includes/SpecialLog.php

index eeec52f..a94f965 100644 (file)
@@ -32,7 +32,7 @@
  * @package MediaWiki
  */
 class LogPage {
-       /* private */ var $type, $action, $comment, $params;
+       /* private */ var $type, $action, $comment, $params, $target;
        var $updateRecentChanges = true;
 
        function LogPage( $type ) {
@@ -65,11 +65,12 @@ class LogPage {
                
                # And update recentchanges
                if ( $this->updateRecentChanges ) {
+                       $titleObj = Title::makeTitle( NS_SPECIAL, 'Log/' . $this->type );
                        $rcComment = $this->actionText;
                        if( '' != $this->comment ) {
                                $rcComment .= ': ' . $this->comment;
                        }
-                       $titleObj = Title::makeTitle( NS_SPECIAL, 'Log/' . $this->type );
+                       
                        RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment );
                }
                return true;
@@ -141,7 +142,7 @@ class LogPage {
        /**
         * @static
         */
-       function actionText( $type, $action, $titleLink = NULL, $params = array(), $filterWikilinks=false ) {
+       function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false ) {
                static $actions = array(
                        'block/block' => 'blocklogentry',
                        'block/unblock' => 'unblocklogentry',
@@ -157,13 +158,28 @@ class LogPage {
                );
                $key = "$type/$action";
                if( isset( $actions[$key] ) ) {
-                       if( is_null( $titleLink ) ) {
+                       if( is_null( $title ) ) {
                                $rv=wfMsgForContent( $actions[$key] );
-                       } elseif ( count( $params ) == 0 ) {
-                               $rv=wfMsgForContent( $actions[$key], $titleLink );
-                       } else {
-                               array_unshift( $params, $titleLink );
-                               $rv=wfMsgReal( $actions[$key], $params, true, true );
+                       } 
+                       else {
+                               if ( $skin ) {
+                                       if ( $type == 'move' ) {
+                                               $titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
+                                               // Change $param[0] into a link to the title specified in $param[0]
+                                               $movedTo = Title::newFromText( $params[0] );
+                                               $params[0] = $skin->makeLinkObj( $movedTo, $params[0] );
+                                       } else {
+                                               $titleLink = $skin->makeLinkObj( $title );
+                                       }
+                               } else {
+                                       $titleLink = $title->getPrefixedText();
+                               }
+                               if ( count( $params ) == 0 ) {
+                                       $rv=wfMsgForContent( $actions[$key], $titleLink );
+                               } else {
+                                       array_unshift( $params, $titleLink );
+                                       $rv=wfMsgReal( $actions[$key], $params, true, true );
+                               }
                        }
                } else {
                        wfDebug( "LogPage::actionText - unknown action $key\n" );
@@ -178,7 +194,7 @@ class LogPage {
 
        /**
         * Add a log entry
-        * @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload'
+        * @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
         * @param object &$target A title object.
         * @param string $comment Description associated
         * @param array $params Parameters passed later to wfMsg.* functions
@@ -196,7 +212,8 @@ class LogPage {
                $this->params = LogPage::makeParamBlob( $params );
                
                $this->actionText = LogPage::actionText( $this->type, $action, 
-                 $target->getPrefixedText(), $params );
+                 $target, NULL, $params );
+
                return $this->saveContent();
        }
 
index f7df7c5..9725ba7 100644 (file)
@@ -231,8 +231,28 @@ class LogViewer {
         * @param OutputPage $out where to send output
         */
        function showList( &$out ) {
-               $html = "\n<ul>\n";
+               global $wgLinkCache;
                $result = $this->reader->getRows();
+
+               // Fetch results and form a batch link existence query
+               $batch = new LinkBatch;
+               while ( $s = $result->fetchObject() ) {
+                       // User link
+                       $title = Title::makeTitleSafe( NS_USER, $s->user_name );
+                       $batch->addObj( $title );
+
+                       // Move destination link
+                       if ( $s->log_type == 'move' ) {
+                               $paramArray = LogPage::extractParams( $s->log_params );
+                               $title = Title::newFromText( $paramArray[0] );
+                               $batch->addObj( $title );
+                       }
+               }
+               $batch->execute( $wgLinkCache );
+
+               // Rewind result pointer and go through it again, making the HTML
+               $result->seek( 0 );
+               $html = "\n<ul>\n";
                while( $s = $result->fetchObject() ) {
                        $html .= $this->logLine( $s );
                }
@@ -247,20 +267,24 @@ class LogViewer {
         * @private
         */
        function logLine( $s ) {
-               global $wgLang;
+               global $wgLang, $wgLinkCache;
                $title = Title::makeTitle( $s->log_namespace, $s->log_title );
                $user = Title::makeTitleSafe( NS_USER, $s->user_name );
                $time = $wgLang->timeanddate( $s->log_timestamp, true );
+
+               // Enter the existence or non-existence of this page into the link cache,
+               // for faster makeLinkObj() in LogPage::actionText()
                if( $s->page_id ) {
-                       $titleLink = $this->skin->makeKnownLinkObj( $title );
+                       $wgLinkCache->addGoodLink( $s->page_id, $title->getPrefixedText() );
                } else {
-                       $titleLink = $this->skin->makeBrokenLinkObj( $title );
+                       $wgLinkCache->addBadLink( $title->getPrefixedText() );
                }
+               
                $userLink = $this->skin->makeLinkObj( $user, htmlspecialchars( $s->user_name ) );
                $comment = $this->skin->commentBlock( $s->log_comment );
                $paramArray = LogPage::extractParams( $s->log_params );
                
-               $action = LogPage::actionText( $s->log_type, $s->log_action, $titleLink, $paramArray, true );
+               $action = LogPage::actionText( $s->log_type, $s->log_action, $title, $this->skin, $paramArray, true );
                $out = "<li>$time $userLink $action $comment</li>\n";
                return $out;
        }