/**
* Interface for log entries. Every log entry has these methods.
+ *
* @since 1.19
*/
interface LogEntry {
+
/**
* The main log type.
+ *
* @return string
*/
public function getType();
/**
* The log subtype.
+ *
* @return string
*/
public function getSubtype();
/**
* The full logtype in format maintype/subtype.
+ *
* @return string
*/
public function getFullType();
/**
* Get the extra parameters stored for this message.
+ *
* @return array
*/
public function getParameters();
/**
* Get the user for performed this action.
+ *
* @return User
*/
public function getPerformer();
/**
* Get the target page of this action.
+ *
* @return Title
*/
public function getTarget();
/**
* Get the timestamp when the action was executed.
+ *
* @return string
*/
public function getTimestamp();
/**
* Get the user provided comment.
+ *
* @return string
*/
public function getComment();
/**
* Get the access restriction.
+ *
* @return string
*/
public function getDeleted();
/**
* Extends the LogEntryInterface with some basic functionality
+ *
* @since 1.19
*/
abstract class LogEntryBase implements LogEntry {
+
public function getFullType() {
return $this->getType() . '/' . $this->getSubtype();
}
/**
* Whether the parameters for this log are stored in new or
* old format.
+ *
* @return bool
*/
public function isLegacy() {
/**
* Create a blob from a parameter array
*
+ * @since 1.26
* @param array $params
* @return string
- * @since 1.26
*/
public static function makeParamBlob( $params ) {
return serialize( (array)$params );
/**
* Extract a parameter array from a blob
*
+ * @since 1.26
* @param string $blob
* @return array
- * @since 1.26
*/
public static function extractParams( $blob ) {
return unserialize( $blob );
/**
* This class wraps around database result row.
+ *
* @since 1.19
*/
class DatabaseLogEntry extends LogEntryBase {
- // Static->
/**
* Returns array of information that is needed for querying
* log entries. Array contains the following keys:
* tables, fields, conds, options and join_conds
+ *
* @return array
*/
public static function getSelectQueryData() {
);
$joins = array(
- // IP's don't have an entry in user table
+ // IPs don't have an entry in user table
'user' => array( 'LEFT JOIN', 'log_user=user_id' ),
);
/**
* Constructs new LogEntry from database result row.
* Supports rows from both logging and recentchanges table.
+ *
* @param stdClass|array $row
* @return DatabaseLogEntry
*/
}
}
- // Non-static->
-
/** @var stdClass Database result row. */
protected $row;
/** @var User */
protected $performer;
- /** @var bool Whether the parameters for this log entry are stored in new
- * or old format.
- */
+ /** @var bool Whether the parameters for this log entry are stored in new or old format. */
protected $legacy;
protected function __construct( $row ) {
/**
* Returns the unique database id.
+ *
* @return int
*/
public function getId() {
/**
* Returns whatever is stored in the database field.
+ *
* @return string
*/
protected function getRawParameters() {
return $this->row->log_params;
}
- // LogEntryBase->
-
public function isLegacy() {
// This does the check
$this->getParameters();
-
return $this->legacy;
}
- // LogEntry->
-
public function getType() {
return $this->row->log_type;
}
public function getPerformer() {
if ( !$this->performer ) {
$userId = (int)$this->row->log_user;
- if ( $userId !== 0 ) { // logged-in users
+ if ( $userId !== 0 ) {
+ // logged-in users
if ( isset( $this->row->user_name ) ) {
$this->performer = User::newFromRow( $this->row );
} else {
$this->performer = User::newFromId( $userId );
}
- } else { // IP users
+ } else {
+ // IP users
$userText = $this->row->log_user_text;
$this->performer = User::newFromName( $userText, false );
}
return $this->row->rc_params;
}
- // LogEntry->
-
public function getType() {
return $this->row->rc_log_type;
}
}
/**
- * Class for creating log entries manually, for
- * example to inject them into the database.
+ * Class for creating log entries manually, to inject them into the database.
+ *
* @since 1.19
*/
class ManualLogEntry extends LogEntryBase {
* Constructor.
*
* @since 1.19
- *
* @param string $type
* @param string $subtype
*/
* You can pass params to the log action message by prefixing the keys with
* a number and optional type, using colons to separate the fields. The
* numbering should start with number 4, the first three parameters are
- * hardcoded for every message. Example:
- * $entry->setParameters(
- * '4::color' => 'blue',
- * '5:number:count' => 3000,
- * 'animal' => 'dog'
- * );
+ * hardcoded for every message.
*
- * @since 1.19
+ * If you want to store stuff that should not be available in messages, don't
+ * prefix the array key with a number and don't use the colons.
+ *
+ * Example:
+ * $entry->setParameters(
+ * '4::color' => 'blue',
+ * '5:number:count' => 3000,
+ * 'animal' => 'dog'
+ * );
*
+ * @since 1.19
* @param array $parameters Associative array
*/
public function setParameters( $parameters ) {
* Set the user that performed the action being logged.
*
* @since 1.19
- *
* @param User $performer
*/
public function setPerformer( User $performer ) {
* Set the title of the object changed.
*
* @since 1.19
- *
* @param Title $target
*/
public function setTarget( Title $target ) {
* Set the timestamp of when the logged action took place.
*
* @since 1.19
- *
* @param string $timestamp
*/
public function setTimestamp( $timestamp ) {
* Set a comment associated with the action being logged.
*
* @since 1.19
- *
* @param string $comment
*/
public function setComment( $comment ) {
/**
* Set an associated revision id.
*
- * @since 1.27
+ * For example, the ID of the revision that was inserted to mark a page move
+ * or protection, file upload, etc.
*
+ * @since 1.27
* @param int $revId
*/
public function setAssociatedRevId( $revId ) {
}
/**
- * TODO: document
+ * Set the 'deleted' flag.
*
* @since 1.19
- *
- * @param int $deleted
+ * @param int $deleted One of LogPage::DELETED_* bitfield constants
*/
public function setDeleted( $deleted ) {
$this->deleted = $deleted;
}
/**
- * Inserts the entry into the logging table.
+ * Insert the entry into the `logging` table.
+ *
* @param IDatabase $dbw
* @return int ID of the log entry
* @throws MWException
$this->timestamp = wfTimestampNow();
}
- # Trim spaces on user supplied text
+ // Trim spaces on user supplied text
$comment = trim( $this->getComment() );
- # Truncate for whole multibyte characters.
+ // Truncate for whole multibyte characters.
$comment = $wgContLang->truncate( $comment, 255 );
$data = array(
/**
* Get a RecentChanges object for the log entry
+ *
* @param int $newId
* @return RecentChange
* @since 1.23
$user = $this->getPerformer();
$ip = "";
if ( $user->isAnon() ) {
- /*
- * "MediaWiki default" and friends may have
- * no IP address in their name
- */
+ // "MediaWiki default" and friends may have
+ // no IP address in their name
if ( IP::isIPAddress( $user->getName() ) ) {
$ip = $user->getName();
}
}
/**
- * Publishes the log entry.
+ * Publish the log entry.
+ *
* @param int $newId Id of the log entry.
* @param string $to One of: rcandudp (default), rc, udp
*/
}
}
- // LogEntry->
-
public function getType() {
return $this->type;
}