2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Contain log classes
|
2010-08-08 14:28:01 +00:00
|
|
|
*
|
|
|
|
|
* Copyright © 2002, 2004 Brion Vibber <brion@pobox.com>
|
2014-03-13 22:23:56 +00:00
|
|
|
* https://www.mediawiki.org/
|
2010-08-08 14:28:01 +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
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2022-04-22 18:01:27 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2018-05-20 21:05:00 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-03-19 04:54:13 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2018-05-20 21:05:00 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Class to simplify the use of log pages.
|
|
|
|
|
* The logs are now kept in a table which is easier to manage and trim
|
|
|
|
|
* than ever-growing wiki pages.
|
2020-06-30 10:13:50 +00:00
|
|
|
*
|
|
|
|
|
* @newable
|
|
|
|
|
* @note marked as newable in 1.35 for lack of a better alternative,
|
2020-09-27 08:09:09 +00:00
|
|
|
* but should become a stateless service, use the command pattern.
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
class LogPage {
|
2020-05-15 22:07:42 +00:00
|
|
|
public const DELETED_ACTION = 1;
|
|
|
|
|
public const DELETED_COMMENT = 2;
|
|
|
|
|
public const DELETED_USER = 4;
|
|
|
|
|
public const DELETED_RESTRICTED = 8;
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2009-07-30 14:08:25 +00:00
|
|
|
// Convenience fields
|
2020-05-15 22:07:42 +00:00
|
|
|
public const SUPPRESSED_USER = self::DELETED_USER | self::DELETED_RESTRICTED;
|
|
|
|
|
public const SUPPRESSED_ACTION = self::DELETED_ACTION | self::DELETED_RESTRICTED;
|
2011-05-26 19:21:50 +00:00
|
|
|
|
2013-12-03 18:26:59 +00:00
|
|
|
/** @var bool */
|
2013-12-03 21:41:33 +00:00
|
|
|
public $updateRecentChanges;
|
2013-12-03 18:26:59 +00:00
|
|
|
|
|
|
|
|
/** @var bool */
|
2013-12-03 21:41:33 +00:00
|
|
|
public $sendToUDP;
|
|
|
|
|
|
|
|
|
|
/** @var string Plaintext version of the message for IRC */
|
|
|
|
|
private $ircActionText;
|
|
|
|
|
|
|
|
|
|
/** @var string Plaintext version of the message */
|
|
|
|
|
private $actionText;
|
2013-12-03 18:26:59 +00:00
|
|
|
|
|
|
|
|
/** @var string One of '', 'block', 'protect', 'rights', 'delete',
|
|
|
|
|
* 'upload', 'move'
|
2011-05-26 19:21:50 +00:00
|
|
|
*/
|
2013-12-03 21:41:33 +00:00
|
|
|
private $type;
|
2013-12-03 18:26:59 +00:00
|
|
|
|
|
|
|
|
/** @var string One of '', 'block', 'protect', 'rights', 'delete',
|
2019-08-05 17:00:00 +00:00
|
|
|
* 'upload', 'move', 'move_redir'
|
|
|
|
|
*/
|
2013-12-03 21:41:33 +00:00
|
|
|
private $action;
|
2013-12-03 18:26:59 +00:00
|
|
|
|
|
|
|
|
/** @var string Comment associated with action */
|
2013-12-03 21:41:33 +00:00
|
|
|
private $comment;
|
2013-12-03 18:26:59 +00:00
|
|
|
|
|
|
|
|
/** @var string Blob made of a parameters array */
|
2013-12-03 21:41:33 +00:00
|
|
|
private $params;
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2021-03-19 04:54:13 +00:00
|
|
|
/** @var UserIdentity The user doing the action */
|
|
|
|
|
private $performer;
|
2011-05-26 19:21:50 +00:00
|
|
|
|
2013-12-03 18:26:59 +00:00
|
|
|
/** @var Title */
|
2013-12-03 21:41:33 +00:00
|
|
|
private $target;
|
2011-05-26 19:21:50 +00:00
|
|
|
|
2005-07-07 13:44:33 +00:00
|
|
|
/**
|
2020-07-13 08:53:06 +00:00
|
|
|
* @stable to call
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param string $type One of '', 'block', 'protect', 'rights', 'delete',
|
|
|
|
|
* 'upload', 'move'
|
|
|
|
|
* @param bool $rc Whether to update recent changes as well as the logging table
|
|
|
|
|
* @param string $udp Pass 'UDP' to send to the UDP feed if NOT sent to RC
|
2010-08-21 12:00:28 +00:00
|
|
|
*/
|
2009-01-29 04:15:47 +00:00
|
|
|
public function __construct( $type, $rc = true, $udp = 'skipUDP' ) {
|
2004-08-24 08:11:46 +00:00
|
|
|
$this->type = $type;
|
2005-09-09 19:26:56 +00:00
|
|
|
$this->updateRecentChanges = $rc;
|
2010-08-21 12:00:28 +00:00
|
|
|
$this->sendToUDP = ( $udp == 'UDP' );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-21 19:54:24 +00:00
|
|
|
/**
|
2014-07-24 17:43:03 +00:00
|
|
|
* @return int The log_id of the inserted log entry
|
2011-05-21 19:54:24 +00:00
|
|
|
*/
|
2008-05-22 22:36:00 +00:00
|
|
|
protected function saveContent() {
|
2022-04-22 18:01:27 +00:00
|
|
|
$logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
|
2004-07-10 03:09:26 +00:00
|
|
|
|
2021-04-29 02:37:11 +00:00
|
|
|
$dbw = wfGetDB( DB_PRIMARY );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2019-09-07 13:44:01 +00:00
|
|
|
$now = wfTimestampNow();
|
2021-04-19 00:58:38 +00:00
|
|
|
$actorId = MediaWikiServices::getInstance()->getActorNormalization()
|
|
|
|
|
->acquireActorId( $this->performer, $dbw );
|
2016-02-17 09:09:32 +00:00
|
|
|
$data = [
|
2007-05-07 13:41:49 +00:00
|
|
|
'log_type' => $this->type,
|
|
|
|
|
'log_action' => $this->action,
|
|
|
|
|
'log_timestamp' => $dbw->timestamp( $now ),
|
2021-04-19 00:58:38 +00:00
|
|
|
'log_actor' => $actorId,
|
2007-05-07 13:41:49 +00:00
|
|
|
'log_namespace' => $this->target->getNamespace(),
|
|
|
|
|
'log_title' => $this->target->getDBkey(),
|
2012-03-11 18:54:55 +00:00
|
|
|
'log_page' => $this->target->getArticleID(),
|
2007-05-07 13:41:49 +00:00
|
|
|
'log_params' => $this->params
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2019-03-31 22:46:40 +00:00
|
|
|
$data += MediaWikiServices::getInstance()->getCommentStore()->insert(
|
|
|
|
|
$dbw,
|
|
|
|
|
'log_comment',
|
|
|
|
|
$this->comment
|
|
|
|
|
);
|
2009-01-09 23:18:47 +00:00
|
|
|
$dbw->insert( 'logging', $data, __METHOD__ );
|
2017-05-10 21:28:24 +00:00
|
|
|
$newId = $dbw->insertId();
|
2007-05-07 13:41:49 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
# And update recentchanges
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $this->updateRecentChanges ) {
|
2009-01-09 18:38:10 +00:00
|
|
|
$titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2010-08-21 12:00:28 +00:00
|
|
|
RecentChange::notifyLog(
|
2021-03-19 04:54:13 +00:00
|
|
|
$now, $titleObj, $this->performer, $this->getRcComment(), '',
|
2010-08-21 12:00:28 +00:00
|
|
|
$this->type, $this->action, $this->target, $this->comment,
|
2012-02-21 23:39:14 +00:00
|
|
|
$this->params, $newId, $this->getRcCommentIRC()
|
2010-08-21 12:00:28 +00:00
|
|
|
);
|
2013-04-20 15:38:24 +00:00
|
|
|
} elseif ( $this->sendToUDP ) {
|
2009-01-09 18:44:52 +00:00
|
|
|
# Don't send private logs to UDP
|
2022-01-06 18:44:56 +00:00
|
|
|
if ( isset( $logRestrictions[$this->type] ) && $logRestrictions[$this->type] != '*' ) {
|
2012-05-13 21:40:15 +00:00
|
|
|
return $newId;
|
2009-01-09 18:44:52 +00:00
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2021-11-25 16:37:36 +00:00
|
|
|
// Notify external application via UDP.
|
|
|
|
|
// We send this to IRC but do not want to add it the RC table.
|
2009-01-09 18:30:47 +00:00
|
|
|
$titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
|
2010-08-21 12:00:28 +00:00
|
|
|
$rc = RecentChange::newLogEntry(
|
2021-03-19 04:54:13 +00:00
|
|
|
$now, $titleObj, $this->performer, $this->getRcComment(), '',
|
2010-08-21 12:00:28 +00:00
|
|
|
$this->type, $this->action, $this->target, $this->comment,
|
2012-02-21 23:39:14 +00:00
|
|
|
$this->params, $newId, $this->getRcCommentIRC()
|
2010-08-21 12:00:28 +00:00
|
|
|
);
|
2013-12-03 21:48:40 +00:00
|
|
|
$rc->notifyRCFeeds();
|
2004-01-17 05:49:39 +00:00
|
|
|
}
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2009-05-13 22:03:32 +00:00
|
|
|
return $newId;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-25 03:08:56 +00:00
|
|
|
/**
|
|
|
|
|
* Get the RC comment from the last addEntry() call
|
2011-09-04 21:40:17 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2008-08-25 03:08:56 +00:00
|
|
|
*/
|
2007-06-16 02:55:25 +00:00
|
|
|
public function getRcComment() {
|
|
|
|
|
$rcComment = $this->actionText;
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $this->comment != '' ) {
|
2010-08-21 12:00:28 +00:00
|
|
|
if ( $rcComment == '' ) {
|
2007-06-16 02:55:25 +00:00
|
|
|
$rcComment = $this->comment;
|
2010-08-21 12:00:28 +00:00
|
|
|
} else {
|
2012-08-19 23:05:20 +00:00
|
|
|
$rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
|
|
|
|
|
$this->comment;
|
2010-08-21 12:00:28 +00:00
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
return $rcComment;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-21 23:39:14 +00:00
|
|
|
/**
|
|
|
|
|
* Get the RC comment from the last addEntry() call for IRC
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getRcCommentIRC() {
|
|
|
|
|
$rcComment = $this->ircActionText;
|
|
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $this->comment != '' ) {
|
2012-02-21 23:39:14 +00:00
|
|
|
if ( $rcComment == '' ) {
|
|
|
|
|
$rcComment = $this->comment;
|
|
|
|
|
} else {
|
2012-08-19 23:05:20 +00:00
|
|
|
$rcComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() .
|
|
|
|
|
$this->comment;
|
2012-02-21 23:39:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $rcComment;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-25 03:08:56 +00:00
|
|
|
/**
|
|
|
|
|
* Get the comment from the last addEntry() call
|
2014-08-23 20:34:25 +00:00
|
|
|
* @return string
|
2008-08-25 03:08:56 +00:00
|
|
|
*/
|
|
|
|
|
public function getComment() {
|
|
|
|
|
return $this->comment;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2010-05-18 20:59:14 +00:00
|
|
|
* Get the list of valid log types
|
|
|
|
|
*
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[]
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2007-05-02 20:37:13 +00:00
|
|
|
public static function validTypes() {
|
2022-04-22 18:01:27 +00:00
|
|
|
$logTypes = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogTypes );
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2022-01-06 18:44:56 +00:00
|
|
|
return $logTypes;
|
2004-08-25 02:13:32 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2010-05-18 20:59:14 +00:00
|
|
|
* Is $type a valid log type
|
|
|
|
|
*
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param string $type Log type to check
|
|
|
|
|
* @return bool
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2007-05-02 20:37:13 +00:00
|
|
|
public static function isLogType( $type ) {
|
2017-07-23 01:24:09 +00:00
|
|
|
return in_array( $type, self::validTypes() );
|
2004-08-25 02:13:32 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2012-10-10 18:13:40 +00:00
|
|
|
* Generate text for a log entry.
|
2012-02-08 19:52:04 +00:00
|
|
|
* Only LogFormatter should call this function.
|
2010-05-18 20:59:14 +00:00
|
|
|
*
|
2014-07-24 17:43:03 +00:00
|
|
|
* @param string $type Log type
|
|
|
|
|
* @param string $action Log action
|
2020-10-27 17:13:40 +00:00
|
|
|
* @param Title|null $title
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param Skin|null $skin Skin object or null. If null, we want to use the wiki
|
|
|
|
|
* content language, since that will go to the IRC feed.
|
2020-10-27 17:13:40 +00:00
|
|
|
* @param array $params
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param bool $filterWikilinks Whether to filter wiki links
|
|
|
|
|
* @return string HTML
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2010-05-18 20:59:14 +00:00
|
|
|
public static function actionText( $type, $action, $title = null, $skin = null,
|
2016-02-17 09:09:32 +00:00
|
|
|
$params = [], $filterWikilinks = false
|
2013-12-01 20:39:00 +00:00
|
|
|
) {
|
2022-01-06 18:44:56 +00:00
|
|
|
global $wgLang;
|
2022-04-22 18:01:27 +00:00
|
|
|
$config = MediaWikiServices::getInstance()->getMainConfig();
|
|
|
|
|
$logActions = $config->get( MainConfigNames::LogActions );
|
2004-08-24 08:11:46 +00:00
|
|
|
$key = "$type/$action";
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2022-01-06 18:44:56 +00:00
|
|
|
if ( isset( $logActions[$key] ) ) {
|
2020-02-13 17:44:15 +00:00
|
|
|
if ( $skin === null ) {
|
|
|
|
|
$langObj = MediaWikiServices::getInstance()->getContentLanguage();
|
|
|
|
|
$langObjOrNull = null;
|
|
|
|
|
} else {
|
|
|
|
|
// TODO Is $skin->getLanguage() safe here?
|
|
|
|
|
StubUserLang::unstub( $wgLang );
|
|
|
|
|
$langObj = $wgLang;
|
|
|
|
|
$langObjOrNull = $wgLang;
|
|
|
|
|
}
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $title === null ) {
|
2022-01-06 18:44:56 +00:00
|
|
|
$rv = wfMessage( $logActions[$key] )->inLanguage( $langObj )->escaped();
|
2005-06-19 20:25:09 +00:00
|
|
|
} else {
|
2020-01-29 12:08:16 +00:00
|
|
|
$titleLink = self::getTitleLink( $title, $langObjOrNull );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( count( $params ) == 0 ) {
|
2022-01-06 18:44:56 +00:00
|
|
|
$rv = wfMessage( $logActions[$key] )->rawParams( $titleLink )
|
2013-12-03 14:58:51 +00:00
|
|
|
->inLanguage( $langObj )->escaped();
|
2005-04-03 07:36:50 +00:00
|
|
|
} else {
|
|
|
|
|
array_unshift( $params, $titleLink );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2022-01-06 18:44:56 +00:00
|
|
|
$rv = wfMessage( $logActions[$key] )->rawParams( $params )
|
2015-08-22 18:29:00 +00:00
|
|
|
->inLanguage( $langObj )->escaped();
|
2005-04-03 07:36:50 +00:00
|
|
|
}
|
2004-08-25 17:24:31 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
} else {
|
2022-04-22 18:01:27 +00:00
|
|
|
$logActionsHandlers = $config->get( MainConfigNames::LogActionsHandlers );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2022-01-06 18:44:56 +00:00
|
|
|
if ( isset( $logActionsHandlers[$key] ) ) {
|
2008-05-14 19:12:00 +00:00
|
|
|
$args = func_get_args();
|
2022-01-06 18:44:56 +00:00
|
|
|
$rv = call_user_func_array( $logActionsHandlers[$key], $args );
|
2008-05-14 19:12:00 +00:00
|
|
|
} else {
|
2020-06-01 05:00:39 +00:00
|
|
|
wfDebug( "LogPage::actionText - unknown action $key" );
|
2008-05-14 19:12:00 +00:00
|
|
|
$rv = "$action";
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2010-08-21 12:00:28 +00:00
|
|
|
|
2009-03-04 01:28:05 +00:00
|
|
|
// For the perplexed, this feature was added in r7855 by Erik.
|
2010-08-21 12:00:28 +00:00
|
|
|
// The feature was added because we liked adding [[$1]] in our log entries
|
|
|
|
|
// but the log entries are parsed as Wikitext on RecentChanges but as HTML
|
|
|
|
|
// on Special:Log. The hack is essentially that [[$1]] represented a link
|
|
|
|
|
// to the title in question. The first parameter to the HTML version (Special:Log)
|
|
|
|
|
// is that link in HTML form, and so this just gets rid of the ugly [[]].
|
|
|
|
|
// However, this is a horrible hack and it doesn't work like you expect if, say,
|
|
|
|
|
// you want to link to something OTHER than the title of the log entry.
|
|
|
|
|
// The real problem, which Erik was trying to fix (and it sort-of works now) is
|
|
|
|
|
// that the same messages are being treated as both wikitext *and* HTML.
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $filterWikilinks ) {
|
2010-08-21 12:00:28 +00:00
|
|
|
$rv = str_replace( '[[', '', $rv );
|
|
|
|
|
$rv = str_replace( ']]', '', $rv );
|
2005-03-24 13:13:08 +00:00
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2005-03-24 13:13:08 +00:00
|
|
|
return $rv;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2010-08-21 12:00:28 +00:00
|
|
|
|
2011-04-16 23:23:28 +00:00
|
|
|
/**
|
2014-04-05 19:54:24 +00:00
|
|
|
* @param Title $title
|
2020-01-29 12:08:16 +00:00
|
|
|
* @param ?Language $lang
|
|
|
|
|
* @return string HTML
|
2011-04-16 23:23:28 +00:00
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
private static function getTitleLink( Title $title, ?Language $lang ): string {
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( !$lang ) {
|
2008-09-10 22:29:24 +00:00
|
|
|
return $title->getPrefixedText();
|
|
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2018-08-12 09:08:58 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$linkRenderer = $services->getLinkRenderer();
|
2020-01-29 12:08:16 +00:00
|
|
|
|
2014-08-04 21:12:53 +00:00
|
|
|
if ( $title->isSpecialPage() ) {
|
2020-01-29 12:08:16 +00:00
|
|
|
[ $name, $par ] = $services->getSpecialPageFactory()->resolveAlias( $title->getDBkey() );
|
2014-08-04 21:12:53 +00:00
|
|
|
|
2020-01-29 12:08:16 +00:00
|
|
|
if ( $name === 'Log' ) {
|
2014-08-04 21:12:53 +00:00
|
|
|
$logPage = new LogPage( $par );
|
2020-01-29 12:08:16 +00:00
|
|
|
return wfMessage( 'parentheses' )
|
|
|
|
|
->rawParams( $linkRenderer->makeLink( $title, $logPage->getName()->text() ) )
|
2014-08-04 21:12:53 +00:00
|
|
|
->inLanguage( $lang )
|
|
|
|
|
->escaped();
|
|
|
|
|
}
|
2008-09-10 22:29:24 +00:00
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2020-01-29 12:08:16 +00:00
|
|
|
return $linkRenderer->makeLink( $title );
|
2008-09-10 22:29:24 +00:00
|
|
|
}
|
2004-10-24 19:14:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a log entry
|
2010-05-18 20:59:14 +00:00
|
|
|
*
|
2014-07-24 17:43:03 +00:00
|
|
|
* @param string $action One of '', 'block', 'protect', 'rights', 'delete',
|
2013-12-03 14:58:51 +00:00
|
|
|
* 'upload', 'move', 'move_redir'
|
2017-12-28 15:06:10 +00:00
|
|
|
* @param Title $target
|
2014-07-24 17:43:03 +00:00
|
|
|
* @param string $comment Description associated
|
|
|
|
|
* @param array $params Parameters passed later to wfMessage function
|
2021-03-19 04:54:13 +00:00
|
|
|
* @param int|UserIdentity $performer The user doing the action, or their user id.
|
|
|
|
|
* Calling with user ID is deprecated since 1.36.
|
2011-09-04 21:40:17 +00:00
|
|
|
*
|
2014-07-24 17:43:03 +00:00
|
|
|
* @return int The log_id of the inserted log entry
|
2004-10-24 19:14:48 +00:00
|
|
|
*/
|
2021-03-19 04:54:13 +00:00
|
|
|
public function addEntry( $action, $target, $comment, $params, $performer ) {
|
2020-08-26 23:59:03 +00:00
|
|
|
// FIXME $params is only documented to accept an array
|
2005-01-14 13:47:19 +00:00
|
|
|
if ( !is_array( $params ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$params = [ $params ];
|
2005-01-14 13:47:19 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2010-08-21 12:00:28 +00:00
|
|
|
if ( $comment === null ) {
|
|
|
|
|
$comment = '';
|
|
|
|
|
}
|
2010-02-22 02:15:30 +00:00
|
|
|
|
2012-12-01 19:11:21 +00:00
|
|
|
# Trim spaces on user supplied text
|
|
|
|
|
$comment = trim( $comment );
|
|
|
|
|
|
2004-08-24 08:11:46 +00:00
|
|
|
$this->action = $action;
|
2006-07-14 04:13:49 +00:00
|
|
|
$this->target = $target;
|
2004-08-24 08:11:46 +00:00
|
|
|
$this->comment = $comment;
|
2017-07-23 01:24:09 +00:00
|
|
|
$this->params = self::makeParamBlob( $params );
|
2010-08-21 12:00:28 +00:00
|
|
|
|
2021-03-19 04:54:13 +00:00
|
|
|
if ( !is_object( $performer ) ) {
|
|
|
|
|
$performer = User::newFromId( $performer );
|
2008-07-09 06:44:31 +00:00
|
|
|
}
|
2010-08-21 12:00:28 +00:00
|
|
|
|
2021-03-19 04:54:13 +00:00
|
|
|
$this->performer = $performer;
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2012-02-08 19:52:04 +00:00
|
|
|
$logEntry = new ManualLogEntry( $this->type, $action );
|
|
|
|
|
$logEntry->setTarget( $target );
|
2021-03-19 04:54:13 +00:00
|
|
|
$logEntry->setPerformer( $performer );
|
2012-02-08 19:52:04 +00:00
|
|
|
$logEntry->setParameters( $params );
|
2015-03-14 11:17:24 +00:00
|
|
|
// All log entries using the LogPage to insert into the logging table
|
|
|
|
|
// are using the old logging system and therefore the legacy flag is
|
|
|
|
|
// needed to say the LogFormatter the parameters have numeric keys
|
|
|
|
|
$logEntry->setLegacy( true );
|
2012-02-08 19:52:04 +00:00
|
|
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $logEntry );
|
|
|
|
|
$context = RequestContext::newExtraneousContext( $target );
|
|
|
|
|
$formatter->setContext( $context );
|
|
|
|
|
|
|
|
|
|
$this->actionText = $formatter->getPlainActionText();
|
2012-02-21 23:42:10 +00:00
|
|
|
$this->ircActionText = $formatter->getIRCActionText();
|
2005-04-03 07:36:50 +00:00
|
|
|
|
2008-04-16 17:34:52 +00:00
|
|
|
return $this->saveContent();
|
2003-05-16 11:19:06 +00:00
|
|
|
}
|
2010-08-21 12:00:28 +00:00
|
|
|
|
2009-05-13 22:03:32 +00:00
|
|
|
/**
|
|
|
|
|
* Add relations to log_search table
|
2010-05-18 20:59:14 +00:00
|
|
|
*
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param string $field
|
|
|
|
|
* @param array $values
|
|
|
|
|
* @param int $logid
|
|
|
|
|
* @return bool
|
2009-05-13 22:03:32 +00:00
|
|
|
*/
|
|
|
|
|
public function addRelations( $field, $values, $logid ) {
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( !strlen( $field ) || empty( $values ) ) {
|
2019-01-09 16:15:21 +00:00
|
|
|
return false;
|
2010-08-21 12:00:28 +00:00
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$data = [];
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
foreach ( $values as $value ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$data[] = [
|
2010-08-21 12:00:28 +00:00
|
|
|
'ls_field' => $field,
|
|
|
|
|
'ls_value' => $value,
|
|
|
|
|
'ls_log_id' => $logid
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2009-05-13 22:03:32 +00:00
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2021-04-29 02:37:11 +00:00
|
|
|
$dbw = wfGetDB( DB_PRIMARY );
|
2019-06-07 17:12:35 +00:00
|
|
|
$dbw->insert( 'log_search', $data, __METHOD__, [ 'IGNORE' ] );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2009-05-13 22:03:32 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2005-01-14 13:47:19 +00:00
|
|
|
|
2005-08-02 13:35:19 +00:00
|
|
|
/**
|
2005-01-14 13:47:19 +00:00
|
|
|
* Create a blob from a parameter array
|
2010-05-18 20:59:14 +00:00
|
|
|
*
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param array $params
|
|
|
|
|
* @return string
|
2005-01-14 13:47:19 +00:00
|
|
|
*/
|
2009-01-09 23:18:47 +00:00
|
|
|
public static function makeParamBlob( $params ) {
|
2005-01-14 13:47:19 +00:00
|
|
|
return implode( "\n", $params );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract a parameter array from a blob
|
2010-05-18 20:59:14 +00:00
|
|
|
*
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param string $blob
|
|
|
|
|
* @return array
|
2005-01-14 13:47:19 +00:00
|
|
|
*/
|
2009-01-09 23:18:47 +00:00
|
|
|
public static function extractParams( $blob ) {
|
2005-01-14 13:47:19 +00:00
|
|
|
if ( $blob === '' ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [];
|
2005-01-14 13:47:19 +00:00
|
|
|
} else {
|
|
|
|
|
return explode( "\n", $blob );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
/**
|
|
|
|
|
* Name of the log.
|
|
|
|
|
* @return Message
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
public function getName() {
|
2022-04-22 18:01:27 +00:00
|
|
|
$logNames = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogNames );
|
2011-09-07 15:32:37 +00:00
|
|
|
|
|
|
|
|
// BC
|
2022-01-06 18:44:56 +00:00
|
|
|
$key = $logNames[$this->type] ?? 'log-name-' . $this->type;
|
2011-09-07 15:32:37 +00:00
|
|
|
|
|
|
|
|
return wfMessage( $key );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Description of this log type.
|
|
|
|
|
* @return Message
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
public function getDescription() {
|
2022-04-22 18:01:27 +00:00
|
|
|
$logHeaders = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogHeaders );
|
2011-09-07 15:32:37 +00:00
|
|
|
// BC
|
2022-01-06 18:44:56 +00:00
|
|
|
$key = $logHeaders[$this->type] ?? 'log-description-' . $this->type;
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
return wfMessage( $key );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the right needed to read this log type.
|
|
|
|
|
* @return string
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
public function getRestriction() {
|
2022-04-22 18:01:27 +00:00
|
|
|
$logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
|
2020-10-18 19:46:38 +00:00
|
|
|
// The empty string fallback will
|
|
|
|
|
// always return true in permission check
|
2022-01-06 18:44:56 +00:00
|
|
|
return $logRestrictions[$this->type] ?? '';
|
2011-09-07 15:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tells if this log is not viewable by all.
|
|
|
|
|
* @return bool
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
public function isRestricted() {
|
|
|
|
|
$restriction = $this->getRestriction();
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2011-09-07 15:32:37 +00:00
|
|
|
return $restriction !== '' && $restriction !== '*';
|
|
|
|
|
}
|
2008-03-12 22:27:25 +00:00
|
|
|
}
|