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>
|
|
|
|
|
* http://www.mediawiki.org/
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
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.
|
2004-09-03 23:00:01 +00:00
|
|
|
*
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
class LogPage {
|
2008-03-12 22:27:25 +00:00
|
|
|
const DELETED_ACTION = 1;
|
|
|
|
|
const DELETED_COMMENT = 2;
|
|
|
|
|
const DELETED_USER = 4;
|
2009-11-14 21:27:13 +00:00
|
|
|
const DELETED_RESTRICTED = 8;
|
2009-07-30 14:08:25 +00:00
|
|
|
// Convenience fields
|
|
|
|
|
const SUPPRESSED_USER = 12;
|
|
|
|
|
const SUPPRESSED_ACTION = 9;
|
2005-09-09 19:26:56 +00:00
|
|
|
/* @access private */
|
2011-05-26 19:21:50 +00:00
|
|
|
var $type, $action, $comment, $params;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var User
|
|
|
|
|
*/
|
|
|
|
|
var $doer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Title
|
|
|
|
|
*/
|
|
|
|
|
var $target;
|
|
|
|
|
|
2013-03-11 03:16:28 +00:00
|
|
|
/* @access public */
|
2009-01-09 18:30:47 +00:00
|
|
|
var $updateRecentChanges, $sendToUDP;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2005-07-07 13:44:33 +00:00
|
|
|
/**
|
2010-08-21 12:00:28 +00:00
|
|
|
* Constructor
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $type one of '', 'block', 'protect', 'rights', 'delete',
|
2010-08-21 12:00:28 +00:00
|
|
|
* 'upload', 'move'
|
|
|
|
|
* @param $rc Boolean: whether to update recent changes as well as the logging table
|
2013-03-11 17:15:01 +00:00
|
|
|
* @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
|
|
|
/**
|
2012-05-13 21:40:15 +00:00
|
|
|
* @return int 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() {
|
2009-01-09 23:18:47 +00:00
|
|
|
global $wgLogRestrictions;
|
2004-07-10 03:09:26 +00:00
|
|
|
|
2008-04-16 17:34:52 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2009-10-28 16:17:16 +00:00
|
|
|
$log_id = $dbw->nextSequenceValue( 'logging_log_id_seq' );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-24 08:11:46 +00:00
|
|
|
$this->timestamp = $now = wfTimestampNow();
|
2007-05-07 13:41:49 +00:00
|
|
|
$data = array(
|
2008-04-28 02:10:31 +00:00
|
|
|
'log_id' => $log_id,
|
2007-05-07 13:41:49 +00:00
|
|
|
'log_type' => $this->type,
|
|
|
|
|
'log_action' => $this->action,
|
|
|
|
|
'log_timestamp' => $dbw->timestamp( $now ),
|
2008-07-09 06:44:31 +00:00
|
|
|
'log_user' => $this->doer->getId(),
|
2009-06-27 10:17:01 +00:00
|
|
|
'log_user_text' => $this->doer->getName(),
|
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_comment' => $this->comment,
|
|
|
|
|
'log_params' => $this->params
|
2004-08-24 08:11:46 +00:00
|
|
|
);
|
2009-01-09 23:18:47 +00:00
|
|
|
$dbw->insert( 'logging', $data, __METHOD__ );
|
2010-08-21 12:00:28 +00:00
|
|
|
$newId = !is_null( $log_id ) ? $log_id : $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(
|
|
|
|
|
$now, $titleObj, $this->doer, $this->getRcComment(), '',
|
|
|
|
|
$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
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( isset( $wgLogRestrictions[$this->type] ) && $wgLogRestrictions[$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
|
|
|
|
2009-01-09 18:30:47 +00:00
|
|
|
# Notify external application via UDP.
|
|
|
|
|
# We send this to IRC but do not want to add it the RC table.
|
|
|
|
|
$titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
|
2010-08-21 12:00:28 +00:00
|
|
|
$rc = RecentChange::newLogEntry(
|
|
|
|
|
$now, $titleObj, $this->doer, $this->getRcComment(), '',
|
|
|
|
|
$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
|
|
|
);
|
2009-01-15 01:42:11 +00:00
|
|
|
$rc->notifyRC2UDP();
|
2004-01-17 05:49:39 +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
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
*
|
|
|
|
|
* @return Array of strings
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2007-05-02 20:37:13 +00:00
|
|
|
public static function validTypes() {
|
2006-05-25 07:37:20 +00:00
|
|
|
global $wgLogTypes;
|
|
|
|
|
return $wgLogTypes;
|
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-03-11 17:15:01 +00:00
|
|
|
* @param string $type log type to check
|
2010-05-18 20:59:14 +00:00
|
|
|
* @return Boolean
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2007-05-02 20:37:13 +00:00
|
|
|
public static function isLogType( $type ) {
|
2004-08-25 02:13:32 +00:00
|
|
|
return in_array( $type, LogPage::validTypes() );
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2010-05-18 20:59:14 +00:00
|
|
|
* Get the name for the given log type
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $type logtype
|
2010-05-18 20:59:14 +00:00
|
|
|
* @return String: log name
|
2011-09-07 15:32:37 +00:00
|
|
|
* @deprecated in 1.19, warnings in 1.21. Use getName()
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2006-11-29 05:45:03 +00:00
|
|
|
public static function logName( $type ) {
|
2010-08-03 19:15:43 +00:00
|
|
|
global $wgLogNames;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( isset( $wgLogNames[$type] ) ) {
|
2012-08-19 23:05:20 +00:00
|
|
|
return str_replace( '_', ' ', wfMessage( $wgLogNames[$type] )->text() );
|
2006-02-14 21:24:48 +00:00
|
|
|
} else {
|
|
|
|
|
// Bogus log types? Perhaps an extension was removed.
|
|
|
|
|
return $type;
|
|
|
|
|
}
|
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
|
|
|
* Get the log header for the given log type
|
|
|
|
|
*
|
2007-04-04 05:22:37 +00:00
|
|
|
* @todo handle missing log types
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $type logtype
|
2010-05-18 20:59:14 +00:00
|
|
|
* @return String: headertext of this logtype
|
2011-09-07 15:32:37 +00:00
|
|
|
* @deprecated in 1.19, warnings in 1.21. Use getDescription()
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2009-01-09 23:18:47 +00:00
|
|
|
public static function logHeader( $type ) {
|
2010-08-03 19:15:43 +00:00
|
|
|
global $wgLogHeaders;
|
2012-08-19 23:05:20 +00:00
|
|
|
return wfMessage( $wgLogHeaders[$type] )->parse();
|
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
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $type log type
|
|
|
|
|
* @param string $action log action
|
2010-05-18 20:59:14 +00:00
|
|
|
* @param $title Mixed: Title object or null
|
|
|
|
|
* @param $skin Mixed: Skin object or null. If null, we want to use the wiki
|
2010-08-21 12:00:28 +00:00
|
|
|
* content language, since that will go to the IRC feed.
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $params parameters
|
2010-05-18 20:59:14 +00:00
|
|
|
* @param $filterWikilinks Boolean: whether to filter wiki links
|
2008-07-06 20:19:04 +00:00
|
|
|
* @return HTML string
|
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,
|
2010-08-21 12:00:28 +00:00
|
|
|
$params = array(), $filterWikilinks = false )
|
2008-09-16 05:21:10 +00:00
|
|
|
{
|
2010-08-03 19:15:43 +00:00
|
|
|
global $wgLang, $wgContLang, $wgLogActions;
|
2005-09-30 15:03:48 +00:00
|
|
|
|
2011-07-10 18:12:11 +00:00
|
|
|
if ( is_null( $skin ) ) {
|
|
|
|
|
$langObj = $wgContLang;
|
|
|
|
|
$langObjOrNull = null;
|
|
|
|
|
} else {
|
|
|
|
|
$langObj = $wgLang;
|
|
|
|
|
$langObjOrNull = $wgLang;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-24 08:11:46 +00:00
|
|
|
$key = "$type/$action";
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( isset( $wgLogActions[$key] ) ) {
|
|
|
|
|
if ( is_null( $title ) ) {
|
2012-08-19 23:05:20 +00:00
|
|
|
$rv = wfMessage( $wgLogActions[$key] )->inLanguage( $langObj )->escaped();
|
2005-06-19 20:25:09 +00:00
|
|
|
} else {
|
2011-07-10 18:12:11 +00:00
|
|
|
$titleLink = self::getTitleLink( $type, $langObjOrNull, $title, $params );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( count( $params ) == 0 ) {
|
2012-08-19 23:05:20 +00:00
|
|
|
$rv = wfMessage( $wgLogActions[$key] )->rawParams( $titleLink )->inLanguage( $langObj )->escaped();
|
2005-04-03 07:36:50 +00:00
|
|
|
} else {
|
2008-09-10 22:06:41 +00:00
|
|
|
$details = '';
|
2005-04-03 07:36:50 +00:00
|
|
|
array_unshift( $params, $titleLink );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2009-04-10 20:01:10 +00:00
|
|
|
// User suppression
|
2009-03-14 10:02:17 +00:00
|
|
|
if ( preg_match( '/^(block|suppress)\/(block|reblock)$/', $key ) ) {
|
2007-09-10 01:53:24 +00:00
|
|
|
if ( $skin ) {
|
2013-07-21 09:44:59 +00:00
|
|
|
// Localize the duration, and add a tooltip
|
|
|
|
|
// in English to help visitors from other wikis.
|
|
|
|
|
// The lrm is needed to make sure that the number
|
|
|
|
|
// is shown on the correct side of the tooltip text.
|
|
|
|
|
$durationTooltip = '‎' . htmlspecialchars( $params[1] );
|
|
|
|
|
$params[1] = "<span class='blockExpiry' title='$durationTooltip'>" .
|
2008-09-10 22:06:41 +00:00
|
|
|
$wgLang->translateBlockExpiry( $params[1] ) . '</span>';
|
2007-09-10 01:53:24 +00:00
|
|
|
} else {
|
|
|
|
|
$params[1] = $wgContLang->translateBlockExpiry( $params[1] );
|
2007-03-21 17:04:01 +00:00
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2010-08-21 12:00:28 +00:00
|
|
|
$params[2] = isset( $params[2] ) ?
|
2011-07-10 18:12:11 +00:00
|
|
|
self::formatBlockFlags( $params[2], $langObj ) : '';
|
2009-04-10 20:01:10 +00:00
|
|
|
// Page protections
|
2013-02-03 18:30:03 +00:00
|
|
|
} elseif ( $type == 'protect' && count( $params ) == 3 ) {
|
2009-09-17 20:20:45 +00:00
|
|
|
// Restrictions and expiries
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $skin ) {
|
2011-07-06 02:26:06 +00:00
|
|
|
$details .= $wgLang->getDirMark() . htmlspecialchars( " {$params[1]}" );
|
2009-09-17 20:20:45 +00:00
|
|
|
} else {
|
|
|
|
|
$details .= " {$params[1]}";
|
|
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2009-09-17 20:20:45 +00:00
|
|
|
// Cascading flag...
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $params[2] ) {
|
2012-08-19 23:05:20 +00:00
|
|
|
$details .= ' [' . wfMessage( 'protect-summary-cascade' )->inLanguage( $langObj )->text() . ']';
|
2008-09-10 22:06:41 +00:00
|
|
|
}
|
2005-08-27 16:35:10 +00:00
|
|
|
}
|
2010-03-22 22:28:15 +00:00
|
|
|
|
2012-08-19 23:05:20 +00:00
|
|
|
$rv = wfMessage( $wgLogActions[$key] )->rawParams( $params )->inLanguage( $langObj )->escaped() . $details;
|
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 {
|
2008-05-14 19:12:00 +00:00
|
|
|
global $wgLogActionsHandlers;
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( isset( $wgLogActionsHandlers[$key] ) ) {
|
2008-05-14 19:12:00 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
|
$rv = call_user_func_array( $wgLogActionsHandlers[$key], $args );
|
|
|
|
|
} else {
|
|
|
|
|
wfDebug( "LogPage::actionText - unknown action $key\n" );
|
|
|
|
|
$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
|
|
|
/**
|
|
|
|
|
* TODO document
|
|
|
|
|
* @param $type String
|
2011-07-10 18:12:11 +00:00
|
|
|
* @param $lang Language or null
|
2011-04-16 23:23:28 +00:00
|
|
|
* @param $title Title
|
|
|
|
|
* @param $params Array
|
|
|
|
|
* @return String
|
|
|
|
|
*/
|
2011-07-10 18:12:11 +00:00
|
|
|
protected static function getTitleLink( $type, $lang, $title, &$params ) {
|
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
|
|
|
|
2013-04-26 14:42:31 +00:00
|
|
|
switch ( $type ) {
|
2008-09-10 22:29:24 +00:00
|
|
|
case 'move':
|
2011-04-16 23:23:28 +00:00
|
|
|
$titleLink = Linker::link(
|
2010-08-21 12:00:28 +00:00
|
|
|
$title,
|
2009-05-08 23:24:31 +00:00
|
|
|
htmlspecialchars( $title->getPrefixedText() ),
|
|
|
|
|
array(),
|
|
|
|
|
array( 'redirect' => 'no' )
|
|
|
|
|
);
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2008-09-10 22:29:24 +00:00
|
|
|
$targetTitle = Title::newFromText( $params[0] );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2008-09-10 22:29:24 +00:00
|
|
|
if ( !$targetTitle ) {
|
|
|
|
|
# Workaround for broken database
|
|
|
|
|
$params[0] = htmlspecialchars( $params[0] );
|
|
|
|
|
} else {
|
2011-04-16 23:23:28 +00:00
|
|
|
$params[0] = Linker::link(
|
2009-05-08 23:24:31 +00:00
|
|
|
$targetTitle,
|
|
|
|
|
htmlspecialchars( $params[0] )
|
|
|
|
|
);
|
2008-09-10 22:29:24 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'block':
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( substr( $title->getText(), 0, 1 ) == '#' ) {
|
2008-09-10 22:29:24 +00:00
|
|
|
$titleLink = $title->getText();
|
|
|
|
|
} else {
|
2011-09-03 11:34:55 +00:00
|
|
|
// @todo Store the user identifier in the parameters
|
2008-09-10 22:29:24 +00:00
|
|
|
// to make this faster for future log entries
|
|
|
|
|
$id = User::idFromName( $title->getText() );
|
2011-04-16 23:23:28 +00:00
|
|
|
$titleLink = Linker::userLink( $id, $title->getText() )
|
|
|
|
|
. Linker::userToolLinks( $id, $title->getText(), false, Linker::TOOL_LINKS_NOBLOCK );
|
2008-09-10 22:29:24 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'merge':
|
2011-04-16 23:23:28 +00:00
|
|
|
$titleLink = Linker::link(
|
2009-05-08 23:24:31 +00:00
|
|
|
$title,
|
|
|
|
|
$title->getPrefixedText(),
|
|
|
|
|
array(),
|
|
|
|
|
array( 'redirect' => 'no' )
|
|
|
|
|
);
|
2011-04-16 23:23:28 +00:00
|
|
|
$params[0] = Linker::link(
|
2009-05-08 23:24:31 +00:00
|
|
|
Title::newFromText( $params[0] ),
|
|
|
|
|
htmlspecialchars( $params[0] )
|
|
|
|
|
);
|
2011-07-10 18:12:11 +00:00
|
|
|
$params[1] = $lang->timeanddate( $params[1] );
|
2008-09-10 22:29:24 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $title->isSpecialPage() ) {
|
2011-04-16 23:23:28 +00:00
|
|
|
list( $name, $par ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2008-09-10 22:29:24 +00:00
|
|
|
# Use the language name for log titles, rather than Log/X
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $name == 'Log' ) {
|
2012-06-18 22:56:55 +00:00
|
|
|
$logPage = new LogPage( $par );
|
|
|
|
|
$titleLink = Linker::link( $title, $logPage->getName()->escaped() );
|
|
|
|
|
$titleLink = wfMessage( 'parentheses' )
|
|
|
|
|
->inLanguage( $lang )
|
|
|
|
|
->rawParams( $titleLink )
|
|
|
|
|
->escaped();
|
2008-09-10 22:29:24 +00:00
|
|
|
} else {
|
2011-04-16 23:23:28 +00:00
|
|
|
$titleLink = Linker::link( $title );
|
2008-09-10 22:29:24 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2011-04-16 23:23:28 +00:00
|
|
|
$titleLink = Linker::link( $title );
|
2008-09-10 22:29:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2008-09-10 22:29:24 +00:00
|
|
|
return $titleLink;
|
|
|
|
|
}
|
2004-10-24 19:14:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a log entry
|
2010-05-18 20:59:14 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $action one of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
|
2010-05-18 20:59:14 +00:00
|
|
|
* @param $target Title object
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $comment description associated
|
|
|
|
|
* @param array $params parameters passed later to wfMessage function
|
2010-05-18 20:59:14 +00:00
|
|
|
* @param $doer User object: the user doing the action
|
2011-09-04 21:40:17 +00:00
|
|
|
*
|
2012-05-13 21:40:15 +00:00
|
|
|
* @return int log_id of the inserted log entry
|
2004-10-24 19:14:48 +00:00
|
|
|
*/
|
2009-01-09 23:18:47 +00:00
|
|
|
public function addEntry( $action, $target, $comment, $params = array(), $doer = null ) {
|
2011-08-24 23:47:54 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
|
2005-01-14 13:47:19 +00:00
|
|
|
if ( !is_array( $params ) ) {
|
|
|
|
|
$params = array( $params );
|
|
|
|
|
}
|
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 );
|
|
|
|
|
|
2011-08-24 23:47:54 +00:00
|
|
|
# Truncate for whole multibyte characters.
|
|
|
|
|
$comment = $wgContLang->truncate( $comment, 255 );
|
|
|
|
|
|
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;
|
2006-11-08 07:12:03 +00:00
|
|
|
$this->params = LogPage::makeParamBlob( $params );
|
2010-08-21 12:00:28 +00:00
|
|
|
|
|
|
|
|
if ( $doer === null ) {
|
2008-07-09 06:44:31 +00:00
|
|
|
global $wgUser;
|
2008-07-09 08:21:51 +00:00
|
|
|
$doer = $wgUser;
|
2010-08-21 12:00:28 +00:00
|
|
|
} elseif ( !is_object( $doer ) ) {
|
2008-07-09 06:44:31 +00:00
|
|
|
$doer = User::newFromId( $doer );
|
|
|
|
|
}
|
2010-08-21 12:00:28 +00:00
|
|
|
|
2008-07-09 06:44:31 +00:00
|
|
|
$this->doer = $doer;
|
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 );
|
|
|
|
|
$logEntry->setPerformer( $doer );
|
|
|
|
|
$logEntry->setParameters( $params );
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
*
|
|
|
|
|
* @param $field String
|
|
|
|
|
* @param $values Array
|
|
|
|
|
* @param $logid Integer
|
|
|
|
|
* @return Boolean
|
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 ) ) {
|
2009-05-13 22:03:32 +00:00
|
|
|
return false; // nothing
|
2010-08-21 12:00:28 +00:00
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2009-05-13 22:03:32 +00:00
|
|
|
$data = array();
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
foreach ( $values as $value ) {
|
2010-08-21 12:00:28 +00:00
|
|
|
$data[] = array(
|
|
|
|
|
'ls_field' => $field,
|
|
|
|
|
'ls_value' => $value,
|
|
|
|
|
'ls_log_id' => $logid
|
|
|
|
|
);
|
2009-05-13 22:03:32 +00:00
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2009-05-13 22:03:32 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
$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
|
|
|
*
|
|
|
|
|
* @param $params Array
|
|
|
|
|
* @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
|
|
|
*
|
|
|
|
|
* @param $blob String
|
|
|
|
|
* @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 === '' ) {
|
|
|
|
|
return array();
|
|
|
|
|
} else {
|
|
|
|
|
return explode( "\n", $blob );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-01-09 01:54:52 +00:00
|
|
|
/**
|
|
|
|
|
* Convert a comma-delimited list of block log flags
|
|
|
|
|
* into a more readable (and translated) form
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $flags Flags to format
|
2011-07-10 18:12:11 +00:00
|
|
|
* @param $lang Language object to use
|
2010-05-18 20:59:14 +00:00
|
|
|
* @return String
|
2007-01-09 01:54:52 +00:00
|
|
|
*/
|
2011-07-10 18:12:11 +00:00
|
|
|
public static function formatBlockFlags( $flags, $lang ) {
|
2013-05-31 20:18:10 +00:00
|
|
|
$flags = trim( $flags );
|
|
|
|
|
if ( $flags === '' ) {
|
|
|
|
|
return ''; //nothing to do
|
|
|
|
|
}
|
|
|
|
|
$flags = explode( ',', $flags );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2013-05-31 20:18:10 +00:00
|
|
|
for ( $i = 0; $i < count( $flags ); $i++ ) {
|
|
|
|
|
$flags[$i] = self::formatBlockFlag( $flags[$i], $lang );
|
2007-01-09 01:54:52 +00:00
|
|
|
}
|
2013-05-31 20:18:10 +00:00
|
|
|
return wfMessage( 'parentheses' )->inLanguage( $lang )
|
|
|
|
|
->rawParams( $lang->commaList( $flags ) )->escaped();
|
2007-01-09 01:54:52 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-01-09 01:54:52 +00:00
|
|
|
/**
|
|
|
|
|
* Translate a block log flag if possible
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $flag Flag to translate
|
2011-07-10 18:12:11 +00:00
|
|
|
* @param $lang Language object to use
|
2010-05-18 20:59:14 +00:00
|
|
|
* @return String
|
2007-01-09 01:54:52 +00:00
|
|
|
*/
|
2011-07-10 18:12:11 +00:00
|
|
|
public static function formatBlockFlag( $flag, $lang ) {
|
2007-01-09 01:54:52 +00:00
|
|
|
static $messages = array();
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( !isset( $messages[$flag] ) ) {
|
2011-01-15 12:46:37 +00:00
|
|
|
$messages[$flag] = htmlspecialchars( $flag ); // Fallback
|
|
|
|
|
|
2011-09-01 15:00:42 +00:00
|
|
|
// For grepping. The following core messages can be used here:
|
|
|
|
|
// * block-log-flags-angry-autoblock
|
|
|
|
|
// * block-log-flags-anononly
|
|
|
|
|
// * block-log-flags-hiddenname
|
|
|
|
|
// * block-log-flags-noautoblock
|
|
|
|
|
// * block-log-flags-nocreate
|
|
|
|
|
// * block-log-flags-noemail
|
|
|
|
|
// * block-log-flags-nousertalk
|
2011-07-10 18:12:11 +00:00
|
|
|
$msg = wfMessage( 'block-log-flags-' . $flag )->inLanguage( $lang );
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2011-01-15 12:46:37 +00:00
|
|
|
if ( $msg->exists() ) {
|
|
|
|
|
$messages[$flag] = $msg->escaped();
|
2010-08-21 12:00:28 +00:00
|
|
|
}
|
2007-01-09 01:54:52 +00:00
|
|
|
}
|
2011-09-03 11:34:55 +00:00
|
|
|
|
2007-01-09 01:54:52 +00:00
|
|
|
return $messages[$flag];
|
|
|
|
|
}
|
2011-09-07 15:32:37 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Name of the log.
|
|
|
|
|
* @return Message
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
public function getName() {
|
|
|
|
|
global $wgLogNames;
|
|
|
|
|
|
|
|
|
|
// BC
|
|
|
|
|
if ( isset( $wgLogNames[$this->type] ) ) {
|
|
|
|
|
$key = $wgLogNames[$this->type];
|
|
|
|
|
} else {
|
|
|
|
|
$key = 'log-name-' . $this->type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return wfMessage( $key );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Description of this log type.
|
|
|
|
|
* @return Message
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
public function getDescription() {
|
|
|
|
|
global $wgLogHeaders;
|
|
|
|
|
// BC
|
|
|
|
|
if ( isset( $wgLogHeaders[$this->type] ) ) {
|
|
|
|
|
$key = $wgLogHeaders[$this->type];
|
|
|
|
|
} else {
|
|
|
|
|
$key = 'log-description-' . $this->type;
|
|
|
|
|
}
|
|
|
|
|
return wfMessage( $key );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the right needed to read this log type.
|
|
|
|
|
* @return string
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
public function getRestriction() {
|
|
|
|
|
global $wgLogRestrictions;
|
|
|
|
|
if ( isset( $wgLogRestrictions[$this->type] ) ) {
|
|
|
|
|
$restriction = $wgLogRestrictions[$this->type];
|
|
|
|
|
} else {
|
|
|
|
|
// '' always returns true with $user->isAllowed()
|
|
|
|
|
$restriction = '';
|
|
|
|
|
}
|
|
|
|
|
return $restriction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tells if this log is not viewable by all.
|
|
|
|
|
* @return bool
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
public function isRestricted() {
|
|
|
|
|
$restriction = $this->getRestriction();
|
|
|
|
|
return $restriction !== '' && $restriction !== '*';
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-12 22:27:25 +00:00
|
|
|
}
|