Merge "[FileBackend] Worked around Akamai CDN purge limits."
[lhc/web/wiklou.git] / includes / logging / LogEntry.php
index f279ee5..37560d8 100644 (file)
@@ -7,6 +7,21 @@
  * - formatting log entries based on database fields
  * - user is now part of the action message
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @author Niklas Laxström
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
@@ -97,6 +112,7 @@ abstract class LogEntryBase implements LogEntry {
        /**
         * Whether the parameters for this log are stored in new or
         * old format.
+        * @return bool
         */
        public function isLegacy() {
                return false;
@@ -127,8 +143,6 @@ class DatabaseLogEntry extends LogEntryBase {
                        'user_id', 'user_name', 'user_editcount',
                );
 
-               $conds = array();
-
                $joins = array(
                        // IP's don't have an entry in user table
                        'user' => array( 'LEFT JOIN', 'log_user=user_id' ),
@@ -210,14 +224,8 @@ class DatabaseLogEntry extends LogEntryBase {
                                $this->params = $params;
                                $this->legacy = false;
                        } else {
-                               $params = FormatJson::decode( $blob, true /* array */ );
-                               if ( $params !== null ) {
-                                       $this->params = $params;
-                                       $this->legacy = false;
-                               } else {
-                                       $this->params = explode( "\n", $blob );
-                                       $this->legacy = true;
-                               }
+                               $this->params = $blob === '' ? array() : explode( "\n", $blob );
+                               $this->legacy = true;
                        }
                }
                return $this->params;
@@ -225,9 +233,13 @@ class DatabaseLogEntry extends LogEntryBase {
 
        public function getPerformer() {
                $userId = (int) $this->row->log_user;
-               if ( $userId !== 0 ) {
-                       return User::newFromRow( $this->row );
-               } else {
+               if ( $userId !== 0 ) { // logged-in users
+                       if ( isset( $this->row->user_name ) ) {
+                               return User::newFromRow( $this->row );
+                       } else {
+                               return User::newFromId( $userId );
+                       }
+               } else { // IP users
                        $userText = $this->row->log_user_text;
                        return User::newFromName( $userText, false );
                }
@@ -318,16 +330,24 @@ class ManualLogEntry extends LogEntryBase {
        protected $performer; ///!< @var User
        protected $target; ///!< @var Title
        protected $timestamp; ///!< @var string
-       protected $comment; ///!< @var string
+       protected $comment = ''; ///!< @var string
        protected $deleted; ///!< @var int
 
+       /**
+        * Constructor.
+        * 
+        * @since 1.19
+        * 
+        * @param string $type
+        * @param string $subtype
+        */
        public function __construct( $type, $subtype ) {
                $this->type = $type;
                $this->subtype = $subtype;
        }
 
        /**
-        * Set extra log parameters. 
+        * Set extra log parameters.
         * You can pass params to the log action message
         * by prefixing the keys with a number and colon.
         * The numbering should start with number 4, the
@@ -337,28 +357,66 @@ class ManualLogEntry extends LogEntryBase {
         *   '4:color' => 'blue',
         *   'animal' => 'dog'
         * );
-        * @param $parameters Associative array
+        * 
+        * @since 1.19
+        * 
+        * @param $parameters array Associative array
         */
        public function setParameters( $parameters ) {
                $this->parameters = $parameters;
        }
 
+       /**
+        * Set the user that performed the action being logged.
+        * 
+        * @since 1.19
+        * 
+        * @param User $performer
+        */
        public function setPerformer( User $performer ) {
                $this->performer = $performer;
        }
 
+       /**
+        * Set the title of the object changed.
+        * 
+        * @since 1.19
+        * 
+        * @param Title $target
+        */
        public function setTarget( Title $target ) {
                $this->target = $target;
        }
 
+       /**
+        * Set the timestamp of when the logged action took place.
+        * 
+        * @since 1.19
+        * 
+        * @param string $timestamp
+        */
        public function setTimestamp( $timestamp ) {
                $this->timestamp = $timestamp;
        }
 
+       /**
+        * Set a comment associated with the action being logged.
+        * 
+        * @since 1.19
+        * 
+        * @param string $comment
+        */
        public function setComment( $comment ) {
                $this->comment = $comment;
        }
 
+       /**
+        * TODO: document
+        * 
+        * @since 1.19
+        * 
+        * @param integer $deleted
+        */
        public function setDeleted( $deleted ) {
                $this->deleted = $deleted;
        }
@@ -368,7 +426,7 @@ class ManualLogEntry extends LogEntryBase {
         * @return int If of the log entry
         */
        public function insert() {
-               global $wgLogRestrictions;
+               global $wgContLang;
 
                $dbw = wfGetDB( DB_MASTER );
                $id = $dbw->nextSequenceValue( 'logging_log_id_seq' );
@@ -377,6 +435,9 @@ class ManualLogEntry extends LogEntryBase {
                        $this->timestamp = wfTimestampNow();
                }
 
+               # Truncate for whole multibyte characters.
+               $comment = $wgContLang->truncate( $this->getComment(), 255 );
+
                $data = array(
                        'log_id' => $id,
                        'log_type' => $this->getType(),
@@ -386,8 +447,8 @@ class ManualLogEntry extends LogEntryBase {
                        'log_user_text' => $this->getPerformer()->getName(),
                        'log_namespace' => $this->getTarget()->getNamespace(),
                        'log_title' => $this->getTarget()->getDBkey(),
-                       'log_page' => $this->getTarget()->getArticleId(),
-                       'log_comment' => $this->getComment(),
+                       'log_page' => $this->getTarget()->getArticleID(),
+                       'log_comment' => $comment,
                        'log_params' => serialize( (array) $this->getParameters() ),
                );
                $dbw->insert( 'logging', $data, __METHOD__ );
@@ -412,22 +473,33 @@ class ManualLogEntry extends LogEntryBase {
 
                $logpage = SpecialPage::getTitleFor( 'Log', $this->getType() );
                $user = $this->getPerformer();
+               $ip = "";
+               if ( $user->isAnon() ) {
+                       /*
+                        * "MediaWiki default" and friends may have
+                        * no IP address in their name
+                        */
+                       if ( IP::isIPAddress( $user->getName() ) ) {
+                               $ip = $user->getName();
+                       }
+               }
                $rc = RecentChange::newLogEntry(
                        $this->getTimestamp(),
                        $logpage,
                        $user,
-                       $formatter->getPlainActionText(), // Used for IRC feeds
-                       $user->isAnon() ? $user->getName() : '',
+                       $formatter->getPlainActionText(),
+                       $ip,
                        $this->getType(),
                        $this->getSubtype(),
                        $this->getTarget(),
                        $this->getComment(),
                        serialize( (array) $this->getParameters() ),
-                       $newId
+                       $newId,
+                       $formatter->getIRCActionComment() // Used for IRC feeds
                );
 
                if ( $to === 'rc' || $to === 'rcandudp' ) {
-                       $rc->save();
+                       $rc->save( 'pleasedontudp' );
                }
 
                if ( $to === 'udp' || $to === 'rcandudp' ) {
@@ -449,10 +521,16 @@ class ManualLogEntry extends LogEntryBase {
                return $this->parameters;
        }
 
+       /**
+        * @return User
+        */
        public function getPerformer() {
                return $this->performer;
        }
 
+       /**
+        * @return Title
+        */
        public function getTarget() {
                return $this->target;
        }
@@ -470,4 +548,4 @@ class ManualLogEntry extends LogEntryBase {
                return (int) $this->deleted;
        }
 
-}
\ No newline at end of file
+}