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/
|
|
|
|
|
#
|
|
|
|
|
# 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.,
|
|
|
|
|
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
# 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
|
|
|
*
|
|
|
|
|
* @package MediaWiki
|
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
|
|
|
*
|
|
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
class LogPage {
|
2005-01-14 13:47:19 +00:00
|
|
|
/* private */ var $type, $action, $comment, $params;
|
2004-08-24 08:11:46 +00:00
|
|
|
var $updateRecentChanges = true;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-24 08:11:46 +00:00
|
|
|
function LogPage( $type ) {
|
2005-01-31 04:07:56 +00:00
|
|
|
# Type is one of 'block', 'protect', 'rights', 'delete', 'upload', 'move'
|
2004-08-24 08:11:46 +00:00
|
|
|
$this->type = $type;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-24 08:11:46 +00:00
|
|
|
function saveContent() {
|
2003-05-16 11:19:06 +00:00
|
|
|
if( wfReadOnly() ) return;
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
global $wgUser;
|
2004-08-22 17:24:50 +00:00
|
|
|
$fname = 'LogPage::saveContent';
|
2004-07-10 03:09:26 +00:00
|
|
|
|
2004-07-18 08:48:43 +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
|
|
|
|
|
);
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
# And update recentchanges
|
2004-08-24 08:11:46 +00:00
|
|
|
if ( $this->updateRecentChanges ) {
|
|
|
|
|
$rcComment = $this->actionText;
|
|
|
|
|
if( '' != $this->comment ) {
|
|
|
|
|
$rcComment .= ': ' . $this->comment;
|
|
|
|
|
}
|
|
|
|
|
$titleObj = Title::makeTitle( NS_SPECIAL, 'Log/' . $this->type );
|
|
|
|
|
RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment );
|
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
|
|
|
|
|
*/
|
|
|
|
|
function validTypes() {
|
2005-01-31 04:07:56 +00:00
|
|
|
static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' );
|
2004-08-25 02:13:32 +00:00
|
|
|
return $types;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
function validActions( $type ) {
|
2004-08-25 17:24:31 +00:00
|
|
|
static $actions = array(
|
|
|
|
|
'' => NULL,
|
|
|
|
|
'block' => array( 'block', 'unblock' ),
|
|
|
|
|
'protect' => array( 'protect', 'unprotect' ),
|
|
|
|
|
'rights' => array( 'rights' ),
|
|
|
|
|
'delete' => array( 'delete', 'restore' ),
|
2005-01-31 04:07:56 +00:00
|
|
|
'upload' => array( 'upload' ),
|
|
|
|
|
'move' => array( 'move' )
|
2004-08-25 17:24:31 +00:00
|
|
|
);
|
|
|
|
|
return $actions[$type];
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
function isLogType( $type ) {
|
2004-08-25 02:13:32 +00:00
|
|
|
return in_array( $type, LogPage::validTypes() );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
function logName( $type ) {
|
2004-08-25 02:13:32 +00:00
|
|
|
static $typeText = array(
|
|
|
|
|
'' => 'log',
|
|
|
|
|
'block' => 'blocklogpage',
|
|
|
|
|
'protect' => 'protectlogpage',
|
|
|
|
|
'rights' => 'bureaucratlog',
|
|
|
|
|
'delete' => 'dellogpage',
|
|
|
|
|
'upload' => 'uploadlogpage',
|
2005-01-31 04:07:56 +00:00
|
|
|
'move' => 'movelogpage'
|
2004-08-25 02:13:32 +00:00
|
|
|
);
|
|
|
|
|
return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
function logHeader( $type ) {
|
2004-08-25 02:13:32 +00:00
|
|
|
static $headerText = array(
|
|
|
|
|
'' => 'alllogstext',
|
|
|
|
|
'block' => 'blocklogtext',
|
|
|
|
|
'protect' => 'protectlogtext',
|
2004-12-23 21:10:24 +00:00
|
|
|
'rights' => 'rightslogtext',
|
2004-08-25 02:13:32 +00:00
|
|
|
'delete' => 'dellogpagetext',
|
2005-01-31 04:07:56 +00:00
|
|
|
'upload' => 'uploadlogpagetext',
|
|
|
|
|
'move' => 'movelogpagetext'
|
2004-08-25 02:13:32 +00:00
|
|
|
);
|
|
|
|
|
return wfMsg( $headerText[$type] );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
2005-01-14 13:47:19 +00:00
|
|
|
function actionText( $type, $action, $titleLink = NULL, $params = array() ) {
|
2004-08-24 08:11:46 +00:00
|
|
|
static $actions = array(
|
|
|
|
|
'block/block' => 'blocklogentry',
|
2004-12-23 06:58:50 +00:00
|
|
|
'block/unblock' => 'unblocklogentry',
|
2004-08-24 08:11:46 +00:00
|
|
|
'protect/protect' => 'protectedarticle',
|
|
|
|
|
'protect/unprotect' => 'unprotectedarticle',
|
|
|
|
|
'rights/rights' => 'bureaucratlogentry',
|
|
|
|
|
'delete/delete' => 'deletedarticle',
|
|
|
|
|
'delete/restore' => 'undeletedarticle',
|
|
|
|
|
'upload/upload' => 'uploadedimage',
|
|
|
|
|
'upload/revert' => 'uploadedimage',
|
2005-01-31 04:07:56 +00:00
|
|
|
'move/move' => '1movedto2',
|
|
|
|
|
'move/move_redir' => '1movedto2_redir'
|
2004-08-24 08:11:46 +00:00
|
|
|
);
|
|
|
|
|
$key = "$type/$action";
|
|
|
|
|
if( isset( $actions[$key] ) ) {
|
2004-08-25 17:24:31 +00:00
|
|
|
if( is_null( $titleLink ) ) {
|
2005-01-14 13:47:19 +00:00
|
|
|
return wfMsgForContent( $actions[$key] );
|
|
|
|
|
} elseif ( count( $params ) == 0 ) {
|
|
|
|
|
return wfMsgForContent( $actions[$key], $titleLink );
|
2004-08-25 17:24:31 +00:00
|
|
|
} else {
|
2005-01-14 13:47:19 +00:00
|
|
|
array_unshift( $params, $titleLink );
|
|
|
|
|
return wfMsgReal( $actions[$key], $params, true, true );
|
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" );
|
|
|
|
|
return "$action $titleLink";
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-10-24 19:14:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a log entry
|
|
|
|
|
* @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload'
|
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
|
|
|
*/
|
2005-01-14 13:47:19 +00:00
|
|
|
function addEntry( $action, &$target, $comment, $params = array() ) {
|
2004-08-24 08:11:46 +00:00
|
|
|
global $wgLang, $wgUser;
|
2003-05-16 11:19:06 +00:00
|
|
|
|
2005-01-14 13:47:19 +00:00
|
|
|
if ( !is_array( $params ) ) {
|
|
|
|
|
$params = array( $params );
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-24 08:11:46 +00:00
|
|
|
$this->action = $action;
|
|
|
|
|
$this->target =& $target;
|
|
|
|
|
$this->comment = $comment;
|
2005-01-14 13:47:19 +00:00
|
|
|
$this->params = LogPage::makeParamBlob( $params );
|
|
|
|
|
|
|
|
|
|
$this->actionText = LogPage::actionText( $this->type, $action,
|
|
|
|
|
$target->getPrefixedText(), $params );
|
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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a blob from a parameter array
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
function makeParamBlob( $params )
|
|
|
|
|
{
|
|
|
|
|
return implode( "\n", $params );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract a parameter array from a blob
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
function extractParams( $blob )
|
|
|
|
|
{
|
|
|
|
|
if ( $blob === '' ) {
|
|
|
|
|
return array();
|
|
|
|
|
} else {
|
|
|
|
|
return explode( "\n", $blob );
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|