* - 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
/**
* Whether the parameters for this log are stored in new or
* old format.
+ * @return bool
*/
public function isLegacy() {
return false;
'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' ),
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 );
}
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
* '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;
}
* @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' );
$this->timestamp = wfTimestampNow();
}
+ # Truncate for whole multibyte characters.
+ $comment = $wgContLang->truncate( $this->getComment(), 255 );
+
$data = array(
'log_id' => $id,
'log_type' => $this->getType(),
'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__ );
$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' ) {
return $this->parameters;
}
+ /**
+ * @return User
+ */
public function getPerformer() {
return $this->performer;
}
+ /**
+ * @return Title
+ */
public function getTarget() {
return $this->target;
}
return (int) $this->deleted;
}
-}
\ No newline at end of file
+}