summaryrefslogtreecommitdiff
path: root/includes/logging/LogEntry.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /includes/logging/LogEntry.php
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/logging/LogEntry.php')
-rw-r--r--includes/logging/LogEntry.php126
1 files changed, 90 insertions, 36 deletions
diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php
index b2a8e50d..46c55157 100644
--- a/includes/logging/LogEntry.php
+++ b/includes/logging/LogEntry.php
@@ -33,7 +33,6 @@
* @since 1.19
*/
interface LogEntry {
-
/**
* The main log type.
* @return string
@@ -89,8 +88,8 @@ interface LogEntry {
public function getDeleted();
/**
- * @param $field Integer: one of LogPage::DELETED_* bitfield constants
- * @return Boolean
+ * @param int $field One of LogPage::DELETED_* bitfield constants
+ * @return bool
*/
public function isDeleted( $field );
}
@@ -100,7 +99,6 @@ interface LogEntry {
* @since 1.19
*/
abstract class LogEntryBase implements LogEntry {
-
public function getFullType() {
return $this->getType() . '/' . $this->getSubtype();
}
@@ -117,7 +115,6 @@ abstract class LogEntryBase implements LogEntry {
public function isLegacy() {
return false;
}
-
}
/**
@@ -160,12 +157,13 @@ class DatabaseLogEntry extends LogEntryBase {
/**
* Constructs new LogEntry from database result row.
* Supports rows from both logging and recentchanges table.
- * @param $row
+ * @param stdClass|array $row
* @return DatabaseLogEntry
*/
public static function newFromRow( $row ) {
- if ( is_array( $row ) && isset( $row['rc_logid'] ) ) {
- return new RCDatabaseLogEntry( (object)$row );
+ $row = (object)$row;
+ if ( isset( $row->rc_logid ) ) {
+ return new RCDatabaseLogEntry( $row );
} else {
return new self( $row );
}
@@ -173,10 +171,17 @@ class DatabaseLogEntry extends LogEntryBase {
// Non-static->
- /// Database result row.
+ /** @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.
+ */
+ protected $legacy;
+
protected function __construct( $row ) {
$this->row = $row;
}
@@ -202,6 +207,7 @@ class DatabaseLogEntry extends LogEntryBase {
public function isLegacy() {
// This does the check
$this->getParameters();
+
return $this->legacy;
}
@@ -229,6 +235,7 @@ class DatabaseLogEntry extends LogEntryBase {
$this->legacy = true;
}
}
+
return $this->params;
}
@@ -246,6 +253,7 @@ class DatabaseLogEntry extends LogEntryBase {
$this->performer = User::newFromName( $userText, false );
}
}
+
return $this->performer;
}
@@ -253,6 +261,7 @@ class DatabaseLogEntry extends LogEntryBase {
$namespace = $this->row->log_namespace;
$page = $this->row->log_title;
$title = Title::makeTitle( $namespace, $page );
+
return $title;
}
@@ -267,7 +276,6 @@ class DatabaseLogEntry extends LogEntryBase {
public function getDeleted() {
return $this->row->log_deleted;
}
-
}
class RCDatabaseLogEntry extends DatabaseLogEntry {
@@ -301,6 +309,7 @@ class RCDatabaseLogEntry extends DatabaseLogEntry {
$this->performer = User::newFromName( $userText, false );
}
}
+
return $this->performer;
}
@@ -308,6 +317,7 @@ class RCDatabaseLogEntry extends DatabaseLogEntry {
$namespace = $this->row->rc_namespace;
$page = $this->row->rc_title;
$title = Title::makeTitle( $namespace, $page );
+
return $title;
}
@@ -322,7 +332,6 @@ class RCDatabaseLogEntry extends DatabaseLogEntry {
public function getDeleted() {
return $this->row->rc_deleted;
}
-
}
/**
@@ -331,15 +340,35 @@ class RCDatabaseLogEntry extends DatabaseLogEntry {
* @since 1.19
*/
class ManualLogEntry extends LogEntryBase {
- protected $type; ///!< @var string
- protected $subtype; ///!< @var string
- protected $parameters = array(); ///!< @var array
- protected $relations = array(); ///!< @var array
- protected $performer; ///!< @var User
- protected $target; ///!< @var Title
- protected $timestamp; ///!< @var string
- protected $comment = ''; ///!< @var string
- protected $deleted; ///!< @var int
+ /** @var string Type of log entry */
+ protected $type;
+
+ /** @var string Sub type of log entry */
+ protected $subtype;
+
+ /** @var array Parameters for log entry */
+ protected $parameters = array();
+
+ /** @var array */
+ protected $relations = array();
+
+ /** @var User Performer of the action for the log entry */
+ protected $performer;
+
+ /** @var Title Target title for the log entry */
+ protected $target;
+
+ /** @var string Timestamp of creation of the log entry */
+ protected $timestamp;
+
+ /** @var string Comment for the log entry */
+ protected $comment = '';
+
+ /** @var int Deletion state of the log entry */
+ protected $deleted;
+
+ /** @var int ID of the log entry */
+ protected $id;
/**
* Constructor.
@@ -378,7 +407,7 @@ class ManualLogEntry extends LogEntryBase {
* Declare arbitrary tag/value relations to this log entry.
* These can be used to filter log entries later on.
*
- * @param array Map of (tag => (list of values))
+ * @param array $relations Map of (tag => (list of values|value))
* @since 1.22
*/
public function setRelations( array $relations ) {
@@ -434,7 +463,7 @@ class ManualLogEntry extends LogEntryBase {
*
* @since 1.19
*
- * @param integer $deleted
+ * @param int $deleted
*/
public function setDeleted( $deleted ) {
$this->deleted = $deleted;
@@ -443,7 +472,8 @@ class ManualLogEntry extends LogEntryBase {
/**
* Inserts the entry into the logging table.
* @param IDatabase $dbw
- * @return int If of the log entry
+ * @return int ID of the log entry
+ * @throws MWException
*/
public function insert( IDatabase $dbw = null ) {
global $wgContLang;
@@ -474,6 +504,10 @@ class ManualLogEntry extends LogEntryBase {
'log_comment' => $comment,
'log_params' => serialize( (array)$this->getParameters() ),
);
+ if ( isset( $this->deleted ) ) {
+ $data['log_deleted'] = $this->deleted;
+ }
+
$dbw->insert( 'logging', $data, __METHOD__ );
$this->id = !is_null( $id ) ? $id : $dbw->insertId();
@@ -482,10 +516,15 @@ class ManualLogEntry extends LogEntryBase {
if ( !strlen( $tag ) ) {
throw new MWException( "Got empty log search tag." );
}
+
+ if ( !is_array( $values ) ) {
+ $values = array( $values );
+ }
+
foreach ( $values as $value ) {
$rows[] = array(
- 'ls_field' => $tag,
- 'ls_value' => $value,
+ 'ls_field' => $tag,
+ 'ls_value' => $value,
'ls_log_id' => $this->id
);
}
@@ -494,20 +533,20 @@ class ManualLogEntry extends LogEntryBase {
$dbw->insert( 'log_search', $rows, __METHOD__, 'IGNORE' );
}
+ // Update any bloom filter cache
+ $member = $this->getTarget()->getNamespace() . ':' . $this->getTarget()->getDBkey();
+ BloomCache::get( 'main' )->insert( wfWikiId(), 'TitleHasLogs', $member );
+
return $this->id;
}
/**
- * Publishes the log entry.
- * @param int $newId id of the log entry.
- * @param string $to rcandudp (default), rc, udp
+ * Get a RecentChanges object for the log entry
+ * @param int $newId
+ * @return RecentChange
+ * @since 1.23
*/
- public function publish( $newId, $to = 'rcandudp' ) {
- $log = new LogPage( $this->getType() );
- if ( $log->isRestricted() ) {
- return;
- }
-
+ public function getRecentChange( $newId = 0 ) {
$formatter = LogFormatter::newFromEntry( $this );
$context = RequestContext::newExtraneousContext( $this->getTarget() );
$formatter->setContext( $context );
@@ -524,7 +563,8 @@ class ManualLogEntry extends LogEntryBase {
$ip = $user->getName();
}
}
- $rc = RecentChange::newLogEntry(
+
+ return RecentChange::newLogEntry(
$this->getTimestamp(),
$logpage,
$user,
@@ -538,6 +578,20 @@ class ManualLogEntry extends LogEntryBase {
$newId,
$formatter->getIRCActionComment() // Used for IRC feeds
);
+ }
+
+ /**
+ * Publishes the log entry.
+ * @param int $newId Id of the log entry.
+ * @param string $to One of: rcandudp (default), rc, udp
+ */
+ public function publish( $newId, $to = 'rcandudp' ) {
+ $log = new LogPage( $this->getType() );
+ if ( $log->isRestricted() ) {
+ return;
+ }
+
+ $rc = $this->getRecentChange( $newId );
if ( $to === 'rc' || $to === 'rcandudp' ) {
$rc->save( 'pleasedontudp' );
@@ -578,6 +632,7 @@ class ManualLogEntry extends LogEntryBase {
public function getTimestamp() {
$ts = $this->timestamp !== null ? $this->timestamp : wfTimestampNow();
+
return wfTimestamp( TS_MW, $ts );
}
@@ -588,5 +643,4 @@ class ManualLogEntry extends LogEntryBase {
public function getDeleted() {
return (int)$this->deleted;
}
-
}