2004-08-24 08:11:46 +00:00
|
|
|
<?php
|
|
|
|
|
# Copyright (C) 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
|
|
|
/**
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* constructor
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function wfSpecialLog( $par = '' ) {
|
|
|
|
|
global $wgRequest;
|
|
|
|
|
$logReader =& new LogReader( $wgRequest );
|
|
|
|
|
if( '' == $wgRequest->getVal( 'type' ) && !empty( $par ) ) {
|
|
|
|
|
$logReader->limitType( $par );
|
|
|
|
|
}
|
|
|
|
|
$logViewer =& new LogViewer( $logReader );
|
|
|
|
|
$logViewer->show();
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
class LogReader {
|
|
|
|
|
var $db, $joinClauses, $whereClauses;
|
|
|
|
|
var $type = '', $user = '', $title = null;
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @param WebRequest $request For internal use use a FauxRequest object to pass arbitrary parameters.
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function LogReader( $request ) {
|
|
|
|
|
$this->db =& wfGetDB( DB_SLAVE );
|
|
|
|
|
$this->setupQuery( $request );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* Basic setup and applies the limiting factors from the WebRequest object.
|
|
|
|
|
* @param WebRequest $request
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function setupQuery( $request ) {
|
|
|
|
|
$cur = $this->db->tableName( 'cur' );
|
|
|
|
|
$user = $this->db->tableName( 'user' );
|
|
|
|
|
$this->joinClauses = array( "LEFT OUTER JOIN $cur ON log_namespace=cur_namespace AND log_title=cur_title" );
|
|
|
|
|
$this->whereClauses = array( 'user_id=log_user' );
|
|
|
|
|
|
|
|
|
|
$this->limitType( $request->getVal( 'type' ) );
|
|
|
|
|
$this->limitUser( $request->getText( 'user' ) );
|
|
|
|
|
$this->limitTitle( $request->getText( 'page' ) );
|
|
|
|
|
$this->limitTime( $request->getVal( 'from' ), '>=' );
|
|
|
|
|
$this->limitTime( $request->getVal( 'until' ), '<=' );
|
|
|
|
|
|
|
|
|
|
list( $this->limit, $this->offset ) = $request->getLimitOffset();
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* Set the log reader to return only entries of the given type.
|
|
|
|
|
* @param string $type A log type ('upload', 'delete', etc)
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function limitType( $type ) {
|
|
|
|
|
if( empty( $type ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->type = $type;
|
|
|
|
|
$safetype = $this->db->strencode( $type );
|
|
|
|
|
$this->whereClauses[] = "log_type='$safetype'";
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* Set the log reader to return only entries by the given user.
|
|
|
|
|
* @param string $name Valid user name
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function limitUser( $name ) {
|
2004-09-04 09:08:22 +00:00
|
|
|
$title = Title::makeTitle( NS_USER, $name );
|
2004-08-24 08:11:46 +00:00
|
|
|
if( empty( $name ) || is_null( $title ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->user = str_replace( '_', ' ', $title->getDBkey() );
|
|
|
|
|
$safename = $this->db->strencode( $this->user );
|
|
|
|
|
$user = $this->db->tableName( 'user' );
|
|
|
|
|
$this->whereClauses[] = "user_name='$safename'";
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +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
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function limitTitle( $page ) {
|
|
|
|
|
$title = Title::newFromText( $page );
|
|
|
|
|
if( empty( $page ) || is_null( $title ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->title =& $title;
|
|
|
|
|
$safetitle = $this->db->strencode( $title->getDBkey() );
|
|
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$this->whereClauses[] = "log_namespace=$ns AND log_title='$safetitle'";
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* Set the log reader to return only entries in a given time range.
|
|
|
|
|
* @param string $time Timestamp of one endpoint
|
|
|
|
|
* @param string $direction either ">=" or "<=" operators
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function limitTime( $time, $direction ) {
|
|
|
|
|
# Direction should be a comparison operator
|
|
|
|
|
if( empty( $time ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$safetime = $this->db->strencode( wfTimestamp( TS_MW, $time ) );
|
|
|
|
|
$this->whereClauses[] = "log_timestamp $direction '$safetime'";
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* Build an SQL query from all the set parameters.
|
|
|
|
|
* @return string the SQL query
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function getQuery() {
|
|
|
|
|
$logging = $this->db->tableName( "logging" );
|
|
|
|
|
$user = $this->db->tableName( 'user' );
|
|
|
|
|
$sql = "SELECT log_type, log_action, log_timestamp,
|
|
|
|
|
log_user, user_name,
|
|
|
|
|
log_namespace, log_title, cur_id,
|
2004-09-08 23:24:17 +00:00
|
|
|
log_comment FROM $user, $logging ";
|
2004-08-24 08:11:46 +00:00
|
|
|
if( !empty( $this->joinClauses ) ) {
|
|
|
|
|
$sql .= implode( ',', $this->joinClauses );
|
|
|
|
|
}
|
|
|
|
|
if( !empty( $this->whereClauses ) ) {
|
|
|
|
|
$sql .= " WHERE " . implode( ' AND ', $this->whereClauses );
|
|
|
|
|
}
|
|
|
|
|
$sql .= " ORDER BY log_timestamp DESC ";
|
|
|
|
|
$sql .= $this->db->limitResult( $this->limit, $this->offset );
|
|
|
|
|
return $sql;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* Execute the query and start returning results.
|
|
|
|
|
* @return ResultWrapper result object to return the relevant rows
|
|
|
|
|
*/
|
2004-09-02 03:13:09 +00:00
|
|
|
function getRows() {
|
|
|
|
|
return $this->db->resultObject( $this->db->query( $this->getQuery() ) );
|
2004-08-24 08:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @return string The query type that this LogReader has been limited to.
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function queryType() {
|
|
|
|
|
return $this->type;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @return string The username type that this LogReader has been limited to, if any.
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function queryUser() {
|
|
|
|
|
return $this->user;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @return string The text of the title that this LogReader has been limited to.
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function queryTitle() {
|
|
|
|
|
if( is_null( $this->title ) ) {
|
|
|
|
|
return '';
|
|
|
|
|
} else {
|
|
|
|
|
return $this->title->getPrefixedText();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
class LogViewer {
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @var LogReader $reader
|
|
|
|
|
*/
|
|
|
|
|
var $reader;
|
2004-08-24 08:11:46 +00:00
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @param LogReader &$reader where to get our data from
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function LogViewer( &$reader ) {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$this->skin =& $wgUser->getSkin();
|
|
|
|
|
$this->reader =& $reader;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* Take over the whole output page in $wgOut with the log display.
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function show() {
|
|
|
|
|
global $wgOut;
|
|
|
|
|
$this->showHeader( $wgOut );
|
|
|
|
|
$this->showOptions( $wgOut );
|
|
|
|
|
$this->showPrevNext( $wgOut );
|
2004-08-29 21:26:00 +00:00
|
|
|
$this->showList( $wgOut );
|
|
|
|
|
$this->showPrevNext( $wgOut );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +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
|
|
|
|
|
*/
|
2004-08-29 21:26:00 +00:00
|
|
|
function showList( &$out ) {
|
|
|
|
|
$html = "";
|
2004-09-02 03:13:09 +00:00
|
|
|
$result = $this->reader->getRows();
|
|
|
|
|
while( $s = $result->fetchObject() ) {
|
2004-08-29 21:26:00 +00:00
|
|
|
$html .= $this->logLine( $s );
|
2004-08-24 08:11:46 +00:00
|
|
|
}
|
2004-09-02 03:13:09 +00:00
|
|
|
$result->free();
|
2004-08-29 21:26:00 +00:00
|
|
|
$out->addHTML( $html );
|
2004-08-24 08:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @param Object $s a single row from the result set
|
|
|
|
|
* @return string Formatted HTML list item
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function logLine( $s ) {
|
|
|
|
|
global $wgLang;
|
|
|
|
|
$title = Title::makeTitle( $s->log_namespace, $s->log_title );
|
|
|
|
|
$user = Title::makeTitleSafe( NS_USER, $s->user_name );
|
|
|
|
|
$time = $wgLang->timeanddate( $s->log_timestamp );
|
|
|
|
|
if( $s->cur_id ) {
|
|
|
|
|
$titleLink = $this->skin->makeKnownLinkObj( $title );
|
|
|
|
|
} else {
|
|
|
|
|
$titleLink = $this->skin->makeBrokenLinkObj( $title );
|
|
|
|
|
}
|
|
|
|
|
$userLink = $this->skin->makeLinkObj( $user, htmlspecialchars( $s->user_name ) );
|
|
|
|
|
if( '' === $s->log_comment ) {
|
|
|
|
|
$comment = '';
|
|
|
|
|
} else {
|
|
|
|
|
$comment = '(<em>' . $this->skin->formatComment( $s->log_comment ) . '</em>)';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$action = LogPage::actionText( $s->log_type, $s->log_action, $titleLink );
|
|
|
|
|
$out = "<li>$time $userLink $action $comment</li>\n";
|
|
|
|
|
return $out;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @param OutputPage &$out where to send output
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function showHeader( &$out ) {
|
|
|
|
|
$type = $this->reader->queryType();
|
2004-08-25 02:13:32 +00:00
|
|
|
if( LogPage::isLogType( $type ) ) {
|
|
|
|
|
$out->setPageTitle( LogPage::logName( $type ) );
|
|
|
|
|
$out->addWikiText( LogPage::logHeader( $type ) );
|
2004-08-24 08:11:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @param OutputPage &$out where to send output
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function showOptions( &$out ) {
|
|
|
|
|
global $wgScript;
|
|
|
|
|
$action = htmlspecialchars( $wgScript );
|
|
|
|
|
$title = Title::makeTitle( NS_SPECIAL, 'Log' );
|
|
|
|
|
$special = htmlspecialchars( $title->getPrefixedDBkey() );
|
|
|
|
|
$out->addHTML( "<form action=\"$action\" method=\"get\">\n" .
|
|
|
|
|
"<input type='hidden' name='title' value=\"$special\" />\n" .
|
|
|
|
|
$this->getTypeMenu() .
|
|
|
|
|
$this->getUserInput() .
|
|
|
|
|
$this->getTitleInput() .
|
|
|
|
|
"<input type='submit' />" .
|
|
|
|
|
"</form>" );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @return string Formatted HTML
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function getTypeMenu() {
|
|
|
|
|
$out = "<select name='type'>\n";
|
2004-08-25 02:13:32 +00:00
|
|
|
foreach( LogPage::validTypes() as $type ) {
|
|
|
|
|
$text = htmlspecialchars( LogPage::logName( $type ) );
|
2004-08-24 08:11:46 +00:00
|
|
|
$selected = ($type == $this->reader->queryType()) ? ' selected="selected"' : '';
|
|
|
|
|
$out .= "<option value=\"$type\"$selected>$text</option>\n";
|
|
|
|
|
}
|
|
|
|
|
$out .= "</select>\n";
|
|
|
|
|
return $out;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @return string Formatted HTML
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function getUserInput() {
|
|
|
|
|
$user = htmlspecialchars( $this->reader->queryUser() );
|
|
|
|
|
return "User: <input type='text' name='user' size='12' value=\"$user\" />\n";
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @return string Formatted HTML
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function getTitleInput() {
|
|
|
|
|
$title = htmlspecialchars( $this->reader->queryTitle() );
|
|
|
|
|
return "Title: <input type='text' name='page' size='20' value=\"$title\" />\n";
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-04 09:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* @param OutputPage &$out where to send output
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2004-08-24 08:11:46 +00:00
|
|
|
function showPrevNext( &$out ) {
|
2004-09-24 16:24:43 +00:00
|
|
|
global $wgContLang;
|
2004-08-24 08:11:46 +00:00
|
|
|
$pieces = array();
|
|
|
|
|
$pieces[] = 'type=' . htmlspecialchars( $this->reader->queryType() );
|
|
|
|
|
$pieces[] = 'user=' . htmlspecialchars( $this->reader->queryUser() );
|
|
|
|
|
$pieces[] = 'page=' . htmlspecialchars( $this->reader->queryTitle() );
|
|
|
|
|
$bits = implode( '&', $pieces );
|
|
|
|
|
$offset = 0; $limit = 50;
|
|
|
|
|
|
|
|
|
|
# TODO: use timestamps instead of offsets to make it more natural
|
|
|
|
|
# to go huge distances in time
|
|
|
|
|
$html = wfViewPrevNext( $offset, $limit,
|
2004-09-24 16:24:43 +00:00
|
|
|
$wgContLang->specialpage( 'Log' ),
|
2004-08-24 08:11:46 +00:00
|
|
|
$bits,
|
|
|
|
|
false);
|
|
|
|
|
$out->addHTML( '<p>' . $html . '</p>' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
?>
|