wiki.techinc.nl/includes/logging/LogEventsList.php

760 lines
23 KiB
PHP
Raw Normal View History

<?php
/**
* Contain classes to list log entries
*
* Copyright © 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
*
* @file
*/
2008-04-02 17:43:57 +00:00
class LogEventsList {
const NO_ACTION_LINK = 1;
const NO_EXTRA_USER_LINKS = 2;
const USE_REVDEL_CHECKBOXES = 4;
2011-03-13 21:17:37 +00:00
/**
* @var Skin
*/
private $skin;
2011-03-13 21:17:37 +00:00
/**
* @var OutputPage
*/
private $out;
public $flags;
2011-03-13 21:17:37 +00:00
/**
* @var Array
*/
protected $message;
/**
* @var Array
*/
protected $mDefaultQuery;
public function __construct( $skin, $out, $flags = 0 ) {
$this->skin = $skin;
$this->out = $out;
$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 ) ) {
$messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink',
'revertmove', 'undeletelink', 'undeleteviewlink', 'revdel-restore', 'hist', 'diff',
'pipe-separator', 'revdel-restore-deleted', 'revdel-restore-visible' );
foreach( $messages as $msg ) {
$this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
}
}
}
/**
* Set page title and show header for this log type
* @param $type Array
* @deprecated in 1.19
*/
public function showHeader( $type ) {
wfDeprecated( __METHOD__, '1.19' );
// If only one log type is used, then show a special message...
$headerType = (count($type) == 1) ? $type[0] : '';
if( LogPage::isLogType( $headerType ) ) {
$page = new LogPage( $headerType );
$this->out->setPageTitle( $page->getName()->text() );
$this->out->addHTML( $page->getDescription()->parseAsBlock() );
} else {
$this->out->addHTML( wfMsgExt('alllogstext',array('parseinline')) );
}
}
/**
* Show options for the log list
2010-06-03 21:00:51 +00:00
*
* @param $types string or Array
2008-12-07 19:56:02 +00:00
* @param $user String
* @param $page String
* @param $pattern String
* @param $year Integer: year
* @param $month Integer: month
* @param $filter: array
* @param $tagFilter: array?
*/
public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='',
2011-03-13 21:17:37 +00:00
$month = '', $filter = null, $tagFilter='' ) {
global $wgScript, $wgMiserMode;
$action = $wgScript;
$title = SpecialPage::getTitleFor( 'Log' );
$special = $title->getPrefixedDBkey();
// For B/C, we take strings, but make sure they are converted...
$types = ($types === '') ? array() : (array)$types;
$tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
$html = Html::hidden( 'title', $special );
// Basic selectors
$html .= $this->getTypeMenu( $types ) . "\n";
$html .= $this->getUserInput( $user ) . "\n";
$html .= $this->getTitleInput( $page ) . "\n";
$html .= $this->getExtraInputs( $types ) . "\n";
// Title pattern, if allowed
if (!$wgMiserMode) {
$html .= $this->getTitlePattern( $pattern ) . "\n";
}
// date menu
$html .= Xml::tags( 'p', null, Xml::dateMenu( $year, $month ) );
// Tag filter
if ($tagSelector) {
Remove most named character references from output Recommit of r66254 to trunk. This was just find extensions phase3 -iname '*.php' \! -iname '*.i18n.php' \! -iname 'Messages*.php' \! -iname '*_Messages.php' -exec sed -i 's/&nbsp;/\&#160;/g;s/&mdash;/―/g;s/&bull;/•/g;s/&aacute;/á/g;s/&acute;/´/g;s/&agrave;/à/g;s/&alpha;/α/g;s/&auml;/ä/g;s/&ccedil;/ç/g;s/&copy;/©/g;s/&darr;/↓/g;s/&deg;/°/g;s/&eacute;/é/g;s/&ecirc;/ê/g;s/&euml;/ë/g;s/&egrave;/è/g;s/&euro;/€/g;s/&harr;//g;s/&hellip;/…/g;s/&iacute;/í/g;s/&igrave;/ì/g;s/&larr;/←/g;s/&ldquo;/“/g;s/&middot;/·/g;s/&minus;/−/g;s/&ndash;/–/g;s/&oacute;/ó/g;s/&ocirc;/ô/g;s/&oelig;/œ/g;s/&ograve;/ò/g;s/&otilde;/õ/g;s/&ouml;/ö/g;s/&pound;/£/g;s/&prime;/′/g;s/&Prime;/″/g;s/&raquo;/»/g;s/&rarr;/→/g;s/&rdquo;/”/g;s/&Sigma;/Σ/g;s/&times;/×/g;s/&uacute;/ú/g;s/&uarr;/↑/g;s/&uuml;/ü/g;s/&yen;/¥/g' {} + followed by reading over every single line of the resulting diff and fixing a whole bunch of false positives. The reason for this change is given in <http://lists.wikimedia.org/pipermail/wikitech-l/2010-April/047617.html>. I cleared it with Tim and Brion on IRC before committing. It might cause a few problems, but I tried to be careful; please report any issues. I skipped all messages files. I plan to make a follow-up commit that alters wfMsgExt() with 'escapenoentities' to sanitize all the entities. That way, the only messages that will be problems will be ones that output raw HTML, and we want to get rid of those anyway. This should get rid of all named entities everywhere except messages. I skipped a few things like &nbsp that I noticed in manual inspection, because they weren't well-formed XML anyway. Also, to everyone who uses non-breaking spaces when they could use a normal space, or nothing at all, or CSS padding: I still hate you. Die.
2010-05-30 17:33:59 +00:00
$html .= Xml::tags( 'p', null, implode( '&#160;', $tagSelector ) );
}
// Filter links
if ($filter) {
$html .= Xml::tags( 'p', null, $this->getFilterLinks( $filter ) );
}
// Submit button
$html .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
// Fieldset
$html = Xml::fieldset( wfMsg( 'log' ), $html );
// Form wrapping
$html = Xml::tags( 'form', array( 'action' => $action, 'method' => 'get' ), $html );
$this->out->addHTML( $html );
}
/**
* @param $filter Array
* @return String: Formatted HTML
*/
private function getFilterLinks( $filter ) {
global $wgLang;
// show/hide links
$messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
// Option value -> message mapping
$links = array();
$hiddens = ''; // keep track for "go" button
foreach( $filter as $type => $val ) {
// Should the below assignment be outside the foreach?
// Then it would have to be copied. Not certain what is more expensive.
$query = $this->getDefaultQuery();
$queryKey = "hide_{$type}_log";
$hideVal = 1 - intval($val);
2009-06-22 03:06:04 +00:00
$query[$queryKey] = $hideVal;
$link = Linker::link(
$this->getDisplayTitle(),
$messages[$hideVal],
array(),
$query,
array( 'known', 'noclasses' )
);
$links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
$hiddens .= Html::hidden( "hide_{$type}_log", $val ) . "\n";
}
// Build links
return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
}
private function getDefaultQuery() {
global $wgRequest;
if ( !isset( $this->mDefaultQuery ) ) {
$this->mDefaultQuery = $wgRequest->getQueryValues();
unset( $this->mDefaultQuery['title'] );
unset( $this->mDefaultQuery['dir'] );
unset( $this->mDefaultQuery['offset'] );
unset( $this->mDefaultQuery['limit'] );
unset( $this->mDefaultQuery['order'] );
unset( $this->mDefaultQuery['month'] );
unset( $this->mDefaultQuery['year'] );
}
return $this->mDefaultQuery;
}
/**
* Get the Title object of the page the links should point to.
* This is NOT the Title of the page the entries should be restricted to.
*
* @return Title object
*/
public function getDisplayTitle() {
return $this->out->getTitle();
}
public function getContext() {
return $this->out->getContext();
}
/**
* @param $queryTypes Array
2008-12-07 19:56:02 +00:00
* @return String: Formatted HTML
*/
private function getTypeMenu( $queryTypes ) {
$queryType = count($queryTypes) == 1 ? $queryTypes[0] : '';
$selector = $this->getTypeSelector();
$selector->setDefault( $queryType );
return $selector->getHtml();
}
/**
* Returns log page selector.
* @return XmlSelect
* @since 1.19
*/
public function getTypeSelector() {
global $wgUser;
$typesByName = array(); // Temporary array
// First pass to load the log names
foreach( LogPage::validTypes() as $type ) {
$page = new LogPage( $type );
$restriction = $page->getRestriction();
if ( $wgUser->isAllowed( $restriction ) ) {
$typesByName[$type] = $page->getName()->text();
}
}
// Second pass to sort by name
asort($typesByName);
// Always put "All public logs" on top
$public = $typesByName[''];
unset( $typesByName[''] );
$typesByName = array( '' => $public ) + $typesByName;
$select = new XmlSelect( 'type' );
foreach( $typesByName as $type => $name ) {
$select->addOption( $name, $type );
}
return $select;
}
/**
2008-12-07 19:56:02 +00:00
* @param $user String
* @return String: Formatted HTML
*/
private function getUserInput( $user ) {
return '<span style="white-space: nowrap">' .
Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user ) .
'</span>';
}
/**
2008-12-07 19:56:02 +00:00
* @param $title String
* @return String: Formatted HTML
*/
private function getTitleInput( $title ) {
return '<span style="white-space: nowrap">' .
Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title ) .
'</span>';
}
/**
* @param $pattern
* @return string Checkbox
*/
private function getTitlePattern( $pattern ) {
return '<span style="white-space: nowrap">' .
Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
'</span>';
}
/**
* @param $types
* @return string
*/
private function getExtraInputs( $types ) {
global $wgRequest;
$offender = $wgRequest->getVal('offender');
$user = User::newFromName( $offender, false );
if( !$user || ($user->getId() == 0 && !IP::isIPAddress($offender) ) ) {
$offender = ''; // Blank field if invalid
}
if( count($types) == 1 && $types[0] == 'suppress' ) {
return Xml::inputLabel( wfMsg('revdelete-offender'), 'offender',
'mw-log-offender', 20, $offender );
}
return '';
}
/**
* @return string
*/
2008-04-02 17:43:57 +00:00
public function beginLogEventsList() {
return "<ul>\n";
}
/**
* @return string
*/
2008-04-02 17:43:57 +00:00
public function endLogEventsList() {
return "</ul>\n";
}
2008-12-07 19:56:02 +00:00
/**
* @param $row Row: a single row from the result set
* @return String: Formatted HTML list item
*/
public function logLine( $row ) {
$entry = DatabaseLogEntry::newFromRow( $row );
$formatter = LogFormatter::newFromEntry( $entry );
$formatter->setShowUserToolLinks( !( $this->flags & self::NO_EXTRA_USER_LINKS ) );
$action = $formatter->getActionText();
$comment = $formatter->getComment();
$classes = array( 'mw-logline-' . $entry->getType() );
$title = $entry->getTarget();
$time = $this->logTimestamp( $entry );
// Extract extra parameters
$paramArray = LogPage::extractParams( $row->log_params );
// Add review/revert links and such...
$revert = $this->logActionLinks( $row, $title, $paramArray, $comment );
// Some user can hide log items and have review links
$del = $this->getShowHideLinks( $row );
if( $del != '' ) $del .= ' ';
// Any tags...
list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'logevent' );
$classes = array_merge( $classes, $newClasses );
return Xml::tags( 'li', array( "class" => implode( ' ', $classes ) ),
$del . "$time $action $comment $revert $tagDisplay" ) . "\n";
}
private function logTimestamp( LogEntry $entry ) {
global $wgLang;
$time = $wgLang->timeanddate( wfTimestamp( TS_MW, $entry->getTimestamp() ), true );
return htmlspecialchars( $time );
}
2011-03-13 21:17:37 +00:00
/**
* @TODO: split up!
*
* @param $row
* @param Title $title
* @param Array $paramArray
* @param $comment
* @return String
*/
private function logActionLinks( $row, $title, $paramArray, &$comment ) {
global $wgUser;
if( ( $this->flags & self::NO_ACTION_LINK ) // we don't want to see the action
|| self::isDeleted( $row, LogPage::DELETED_ACTION ) ) // action is hidden
{
return '';
}
$revert = '';
if( self::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) {
$destTitle = Title::newFromText( $paramArray[0] );
if( $destTitle ) {
$revert = Linker::link(
SpecialPage::getTitleFor( 'Movepage' ),
$this->message['revertmove'],
array(),
array(
'wpOldTitle' => $destTitle->getPrefixedDBkey(),
'wpNewTitle' => $title->getPrefixedDBkey(),
'wpReason' => wfMsgForContent( 'revertmove' ),
'wpMovetalk' => 0
),
array( 'known', 'noclasses' )
);
$revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
}
// Show undelete link
} elseif( self::typeAction( $row, array( 'delete', 'suppress' ), 'delete', 'deletedhistory' ) ) {
if( !$wgUser->isAllowed( 'undelete' ) ) {
$viewdeleted = $this->message['undeleteviewlink'];
} else {
$viewdeleted = $this->message['undeletelink'];
}
$revert = Linker::link(
SpecialPage::getTitleFor( 'Undelete' ),
$viewdeleted,
array(),
array( 'target' => $title->getPrefixedDBkey() ),
array( 'known', 'noclasses' )
);
$revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
// Show unblock/change block link
} elseif( self::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) {
$revert = Linker::link(
SpecialPage::getTitleFor( 'Unblock', $row->log_title ),
$this->message['unblocklink'],
array(),
array(),
'known'
) .
$this->message['pipe-separator'] .
Linker::link(
SpecialPage::getTitleFor( 'Block', $row->log_title ),
$this->message['change-blocklink'],
array(),
array(),
'known'
);
$revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
// Show change protection link
} elseif( self::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
$revert .= Linker::link( $title,
$this->message['hist'],
array(),
array(
'action' => 'history',
'offset' => $row->log_timestamp
)
);
if( $wgUser->isAllowed( 'protect' ) ) {
$revert .= $this->message['pipe-separator'] .
Linker::link( $title,
$this->message['protect_change'],
array(),
array( 'action' => 'protect' ),
'known' );
}
$revert = ' ' . wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
// Show unmerge link
} elseif( self::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) {
$revert = Linker::link(
SpecialPage::getTitleFor( 'MergeHistory' ),
$this->message['revertmerge'],
array(),
array(
'target' => $paramArray[0],
'dest' => $title->getPrefixedDBkey(),
'mergepoint' => $paramArray[1]
),
array( 'known', 'noclasses' )
);
$revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
// If an edit was hidden from a page give a review link to the history
} elseif( self::typeAction( $row, array( 'delete', 'suppress' ), 'revision', 'deletedhistory' ) ) {
$revert = RevisionDeleter::getLogLinks( $title, $paramArray,
$this->message );
// Hidden log items, give review link
} elseif( self::typeAction( $row, array( 'delete', 'suppress' ), 'event', 'deletedhistory' ) ) {
if( count($paramArray) >= 1 ) {
$revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
In Special:RevisionDelete: * Refactored to remove massive duplication * Removed page parameter and associated contextPage member variable, doesn't seem to do anything. * Put ID lists into a single ids parameter and member variable instead of having one for each type. * Fixed inappropriate call of Title::newFromUrl(), always wrong * Don't pretend to use the return value from functions that don't return anything, this reduces readability. * Use the table names for deleteKey/typeName values, they look more like English * Use protected not private * Remove requirement for log type to be specified in the target * Use POST for RevisionDelete entry forms, to avoid URL size limits and issues with non-PATH_INFO URLs * Don't purge all pages that use the given file * LocalFile::purgeCache() already calls purgeHistory,() no need to do it again. But do call purgeDescription(). * Removed token from unhide=1 links, unnecessary * Tokens are necessary on file streaming links, added them * Fixed private data leakage due to incorrect use of LocalRepo::newFromArchiveName(). Non-existent placeholder file was returned which meant that $oimage->userCan(File::DELETED_FILE) was always true. Pass the archive name to tryShowFile() instead of the storage key. * Using ls_field='oi_timestamp' is not correct, oi_timestamp refers to the timestamp of the revision in question, whereas the key that is stored is the timestamp of the previous revision (i.e. the timestamp in oi_archive_name). oi_archive_name would be more correct, although only half the field is used. Elsewhere: * Added missing message filehist-missing * Fixed double asterisk in Status::getWikiText() * Fixed escaping of the target parameter to Special:RevisionDelete from ImagePage * Deleted FileStore.php. Deprecated in filerepo refactor except for get()/export() but somehow resurrected by RevisionDelete. Hopefully this will be the end of it. New interfaces will be added for wfStreamFile() in a later commit. * Added convenience function File::getStorageKey(), factored out of Special:Undelete * Added convenience function Revision::newFromArchiveRow(), factored out of Special:Undelete and Special:RevisionDelete * Fixed notice in Special:Upload, uninitialised $pageText FIXME: current revision can be suppressed on undeletion causing an unauthenticated unsuppress. Comments indicate this is a known issue. I fixed the parser cache pollution in this case but not the rest.
2009-06-01 11:37:06 +00:00
// $paramArray[1] is a CSV of the IDs
$query = $paramArray[0];
// Link to each hidden object ID, $paramArray[1] is the url param
$revert = Linker::link(
$revdel,
$this->message['revdel-restore'],
array(),
array(
'target' => $title->getPrefixedText(),
'type' => 'logging',
'ids' => $query
),
array( 'known', 'noclasses' )
);
$revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
}
2008-09-13 00:29:33 +00:00
// Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
} else {
wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
&$comment, &$revert, $row->log_timestamp ) );
}
if( $revert != '' ) {
$revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
}
return $revert;
}
/**
2008-12-07 19:56:02 +00:00
* @param $row Row
2008-04-13 15:18:59 +00:00
* @return string
*/
private function getShowHideLinks( $row ) {
global $wgUser;
if( ( $this->flags == self::NO_ACTION_LINK ) // we don't want to see the links
2011-03-13 21:17:37 +00:00
|| $row->log_type == 'suppress' ) { // no one can hide items from the suppress log
return '';
}
$del = '';
// Don't show useless checkbox to people who cannot hide revisions
if( $wgUser->isAllowed( 'deletedhistory' ) ) {
if( $row->log_deleted || $wgUser->isAllowed( 'deleterevision' ) ) {
$canHide = $wgUser->isAllowed( 'deleterevision' );
if ( $this->flags & self::USE_REVDEL_CHECKBOXES ) { // Show checkboxes instead of links.
if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) { // If event was hidden from sysops
$del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
} else {
$del = Xml::check( 'showhiderevisions', false, array( 'name' => 'ids[' . $row->log_id . ']' ) );
}
} else {
if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) { // If event was hidden from sysops
$del = Linker::revDeleteLinkDisabled( $canHide );
} else {
$query = array(
'target' => SpecialPage::getTitleFor( 'Log', $row->log_type )->getPrefixedDBkey(),
'type' => 'logging',
'ids' => $row->log_id,
);
$del = Linker::revDeleteLink( $query, self::isDeleted( $row, LogPage::DELETED_RESTRICTED ), $canHide );
}
}
}
}
return $del;
}
2008-04-13 15:18:59 +00:00
/**
2008-12-07 19:56:02 +00:00
* @param $row Row
* @param $type Mixed: string/array
* @param $action Mixed: string/array
* @param $right string
2010-06-03 21:00:51 +00:00
* @return Boolean
2008-04-13 15:18:59 +00:00
*/
public static function typeAction( $row, $type, $action, $right='' ) {
$match = is_array($type) ?
in_array( $row->log_type, $type ) : $row->log_type == $type;
if( $match ) {
$match = is_array( $action ) ?
in_array( $row->log_action, $action ) : $row->log_action == $action;
if( $match && $right ) {
global $wgUser;
$match = $wgUser->isAllowed( $right );
}
2008-04-16 18:05:54 +00:00
}
return $match;
2008-04-13 15:18:59 +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.
2010-06-03 21:00:51 +00:00
*
2008-12-07 19:56:02 +00:00
* @param $row Row
* @param $field Integer
* @param $user User object to check, or null to use $wgUser
2008-12-07 19:56:02 +00:00
* @return Boolean
2008-04-02 17:11:58 +00:00
*/
public static function userCan( $row, $field, User $user = null ) {
return self::userCanBitfield( $row->log_deleted, $field, $user );
}
2010-06-03 21:00:51 +00:00
/**
* Determine if the current user is allowed to view a particular
* field of this log row, if it's marked as deleted.
2010-06-03 21:00:51 +00:00
*
* @param $bitfield Integer (current field)
* @param $field Integer
* @param $user User object to check, or null to use $wgUser
* @return Boolean
*/
public static function userCanBitfield( $bitfield, $field, User $user = null ) {
if( $bitfield & $field ) {
if ( $bitfield & LogPage::DELETED_RESTRICTED ) {
2009-10-09 19:01:39 +00:00
$permission = 'suppressrevision';
} else {
$permission = 'deletedhistory';
}
wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
if ( $user === null ) {
global $wgUser;
$user = $wgUser;
}
return $user->isAllowed( $permission );
2008-04-02 17:11:58 +00:00
} else {
return true;
}
}
/**
2008-12-07 19:56:02 +00:00
* @param $row Row
* @param $field Integer: one of DELETED_* bitfield constants
* @return Boolean
2008-04-02 17:11:58 +00:00
*/
public static function isDeleted( $row, $field ) {
return ( $row->log_deleted & $field ) == $field;
2008-04-02 17:11:58 +00:00
}
2008-04-02 19:01:41 +00:00
/**
* Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
2010-06-03 21:00:51 +00:00
*
* @param $out OutputPage|String-by-reference
* @param $types String|Array Log types to show
* @param $page String|Title The page title to show log entries for
* @param $user String The user who made the log entries
* @param $param array Associative Array with the following additional options:
* - lim Integer Limit of items to show, default is 50
* - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
* - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
* if set to true (default), "No matching items in log" is displayed if loglist is empty
* - msgKey Array If you want a nice box with a message, set this to the key of the message.
* First element is the message key, additional optional elements are parameters for the key
* that are processed with wfMsgExt and option 'parse'
* - offset Set to overwrite offset parameter in $wgRequest
* set to '' to unset offset
* - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
* - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
* @return Integer Number of total log items (not limited by $lim)
*/
public static function showLogExtract(
&$out, $types=array(), $page='', $user='', $param = array()
) {
$defaultParameters = array(
2009-10-02 18:04:58 +00:00
'lim' => 25,
'conds' => array(),
'showIfEmpty' => true,
'msgKey' => array(''),
'wrap' => "$1",
'flags' => 0
);
# The + operator appends elements of remaining keys from the right
# handed array to the left handed, whereas duplicated keys are NOT overwritten.
$param += $defaultParameters;
# Convert $param array to individual variables
$lim = $param['lim'];
$conds = $param['conds'];
$showIfEmpty = $param['showIfEmpty'];
$msgKey = $param['msgKey'];
$wrap = $param['wrap'];
$flags = $param['flags'];
if ( !is_array( $msgKey ) ) {
$msgKey = array( $msgKey );
}
if ( $out instanceof OutputPage ) {
$context = $out->getContext();
} else {
$context = RequestContext::getMain();
}
# Insert list of top 50 (or top $lim) items
$loglist = new LogEventsList( $context->getSkin(), $context->getOutput(), $flags );
$pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
if ( isset( $param['offset'] ) ) { # Tell pager to ignore $wgRequest offset
$pager->setOffset( $param['offset'] );
}
2008-10-18 23:36:41 +00:00
if( $lim > 0 ) $pager->mLimit = $lim;
$logBody = $pager->getBody();
$s = '';
if( $logBody ) {
if ( $msgKey[0] ) {
$s = '<div class="mw-warning-with-logexcerpt">';
if ( count( $msgKey ) == 1 ) {
$s .= wfMsgExt( $msgKey[0], array( 'parse' ) );
} else { // Process additional arguments
$args = $msgKey;
array_shift( $args );
$s .= wfMsgExt( $msgKey[0], array( 'parse' ), $args );
}
}
$s .= $loglist->beginLogEventsList() .
$logBody .
$loglist->endLogEventsList();
} else {
if ( $showIfEmpty ) {
$s = Html::rawElement( 'div', array( 'class' => 'mw-warning-logempty' ),
wfMsgExt( 'logempty', array( 'parseinline' ) ) );
}
}
if( $pager->getNumRows() > $pager->mLimit ) { # Show "Full log" link
$urlParam = array();
if ( $page instanceof Title ) {
$urlParam['page'] = $page->getPrefixedDBkey();
} elseif ( $page != '' ) {
$urlParam['page'] = $page;
}
if ( $user != '')
$urlParam['user'] = $user;
if ( !is_array( $types ) ) # Make it an array, if it isn't
$types = array( $types );
# If there is exactly one log type, we can link to Special:Log?type=foo
if ( count( $types ) == 1 )
$urlParam['type'] = $types[0];
$s .= Linker::link(
SpecialPage::getTitleFor( 'Log' ),
wfMsgHtml( 'log-fulllog' ),
array(),
$urlParam
);
}
if ( $logBody && $msgKey[0] ) {
$s .= '</div>';
}
if ( $wrap != '' ) { // Wrap message in html
$s = str_replace( '$1', $s, $wrap );
}
/* hook can return false, if we don't want the message to be emitted (Wikia BugId:7093) */
if ( wfRunHooks( 'LogEventsListShowLogExtract', array( &$s, $types, $page, $user, $param ) ) ) {
// $out can be either an OutputPage object or a String-by-reference
if ( $out instanceof OutputPage ){
$out->addHTML( $s );
} else {
$out = $s;
}
}
return $pager->getNumRows();
}
2008-12-07 19:56:02 +00:00
/**
2008-04-02 19:01:41 +00:00
* SQL clause to skip forbidden log types for this user
2010-06-03 21:00:51 +00:00
*
2011-10-28 18:11:47 +00:00
* @param $db DatabaseBase
* @param $audience string, public/user
2010-06-03 21:00:51 +00:00
* @return Mixed: string or false
2008-04-02 19:01:41 +00:00
*/
public static function getExcludeClause( $db, $audience = 'public' ) {
2008-04-02 19:01:41 +00:00
global $wgLogRestrictions, $wgUser;
// Reset the array, clears extra "where" clauses when $par is used
$hiddenLogs = array();
// Don't show private logs to unprivileged users
foreach( $wgLogRestrictions as $logType => $right ) {
if( $audience == 'public' || !$wgUser->isAllowed($right) ) {
$safeType = $db->strencode( $logType );
$hiddenLogs[] = $safeType;
2008-04-02 19:01:41 +00:00
}
}
if( count($hiddenLogs) == 1 ) {
return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
} elseif( $hiddenLogs ) {
return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
2008-04-02 19:01:41 +00:00
}
return false;
}
}