2011-09-07 15:32:37 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Contain classes for dealing with individual log entries
|
|
|
|
|
*
|
|
|
|
|
* This is how I see the log system history:
|
|
|
|
|
* - appending to plain wiki pages
|
|
|
|
|
* - formatting log entries based on database fields
|
|
|
|
|
* - user is now part of the action message
|
|
|
|
|
*
|
2012-04-30 07:16:10 +00:00
|
|
|
* 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
|
|
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @file
|
|
|
|
|
* @author Niklas Laxström
|
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
|
2017-02-10 18:09:05 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
|
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
/**
|
|
|
|
|
* Interface for log entries. Every log entry has these methods.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
interface LogEntry {
|
2015-12-28 23:56:18 +00:00
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
/**
|
|
|
|
|
* The main log type.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getType();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The log subtype.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getSubtype();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The full logtype in format maintype/subtype.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getFullType();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the extra parameters stored for this message.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getParameters();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the user for performed this action.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return User
|
|
|
|
|
*/
|
|
|
|
|
public function getPerformer();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the target page of this action.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return Title
|
|
|
|
|
*/
|
|
|
|
|
public function getTarget();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the timestamp when the action was executed.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getTimestamp();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the user provided comment.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getComment();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the access restriction.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getDeleted();
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-19 20:22:20 +00:00
|
|
|
* @param int $field One of LogPage::DELETED_* bitfield constants
|
|
|
|
|
* @return bool
|
2011-09-07 15:32:37 +00:00
|
|
|
*/
|
|
|
|
|
public function isDeleted( $field );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extends the LogEntryInterface with some basic functionality
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
abstract class LogEntryBase implements LogEntry {
|
2015-12-28 23:56:18 +00:00
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
public function getFullType() {
|
|
|
|
|
return $this->getType() . '/' . $this->getSubtype();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isDeleted( $field ) {
|
|
|
|
|
return ( $this->getDeleted() & $field ) === $field;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the parameters for this log are stored in new or
|
|
|
|
|
* old format.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool
|
2011-09-07 15:32:37 +00:00
|
|
|
*/
|
|
|
|
|
public function isLegacy() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-03-28 17:55:45 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a blob from a parameter array
|
|
|
|
|
*
|
2015-12-28 23:56:18 +00:00
|
|
|
* @since 1.26
|
2015-03-28 17:55:45 +00:00
|
|
|
* @param array $params
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function makeParamBlob( $params ) {
|
|
|
|
|
return serialize( (array)$params );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract a parameter array from a blob
|
|
|
|
|
*
|
2015-12-28 23:56:18 +00:00
|
|
|
* @since 1.26
|
2015-03-28 17:55:45 +00:00
|
|
|
* @param string $blob
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function extractParams( $blob ) {
|
|
|
|
|
return unserialize( $blob );
|
|
|
|
|
}
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class wraps around database result row.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
class DatabaseLogEntry extends LogEntryBase {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns array of information that is needed for querying
|
|
|
|
|
* log entries. Array contains the following keys:
|
|
|
|
|
* tables, fields, conds, options and join_conds
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getSelectQueryData() {
|
2018-01-24 23:41:01 +00:00
|
|
|
$commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
|
2017-06-06 17:39:14 +00:00
|
|
|
|
|
|
|
|
$tables = [ 'logging', 'user' ] + $commentQuery['tables'];
|
2016-02-17 09:09:32 +00:00
|
|
|
$fields = [
|
2011-09-07 15:32:37 +00:00
|
|
|
'log_id', 'log_type', 'log_action', 'log_timestamp',
|
|
|
|
|
'log_user', 'log_user_text',
|
2011-09-07 17:25:52 +00:00
|
|
|
'log_namespace', 'log_title', // unused log_page
|
2017-06-06 17:39:14 +00:00
|
|
|
'log_params', 'log_deleted',
|
2011-09-07 15:32:37 +00:00
|
|
|
'user_id', 'user_name', 'user_editcount',
|
2017-06-06 17:39:14 +00:00
|
|
|
] + $commentQuery['fields'];
|
2011-09-07 15:32:37 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$joins = [
|
2015-12-28 23:56:18 +00:00
|
|
|
// IPs don't have an entry in user table
|
2016-02-17 09:09:32 +00:00
|
|
|
'user' => [ 'LEFT JOIN', 'log_user=user_id' ],
|
2017-06-06 17:39:14 +00:00
|
|
|
] + $commentQuery['joins'];
|
2011-09-07 15:32:37 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2011-09-07 15:32:37 +00:00
|
|
|
'tables' => $tables,
|
|
|
|
|
'fields' => $fields,
|
2016-02-17 09:09:32 +00:00
|
|
|
'conds' => [],
|
|
|
|
|
'options' => [],
|
2011-09-07 15:32:37 +00:00
|
|
|
'join_conds' => $joins,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs new LogEntry from database result row.
|
|
|
|
|
* Supports rows from both logging and recentchanges table.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2013-12-27 12:56:52 +00:00
|
|
|
* @param stdClass|array $row
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return DatabaseLogEntry
|
|
|
|
|
*/
|
|
|
|
|
public static function newFromRow( $row ) {
|
2013-12-31 06:42:35 +00:00
|
|
|
$row = (object)$row;
|
|
|
|
|
if ( isset( $row->rc_logid ) ) {
|
|
|
|
|
return new RCDatabaseLogEntry( $row );
|
2011-09-07 15:32:37 +00:00
|
|
|
} else {
|
|
|
|
|
return new self( $row );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 18:26:59 +00:00
|
|
|
/** @var stdClass Database result row. */
|
2011-09-07 15:32:37 +00:00
|
|
|
protected $row;
|
2013-12-03 18:26:59 +00:00
|
|
|
|
|
|
|
|
/** @var User */
|
2012-10-21 15:57:54 +00:00
|
|
|
protected $performer;
|
2011-09-07 15:32:37 +00:00
|
|
|
|
2015-12-29 00:21:50 +00:00
|
|
|
/** @var array Parameters for log entry */
|
|
|
|
|
protected $params;
|
|
|
|
|
|
|
|
|
|
/** @var int A rev id associated to the log entry */
|
|
|
|
|
protected $revId = null;
|
|
|
|
|
|
2015-12-28 23:56:18 +00:00
|
|
|
/** @var bool Whether the parameters for this log entry are stored in new or old format. */
|
2013-12-03 21:41:33 +00:00
|
|
|
protected $legacy;
|
|
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
protected function __construct( $row ) {
|
|
|
|
|
$this->row = $row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the unique database id.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function getId() {
|
|
|
|
|
return (int)$this->row->log_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whatever is stored in the database field.
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function getRawParameters() {
|
|
|
|
|
return $this->row->log_params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isLegacy() {
|
2015-12-29 00:21:50 +00:00
|
|
|
// This extracts the property
|
2011-09-07 15:32:37 +00:00
|
|
|
$this->getParameters();
|
|
|
|
|
return $this->legacy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getType() {
|
|
|
|
|
return $this->row->log_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getSubtype() {
|
|
|
|
|
return $this->row->log_action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getParameters() {
|
|
|
|
|
if ( !isset( $this->params ) ) {
|
|
|
|
|
$blob = $this->getRawParameters();
|
2015-06-10 18:29:05 +00:00
|
|
|
MediaWiki\suppressWarnings();
|
2015-03-28 17:55:45 +00:00
|
|
|
$params = LogEntryBase::extractParams( $blob );
|
2015-06-10 18:29:05 +00:00
|
|
|
MediaWiki\restoreWarnings();
|
2011-09-08 16:59:19 +00:00
|
|
|
if ( $params !== false ) {
|
2011-09-07 15:32:37 +00:00
|
|
|
$this->params = $params;
|
|
|
|
|
$this->legacy = false;
|
|
|
|
|
} else {
|
2015-03-28 17:55:45 +00:00
|
|
|
$this->params = LogPage::extractParams( $blob );
|
2011-09-14 07:47:32 +00:00
|
|
|
$this->legacy = true;
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
2015-12-29 00:21:50 +00:00
|
|
|
|
|
|
|
|
if ( isset( $this->params['associated_rev_id'] ) ) {
|
|
|
|
|
$this->revId = $this->params['associated_rev_id'];
|
|
|
|
|
unset( $this->params['associated_rev_id'] );
|
|
|
|
|
}
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
return $this->params;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-29 00:21:50 +00:00
|
|
|
public function getAssociatedRevId() {
|
|
|
|
|
// This extracts the property
|
|
|
|
|
$this->getParameters();
|
|
|
|
|
return $this->revId;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
public function getPerformer() {
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( !$this->performer ) {
|
2013-08-31 16:36:02 +00:00
|
|
|
$userId = (int)$this->row->log_user;
|
2015-12-28 23:56:18 +00:00
|
|
|
if ( $userId !== 0 ) {
|
|
|
|
|
// logged-in users
|
2012-10-21 15:57:54 +00:00
|
|
|
if ( isset( $this->row->user_name ) ) {
|
|
|
|
|
$this->performer = User::newFromRow( $this->row );
|
|
|
|
|
} else {
|
|
|
|
|
$this->performer = User::newFromId( $userId );
|
|
|
|
|
}
|
2015-12-28 23:56:18 +00:00
|
|
|
} else {
|
|
|
|
|
// IP users
|
2012-10-21 15:57:54 +00:00
|
|
|
$userText = $this->row->log_user_text;
|
|
|
|
|
$this->performer = User::newFromName( $userText, false );
|
2012-02-07 22:22:27 +00:00
|
|
|
}
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2012-10-21 15:57:54 +00:00
|
|
|
return $this->performer;
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTarget() {
|
|
|
|
|
$namespace = $this->row->log_namespace;
|
|
|
|
|
$page = $this->row->log_title;
|
|
|
|
|
$title = Title::makeTitle( $namespace, $page );
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTimestamp() {
|
|
|
|
|
return wfTimestamp( TS_MW, $this->row->log_timestamp );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getComment() {
|
2018-01-24 23:41:01 +00:00
|
|
|
return CommentStore::getStore()->getComment( 'log_comment', $this->row )->text;
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getDeleted() {
|
|
|
|
|
return $this->row->log_deleted;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RCDatabaseLogEntry extends DatabaseLogEntry {
|
|
|
|
|
|
|
|
|
|
public function getId() {
|
|
|
|
|
return $this->row->rc_logid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getRawParameters() {
|
|
|
|
|
return $this->row->rc_params;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-29 00:21:50 +00:00
|
|
|
public function getAssociatedRevId() {
|
|
|
|
|
return $this->row->rc_this_oldid;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
public function getType() {
|
|
|
|
|
return $this->row->rc_log_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getSubtype() {
|
|
|
|
|
return $this->row->rc_log_action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPerformer() {
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( !$this->performer ) {
|
2013-08-31 16:36:02 +00:00
|
|
|
$userId = (int)$this->row->rc_user;
|
2012-10-21 15:57:54 +00:00
|
|
|
if ( $userId !== 0 ) {
|
|
|
|
|
$this->performer = User::newFromId( $userId );
|
|
|
|
|
} else {
|
|
|
|
|
$userText = $this->row->rc_user_text;
|
|
|
|
|
// Might be an IP, don't validate the username
|
|
|
|
|
$this->performer = User::newFromName( $userText, false );
|
|
|
|
|
}
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2012-10-21 15:57:54 +00:00
|
|
|
return $this->performer;
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTarget() {
|
|
|
|
|
$namespace = $this->row->rc_namespace;
|
|
|
|
|
$page = $this->row->rc_title;
|
|
|
|
|
$title = Title::makeTitle( $namespace, $page );
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTimestamp() {
|
|
|
|
|
return wfTimestamp( TS_MW, $this->row->rc_timestamp );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getComment() {
|
2018-01-24 23:41:01 +00:00
|
|
|
return CommentStore::getStore()
|
2017-10-06 17:03:55 +00:00
|
|
|
// Legacy because the row may have used RecentChange::selectFields()
|
2018-01-24 23:41:01 +00:00
|
|
|
->getCommentLegacy( wfGetDB( DB_REPLICA ), 'rc_comment', $this->row )->text;
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getDeleted() {
|
|
|
|
|
return $this->row->rc_deleted;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-28 23:56:18 +00:00
|
|
|
* Class for creating log entries manually, to inject them into the database.
|
|
|
|
|
*
|
2011-09-07 15:32:37 +00:00
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
class ManualLogEntry extends LogEntryBase {
|
2013-12-03 18:26:59 +00:00
|
|
|
/** @var string Type of log entry */
|
|
|
|
|
protected $type;
|
|
|
|
|
|
|
|
|
|
/** @var string Sub type of log entry */
|
|
|
|
|
protected $subtype;
|
|
|
|
|
|
|
|
|
|
/** @var array Parameters for log entry */
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $parameters = [];
|
2013-12-03 18:26:59 +00:00
|
|
|
|
|
|
|
|
/** @var array */
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $relations = [];
|
2013-12-03 18:26:59 +00:00
|
|
|
|
|
|
|
|
/** @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 = '';
|
|
|
|
|
|
Option to associate a rev id to a RC log entry, allowing unpatrolled status
This provides a mechanism to associate a revision id to an action.
For example in core, it makes sense for moves and uploads, which both
generate null revisions (also protections, but it isn't interesting if one
has patrolling in mind).
Crucially, in that case an unpatrolled status is allowed for the RC item.
So if the performer of the action is not autopatrolled, it will be displayed
as unpatrolled, and if the performer is autopatrolled, it will record an
autopatrol action.
When one associates a rev id to a type of action, one should also implement
a mechanism to patrol said action, since getting the diff for the associated
revision is not user friendly and works only if RC patrol is enabled.
This is done for uploads in If71af58719a4461f12d125455b7bef07164525ca (with
a new file patrol) and for moves in Ie0fa417feaf930c096b69521fc54d57aecd6cd51
(within RC patrol).
Extensions might possess other such actions that could benefit from patrolling.
Bug: T122089
Change-Id: I694424eca32b69e277f89d4c15183870983d0993
2015-11-07 19:24:33 +00:00
|
|
|
/** @var int A rev id associated to the log entry */
|
|
|
|
|
protected $revId = 0;
|
|
|
|
|
|
2016-01-25 04:11:36 +00:00
|
|
|
/** @var array Change tags add to the log entry */
|
|
|
|
|
protected $tags = null;
|
|
|
|
|
|
2013-12-03 18:26:59 +00:00
|
|
|
/** @var int Deletion state of the log entry */
|
|
|
|
|
protected $deleted;
|
2011-09-07 15:32:37 +00:00
|
|
|
|
2013-12-03 21:41:33 +00:00
|
|
|
/** @var int ID of the log entry */
|
|
|
|
|
protected $id;
|
|
|
|
|
|
2016-12-14 15:09:34 +00:00
|
|
|
/** @var bool Can this log entry be patrolled? */
|
2016-02-23 17:17:17 +00:00
|
|
|
protected $isPatrollable = false;
|
|
|
|
|
|
2015-03-14 11:17:24 +00:00
|
|
|
/** @var bool Whether this is a legacy log entry */
|
|
|
|
|
protected $legacy = false;
|
|
|
|
|
|
2012-01-15 16:13:16 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.19
|
|
|
|
|
* @param string $type
|
|
|
|
|
* @param string $subtype
|
|
|
|
|
*/
|
2011-09-07 15:32:37 +00:00
|
|
|
public function __construct( $type, $subtype ) {
|
|
|
|
|
$this->type = $type;
|
|
|
|
|
$this->subtype = $subtype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-10-29 01:17:26 +00:00
|
|
|
* Set extra log parameters.
|
2015-01-28 19:15:13 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2015-12-28 23:56:18 +00:00
|
|
|
* hardcoded for every message.
|
2012-10-10 18:13:40 +00:00
|
|
|
*
|
2015-12-28 23:56:18 +00:00
|
|
|
* 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'
|
|
|
|
|
* );
|
2012-10-10 18:13:40 +00:00
|
|
|
*
|
2015-12-28 23:56:18 +00:00
|
|
|
* @since 1.19
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $parameters Associative array
|
2011-09-07 15:32:37 +00:00
|
|
|
*/
|
|
|
|
|
public function setParameters( $parameters ) {
|
|
|
|
|
$this->parameters = $parameters;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 06:33:59 +00:00
|
|
|
/**
|
|
|
|
|
* Declare arbitrary tag/value relations to this log entry.
|
|
|
|
|
* These can be used to filter log entries later on.
|
|
|
|
|
*
|
2014-04-16 17:20:36 +00:00
|
|
|
* @param array $relations Map of (tag => (list of values|value))
|
2013-07-06 06:33:59 +00:00
|
|
|
* @since 1.22
|
|
|
|
|
*/
|
|
|
|
|
public function setRelations( array $relations ) {
|
|
|
|
|
$this->relations = $relations;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 16:13:16 +00:00
|
|
|
/**
|
|
|
|
|
* Set the user that performed the action being logged.
|
2012-10-10 18:13:40 +00:00
|
|
|
*
|
2012-01-15 16:13:16 +00:00
|
|
|
* @since 1.19
|
|
|
|
|
* @param User $performer
|
|
|
|
|
*/
|
2011-09-07 15:32:37 +00:00
|
|
|
public function setPerformer( User $performer ) {
|
|
|
|
|
$this->performer = $performer;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 16:13:16 +00:00
|
|
|
/**
|
|
|
|
|
* Set the title of the object changed.
|
2012-10-10 18:13:40 +00:00
|
|
|
*
|
2012-01-15 16:13:16 +00:00
|
|
|
* @since 1.19
|
|
|
|
|
* @param Title $target
|
|
|
|
|
*/
|
2011-09-07 15:32:37 +00:00
|
|
|
public function setTarget( Title $target ) {
|
|
|
|
|
$this->target = $target;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 16:13:16 +00:00
|
|
|
/**
|
|
|
|
|
* Set the timestamp of when the logged action took place.
|
2012-10-10 18:13:40 +00:00
|
|
|
*
|
2012-01-15 16:13:16 +00:00
|
|
|
* @since 1.19
|
|
|
|
|
* @param string $timestamp
|
|
|
|
|
*/
|
2011-09-07 15:32:37 +00:00
|
|
|
public function setTimestamp( $timestamp ) {
|
|
|
|
|
$this->timestamp = $timestamp;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 16:13:16 +00:00
|
|
|
/**
|
|
|
|
|
* Set a comment associated with the action being logged.
|
2012-10-10 18:13:40 +00:00
|
|
|
*
|
2012-01-15 16:13:16 +00:00
|
|
|
* @since 1.19
|
|
|
|
|
* @param string $comment
|
|
|
|
|
*/
|
2011-09-07 15:32:37 +00:00
|
|
|
public function setComment( $comment ) {
|
|
|
|
|
$this->comment = $comment;
|
|
|
|
|
}
|
|
|
|
|
|
Option to associate a rev id to a RC log entry, allowing unpatrolled status
This provides a mechanism to associate a revision id to an action.
For example in core, it makes sense for moves and uploads, which both
generate null revisions (also protections, but it isn't interesting if one
has patrolling in mind).
Crucially, in that case an unpatrolled status is allowed for the RC item.
So if the performer of the action is not autopatrolled, it will be displayed
as unpatrolled, and if the performer is autopatrolled, it will record an
autopatrol action.
When one associates a rev id to a type of action, one should also implement
a mechanism to patrol said action, since getting the diff for the associated
revision is not user friendly and works only if RC patrol is enabled.
This is done for uploads in If71af58719a4461f12d125455b7bef07164525ca (with
a new file patrol) and for moves in Ie0fa417feaf930c096b69521fc54d57aecd6cd51
(within RC patrol).
Extensions might possess other such actions that could benefit from patrolling.
Bug: T122089
Change-Id: I694424eca32b69e277f89d4c15183870983d0993
2015-11-07 19:24:33 +00:00
|
|
|
/**
|
|
|
|
|
* Set an associated revision id.
|
|
|
|
|
*
|
2015-12-28 23:56:18 +00:00
|
|
|
* For example, the ID of the revision that was inserted to mark a page move
|
|
|
|
|
* or protection, file upload, etc.
|
Option to associate a rev id to a RC log entry, allowing unpatrolled status
This provides a mechanism to associate a revision id to an action.
For example in core, it makes sense for moves and uploads, which both
generate null revisions (also protections, but it isn't interesting if one
has patrolling in mind).
Crucially, in that case an unpatrolled status is allowed for the RC item.
So if the performer of the action is not autopatrolled, it will be displayed
as unpatrolled, and if the performer is autopatrolled, it will record an
autopatrol action.
When one associates a rev id to a type of action, one should also implement
a mechanism to patrol said action, since getting the diff for the associated
revision is not user friendly and works only if RC patrol is enabled.
This is done for uploads in If71af58719a4461f12d125455b7bef07164525ca (with
a new file patrol) and for moves in Ie0fa417feaf930c096b69521fc54d57aecd6cd51
(within RC patrol).
Extensions might possess other such actions that could benefit from patrolling.
Bug: T122089
Change-Id: I694424eca32b69e277f89d4c15183870983d0993
2015-11-07 19:24:33 +00:00
|
|
|
*
|
2015-12-28 23:56:18 +00:00
|
|
|
* @since 1.27
|
Option to associate a rev id to a RC log entry, allowing unpatrolled status
This provides a mechanism to associate a revision id to an action.
For example in core, it makes sense for moves and uploads, which both
generate null revisions (also protections, but it isn't interesting if one
has patrolling in mind).
Crucially, in that case an unpatrolled status is allowed for the RC item.
So if the performer of the action is not autopatrolled, it will be displayed
as unpatrolled, and if the performer is autopatrolled, it will record an
autopatrol action.
When one associates a rev id to a type of action, one should also implement
a mechanism to patrol said action, since getting the diff for the associated
revision is not user friendly and works only if RC patrol is enabled.
This is done for uploads in If71af58719a4461f12d125455b7bef07164525ca (with
a new file patrol) and for moves in Ie0fa417feaf930c096b69521fc54d57aecd6cd51
(within RC patrol).
Extensions might possess other such actions that could benefit from patrolling.
Bug: T122089
Change-Id: I694424eca32b69e277f89d4c15183870983d0993
2015-11-07 19:24:33 +00:00
|
|
|
* @param int $revId
|
|
|
|
|
*/
|
|
|
|
|
public function setAssociatedRevId( $revId ) {
|
|
|
|
|
$this->revId = $revId;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 04:11:36 +00:00
|
|
|
/**
|
|
|
|
|
* Set change tags for the log entry.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.27
|
|
|
|
|
* @param string|string[] $tags
|
|
|
|
|
*/
|
|
|
|
|
public function setTags( $tags ) {
|
|
|
|
|
if ( is_string( $tags ) ) {
|
|
|
|
|
$tags = [ $tags ];
|
|
|
|
|
}
|
|
|
|
|
$this->tags = $tags;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 17:17:17 +00:00
|
|
|
/**
|
|
|
|
|
* Set whether this log entry should be made patrollable
|
|
|
|
|
* This shouldn't depend on config, only on whether there is full support
|
|
|
|
|
* in the software for patrolling this log entry.
|
|
|
|
|
* False by default
|
|
|
|
|
*
|
|
|
|
|
* @since 1.27
|
|
|
|
|
* @param bool $patrollable
|
|
|
|
|
*/
|
|
|
|
|
public function setIsPatrollable( $patrollable ) {
|
|
|
|
|
$this->isPatrollable = (bool)$patrollable;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 11:17:24 +00:00
|
|
|
/**
|
|
|
|
|
* Set the 'legacy' flag
|
|
|
|
|
*
|
|
|
|
|
* @since 1.25
|
|
|
|
|
* @param bool $legacy
|
|
|
|
|
*/
|
|
|
|
|
public function setLegacy( $legacy ) {
|
|
|
|
|
$this->legacy = $legacy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 16:13:16 +00:00
|
|
|
/**
|
2015-12-28 23:56:18 +00:00
|
|
|
* Set the 'deleted' flag.
|
2012-10-10 18:13:40 +00:00
|
|
|
*
|
2012-01-15 16:13:16 +00:00
|
|
|
* @since 1.19
|
2015-12-28 23:56:18 +00:00
|
|
|
* @param int $deleted One of LogPage::DELETED_* bitfield constants
|
2012-01-15 16:13:16 +00:00
|
|
|
*/
|
2011-09-07 15:32:37 +00:00
|
|
|
public function setDeleted( $deleted ) {
|
|
|
|
|
$this->deleted = $deleted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-28 23:56:18 +00:00
|
|
|
* Insert the entry into the `logging` table.
|
|
|
|
|
*
|
2013-07-18 03:37:38 +00:00
|
|
|
* @param IDatabase $dbw
|
2013-12-03 18:26:59 +00:00
|
|
|
* @return int ID of the log entry
|
|
|
|
|
* @throws MWException
|
2011-09-07 15:32:37 +00:00
|
|
|
*/
|
2013-07-18 03:37:38 +00:00
|
|
|
public function insert( IDatabase $dbw = null ) {
|
2013-12-04 08:52:51 +00:00
|
|
|
$dbw = $dbw ?: wfGetDB( DB_MASTER );
|
2011-09-07 15:32:37 +00:00
|
|
|
|
|
|
|
|
if ( $this->timestamp === null ) {
|
|
|
|
|
$this->timestamp = wfTimestampNow();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-28 23:56:18 +00:00
|
|
|
// Trim spaces on user supplied text
|
2012-12-01 19:11:21 +00:00
|
|
|
$comment = trim( $this->getComment() );
|
|
|
|
|
|
2015-12-29 00:21:50 +00:00
|
|
|
$params = $this->getParameters();
|
|
|
|
|
$relations = $this->relations;
|
|
|
|
|
|
|
|
|
|
// Additional fields for which there's no space in the database table schema
|
|
|
|
|
$revId = $this->getAssociatedRevId();
|
|
|
|
|
if ( $revId ) {
|
|
|
|
|
$params['associated_rev_id'] = $revId;
|
|
|
|
|
$relations['associated_rev_id'] = $revId;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$data = [
|
2011-09-07 15:32:37 +00:00
|
|
|
'log_type' => $this->getType(),
|
|
|
|
|
'log_action' => $this->getSubtype(),
|
|
|
|
|
'log_timestamp' => $dbw->timestamp( $this->getTimestamp() ),
|
|
|
|
|
'log_user' => $this->getPerformer()->getId(),
|
|
|
|
|
'log_user_text' => $this->getPerformer()->getName(),
|
|
|
|
|
'log_namespace' => $this->getTarget()->getNamespace(),
|
|
|
|
|
'log_title' => $this->getTarget()->getDBkey(),
|
2012-03-11 18:54:55 +00:00
|
|
|
'log_page' => $this->getTarget()->getArticleID(),
|
2015-12-29 00:21:50 +00:00
|
|
|
'log_params' => LogEntryBase::makeParamBlob( $params ),
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-04-28 22:28:41 +00:00
|
|
|
if ( isset( $this->deleted ) ) {
|
|
|
|
|
$data['log_deleted'] = $this->deleted;
|
|
|
|
|
}
|
2018-01-24 23:41:01 +00:00
|
|
|
$data += CommentStore::getStore()->insert( $dbw, 'log_comment', $comment );
|
2014-04-28 22:28:41 +00:00
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
$dbw->insert( 'logging', $data, __METHOD__ );
|
2017-05-10 21:28:24 +00:00
|
|
|
$this->id = $dbw->insertId();
|
2013-07-06 06:33:59 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$rows = [];
|
2015-12-29 00:21:50 +00:00
|
|
|
foreach ( $relations as $tag => $values ) {
|
2013-07-06 06:33:59 +00:00
|
|
|
if ( !strlen( $tag ) ) {
|
|
|
|
|
throw new MWException( "Got empty log search tag." );
|
|
|
|
|
}
|
2014-04-16 17:20:36 +00:00
|
|
|
|
|
|
|
|
if ( !is_array( $values ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$values = [ $values ];
|
2014-04-16 17:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-06 06:33:59 +00:00
|
|
|
foreach ( $values as $value ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$rows[] = [
|
2013-12-03 14:36:21 +00:00
|
|
|
'ls_field' => $tag,
|
|
|
|
|
'ls_value' => $value,
|
2013-07-06 06:33:59 +00:00
|
|
|
'ls_log_id' => $this->id
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-07-06 06:33:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( count( $rows ) ) {
|
|
|
|
|
$dbw->insert( 'log_search', $rows, __METHOD__, 'IGNORE' );
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
return $this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-11-05 08:02:54 +00:00
|
|
|
* Get a RecentChanges object for the log entry
|
2015-12-28 23:56:18 +00:00
|
|
|
*
|
2013-11-05 08:02:54 +00:00
|
|
|
* @param int $newId
|
|
|
|
|
* @return RecentChange
|
|
|
|
|
* @since 1.23
|
2011-09-07 15:32:37 +00:00
|
|
|
*/
|
2013-11-05 08:02:54 +00:00
|
|
|
public function getRecentChange( $newId = 0 ) {
|
2011-09-07 15:32:37 +00:00
|
|
|
$formatter = LogFormatter::newFromEntry( $this );
|
|
|
|
|
$context = RequestContext::newExtraneousContext( $this->getTarget() );
|
|
|
|
|
$formatter->setContext( $context );
|
|
|
|
|
|
|
|
|
|
$logpage = SpecialPage::getTitleFor( 'Log', $this->getType() );
|
|
|
|
|
$user = $this->getPerformer();
|
Unbreak maintenance/deleteDefaultMessages.php for PostgreSQL
deleteDefaultMessages.php was failing during upgrade
from MediaWiki 1.7.3 with a databaser error.
A stub user:
$user = User::newFromName( 'MediaWiki default' );
has user ID 0, so that $user->isAnon() is true.
Unfortunately, ManualLogEntry::publish() from r96441
tries to insert $user->getName() ("MediaWiki default")
into rc_ip.
PostgreSQL won't allow this, because rc_ip is of
Postgres-specific CIDR type.
Traceback:
Checking existence of old default messages...
...deleting old default messages (this may take a long time!)...A database query syntax error has occurred.
The last attempted database query was:
"INSERT INTO "recentchanges" (rc_timestamp,rc_cur_time,rc_namespace,rc_title,rc_type,rc_minor,rc_user,rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot,rc_moved_to_ns,rc_moved_to_title,rc_ip,rc_patrolled,rc_new,rc_old_len,rc_new_len,rc_deleted,rc_logid,rc_log_type,rc_log_action,rc_params,rc_id) VALUES ('2012-03-14 21:51:05 GMT','2012-03-14 21:51:05 GMT','8','1movedto2','3','0','0','MediaWiki default','No longer required','0','0',1,'0','','MediaWiki default','1','0',NULL,NULL,'0','1','delete','delete','a:0:{}','1')"
from within function "RecentChange::save".
MySQL returned error "1: ERROR: invalid input syntax for type cidr: "MediaWiki default"
LINE 1: ...ki default','No longer required','0','0',1,'0','','MediaWiki...
^"
Backtrace:
#0 /usr/home/saper/public_html/pg/w/includes/db/DatabasePostgres.php(332): DatabaseBase->reportQueryError('ERROR: invalid...', 1, 'INSERT INTO "re...', 'RecentChange::s...', '')
#1 /usr/home/saper/public_html/pg/w/includes/db/Database.php(904): DatabasePostgres->reportQueryError('ERROR: invalid...', 1, 'INSERT INTO "re...', 'RecentChange::s...', '')
#2 /usr/home/saper/public_html/pg/w/includes/db/DatabasePostgres.php(604): DatabaseBase->query('INSERT INTO "re...', 'RecentChange::s...', '')
#3 /usr/home/saper/public_html/pg/w/includes/RecentChange.php(199): DatabasePostgres->insert('recentchanges', Array, 'RecentChange::s...')
#4 /usr/home/saper/public_html/pg/w/includes/logging/LogEntry.php(479): RecentChange->save('pleasedontudp')
#5 /usr/home/saper/public_html/pg/w/includes/WikiPage.php(2042): ManualLogEntry->publish('1')
#6 /usr/home/saper/public_html/pg/w/includes/WikiPage.php(1937): WikiPage->doDeleteArticleReal('No longer requi...', false, 0, false, '', Object(User))
#7 /usr/home/saper/public_html/pg/w/maintenance/deleteDefaultMessages.php(73): WikiPage->doDeleteArticle('No longer requi...', false, 0, false, '', Object(User))
#8 /usr/home/saper/public_html/pg/w/maintenance/update.php(128): DeleteDefaultMessages->execute()
#9 /usr/home/saper/public_html/pg/w/maintenance/doMaintenance.php(105): UpdateMediaWiki->execute()
#10 /usr/home/saper/public_html/pg/w/maintenance/update.php(151): require_once('/usr/home/saper...')
#11 {main}
2012-03-15 01:52:38 +00:00
|
|
|
$ip = "";
|
|
|
|
|
if ( $user->isAnon() ) {
|
2015-12-28 23:56:18 +00:00
|
|
|
// "MediaWiki default" and friends may have
|
|
|
|
|
// no IP address in their name
|
Unbreak maintenance/deleteDefaultMessages.php for PostgreSQL
deleteDefaultMessages.php was failing during upgrade
from MediaWiki 1.7.3 with a databaser error.
A stub user:
$user = User::newFromName( 'MediaWiki default' );
has user ID 0, so that $user->isAnon() is true.
Unfortunately, ManualLogEntry::publish() from r96441
tries to insert $user->getName() ("MediaWiki default")
into rc_ip.
PostgreSQL won't allow this, because rc_ip is of
Postgres-specific CIDR type.
Traceback:
Checking existence of old default messages...
...deleting old default messages (this may take a long time!)...A database query syntax error has occurred.
The last attempted database query was:
"INSERT INTO "recentchanges" (rc_timestamp,rc_cur_time,rc_namespace,rc_title,rc_type,rc_minor,rc_user,rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot,rc_moved_to_ns,rc_moved_to_title,rc_ip,rc_patrolled,rc_new,rc_old_len,rc_new_len,rc_deleted,rc_logid,rc_log_type,rc_log_action,rc_params,rc_id) VALUES ('2012-03-14 21:51:05 GMT','2012-03-14 21:51:05 GMT','8','1movedto2','3','0','0','MediaWiki default','No longer required','0','0',1,'0','','MediaWiki default','1','0',NULL,NULL,'0','1','delete','delete','a:0:{}','1')"
from within function "RecentChange::save".
MySQL returned error "1: ERROR: invalid input syntax for type cidr: "MediaWiki default"
LINE 1: ...ki default','No longer required','0','0',1,'0','','MediaWiki...
^"
Backtrace:
#0 /usr/home/saper/public_html/pg/w/includes/db/DatabasePostgres.php(332): DatabaseBase->reportQueryError('ERROR: invalid...', 1, 'INSERT INTO "re...', 'RecentChange::s...', '')
#1 /usr/home/saper/public_html/pg/w/includes/db/Database.php(904): DatabasePostgres->reportQueryError('ERROR: invalid...', 1, 'INSERT INTO "re...', 'RecentChange::s...', '')
#2 /usr/home/saper/public_html/pg/w/includes/db/DatabasePostgres.php(604): DatabaseBase->query('INSERT INTO "re...', 'RecentChange::s...', '')
#3 /usr/home/saper/public_html/pg/w/includes/RecentChange.php(199): DatabasePostgres->insert('recentchanges', Array, 'RecentChange::s...')
#4 /usr/home/saper/public_html/pg/w/includes/logging/LogEntry.php(479): RecentChange->save('pleasedontudp')
#5 /usr/home/saper/public_html/pg/w/includes/WikiPage.php(2042): ManualLogEntry->publish('1')
#6 /usr/home/saper/public_html/pg/w/includes/WikiPage.php(1937): WikiPage->doDeleteArticleReal('No longer requi...', false, 0, false, '', Object(User))
#7 /usr/home/saper/public_html/pg/w/maintenance/deleteDefaultMessages.php(73): WikiPage->doDeleteArticle('No longer requi...', false, 0, false, '', Object(User))
#8 /usr/home/saper/public_html/pg/w/maintenance/update.php(128): DeleteDefaultMessages->execute()
#9 /usr/home/saper/public_html/pg/w/maintenance/doMaintenance.php(105): UpdateMediaWiki->execute()
#10 /usr/home/saper/public_html/pg/w/maintenance/update.php(151): require_once('/usr/home/saper...')
#11 {main}
2012-03-15 01:52:38 +00:00
|
|
|
if ( IP::isIPAddress( $user->getName() ) ) {
|
|
|
|
|
$ip = $user->getName();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2013-11-05 08:02:54 +00:00
|
|
|
return RecentChange::newLogEntry(
|
2011-09-07 15:32:37 +00:00
|
|
|
$this->getTimestamp(),
|
|
|
|
|
$logpage,
|
|
|
|
|
$user,
|
2012-02-21 23:51:18 +00:00
|
|
|
$formatter->getPlainActionText(),
|
Unbreak maintenance/deleteDefaultMessages.php for PostgreSQL
deleteDefaultMessages.php was failing during upgrade
from MediaWiki 1.7.3 with a databaser error.
A stub user:
$user = User::newFromName( 'MediaWiki default' );
has user ID 0, so that $user->isAnon() is true.
Unfortunately, ManualLogEntry::publish() from r96441
tries to insert $user->getName() ("MediaWiki default")
into rc_ip.
PostgreSQL won't allow this, because rc_ip is of
Postgres-specific CIDR type.
Traceback:
Checking existence of old default messages...
...deleting old default messages (this may take a long time!)...A database query syntax error has occurred.
The last attempted database query was:
"INSERT INTO "recentchanges" (rc_timestamp,rc_cur_time,rc_namespace,rc_title,rc_type,rc_minor,rc_user,rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot,rc_moved_to_ns,rc_moved_to_title,rc_ip,rc_patrolled,rc_new,rc_old_len,rc_new_len,rc_deleted,rc_logid,rc_log_type,rc_log_action,rc_params,rc_id) VALUES ('2012-03-14 21:51:05 GMT','2012-03-14 21:51:05 GMT','8','1movedto2','3','0','0','MediaWiki default','No longer required','0','0',1,'0','','MediaWiki default','1','0',NULL,NULL,'0','1','delete','delete','a:0:{}','1')"
from within function "RecentChange::save".
MySQL returned error "1: ERROR: invalid input syntax for type cidr: "MediaWiki default"
LINE 1: ...ki default','No longer required','0','0',1,'0','','MediaWiki...
^"
Backtrace:
#0 /usr/home/saper/public_html/pg/w/includes/db/DatabasePostgres.php(332): DatabaseBase->reportQueryError('ERROR: invalid...', 1, 'INSERT INTO "re...', 'RecentChange::s...', '')
#1 /usr/home/saper/public_html/pg/w/includes/db/Database.php(904): DatabasePostgres->reportQueryError('ERROR: invalid...', 1, 'INSERT INTO "re...', 'RecentChange::s...', '')
#2 /usr/home/saper/public_html/pg/w/includes/db/DatabasePostgres.php(604): DatabaseBase->query('INSERT INTO "re...', 'RecentChange::s...', '')
#3 /usr/home/saper/public_html/pg/w/includes/RecentChange.php(199): DatabasePostgres->insert('recentchanges', Array, 'RecentChange::s...')
#4 /usr/home/saper/public_html/pg/w/includes/logging/LogEntry.php(479): RecentChange->save('pleasedontudp')
#5 /usr/home/saper/public_html/pg/w/includes/WikiPage.php(2042): ManualLogEntry->publish('1')
#6 /usr/home/saper/public_html/pg/w/includes/WikiPage.php(1937): WikiPage->doDeleteArticleReal('No longer requi...', false, 0, false, '', Object(User))
#7 /usr/home/saper/public_html/pg/w/maintenance/deleteDefaultMessages.php(73): WikiPage->doDeleteArticle('No longer requi...', false, 0, false, '', Object(User))
#8 /usr/home/saper/public_html/pg/w/maintenance/update.php(128): DeleteDefaultMessages->execute()
#9 /usr/home/saper/public_html/pg/w/maintenance/doMaintenance.php(105): UpdateMediaWiki->execute()
#10 /usr/home/saper/public_html/pg/w/maintenance/update.php(151): require_once('/usr/home/saper...')
#11 {main}
2012-03-15 01:52:38 +00:00
|
|
|
$ip,
|
2011-09-07 15:32:37 +00:00
|
|
|
$this->getType(),
|
|
|
|
|
$this->getSubtype(),
|
|
|
|
|
$this->getTarget(),
|
|
|
|
|
$this->getComment(),
|
2015-03-28 17:55:45 +00:00
|
|
|
LogEntryBase::makeParamBlob( $this->getParameters() ),
|
2012-02-21 23:51:18 +00:00
|
|
|
$newId,
|
Option to associate a rev id to a RC log entry, allowing unpatrolled status
This provides a mechanism to associate a revision id to an action.
For example in core, it makes sense for moves and uploads, which both
generate null revisions (also protections, but it isn't interesting if one
has patrolling in mind).
Crucially, in that case an unpatrolled status is allowed for the RC item.
So if the performer of the action is not autopatrolled, it will be displayed
as unpatrolled, and if the performer is autopatrolled, it will record an
autopatrol action.
When one associates a rev id to a type of action, one should also implement
a mechanism to patrol said action, since getting the diff for the associated
revision is not user friendly and works only if RC patrol is enabled.
This is done for uploads in If71af58719a4461f12d125455b7bef07164525ca (with
a new file patrol) and for moves in Ie0fa417feaf930c096b69521fc54d57aecd6cd51
(within RC patrol).
Extensions might possess other such actions that could benefit from patrolling.
Bug: T122089
Change-Id: I694424eca32b69e277f89d4c15183870983d0993
2015-11-07 19:24:33 +00:00
|
|
|
$formatter->getIRCActionComment(), // Used for IRC feeds
|
2016-02-23 17:17:17 +00:00
|
|
|
$this->getAssociatedRevId(), // Used for e.g. moves and uploads
|
|
|
|
|
$this->getIsPatrollable()
|
2011-09-07 15:32:37 +00:00
|
|
|
);
|
2013-11-05 08:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-28 23:56:18 +00:00
|
|
|
* Publish the log entry.
|
|
|
|
|
*
|
2014-04-19 20:22:20 +00:00
|
|
|
* @param int $newId Id of the log entry.
|
|
|
|
|
* @param string $to One of: rcandudp (default), rc, udp
|
2013-11-05 08:02:54 +00:00
|
|
|
*/
|
|
|
|
|
public function publish( $newId, $to = 'rcandudp' ) {
|
2016-02-23 02:16:42 +00:00
|
|
|
DeferredUpdates::addCallableUpdate(
|
|
|
|
|
function () use ( $newId, $to ) {
|
|
|
|
|
$log = new LogPage( $this->getType() );
|
|
|
|
|
if ( !$log->isRestricted() ) {
|
|
|
|
|
$rc = $this->getRecentChange( $newId );
|
|
|
|
|
|
|
|
|
|
if ( $to === 'rc' || $to === 'rcandudp' ) {
|
2016-09-23 14:36:48 +00:00
|
|
|
// save RC, passing tags so they are applied there
|
|
|
|
|
$tags = $this->getTags();
|
|
|
|
|
if ( is_null( $tags ) ) {
|
|
|
|
|
$tags = [];
|
|
|
|
|
}
|
|
|
|
|
$rc->addTags( $tags );
|
2016-02-23 02:16:42 +00:00
|
|
|
$rc->save( 'pleasedontudp' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $to === 'udp' || $to === 'rcandudp' ) {
|
|
|
|
|
$rc->notifyRCFeeds();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Log the autopatrol if the log entry is patrollable
|
|
|
|
|
if ( $this->getIsPatrollable() &&
|
|
|
|
|
$rc->getAttribute( 'rc_patrolled' ) === 1
|
|
|
|
|
) {
|
|
|
|
|
PatrolLog::record( $rc, true, $this->getPerformer() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
DeferredUpdates::POSTSEND,
|
|
|
|
|
wfGetDB( DB_MASTER )
|
|
|
|
|
);
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getType() {
|
|
|
|
|
return $this->type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getSubtype() {
|
|
|
|
|
return $this->subtype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getParameters() {
|
|
|
|
|
return $this->parameters;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-21 21:15:05 +00:00
|
|
|
/**
|
|
|
|
|
* @return User
|
|
|
|
|
*/
|
2011-09-07 15:32:37 +00:00
|
|
|
public function getPerformer() {
|
|
|
|
|
return $this->performer;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-11 18:54:55 +00:00
|
|
|
/**
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
2011-09-07 15:32:37 +00:00
|
|
|
public function getTarget() {
|
|
|
|
|
return $this->target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTimestamp() {
|
|
|
|
|
$ts = $this->timestamp !== null ? $this->timestamp : wfTimestampNow();
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
return wfTimestamp( TS_MW, $ts );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getComment() {
|
|
|
|
|
return $this->comment;
|
|
|
|
|
}
|
|
|
|
|
|
Option to associate a rev id to a RC log entry, allowing unpatrolled status
This provides a mechanism to associate a revision id to an action.
For example in core, it makes sense for moves and uploads, which both
generate null revisions (also protections, but it isn't interesting if one
has patrolling in mind).
Crucially, in that case an unpatrolled status is allowed for the RC item.
So if the performer of the action is not autopatrolled, it will be displayed
as unpatrolled, and if the performer is autopatrolled, it will record an
autopatrol action.
When one associates a rev id to a type of action, one should also implement
a mechanism to patrol said action, since getting the diff for the associated
revision is not user friendly and works only if RC patrol is enabled.
This is done for uploads in If71af58719a4461f12d125455b7bef07164525ca (with
a new file patrol) and for moves in Ie0fa417feaf930c096b69521fc54d57aecd6cd51
(within RC patrol).
Extensions might possess other such actions that could benefit from patrolling.
Bug: T122089
Change-Id: I694424eca32b69e277f89d4c15183870983d0993
2015-11-07 19:24:33 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.27
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function getAssociatedRevId() {
|
|
|
|
|
return $this->revId;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 04:11:36 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.27
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getTags() {
|
|
|
|
|
return $this->tags;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 17:17:17 +00:00
|
|
|
/**
|
|
|
|
|
* Whether this log entry is patrollable
|
|
|
|
|
*
|
|
|
|
|
* @since 1.27
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function getIsPatrollable() {
|
|
|
|
|
return $this->isPatrollable;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 11:17:24 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.25
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isLegacy() {
|
|
|
|
|
return $this->legacy;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
public function getDeleted() {
|
2013-08-31 16:36:02 +00:00
|
|
|
return (int)$this->deleted;
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
2011-10-27 20:48:09 +00:00
|
|
|
}
|