2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-08-20 13:43:45 +00:00
|
|
|
#
|
2004-08-24 08:11:46 +00:00
|
|
|
# Copyright (C) 2002, 2004 Brion Vibber <brion@pobox.com>
|
|
|
|
|
# http://www.mediawiki.org/
|
2005-08-02 13:35:19 +00:00
|
|
|
#
|
2004-08-24 08:11:46 +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
|
2005-08-02 13:35:19 +00:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
2004-08-24 08:11:46 +00:00
|
|
|
# (at your option) any later version.
|
2005-08-02 13:35:19 +00:00
|
|
|
#
|
2004-08-24 08:11:46 +00:00
|
|
|
# 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.
|
2005-08-02 13:35:19 +00:00
|
|
|
#
|
2004-08-24 08:11:46 +00:00
|
|
|
# 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.,
|
2006-04-05 07:43:17 +00:00
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-08-24 08:11:46 +00:00
|
|
|
# http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Contain log classes
|
2004-09-03 23:00:01 +00:00
|
|
|
*
|
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 {
|
2005-09-09 19:26:56 +00:00
|
|
|
/* @access private */
|
2006-05-11 22:40:38 +00:00
|
|
|
var $type, $action, $comment, $params, $target;
|
2005-09-09 19:26:56 +00:00
|
|
|
/* @acess public */
|
2006-05-11 22:40:38 +00:00
|
|
|
var $updateRecentChanges;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2005-07-07 13:44:33 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
2005-07-07 14:10:00 +00:00
|
|
|
* @param string $type One of '', 'block', 'protect', 'rights', 'delete',
|
2005-07-07 13:44:33 +00:00
|
|
|
* 'upload', 'move'
|
2005-09-09 19:26:56 +00:00
|
|
|
* @param bool $rc Whether to update recent changes as well as the logging table
|
2005-07-07 13:44:33 +00:00
|
|
|
*/
|
2007-01-20 13:34:31 +00:00
|
|
|
function __construct( $type, $rc = true ) {
|
2004-08-24 08:11:46 +00:00
|
|
|
$this->type = $type;
|
2005-09-09 19:26:56 +00:00
|
|
|
$this->updateRecentChanges = $rc;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-24 08:11:46 +00:00
|
|
|
function saveContent() {
|
2006-05-01 10:53:59 +00:00
|
|
|
if( wfReadOnly() ) return false;
|
2003-05-16 11:19:06 +00:00
|
|
|
|
2007-03-16 16:01:07 +00:00
|
|
|
global $wgUser;
|
2004-08-22 17:24:50 +00:00
|
|
|
$fname = 'LogPage::saveContent';
|
2004-07-10 03:09:26 +00:00
|
|
|
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2003-04-14 23:10:40 +00:00
|
|
|
$uid = $wgUser->getID();
|
|
|
|
|
|
2004-08-24 08:11:46 +00:00
|
|
|
$this->timestamp = $now = wfTimestampNow();
|
2004-10-24 07:10:33 +00:00
|
|
|
$dbw->insert( 'logging',
|
2004-08-24 08:11:46 +00:00
|
|
|
array(
|
|
|
|
|
'log_type' => $this->type,
|
|
|
|
|
'log_action' => $this->action,
|
|
|
|
|
'log_timestamp' => $dbw->timestamp( $now ),
|
|
|
|
|
'log_user' => $uid,
|
|
|
|
|
'log_namespace' => $this->target->getNamespace(),
|
|
|
|
|
'log_title' => $this->target->getDBkey(),
|
2005-01-14 13:47:19 +00:00
|
|
|
'log_comment' => $this->comment,
|
|
|
|
|
'log_params' => $this->params
|
2004-08-24 08:11:46 +00:00
|
|
|
), $fname
|
|
|
|
|
);
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
# And update recentchanges
|
2004-08-24 08:11:46 +00:00
|
|
|
if ( $this->updateRecentChanges ) {
|
2007-03-16 16:01:07 +00:00
|
|
|
$titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
|
|
|
|
|
$rcComment = $this->actionText;
|
|
|
|
|
if( '' != $this->comment ) {
|
|
|
|
|
if ($rcComment == '')
|
|
|
|
|
$rcComment = $this->comment;
|
|
|
|
|
else
|
|
|
|
|
$rcComment .= ': ' . $this->comment;
|
2004-08-24 08:11:46 +00:00
|
|
|
}
|
2007-03-16 16:01:07 +00:00
|
|
|
|
|
|
|
|
RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment, '',
|
|
|
|
|
$this->type, $this->action, $this->target, $this->comment, $this->params );
|
2004-01-17 05:49:39 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
2006-05-11 22:40:38 +00:00
|
|
|
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
|
|
|
/**
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
2006-05-11 22:40:38 +00:00
|
|
|
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
|
|
|
/**
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
2006-11-29 05:45:03 +00:00
|
|
|
public static function logName( $type ) {
|
2006-05-25 07:37:20 +00:00
|
|
|
global $wgLogNames;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2006-05-25 07:37:20 +00:00
|
|
|
if( isset( $wgLogNames[$type] ) ) {
|
|
|
|
|
return str_replace( '_', ' ', wfMsg( $wgLogNames[$type] ) );
|
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
|
|
|
/**
|
2007-03-28 14:16:43 +00:00
|
|
|
* @fixme: handle missing log types
|
2004-09-02 23:28:24 +00:00
|
|
|
* @static
|
|
|
|
|
*/
|
2006-05-11 22:40:38 +00:00
|
|
|
function logHeader( $type ) {
|
2006-05-25 07:37:20 +00:00
|
|
|
global $wgLogHeaders;
|
2007-03-16 16:01:07 +00:00
|
|
|
return wfMsg( $wgLogHeaders[$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
|
|
|
/**
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
2007-03-16 16:01:07 +00:00
|
|
|
function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false, $translate=false ) {
|
2006-05-25 07:37:20 +00:00
|
|
|
global $wgLang, $wgContLang, $wgLogActions;
|
2005-09-30 15:03:48 +00:00
|
|
|
|
2004-08-24 08:11:46 +00:00
|
|
|
$key = "$type/$action";
|
2007-01-16 17:05:30 +00:00
|
|
|
|
|
|
|
|
if( $key == 'patrol/patrol' )
|
|
|
|
|
return PatrolLog::makeActionText( $title, $params, $skin );
|
|
|
|
|
|
2006-05-25 07:37:20 +00:00
|
|
|
if( isset( $wgLogActions[$key] ) ) {
|
2005-04-03 07:36:50 +00:00
|
|
|
if( is_null( $title ) ) {
|
2006-05-25 07:37:20 +00:00
|
|
|
$rv=wfMsg( $wgLogActions[$key] );
|
2005-06-19 20:25:09 +00:00
|
|
|
} else {
|
2006-11-08 07:12:03 +00:00
|
|
|
if( $skin ) {
|
|
|
|
|
|
2006-01-29 23:24:01 +00:00
|
|
|
switch( $type ) {
|
|
|
|
|
case 'move':
|
2006-11-08 07:12:03 +00:00
|
|
|
$titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
|
|
|
|
|
$params[0] = $skin->makeLinkObj( Title::newFromText( $params[0] ), $params[0] );
|
2006-01-29 23:24:01 +00:00
|
|
|
break;
|
|
|
|
|
case 'block':
|
2006-02-05 22:54:12 +00:00
|
|
|
if( substr( $title->getText(), 0, 1 ) == '#' ) {
|
2006-02-05 22:59:53 +00:00
|
|
|
$titleLink = $title->getText();
|
2006-01-29 23:24:01 +00:00
|
|
|
} else {
|
2006-11-08 07:12:03 +00:00
|
|
|
$titleLink = $skin->makeLinkObj( $title, $title->getText() );
|
|
|
|
|
$titleLink .= ' (' . $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions', $title->getDBkey() ), wfMsg( 'contribslink' ) ) . ')';
|
2006-01-29 23:24:01 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2006-04-15 15:18:33 +00:00
|
|
|
case 'rights':
|
|
|
|
|
$text = $wgContLang->ucfirst( $title->getText() );
|
2006-11-08 07:12:03 +00:00
|
|
|
$titleLink = $skin->makeLinkObj( Title::makeTitle( NS_USER, $text ) );
|
2006-04-15 15:18:33 +00:00
|
|
|
break;
|
2006-01-29 23:24:01 +00:00
|
|
|
default:
|
2006-11-08 07:12:03 +00:00
|
|
|
$titleLink = $skin->makeLinkObj( $title );
|
2005-04-03 07:36:50 +00:00
|
|
|
}
|
2006-11-08 07:12:03 +00:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
$titleLink = $title->getPrefixedText();
|
2005-04-03 07:36:50 +00:00
|
|
|
}
|
2006-06-20 09:09:20 +00:00
|
|
|
if( $key == 'rights/rights' ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
if ($skin) {
|
2006-11-08 05:21:15 +00:00
|
|
|
$rightsnone = wfMsg( 'rightsnone' );
|
2006-11-08 07:12:03 +00:00
|
|
|
} else {
|
|
|
|
|
$rightsnone = wfMsgForContent( 'rightsnone' );
|
2006-06-20 09:09:20 +00:00
|
|
|
}
|
|
|
|
|
if( !isset( $params[0] ) || trim( $params[0] ) == '' )
|
|
|
|
|
$params[0] = $rightsnone;
|
|
|
|
|
if( !isset( $params[1] ) || trim( $params[1] ) == '' )
|
|
|
|
|
$params[1] = $rightsnone;
|
|
|
|
|
}
|
2005-06-19 20:25:09 +00:00
|
|
|
if( count( $params ) == 0 ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
if ( $skin ) {
|
2006-11-08 05:21:15 +00:00
|
|
|
$rv = wfMsg( $wgLogActions[$key], $titleLink );
|
2006-11-08 07:12:03 +00:00
|
|
|
} else {
|
|
|
|
|
$rv = wfMsgForContent( $wgLogActions[$key], $titleLink );
|
2006-04-18 18:05:13 +00:00
|
|
|
}
|
2005-04-03 07:36:50 +00:00
|
|
|
} else {
|
|
|
|
|
array_unshift( $params, $titleLink );
|
2007-03-21 17:04:01 +00:00
|
|
|
if ( $key == 'block/block' ) {
|
|
|
|
|
if ( $translate ) {
|
|
|
|
|
$params[1] = $wgLang->translateBlockExpiry( $params[1] );
|
|
|
|
|
}
|
2007-01-09 01:54:52 +00:00
|
|
|
$params[2] = isset( $params[2] )
|
|
|
|
|
? self::formatBlockFlags( $params[2] )
|
|
|
|
|
: '';
|
2005-08-27 16:35:10 +00:00
|
|
|
}
|
2006-11-08 07:12:03 +00:00
|
|
|
$rv = wfMsgReal( $wgLogActions[$key], $params, true, !$skin );
|
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 {
|
2004-08-24 08:11:46 +00:00
|
|
|
wfDebug( "LogPage::actionText - unknown action $key\n" );
|
2005-07-07 13:44:33 +00:00
|
|
|
$rv = "$action";
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2005-06-19 20:25:09 +00:00
|
|
|
if( $filterWikilinks ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
$rv = str_replace( "[[", "", $rv );
|
|
|
|
|
$rv = str_replace( "]]", "", $rv );
|
2005-03-24 13:13:08 +00:00
|
|
|
}
|
|
|
|
|
return $rv;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2004-10-24 19:14:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a log entry
|
2005-07-07 14:10:00 +00:00
|
|
|
* @param string $action one of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
|
2005-01-31 04:07:56 +00:00
|
|
|
* @param object &$target A title object.
|
2004-10-24 19:14:48 +00:00
|
|
|
* @param string $comment Description associated
|
2005-01-31 04:07:56 +00:00
|
|
|
* @param array $params Parameters passed later to wfMsg.* functions
|
2004-10-24 19:14:48 +00:00
|
|
|
*/
|
2006-07-14 04:13:49 +00:00
|
|
|
function addEntry( $action, $target, $comment, $params = array() ) {
|
2005-01-14 13:47:19 +00:00
|
|
|
if ( !is_array( $params ) ) {
|
|
|
|
|
$params = array( $params );
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
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 );
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2007-03-16 16:01:07 +00:00
|
|
|
$this->actionText = LogPage::actionText( $this->type, $action, $target, NULL, $params );
|
2005-04-03 07:36:50 +00:00
|
|
|
|
2004-08-24 08:11:46 +00:00
|
|
|
return $this->saveContent();
|
2003-05-16 11:19:06 +00:00
|
|
|
}
|
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
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeParamBlob( $params ) {
|
2005-01-14 13:47:19 +00:00
|
|
|
return implode( "\n", $params );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract a parameter array from a blob
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function extractParams( $blob ) {
|
2005-01-14 13:47:19 +00:00
|
|
|
if ( $blob === '' ) {
|
|
|
|
|
return array();
|
|
|
|
|
} else {
|
|
|
|
|
return explode( "\n", $blob );
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-01-09 01:54:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert a comma-delimited list of block log flags
|
|
|
|
|
* into a more readable (and translated) form
|
|
|
|
|
*
|
|
|
|
|
* @param $flags Flags to format
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function formatBlockFlags( $flags ) {
|
|
|
|
|
$flags = explode( ',', trim( $flags ) );
|
|
|
|
|
if( count( $flags ) > 0 ) {
|
|
|
|
|
for( $i = 0; $i < count( $flags ); $i++ )
|
|
|
|
|
$flags[$i] = self::formatBlockFlag( $flags[$i] );
|
|
|
|
|
return '(' . implode( ', ', $flags ) . ')';
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Translate a block log flag if possible
|
|
|
|
|
*
|
|
|
|
|
* @param $flag Flag to translate
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function formatBlockFlag( $flag ) {
|
|
|
|
|
static $messages = array();
|
|
|
|
|
if( !isset( $messages[$flag] ) ) {
|
|
|
|
|
$k = 'block-log-flags-' . $flag;
|
|
|
|
|
$msg = wfMsg( $k );
|
|
|
|
|
$messages[$flag] = htmlspecialchars( wfEmptyMsg( $k, $msg ) ? $flag : $msg );
|
|
|
|
|
}
|
|
|
|
|
return $messages[$flag];
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|