2008-04-02 05:48:16 +00:00
|
|
|
<?php
|
|
|
|
|
# Copyright (C) 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz
|
|
|
|
|
# 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
|
|
|
|
|
|
2008-04-02 17:43:57 +00:00
|
|
|
class LogEventsList {
|
2008-04-02 05:48:16 +00:00
|
|
|
const NO_ACTION_LINK = 1;
|
2008-04-02 19:01:41 +00:00
|
|
|
|
2008-04-02 16:24:30 +00:00
|
|
|
private $skin;
|
|
|
|
|
public $flags;
|
2008-04-02 05:48:16 +00:00
|
|
|
|
|
|
|
|
function __construct( &$skin, $flags = 0 ) {
|
|
|
|
|
$this->skin =& $skin;
|
|
|
|
|
$this->flags = $flags;
|
|
|
|
|
$this->preCacheMessages();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* As we use the same small set of messages in various methods and that
|
|
|
|
|
* they are called often, we call them once and save them in $this->message
|
|
|
|
|
*/
|
|
|
|
|
private function preCacheMessages() {
|
|
|
|
|
// Precache various messages
|
|
|
|
|
if( !isset( $this->message ) ) {
|
2008-04-02 18:46:32 +00:00
|
|
|
$messages = 'revertmerge protect_change unblocklink revertmove undeletelink revdel-restore rev-delundel';
|
|
|
|
|
foreach( explode(' ', $messages ) as $msg ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
$this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set page title and show header for this log type
|
|
|
|
|
* @param OutputPage $out where to send output
|
|
|
|
|
* @param strin $type
|
|
|
|
|
*/
|
|
|
|
|
public function showHeader( $out, $type ) {
|
|
|
|
|
if( LogPage::isLogType( $type ) ) {
|
|
|
|
|
$out->setPageTitle( LogPage::logName( $type ) );
|
|
|
|
|
$out->addWikiText( LogPage::logHeader( $type ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show options for the log list
|
|
|
|
|
* @param OutputPage $out where to send output
|
|
|
|
|
* @param string $type,
|
|
|
|
|
* @param string $user,
|
|
|
|
|
* @param string $page,
|
|
|
|
|
* @param string $pattern
|
|
|
|
|
*/
|
|
|
|
|
public function showOptions( $out, $type, $user, $page, $pattern ) {
|
|
|
|
|
global $wgScript, $wgMiserMode;
|
|
|
|
|
$action = htmlspecialchars( $wgScript );
|
|
|
|
|
$title = SpecialPage::getTitleFor( 'Log' );
|
|
|
|
|
$special = htmlspecialchars( $title->getPrefixedDBkey() );
|
|
|
|
|
$out->addHTML( "<form action=\"$action\" method=\"get\"><fieldset>" .
|
|
|
|
|
Xml::element( 'legend', array(), wfMsg( 'log' ) ) .
|
|
|
|
|
Xml::hidden( 'title', $special ) . "\n" .
|
|
|
|
|
$this->getTypeMenu( $type ) . "\n" .
|
|
|
|
|
$this->getUserInput( $user ) . "\n" .
|
|
|
|
|
$this->getTitleInput( $page ) . "\n" .
|
|
|
|
|
( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) .
|
|
|
|
|
Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
|
|
|
|
|
"</fieldset></form>" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string Formatted HTML
|
|
|
|
|
*/
|
|
|
|
|
private function getTypeMenu( $queryType ) {
|
|
|
|
|
global $wgLogRestrictions, $wgUser;
|
|
|
|
|
|
|
|
|
|
$out = "<select name='type'>\n";
|
|
|
|
|
|
|
|
|
|
$validTypes = LogPage::validTypes();
|
|
|
|
|
$m = array(); // Temporary array
|
|
|
|
|
|
|
|
|
|
// First pass to load the log names
|
|
|
|
|
foreach( $validTypes as $type ) {
|
|
|
|
|
$text = LogPage::logName( $type );
|
|
|
|
|
$m[$text] = $type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Second pass to sort by name
|
|
|
|
|
ksort($m);
|
|
|
|
|
|
|
|
|
|
// Third pass generates sorted XHTML content
|
|
|
|
|
foreach( $m as $text => $type ) {
|
|
|
|
|
$selected = ($type == $queryType);
|
|
|
|
|
// Restricted types
|
|
|
|
|
if ( isset($wgLogRestrictions[$type]) ) {
|
|
|
|
|
if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
|
|
|
|
|
$out .= Xml::option( $text, $type, $selected ) . "\n";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$out .= Xml::option( $text, $type, $selected ) . "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$out .= '</select>';
|
|
|
|
|
return $out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string Formatted HTML
|
|
|
|
|
*/
|
|
|
|
|
private function getUserInput( $user ) {
|
|
|
|
|
return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 12, $user );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string Formatted HTML
|
|
|
|
|
*/
|
|
|
|
|
private function getTitleInput( $title ) {
|
|
|
|
|
return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'page', 20, $title );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return boolean Checkbox
|
|
|
|
|
*/
|
|
|
|
|
private function getTitlePattern( $pattern ) {
|
|
|
|
|
return Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern );
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-02 17:43:57 +00:00
|
|
|
public function beginLogEventsList() {
|
2008-04-08 18:20:28 +00:00
|
|
|
return "<ul>\n";
|
2008-04-02 07:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-02 17:43:57 +00:00
|
|
|
public function endLogEventsList() {
|
2008-04-08 18:20:28 +00:00
|
|
|
return "</ul>\n";
|
2008-04-02 07:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-02 05:48:16 +00:00
|
|
|
/**
|
|
|
|
|
* @param Row $row a single row from the result set
|
|
|
|
|
* @return string Formatted HTML list item
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
public function logLine( $row ) {
|
|
|
|
|
global $wgLang, $wgUser, $wgContLang;
|
2008-04-08 15:50:16 +00:00
|
|
|
|
2008-04-02 05:48:16 +00:00
|
|
|
$title = Title::makeTitle( $row->log_namespace, $row->log_title );
|
|
|
|
|
$time = $wgLang->timeanddate( wfTimestamp(TS_MW, $row->log_timestamp), true );
|
|
|
|
|
// User links
|
2008-04-02 17:11:58 +00:00
|
|
|
if( self::isDeleted($row,LogPage::DELETED_USER) ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
$userLink = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
|
|
|
|
|
} else {
|
2008-04-08 15:50:16 +00:00
|
|
|
$userLink = $this->skin->userLink( $row->log_user, $row->user_name );
|
|
|
|
|
$this->skin->userToolLinks( $row->log_user, $row->user_name );
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
// Comment
|
2008-04-02 18:46:32 +00:00
|
|
|
if( self::isDeleted($row,LogPage::DELETED_COMMENT) ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
$comment = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
|
|
|
|
|
} else {
|
|
|
|
|
$comment = $wgContLang->getDirMark() . $this->skin->commentBlock( $row->log_comment );
|
|
|
|
|
}
|
|
|
|
|
// Extract extra parameters
|
|
|
|
|
$paramArray = LogPage::extractParams( $row->log_params );
|
|
|
|
|
$revert = $del = '';
|
|
|
|
|
// Some user can hide log items and have review links
|
|
|
|
|
if( $wgUser->isAllowed( 'deleterevision' ) ) {
|
|
|
|
|
$del = $this->showhideLinks( $row ) . ' ';
|
|
|
|
|
}
|
|
|
|
|
// Add review links and such...
|
|
|
|
|
if( !($this->flags & self::NO_ACTION_LINK) && !($row->log_deleted & LogPage::DELETED_ACTION) ) {
|
|
|
|
|
if( $row->log_type == 'move' && isset( $paramArray[0] ) && $wgUser->isAllowed( 'move' ) ) {
|
|
|
|
|
$destTitle = Title::newFromText( $paramArray[0] );
|
|
|
|
|
if( $destTitle ) {
|
|
|
|
|
$revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
|
2008-04-02 18:46:32 +00:00
|
|
|
$this->message['revertmove'],
|
2008-04-02 05:48:16 +00:00
|
|
|
'wpOldTitle=' . urlencode( $destTitle->getPrefixedDBkey() ) .
|
|
|
|
|
'&wpNewTitle=' . urlencode( $title->getPrefixedDBkey() ) .
|
|
|
|
|
'&wpReason=' . urlencode( wfMsgForContent( 'revertmove' ) ) .
|
|
|
|
|
'&wpMovetalk=0' ) . ')';
|
|
|
|
|
}
|
|
|
|
|
// Show undelete link
|
|
|
|
|
} else if( $row->log_action == 'delete' && $wgUser->isAllowed( 'delete' ) ) {
|
|
|
|
|
$revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
|
2008-04-02 18:46:32 +00:00
|
|
|
$this->message['undeletelink'], 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
|
2008-04-02 05:48:16 +00:00
|
|
|
// Show unblock link
|
|
|
|
|
} else if( $row->log_action == 'block' && $wgUser->isAllowed( 'block' ) ) {
|
|
|
|
|
$revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Ipblocklist' ),
|
2008-04-02 18:46:32 +00:00
|
|
|
$this->message['unblocklink'],
|
2008-04-02 05:48:16 +00:00
|
|
|
'action=unblock&ip=' . urlencode( $row->log_title ) ) . ')';
|
|
|
|
|
// Show change protection link
|
|
|
|
|
} else if( ( $row->log_action == 'protect' || $row->log_action == 'modify' ) && $wgUser->isAllowed( 'protect' ) ) {
|
2008-04-02 18:46:32 +00:00
|
|
|
$revert = '(' . $this->skin->makeKnownLinkObj( $title, $this->message['protect_change'], 'action=unprotect' ) . ')';
|
2008-04-02 05:48:16 +00:00
|
|
|
// Show unmerge link
|
|
|
|
|
} else if ( $row->log_action == 'merge' ) {
|
|
|
|
|
$merge = SpecialPage::getTitleFor( 'Mergehistory' );
|
2008-04-02 18:46:32 +00:00
|
|
|
$revert = '(' . $this->skin->makeKnownLinkObj( $merge, $this->message['revertmerge'],
|
2008-04-02 05:48:16 +00:00
|
|
|
wfArrayToCGI(
|
|
|
|
|
array('target' => $paramArray[0], 'dest' => $title->getPrefixedText(), 'mergepoint' => $paramArray[1] )
|
|
|
|
|
)
|
|
|
|
|
) . ')';
|
|
|
|
|
// If an edit was hidden from a page give a review link to the history
|
2008-04-04 03:56:48 +00:00
|
|
|
} else if( $row->log_action == 'revision' && $wgUser->isAllowed( 'deleterevision' ) && isset($paramArray[2]) ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
$revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
|
|
|
|
|
// Different revision types use different URL params...
|
|
|
|
|
$subtype = isset($paramArray[2]) ? $paramArray[1] : '';
|
|
|
|
|
// Link to each hidden object ID, $paramArray[1] is the url param. List if several...
|
|
|
|
|
$Ids = explode( ',', $paramArray[2] );
|
|
|
|
|
if( count($Ids) == 1 ) {
|
2008-04-02 18:46:32 +00:00
|
|
|
$revert = $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
|
2008-04-02 05:48:16 +00:00
|
|
|
wfArrayToCGI( array('target' => $paramArray[0], $paramArray[1] => $Ids[0] ) ) );
|
|
|
|
|
} else {
|
2008-04-02 18:46:32 +00:00
|
|
|
$revert .= $this->message['revdel-restore'].':';
|
2008-04-02 05:48:16 +00:00
|
|
|
foreach( $Ids as $n => $id ) {
|
|
|
|
|
$revert .= ' '.$this->skin->makeKnownLinkObj( $revdel, '#'.($n+1),
|
|
|
|
|
wfArrayToCGI( array('target' => $paramArray[0], $paramArray[1] => $id ) ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$revert = "($revert)";
|
|
|
|
|
// Hidden log items, give review link
|
2008-04-06 01:22:30 +00:00
|
|
|
} else if( $row->log_action == 'event' && $wgUser->isAllowed( 'deleterevision' ) && isset($paramArray[0]) ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
$revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
|
2008-04-02 18:46:32 +00:00
|
|
|
$revert .= $this->message['revdel-restore'];
|
2008-04-02 05:48:16 +00:00
|
|
|
$Ids = explode( ',', $paramArray[0] );
|
|
|
|
|
// Link to each hidden object ID, $paramArray[1] is the url param. List if several...
|
|
|
|
|
if( count($Ids) == 1 ) {
|
2008-04-02 18:46:32 +00:00
|
|
|
$revert = $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
|
2008-04-02 05:48:16 +00:00
|
|
|
wfArrayToCGI( array('logid' => $Ids[0] ) ) );
|
|
|
|
|
} else {
|
|
|
|
|
foreach( $Ids as $n => $id ) {
|
|
|
|
|
$revert .= $this->skin->makeKnownLinkObj( $revdel, '#'.($n+1),
|
|
|
|
|
wfArrayToCGI( array('logid' => $id ) ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$revert = "($revert)";
|
|
|
|
|
} else {
|
|
|
|
|
wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
|
|
|
|
|
&$comment, &$revert, $row->log_timestamp ) );
|
|
|
|
|
// wfDebug( "Invoked LogLine hook for " $row->log_type . ", " . $row->log_action . "\n" );
|
|
|
|
|
// Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Event description
|
2008-04-02 19:01:41 +00:00
|
|
|
if( self::isDeleted($row,LogPage::DELETED_ACTION) ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
$action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
|
|
|
|
|
} else {
|
|
|
|
|
$action = LogPage::actionText( $row->log_type, $row->log_action, $title, $this->skin, $paramArray, true );
|
|
|
|
|
}
|
2008-04-08 18:20:28 +00:00
|
|
|
|
|
|
|
|
return "<li>$del$time $userLink $action $comment $revert</li>\n";
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Row $row
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
private function showhideLinks( $row ) {
|
|
|
|
|
global $wgAllowLogDeletion;
|
|
|
|
|
|
|
|
|
|
if( !$wgAllowLogDeletion )
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
$revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
|
|
|
|
|
// If event was hidden from sysops
|
2008-04-02 17:11:58 +00:00
|
|
|
if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
$del = $this->message['rev-delundel'];
|
|
|
|
|
} else if( $row->log_type == 'suppress' ) {
|
2008-04-02 13:17:50 +00:00
|
|
|
// No one should be hiding from the oversight log
|
|
|
|
|
$del = $this->message['rev-delundel'];
|
2008-04-02 05:48:16 +00:00
|
|
|
} else {
|
|
|
|
|
$del = $this->skin->makeKnownLinkObj( $revdel, $this->message['rev-delundel'], 'logid='.$row->log_id );
|
|
|
|
|
// Bolden oversighted content
|
2008-04-02 17:11:58 +00:00
|
|
|
if( self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) )
|
2008-04-02 05:48:16 +00:00
|
|
|
$del = "<strong>$del</strong>";
|
|
|
|
|
}
|
|
|
|
|
return "<tt>(<small>$del</small>)</tt>";
|
|
|
|
|
}
|
2008-04-02 07:10:41 +00:00
|
|
|
|
2008-04-02 17:11:58 +00:00
|
|
|
/**
|
|
|
|
|
* Determine if the current user is allowed to view a particular
|
|
|
|
|
* field of this log row, if it's marked as deleted.
|
|
|
|
|
* @param Row $row
|
|
|
|
|
* @param int $field
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function userCan( $row, $field ) {
|
|
|
|
|
if( ( $row->log_deleted & $field ) == $field ) {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$permission = ( $row->log_deleted & LogPage::DELETED_RESTRICTED ) == LogPage::DELETED_RESTRICTED
|
|
|
|
|
? 'hiderevision'
|
|
|
|
|
: 'deleterevision';
|
|
|
|
|
wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" );
|
|
|
|
|
return $wgUser->isAllowed( $permission );
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Row $row
|
2008-04-02 17:12:45 +00:00
|
|
|
* @param int $field one of DELETED_* bitfield constants
|
2008-04-02 17:11:58 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function isDeleted( $row, $field ) {
|
|
|
|
|
return ($row->log_deleted & $field) == $field;
|
|
|
|
|
}
|
2008-04-02 19:01:41 +00:00
|
|
|
|
|
|
|
|
/**
|
2008-04-02 20:20:47 +00:00
|
|
|
* Quick function to show a short log extract
|
|
|
|
|
* @param OutputPage $out
|
|
|
|
|
* @param string $type
|
|
|
|
|
* @param string $page
|
2008-04-04 04:15:21 +00:00
|
|
|
* @param string $user
|
2008-04-02 20:20:47 +00:00
|
|
|
*/
|
|
|
|
|
public static function showLogExtract( $out, $type='', $page='', $user='' ) {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
# Insert list of top 50 or so items
|
|
|
|
|
$loglist = new LogEventsList( $wgUser->getSkin() );
|
|
|
|
|
$pager = new LogPager( $loglist, $type, $user, $page, '' );
|
|
|
|
|
$logBody = $pager->getBody();
|
|
|
|
|
if( $logBody ) {
|
|
|
|
|
$out->addHTML(
|
|
|
|
|
$loglist->beginLogEventsList() .
|
|
|
|
|
$logBody .
|
|
|
|
|
$loglist->endLogEventsList()
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$out->addWikiMsg( 'logempty' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-02 19:01:41 +00:00
|
|
|
* SQL clause to skip forbidden log types for this user
|
|
|
|
|
* @param Database $db
|
|
|
|
|
* @returns mixed (string or false)
|
|
|
|
|
*/
|
|
|
|
|
public static function getExcludeClause( $db ) {
|
|
|
|
|
global $wgLogRestrictions, $wgUser;
|
|
|
|
|
// Reset the array, clears extra "where" clauses when $par is used
|
|
|
|
|
$hiddenLogs = array();
|
2008-04-08 13:58:33 +00:00
|
|
|
// Don't show private logs to unprivileged users
|
2008-04-02 19:01:41 +00:00
|
|
|
foreach( $wgLogRestrictions as $logtype => $right ) {
|
|
|
|
|
if( !$wgUser->isAllowed($right) ) {
|
|
|
|
|
$safetype = $db->strencode( $logtype );
|
2008-04-08 13:58:33 +00:00
|
|
|
$hiddenLogs[] = $safetype;
|
2008-04-02 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-04-08 13:58:33 +00:00
|
|
|
if( count($hiddenLogs) == 1 ) {
|
|
|
|
|
return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
|
|
|
|
|
} elseif( !empty( $hiddenLogs ) ) {
|
|
|
|
|
return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
|
2008-04-02 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-02 16:24:30 +00:00
|
|
|
* @addtogroup Pager
|
2008-04-02 05:48:16 +00:00
|
|
|
*/
|
2008-04-02 16:24:30 +00:00
|
|
|
class LogPager extends ReverseChronologicalPager {
|
|
|
|
|
private $type = '', $user = '', $title = '', $pattern = '';
|
2008-04-02 17:43:57 +00:00
|
|
|
public $mLogEventsList;
|
2008-04-02 05:48:16 +00:00
|
|
|
/**
|
2008-04-02 16:24:30 +00:00
|
|
|
* constructor
|
2008-04-02 17:43:57 +00:00
|
|
|
* @param LogEventsList $loglist,
|
2008-04-02 16:24:30 +00:00
|
|
|
* @param string $type,
|
|
|
|
|
* @param string $user,
|
|
|
|
|
* @param string $page,
|
|
|
|
|
* @param string $pattern
|
|
|
|
|
* @param array $conds
|
|
|
|
|
*/
|
2008-04-02 20:20:47 +00:00
|
|
|
function __construct( $loglist, $type='', $user='', $title='', $pattern='', $conds = array() ) {
|
2008-04-02 16:24:30 +00:00
|
|
|
parent::__construct();
|
|
|
|
|
$this->mConds = $conds;
|
2008-04-02 05:48:16 +00:00
|
|
|
|
2008-04-02 17:43:57 +00:00
|
|
|
$this->mLogEventsList = $loglist;
|
2008-04-02 16:24:30 +00:00
|
|
|
|
|
|
|
|
$this->limitType( $type );
|
|
|
|
|
$this->limitUser( $user );
|
|
|
|
|
$this->limitTitle( $title, $pattern );
|
2008-04-08 20:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getDefaultQuery() {
|
|
|
|
|
$query = parent::getDefaultQuery();
|
|
|
|
|
$query['type'] = $this->type;
|
|
|
|
|
return $query;
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
2008-04-02 16:24:30 +00:00
|
|
|
|
2008-04-02 05:48:16 +00:00
|
|
|
/**
|
|
|
|
|
* Set the log reader to return only entries of the given type.
|
|
|
|
|
* Type restrictions enforced here
|
|
|
|
|
* @param string $type A log type ('upload', 'delete', etc)
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2008-04-02 16:24:30 +00:00
|
|
|
private function limitType( $type ) {
|
2008-04-02 18:09:02 +00:00
|
|
|
global $wgLogRestrictions, $wgUser;
|
|
|
|
|
// Don't even show header for private logs; don't recognize it...
|
|
|
|
|
if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
|
|
|
|
|
$type = '';
|
|
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
// Don't show private logs to unpriviledged users
|
2008-04-02 17:43:57 +00:00
|
|
|
$hideLogs = LogEventsList::getExcludeClause( $this->mDb );
|
2008-04-02 16:24:30 +00:00
|
|
|
if( $hideLogs !== false ) {
|
|
|
|
|
$this->mConds[] = $hideLogs;
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
if( empty($type) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->type = $type;
|
2008-04-02 16:24:30 +00:00
|
|
|
$this->mConds['log_type'] = $type;
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
2008-04-02 16:24:30 +00:00
|
|
|
|
2008-04-02 05:48:16 +00:00
|
|
|
/**
|
|
|
|
|
* Set the log reader to return only entries by the given user.
|
|
|
|
|
* @param string $name (In)valid user name
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function limitUser( $name ) {
|
2008-04-02 16:24:30 +00:00
|
|
|
if( $name == '' ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
return false;
|
2008-04-02 16:24:30 +00:00
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
$usertitle = Title::makeTitleSafe( NS_USER, $name );
|
2008-04-02 16:24:30 +00:00
|
|
|
if( is_null($usertitle) ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
return false;
|
2008-04-02 16:24:30 +00:00
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
$this->user = $usertitle->getText();
|
|
|
|
|
/* Fetch userid at first, if known, provides awesome query plan afterwards */
|
2008-04-02 16:24:30 +00:00
|
|
|
$userid = User::idFromName( $this->user );
|
|
|
|
|
if( !$userid ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
/* It should be nicer to abort query at all,
|
|
|
|
|
but for now it won't pass anywhere behind the optimizer */
|
2008-04-02 16:24:30 +00:00
|
|
|
$this->mConds[] = "NULL";
|
|
|
|
|
} else {
|
|
|
|
|
$this->mConds['log_user'] = $userid;
|
|
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the log reader to return only entries affecting the given page.
|
|
|
|
|
* (For the block and rights logs, this is a user page.)
|
|
|
|
|
* @param string $page Title name as text
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2008-04-02 16:24:30 +00:00
|
|
|
function limitTitle( $page, $pattern ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
global $wgMiserMode;
|
|
|
|
|
|
|
|
|
|
$title = Title::newFromText( $page );
|
2008-04-02 16:24:30 +00:00
|
|
|
if( strlen($page) == 0 || !$title instanceof Title )
|
2008-04-02 05:48:16 +00:00
|
|
|
return false;
|
2008-04-02 16:24:30 +00:00
|
|
|
|
|
|
|
|
$this->title = $title->getPrefixedText();
|
2008-04-02 05:48:16 +00:00
|
|
|
$this->pattern = $pattern;
|
|
|
|
|
$ns = $title->getNamespace();
|
2008-04-02 16:24:30 +00:00
|
|
|
if( $pattern && !$wgMiserMode ) {
|
|
|
|
|
# use escapeLike to avoid expensive search patterns like 't%st%'
|
|
|
|
|
$safetitle = $this->mDb->escapeLike( $title->getDBkey() );
|
|
|
|
|
$this->mConds['log_namespace'] = $ns;
|
|
|
|
|
$this->mConds[] = "log_title LIKE '$safetitle%'";
|
2008-04-02 05:48:16 +00:00
|
|
|
} else {
|
2008-04-02 16:24:30 +00:00
|
|
|
$this->mConds['log_namespace'] = $ns;
|
|
|
|
|
$this->mConds['log_title'] = $title->getDBkey();
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-02 16:24:30 +00:00
|
|
|
function getQueryInfo() {
|
|
|
|
|
$this->mConds[] = 'user_id = log_user';
|
|
|
|
|
# Hack this until live
|
2008-04-02 05:48:16 +00:00
|
|
|
global $wgAllowLogDeletion;
|
2008-04-02 16:24:30 +00:00
|
|
|
$log_id = $wgAllowLogDeletion ? 'log_id' : '0 AS log_id';
|
2008-04-08 08:46:15 +00:00
|
|
|
# Don't use the wrong logging index
|
2008-04-08 15:50:16 +00:00
|
|
|
if( $this->title || $this->pattern || $this->user ) {
|
|
|
|
|
$index = array( 'USE INDEX' => array( 'logging' => array('page_time','user_time') ) );
|
2008-04-08 08:51:52 +00:00
|
|
|
} else if( $this->type ) {
|
|
|
|
|
$index = array( 'USE INDEX' => array( 'logging' => 'type_time' ) );
|
2008-04-08 08:46:15 +00:00
|
|
|
} else {
|
|
|
|
|
$index = array( 'USE INDEX' => array( 'logging' => 'times' ) );
|
|
|
|
|
}
|
2008-04-02 16:24:30 +00:00
|
|
|
return array(
|
|
|
|
|
'tables' => array( 'logging', 'user' ),
|
|
|
|
|
'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title',
|
|
|
|
|
'log_params', 'log_comment', $log_id, 'log_deleted', 'log_timestamp', 'user_name' ),
|
|
|
|
|
'conds' => $this->mConds,
|
2008-04-08 08:46:15 +00:00
|
|
|
'options' => $index
|
2008-04-02 16:24:30 +00:00
|
|
|
);
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-02 16:24:30 +00:00
|
|
|
function getIndexField() {
|
|
|
|
|
return 'log_timestamp';
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
2008-04-08 15:50:16 +00:00
|
|
|
|
|
|
|
|
function getStartBody() {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
# Do a link batch query
|
|
|
|
|
$lb = new LinkBatch;
|
|
|
|
|
while( $row = $this->mResult->fetchObject() ) {
|
|
|
|
|
$lb->add( $row->log_namespace, $row->log_title );
|
|
|
|
|
$lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
|
|
|
|
|
$lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
|
|
|
|
|
}
|
|
|
|
|
$lb->execute();
|
|
|
|
|
$this->mResult->seek( 0 );
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
|
2008-04-02 16:24:30 +00:00
|
|
|
function formatRow( $row ) {
|
2008-04-02 17:43:57 +00:00
|
|
|
return $this->mLogEventsList->logLine( $row );
|
2008-04-02 16:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getType() {
|
2008-04-02 05:48:16 +00:00
|
|
|
return $this->type;
|
|
|
|
|
}
|
2008-04-02 16:24:30 +00:00
|
|
|
|
|
|
|
|
public function getUser() {
|
2008-04-02 05:48:16 +00:00
|
|
|
return $this->user;
|
|
|
|
|
}
|
2008-04-02 16:24:30 +00:00
|
|
|
|
|
|
|
|
public function getPage() {
|
|
|
|
|
return $this->title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPattern() {
|
2008-04-02 05:48:16 +00:00
|
|
|
return $this->pattern;
|
|
|
|
|
}
|
2008-04-02 16:24:30 +00:00
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
|
2008-04-02 16:24:30 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @addtogroup SpecialPage
|
|
|
|
|
*/
|
|
|
|
|
class LogReader {
|
2008-04-04 02:12:27 +00:00
|
|
|
var $pager;
|
2008-04-02 05:48:16 +00:00
|
|
|
/**
|
2008-04-02 16:24:30 +00:00
|
|
|
* @param WebRequest $request For internal use use a FauxRequest object to pass arbitrary parameters.
|
2008-04-02 05:48:16 +00:00
|
|
|
*/
|
2008-04-02 17:28:26 +00:00
|
|
|
function __construct( $request ) {
|
2008-04-02 16:24:30 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
# Get parameters
|
|
|
|
|
$type = $request->getVal( 'type' );
|
|
|
|
|
$user = $request->getText( 'user' );
|
|
|
|
|
$title = $request->getText( 'page' );
|
|
|
|
|
$pattern = $request->getBool( 'pattern' );
|
|
|
|
|
|
2008-04-02 17:43:57 +00:00
|
|
|
$loglist = new LogEventsList( $wgUser->getSkin() );
|
2008-04-02 16:24:30 +00:00
|
|
|
$this->pager = new LogPager( $loglist, $type, $user, $title, $pattern );
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
2008-04-02 17:28:26 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is there at least one row?
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function hasRows() {
|
|
|
|
|
return isset($this->pager) ? ($this->pager->getNumRows() > 0) : false;
|
|
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @addtogroup SpecialPage
|
|
|
|
|
*/
|
|
|
|
|
class LogViewer {
|
2008-04-02 06:03:00 +00:00
|
|
|
const NO_ACTION_LINK = 1;
|
2008-04-02 05:48:16 +00:00
|
|
|
/**
|
|
|
|
|
* @var LogReader $reader
|
|
|
|
|
*/
|
|
|
|
|
var $reader;
|
|
|
|
|
/**
|
|
|
|
|
* @param LogReader &$reader where to get our data from
|
|
|
|
|
* @param integer $flags Bitwise combination of flags:
|
2008-04-02 17:43:57 +00:00
|
|
|
* LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
|
2008-04-02 05:48:16 +00:00
|
|
|
*/
|
2008-04-02 17:28:26 +00:00
|
|
|
function __construct( &$reader, $flags = 0 ) {
|
2008-04-02 05:48:16 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
$this->reader =& $reader;
|
2008-04-02 17:43:57 +00:00
|
|
|
$this->reader->pager->mLogEventsList->flags = $flags;
|
2008-04-02 16:24:30 +00:00
|
|
|
# Aliases for shorter code...
|
|
|
|
|
$this->pager =& $this->reader->pager;
|
2008-04-02 17:43:57 +00:00
|
|
|
$this->logEventsList =& $this->reader->pager->mLogEventsList;
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Take over the whole output page in $wgOut with the log display.
|
|
|
|
|
*/
|
2008-04-02 17:28:26 +00:00
|
|
|
public function show() {
|
2008-04-02 05:48:16 +00:00
|
|
|
global $wgOut;
|
2008-04-02 16:24:30 +00:00
|
|
|
# Set title and add header
|
2008-04-02 17:43:57 +00:00
|
|
|
$this->logEventsList->showHeader( $wgOut, $pager->getType() );
|
2008-04-02 16:24:30 +00:00
|
|
|
# Show form options
|
2008-04-02 17:43:57 +00:00
|
|
|
$this->logEventsList->showOptions( $wgOut, $this->pager->getType(), $this->pager->getUser(),
|
2008-04-02 16:24:30 +00:00
|
|
|
$this->pager->getPage(), $this->pager->getPattern() );
|
|
|
|
|
# Insert list
|
|
|
|
|
$logBody = $this->pager->getBody();
|
|
|
|
|
if( $logBody ) {
|
|
|
|
|
$wgOut->addHTML(
|
|
|
|
|
$this->pager->getNavigationBar() .
|
2008-04-02 17:43:57 +00:00
|
|
|
$this->logEventsList->beginLogEventsList() .
|
2008-04-02 16:24:30 +00:00
|
|
|
$logBody .
|
2008-04-02 17:43:57 +00:00
|
|
|
$this->logEventsList->endLogEventsList() .
|
2008-04-02 16:24:30 +00:00
|
|
|
$this->pager->getNavigationBar()
|
|
|
|
|
);
|
2008-04-02 05:48:16 +00:00
|
|
|
} else {
|
2008-04-02 16:24:30 +00:00
|
|
|
$wgOut->addWikiMsg( 'logempty' );
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Output just the list of entries given by the linked LogReader,
|
|
|
|
|
* with extraneous UI elements. Use for displaying log fragments in
|
|
|
|
|
* another page (eg at Special:Undelete)
|
|
|
|
|
* @param OutputPage $out where to send output
|
|
|
|
|
*/
|
2008-04-02 17:28:26 +00:00
|
|
|
public function showList( &$out ) {
|
2008-04-02 16:24:30 +00:00
|
|
|
$logBody = $this->pager->getBody();
|
|
|
|
|
if( $logBody ) {
|
|
|
|
|
$out->addHTML(
|
2008-04-02 17:43:57 +00:00
|
|
|
$this->logEventsList->beginLogEventsList() .
|
2008-04-02 16:24:30 +00:00
|
|
|
$logBody .
|
2008-04-02 17:43:57 +00:00
|
|
|
$this->logEventsList->endLogEventsList()
|
2008-04-02 16:24:30 +00:00
|
|
|
);
|
2008-04-02 05:48:16 +00:00
|
|
|
} else {
|
2008-04-02 16:59:16 +00:00
|
|
|
$out->addWikiMsg( 'logempty' );
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|