API: documentation and cleanup.
[lhc/web/wiklou.git] / includes / LogPage.php
index a1e4638..b8ef781 100644 (file)
@@ -50,36 +50,45 @@ class LogPage {
        function saveContent() {
                if( wfReadOnly() ) return false;
 
-               global $wgUser, $wgLogRestrictions;
+               global $wgUser;
                $fname = 'LogPage::saveContent';
 
                $dbw = wfGetDB( DB_MASTER );
                $uid = $wgUser->getID();
+               $log_id = $dbw->nextSequenceValue( 'log_log_id_seq' );
 
                $this->timestamp = $now = wfTimestampNow();
-               
-               $log_id = $dbw->nextSequenceValue( 'log_log_id_seq' );
-               $dbw->insert( 'logging',
-                       array(
-                               'log_type' => $this->type,
-                               'log_action' => $this->action,
-                               'log_timestamp' => $dbw->timestamp( $now ),
-                               'log_user' => $uid,
-                               'log_namespace' => $this->target->getNamespace(),
-                               'log_title' => $this->target->getDBkey(),
-                               'log_comment' => $this->comment,
-                               'log_params' => $this->params
-                       ), $fname
+               $data = array(
+                       'log_type' => $this->type,
+                       'log_action' => $this->action,
+                       'log_timestamp' => $dbw->timestamp( $now ),
+                       'log_user' => $uid,
+                       'log_namespace' => $this->target->getNamespace(),
+                       'log_title' => $this->target->getDBkey(),
+                       'log_comment' => $this->comment,
+                       'log_params' => $this->params
                );
-               $newId = $dbw->insertId();
+
+               # log_id doesn't exist on Wikimedia servers yet, and it's a tricky 
+               # schema update to do. Hack it for now to ignore the field on MySQL.
+               if ( !is_null( $log_id ) ) {
+                       $data['log_id'] = $log_id;
+               }
+               $dbw->insert( 'logging', $data, $fname );
 
                # And update recentchanges
                if ( $this->updateRecentChanges ) {
-                       # Don't add private logs to RC!!!
-                       if ( !isset($wgLogRestrictions[$this->type]) || $wgLogRestrictions[$this->type]=='*' ) {
-                               RecentChange::notifyLog( $now, $this->target, $wgUser, $this->actionText, '',
-                               $this->type, $this->action, $this->target, $this->comment, $this->params, $newId );
+                       $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
+                       $rcComment = $this->actionText;
+                       if( '' != $this->comment ) {
+                               if ($rcComment == '')
+                                       $rcComment = $this->comment;
+                               else
+                                       $rcComment .= ': ' . $this->comment;
                        }
+
+                       RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment, '',
+                               $this->type, $this->action, $this->target, $this->comment, $this->params );
                }
                return true;
        }
@@ -87,7 +96,7 @@ class LogPage {
        /**
         * @static
         */
-       function validTypes() {
+       public static function validTypes() {
                global $wgLogTypes;
                return $wgLogTypes;
        }
@@ -95,7 +104,7 @@ class LogPage {
        /**
         * @static
         */
-       function isLogType( $type ) {
+       public static function isLogType( $type ) {
                return in_array( $type, LogPage::validTypes() );
        }
 
@@ -114,18 +123,18 @@ class LogPage {
        }
 
        /**
-        * @fixme: handle missing log types
+        * @todo handle missing log types
         * @static
         */
-       function logHeader( $type ) {
+       static function logHeader( $type ) {
                global $wgLogHeaders;
-               return wfMsgHtml( $wgLogHeaders[$type] );
+               return wfMsg( $wgLogHeaders[$type] );
        }
 
        /**
         * @static
         */
-       function actionText( $type, $action, $title=NULL, $skin=NULL, $params = array(), $filterWikilinks=false, $translate=false, $forRC=false ) {
+       static function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false, $translate=false ) {
                global $wgLang, $wgContLang, $wgLogActions;
 
                $key = "$type/$action";
@@ -182,17 +191,14 @@ class LogPage {
                                        }
                                } else {
                                        array_unshift( $params, $titleLink );
-                                       // Oversighted blocks show as normal
-                                       if ( $translate && ($key == 'block/block' || $key == 'oversight/block') ) {
-                                               $params[1] = $wgLang->translateBlockExpiry( $params[1] );
+                                       if ( $key == 'block/block' ) {
+                                               if ( $translate ) {
+                                                       $params[1] = $wgLang->translateBlockExpiry( $params[1] );
+                                               }
                                                $params[2] = isset( $params[2] )
                                                                                ? self::formatBlockFlags( $params[2] )
                                                                                : '';
                                        }
-                                       if ( $forRC ) {
-                                               $params[1] = $wgLang->translateBlockExpiry( $params[1], true );
-                                               $params[2] = isset( $params[2] ) ? str_replace( ",", ", ", self::formatBlockFlags( $params[2] ) ) : '';
-                                       }
                                        $rv = wfMsgReal( $wgLogActions[$key], $params, true, !$skin );
                                }
                        }
@@ -224,7 +230,7 @@ class LogPage {
                $this->comment = $comment;
                $this->params = LogPage::makeParamBlob( $params );
 
-               $this->actionText = LogPage::actionText( $this->type, $action, $target, NULL, $params, false, false, true );
+               $this->actionText = LogPage::actionText( $this->type, $action, $target, NULL, $params );
 
                return $this->saveContent();
        }
@@ -233,7 +239,7 @@ class LogPage {
         * Create a blob from a parameter array
         * @static
         */
-       function makeParamBlob( $params ) {
+       static function makeParamBlob( $params ) {
                return implode( "\n", $params );
        }
 
@@ -241,7 +247,7 @@ class LogPage {
         * Extract a parameter array from a blob
         * @static
         */
-       function extractParams( $blob ) {
+       static function extractParams( $blob ) {
                if ( $blob === '' ) {
                        return array();
                } else {