2008-04-02 05:48:16 +00:00
|
|
|
<?php
|
2010-08-08 14:28:01 +00:00
|
|
|
/**
|
|
|
|
|
* Contain classes to list log entries
|
|
|
|
|
*
|
2017-06-27 06:14:22 +00:00
|
|
|
* Copyright © 2004 Brion Vibber <brion@pobox.com>
|
2014-03-13 22:23:56 +00:00
|
|
|
* https://www.mediawiki.org/
|
2010-08-08 14:28:01 +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
|
|
|
|
|
* 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 05:48:16 +00:00
|
|
|
|
2017-06-30 09:05:29 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2016-11-30 01:07:37 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2017-02-10 18:09:05 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2016-11-30 01:07:37 +00:00
|
|
|
|
2012-06-16 15:33:21 +00:00
|
|
|
class LogEventsList extends ContextSource {
|
2008-04-02 05:48:16 +00:00
|
|
|
const NO_ACTION_LINK = 1;
|
2010-03-01 22:47:12 +00:00
|
|
|
const NO_EXTRA_USER_LINKS = 2;
|
2015-04-29 17:34:30 +00:00
|
|
|
const USE_CHECKBOXES = 4;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-04-02 16:24:30 +00:00
|
|
|
public $flags;
|
2008-04-02 05:48:16 +00:00
|
|
|
|
2011-03-13 21:17:37 +00:00
|
|
|
/**
|
2014-04-19 20:22:20 +00:00
|
|
|
* @var array
|
2019-08-29 21:16:28 +00:00
|
|
|
* @deprecated since 1.34, no longer used.
|
2011-03-13 21:17:37 +00:00
|
|
|
*/
|
|
|
|
|
protected $mDefaultQuery;
|
|
|
|
|
|
2015-06-14 18:00:52 +00:00
|
|
|
/**
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
protected $showTagEditUI;
|
|
|
|
|
|
2015-11-13 21:51:40 +00:00
|
|
|
/**
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $allowedActions = null;
|
|
|
|
|
|
2017-06-30 09:05:29 +00:00
|
|
|
/**
|
|
|
|
|
* @var LinkRenderer|null
|
|
|
|
|
*/
|
|
|
|
|
private $linkRenderer;
|
|
|
|
|
|
2012-06-16 15:33:21 +00:00
|
|
|
/**
|
|
|
|
|
* The first two parameters used to be $skin and $out, but now only a context
|
|
|
|
|
* is needed, that's why there's a second unused parameter.
|
|
|
|
|
*
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param IContextSource|Skin $context Context to use; formerly it was
|
|
|
|
|
* a Skin object. Use of Skin is deprecated.
|
2017-08-11 16:09:41 +00:00
|
|
|
* @param LinkRenderer|null $linkRenderer previously unused
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param int $flags Can be a combination of self::NO_ACTION_LINK,
|
2015-04-29 17:34:30 +00:00
|
|
|
* self::NO_EXTRA_USER_LINKS or self::USE_CHECKBOXES.
|
2012-06-16 15:33:21 +00:00
|
|
|
*/
|
2017-06-30 09:05:29 +00:00
|
|
|
public function __construct( $context, $linkRenderer = null, $flags = 0 ) {
|
2012-06-16 15:33:21 +00:00
|
|
|
if ( $context instanceof IContextSource ) {
|
|
|
|
|
$this->setContext( $context );
|
|
|
|
|
} else {
|
|
|
|
|
// Old parameters, $context should be a Skin object
|
|
|
|
|
$this->setContext( $context->getContext() );
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-02 05:48:16 +00:00
|
|
|
$this->flags = $flags;
|
2015-06-14 18:00:52 +00:00
|
|
|
$this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() );
|
2017-06-30 09:05:29 +00:00
|
|
|
if ( $linkRenderer instanceof LinkRenderer ) {
|
|
|
|
|
$this->linkRenderer = $linkRenderer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @since 1.30
|
|
|
|
|
* @return LinkRenderer
|
|
|
|
|
*/
|
|
|
|
|
protected function getLinkRenderer() {
|
|
|
|
|
if ( $this->linkRenderer !== null ) {
|
|
|
|
|
return $this->linkRenderer;
|
|
|
|
|
} else {
|
|
|
|
|
return MediaWikiServices::getInstance()->getLinkRenderer();
|
|
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show options for the log list
|
2010-06-03 21:00:51 +00:00
|
|
|
*
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param array|string $types
|
|
|
|
|
* @param string $user
|
|
|
|
|
* @param string $page
|
2018-05-07 18:48:01 +00:00
|
|
|
* @param bool $pattern
|
2017-12-28 15:06:10 +00:00
|
|
|
* @param int|string $year Use 0 to start with no year preselected.
|
|
|
|
|
* @param int|string $month A month in the 1..12 range. Use 0 to start with no month
|
|
|
|
|
* preselected.
|
2018-04-25 05:22:19 +00:00
|
|
|
* @param int|string $day A day in the 1..31 range. Use 0 to start with no month
|
|
|
|
|
* preselected.
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param array|null $filter
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param string $tagFilter Tag to select by default
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $action
|
2008-04-02 05:48:16 +00:00
|
|
|
*/
|
2018-05-07 18:48:01 +00:00
|
|
|
public function showOptions( $types = [], $user = '', $page = '', $pattern = false, $year = 0,
|
2018-04-25 05:22:19 +00:00
|
|
|
$month = 0, $day = 0, $filter = null, $tagFilter = '', $action = null
|
2013-12-03 21:52:43 +00:00
|
|
|
) {
|
2009-05-02 14:34:45 +00:00
|
|
|
// For B/C, we take strings, but make sure they are converted...
|
2016-02-17 09:09:32 +00:00
|
|
|
$types = ( $types === '' ) ? [] : (array)$types;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2018-04-25 05:22:19 +00:00
|
|
|
$formDescriptor = [];
|
2009-10-11 19:55:56 +00:00
|
|
|
|
2009-08-10 17:36:57 +00:00
|
|
|
// Basic selectors
|
2018-04-25 05:22:19 +00:00
|
|
|
$formDescriptor['type'] = $this->getTypeMenuDesc( $types );
|
|
|
|
|
$formDescriptor['user'] = $this->getUserInputDesc( $user );
|
2018-07-23 16:18:04 +00:00
|
|
|
$formDescriptor['page'] = $this->getTitleInputDesc( $page );
|
2018-04-25 05:22:19 +00:00
|
|
|
|
|
|
|
|
// Add extra inputs if any
|
2018-07-13 02:02:13 +00:00
|
|
|
// This could either be a form descriptor array or a string with raw HTML.
|
|
|
|
|
// We need it to work in both cases and show a deprecation warning if it
|
|
|
|
|
// is a string. See T199495.
|
2018-04-25 05:22:19 +00:00
|
|
|
$extraInputsDescriptor = $this->getExtraInputsDesc( $types );
|
2018-07-13 02:02:13 +00:00
|
|
|
if (
|
|
|
|
|
is_array( $extraInputsDescriptor ) &&
|
|
|
|
|
!empty( $extraInputsDescriptor )
|
|
|
|
|
) {
|
2018-04-25 05:22:19 +00:00
|
|
|
$formDescriptor[ 'extra' ] = $extraInputsDescriptor;
|
2018-08-07 05:14:55 +00:00
|
|
|
} elseif (
|
|
|
|
|
is_string( $extraInputsDescriptor ) &&
|
|
|
|
|
$extraInputsDescriptor !== ''
|
|
|
|
|
) {
|
2018-07-13 02:02:13 +00:00
|
|
|
// We'll add this to the footer of the form later
|
|
|
|
|
$extraInputsString = $extraInputsDescriptor;
|
2018-08-07 05:14:55 +00:00
|
|
|
wfDeprecated( '$input in LogEventsListGetExtraInputs hook', '1.32' );
|
2018-04-25 05:22:19 +00:00
|
|
|
}
|
2009-01-30 23:24:29 +00:00
|
|
|
|
2009-08-10 17:36:57 +00:00
|
|
|
// Title pattern, if allowed
|
2018-04-25 05:22:19 +00:00
|
|
|
if ( !$this->getConfig()->get( 'MiserMode' ) ) {
|
|
|
|
|
$formDescriptor['pattern'] = $this->getTitlePatternDesc( $pattern );
|
2009-08-10 17:36:57 +00:00
|
|
|
}
|
2009-10-11 19:55:56 +00:00
|
|
|
|
2018-04-25 05:22:19 +00:00
|
|
|
// Date menu
|
|
|
|
|
$formDescriptor['date'] = [
|
|
|
|
|
'type' => 'date',
|
2018-07-26 19:55:24 +00:00
|
|
|
'label-message' => 'date',
|
2018-11-14 14:49:22 +00:00
|
|
|
'default' => $year && $month && $day ? sprintf( "%04d-%02d-%02d", $year, $month, $day ) : '',
|
2018-04-25 05:22:19 +00:00
|
|
|
];
|
2009-10-11 19:55:56 +00:00
|
|
|
|
2009-08-10 17:36:57 +00:00
|
|
|
// Tag filter
|
2018-04-25 05:22:19 +00:00
|
|
|
$formDescriptor['tagfilter'] = [
|
|
|
|
|
'type' => 'tagfilter',
|
|
|
|
|
'name' => 'tagfilter',
|
|
|
|
|
'label-raw' => $this->msg( 'tag-filter' )->parse(),
|
|
|
|
|
];
|
2009-10-11 19:55:56 +00:00
|
|
|
|
2009-08-10 17:36:57 +00:00
|
|
|
// Filter links
|
2013-02-03 18:30:03 +00:00
|
|
|
if ( $filter ) {
|
2018-04-25 05:22:19 +00:00
|
|
|
$formDescriptor['filters'] = $this->getFiltersDesc( $filter );
|
2009-08-10 17:36:57 +00:00
|
|
|
}
|
2009-10-11 19:55:56 +00:00
|
|
|
|
2015-11-13 21:51:40 +00:00
|
|
|
// Action filter
|
2018-04-25 05:22:19 +00:00
|
|
|
if (
|
|
|
|
|
$action !== null &&
|
|
|
|
|
$this->allowedActions !== null &&
|
|
|
|
|
count( $this->allowedActions ) > 0
|
|
|
|
|
) {
|
|
|
|
|
$formDescriptor['subtype'] = $this->getActionSelectorDesc( $types, $action );
|
2015-11-13 21:51:40 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-23 04:22:36 +00:00
|
|
|
$context = new DerivativeContext( $this->getContext() );
|
2018-07-23 16:18:04 +00:00
|
|
|
$context->setTitle( SpecialPage::getTitleFor( 'Log' ) ); // Remove subpage
|
2018-11-11 01:10:08 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $context );
|
2018-04-25 05:22:19 +00:00
|
|
|
$htmlForm
|
|
|
|
|
->setSubmitText( $this->msg( 'logeventslist-submit' )->text() )
|
2018-07-18 05:08:03 +00:00
|
|
|
->setMethod( 'get' )
|
2018-04-25 05:22:19 +00:00
|
|
|
->setWrapperLegendMsg( 'log' );
|
2009-10-11 19:55:56 +00:00
|
|
|
|
2018-07-13 02:02:13 +00:00
|
|
|
// TODO This will should be removed at some point. See T199495.
|
|
|
|
|
if ( isset( $extraInputsString ) ) {
|
|
|
|
|
$htmlForm->addFooterText( Html::rawElement(
|
|
|
|
|
'div',
|
|
|
|
|
null,
|
|
|
|
|
$extraInputsString
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-25 05:22:19 +00:00
|
|
|
$htmlForm->prepareForm()->displayForm( false );
|
2008-10-27 07:18:36 +00:00
|
|
|
}
|
2009-10-11 19:55:56 +00:00
|
|
|
|
2009-05-02 14:34:45 +00:00
|
|
|
/**
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param array $filter
|
2018-04-25 05:22:19 +00:00
|
|
|
* @return array Form descriptor
|
2009-05-02 14:34:45 +00:00
|
|
|
*/
|
2018-04-25 05:22:19 +00:00
|
|
|
private function getFiltersDesc( $filter ) {
|
|
|
|
|
$options = [];
|
|
|
|
|
$default = [];
|
2013-04-20 15:38:24 +00:00
|
|
|
foreach ( $filter as $type => $val ) {
|
2018-07-18 04:19:36 +00:00
|
|
|
$message = $this->msg( "logeventslist-{$type}-log" );
|
|
|
|
|
// FIXME: Remove this check once T199657 is fully resolved.
|
|
|
|
|
if ( !$message->exists() ) {
|
|
|
|
|
$message = $this->msg( "log-show-hide-{$type}" )->params( $this->msg( 'show' )->text() );
|
|
|
|
|
}
|
|
|
|
|
$options[ $message->text() ] = $type;
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2018-07-19 05:02:24 +00:00
|
|
|
if ( $val === false ) {
|
2018-04-25 05:22:19 +00:00
|
|
|
$default[] = $type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return [
|
|
|
|
|
'class' => 'HTMLMultiSelectField',
|
|
|
|
|
'label-message' => 'logeventslist-more-filters',
|
|
|
|
|
'flatlist' => true,
|
|
|
|
|
'options' => $options,
|
|
|
|
|
'default' => $default,
|
|
|
|
|
];
|
2008-10-27 07:18:36 +00:00
|
|
|
}
|
2009-10-11 19:55:56 +00:00
|
|
|
|
2008-04-02 05:48:16 +00:00
|
|
|
/**
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param array $queryTypes
|
2018-04-25 05:22:19 +00:00
|
|
|
* @return array Form descriptor
|
2008-04-02 05:48:16 +00:00
|
|
|
*/
|
2018-04-25 05:22:19 +00:00
|
|
|
private function getTypeMenuDesc( $queryTypes ) {
|
2013-02-03 18:30:03 +00:00
|
|
|
$queryType = count( $queryTypes ) == 1 ? $queryTypes[0] : '';
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$typesByName = []; // Temporary array
|
2008-04-02 05:48:16 +00:00
|
|
|
// First pass to load the log names
|
2013-04-20 15:38:24 +00:00
|
|
|
foreach ( LogPage::validTypes() as $type ) {
|
2011-09-08 08:51:32 +00:00
|
|
|
$page = new LogPage( $type );
|
|
|
|
|
$restriction = $page->getRestriction();
|
2019-08-21 02:01:06 +00:00
|
|
|
if ( MediaWikiServices::getInstance()
|
|
|
|
|
->getPermissionManager()
|
|
|
|
|
->userHasRight( $this->getUser(), $restriction )
|
|
|
|
|
) {
|
2011-09-08 08:51:32 +00:00
|
|
|
$typesByName[$type] = $page->getName()->text();
|
|
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Second pass to sort by name
|
2013-02-03 18:30:03 +00:00
|
|
|
asort( $typesByName );
|
2008-04-02 05:48:16 +00:00
|
|
|
|
2010-04-07 12:16:56 +00:00
|
|
|
// Always put "All public logs" on top
|
2011-09-08 08:51:32 +00:00
|
|
|
$public = $typesByName[''];
|
|
|
|
|
unset( $typesByName[''] );
|
2016-02-17 09:09:32 +00:00
|
|
|
$typesByName = [ '' => $public ] + $typesByName;
|
2010-04-07 12:16:56 +00:00
|
|
|
|
2018-04-25 05:22:19 +00:00
|
|
|
return [
|
|
|
|
|
'class' => 'HTMLSelectField',
|
|
|
|
|
'name' => 'type',
|
|
|
|
|
'options' => array_flip( $typesByName ),
|
|
|
|
|
'default' => $queryType,
|
|
|
|
|
];
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param string $user
|
2018-04-25 05:22:19 +00:00
|
|
|
* @return array Form descriptor
|
2008-04-02 05:48:16 +00:00
|
|
|
*/
|
2018-04-25 05:22:19 +00:00
|
|
|
private function getUserInputDesc( $user ) {
|
|
|
|
|
return [
|
|
|
|
|
'class' => 'HTMLUserTextField',
|
|
|
|
|
'label-message' => 'specialloguserlabel',
|
|
|
|
|
'name' => 'user',
|
2018-07-26 16:50:56 +00:00
|
|
|
'default' => $user,
|
2018-04-25 05:22:19 +00:00
|
|
|
];
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param string $title
|
2018-04-25 05:22:19 +00:00
|
|
|
* @return array Form descriptor
|
2008-04-02 05:48:16 +00:00
|
|
|
*/
|
2018-04-25 05:22:19 +00:00
|
|
|
private function getTitleInputDesc( $title ) {
|
|
|
|
|
return [
|
|
|
|
|
'class' => 'HTMLTitleTextField',
|
|
|
|
|
'label-message' => 'speciallogtitlelabel',
|
|
|
|
|
'name' => 'page',
|
|
|
|
|
'required' => false
|
|
|
|
|
];
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-04-02 05:48:16 +00:00
|
|
|
/**
|
2018-05-07 18:48:01 +00:00
|
|
|
* @param bool $pattern
|
2018-04-25 05:22:19 +00:00
|
|
|
* @return array Form descriptor
|
2008-04-02 05:48:16 +00:00
|
|
|
*/
|
2018-04-25 05:22:19 +00:00
|
|
|
private function getTitlePatternDesc( $pattern ) {
|
|
|
|
|
return [
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'log-title-wildcard',
|
|
|
|
|
'name' => 'pattern',
|
|
|
|
|
];
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
2009-10-11 19:55:56 +00:00
|
|
|
|
2011-09-04 21:40:17 +00:00
|
|
|
/**
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param array $types
|
2018-07-13 02:02:13 +00:00
|
|
|
* @return array|string Form descriptor or string with HTML
|
2011-09-04 21:40:17 +00:00
|
|
|
*/
|
2018-04-25 05:22:19 +00:00
|
|
|
private function getExtraInputsDesc( $types ) {
|
2014-10-28 17:49:19 +00:00
|
|
|
if ( count( $types ) == 1 ) {
|
|
|
|
|
if ( $types[0] == 'suppress' ) {
|
2018-04-25 05:22:19 +00:00
|
|
|
return [
|
|
|
|
|
'type' => 'text',
|
|
|
|
|
'label-message' => 'revdelete-offender',
|
|
|
|
|
'name' => 'offender',
|
|
|
|
|
];
|
2014-10-28 17:49:19 +00:00
|
|
|
} else {
|
|
|
|
|
// Allow extensions to add their own extra inputs
|
2018-07-13 02:02:13 +00:00
|
|
|
// This could be an array or string. See T199495.
|
|
|
|
|
$input = ''; // Deprecated
|
2018-04-25 05:22:19 +00:00
|
|
|
$formDescriptor = [];
|
2018-07-13 02:02:13 +00:00
|
|
|
Hooks::run( 'LogEventsListGetExtraInputs', [ $types[0], $this, &$input, &$formDescriptor ] );
|
|
|
|
|
|
|
|
|
|
return empty( $formDescriptor ) ? $input : $formDescriptor;
|
2014-10-28 17:49:19 +00:00
|
|
|
}
|
2009-09-14 17:09:13 +00:00
|
|
|
}
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2018-04-25 05:22:19 +00:00
|
|
|
return [];
|
2009-09-14 17:09:13 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2015-11-13 21:51:40 +00:00
|
|
|
/**
|
|
|
|
|
* Drop down menu for selection of actions that can be used to filter the log
|
|
|
|
|
* @param array $types
|
|
|
|
|
* @param string $action
|
2018-04-25 05:22:19 +00:00
|
|
|
* @return array Form descriptor
|
2015-11-13 21:51:40 +00:00
|
|
|
*/
|
2018-04-25 05:22:19 +00:00
|
|
|
private function getActionSelectorDesc( $types, $action ) {
|
|
|
|
|
$actionOptions = [];
|
|
|
|
|
$actionOptions[ 'log-action-filter-all' ] = '';
|
|
|
|
|
|
2015-11-13 21:51:40 +00:00
|
|
|
foreach ( $this->allowedActions as $value ) {
|
|
|
|
|
$msgKey = 'log-action-filter-' . $types[0] . '-' . $value;
|
2018-04-25 05:22:19 +00:00
|
|
|
$actionOptions[ $msgKey ] = $value;
|
2015-11-13 21:51:40 +00:00
|
|
|
}
|
2018-04-25 05:22:19 +00:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'class' => 'HTMLSelectField',
|
|
|
|
|
'name' => 'subtype',
|
|
|
|
|
'options-messages' => $actionOptions,
|
|
|
|
|
'default' => $action,
|
|
|
|
|
'label' => $this->msg( 'log-action-filter-' . $types[0] )->text(),
|
|
|
|
|
];
|
2015-11-13 21:51:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the action types allowed for log filtering
|
|
|
|
|
* To one action type may correspond several log_actions
|
|
|
|
|
* @param array $actions
|
|
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
public function setAllowedActions( $actions ) {
|
|
|
|
|
$this->allowedActions = $actions;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-04 21:40:17 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
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-14 07:45:50 +00:00
|
|
|
|
2011-09-04 21:40:17 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
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-14 07:45:50 +00:00
|
|
|
|
2008-12-07 19:56:02 +00:00
|
|
|
/**
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param stdClass $row A single row from the result set
|
|
|
|
|
* @return string Formatted HTML list item
|
2008-04-02 05:48:16 +00:00
|
|
|
*/
|
|
|
|
|
public function logLine( $row ) {
|
2011-09-08 08:57:02 +00:00
|
|
|
$entry = DatabaseLogEntry::newFromRow( $row );
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
2012-06-16 15:33:21 +00:00
|
|
|
$formatter->setContext( $this->getContext() );
|
2017-06-30 09:05:29 +00:00
|
|
|
$formatter->setLinkRenderer( $this->getLinkRenderer() );
|
2011-09-08 08:57:02 +00:00
|
|
|
$formatter->setShowUserToolLinks( !( $this->flags & self::NO_EXTRA_USER_LINKS ) );
|
|
|
|
|
|
2012-06-30 18:18:03 +00:00
|
|
|
$time = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
|
|
|
|
|
$entry->getTimestamp(), $this->getUser() ) );
|
|
|
|
|
|
2011-09-08 08:57:02 +00:00
|
|
|
$action = $formatter->getActionText();
|
|
|
|
|
|
2012-06-30 18:18:03 +00:00
|
|
|
if ( $this->flags & self::NO_ACTION_LINK ) {
|
|
|
|
|
$revert = '';
|
|
|
|
|
} else {
|
|
|
|
|
$revert = $formatter->getActionLinks();
|
|
|
|
|
if ( $revert != '' ) {
|
|
|
|
|
$revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-09-08 08:57:02 +00:00
|
|
|
|
2012-06-30 18:18:03 +00:00
|
|
|
$comment = $formatter->getComment();
|
2010-03-01 22:47:12 +00:00
|
|
|
|
|
|
|
|
// Some user can hide log items and have review links
|
|
|
|
|
$del = $this->getShowHideLinks( $row );
|
|
|
|
|
|
|
|
|
|
// Any tags...
|
2016-01-29 13:03:41 +00:00
|
|
|
list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow(
|
|
|
|
|
$row->ts_tags,
|
|
|
|
|
'logevent',
|
|
|
|
|
$this->getContext()
|
|
|
|
|
);
|
2012-06-30 18:18:03 +00:00
|
|
|
$classes = array_merge(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'mw-logline-' . $entry->getType() ],
|
2012-06-30 18:18:03 +00:00
|
|
|
$newClasses
|
|
|
|
|
);
|
2017-02-10 05:31:32 +00:00
|
|
|
$attribs = [
|
|
|
|
|
'data-mw-logid' => $entry->getId(),
|
|
|
|
|
'data-mw-logaction' => $entry->getFullType(),
|
|
|
|
|
];
|
|
|
|
|
$ret = "$del $time $action $comment $revert $tagDisplay";
|
|
|
|
|
|
|
|
|
|
// Let extensions add data
|
|
|
|
|
Hooks::run( 'LogEventsListLineEnding', [ $this, &$ret, $entry, &$classes, &$attribs ] );
|
2018-07-18 08:42:52 +00:00
|
|
|
$attribs = array_filter( $attribs,
|
|
|
|
|
[ Sanitizer::class, 'isReservedDataAttribute' ],
|
|
|
|
|
ARRAY_FILTER_USE_KEY
|
|
|
|
|
);
|
2017-02-10 05:31:32 +00:00
|
|
|
$attribs['class'] = implode( ' ', $classes );
|
|
|
|
|
|
|
|
|
|
return Html::rawElement( 'li', $attribs, $ret ) . "\n";
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-04-02 05:48:16 +00:00
|
|
|
/**
|
2017-12-28 15:06:10 +00:00
|
|
|
* @param stdClass $row
|
2008-04-13 15:18:59 +00:00
|
|
|
* @return string
|
2008-04-02 05:48:16 +00:00
|
|
|
*/
|
2008-11-04 00:33:09 +00:00
|
|
|
private function getShowHideLinks( $row ) {
|
2013-12-03 14:36:21 +00:00
|
|
|
// We don't want to see the links and
|
2015-04-29 17:34:30 +00:00
|
|
|
if ( $this->flags == self::NO_ACTION_LINK ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
|
|
|
|
|
// If change tag editing is available to this user, return the checkbox
|
2015-06-14 18:00:52 +00:00
|
|
|
if ( $this->flags & self::USE_CHECKBOXES && $this->showTagEditUI ) {
|
2015-04-29 17:34:30 +00:00
|
|
|
return Xml::check(
|
|
|
|
|
'showhiderevisions',
|
|
|
|
|
false,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'name' => 'ids[' . $row->log_id . ']' ]
|
2015-04-29 17:34:30 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:36:21 +00:00
|
|
|
// no one can hide items from the suppress log.
|
2015-04-29 17:34:30 +00:00
|
|
|
if ( $row->log_type == 'suppress' ) {
|
2010-03-01 22:47:12 +00:00
|
|
|
return '';
|
2009-10-30 02:14:22 +00:00
|
|
|
}
|
2015-04-29 17:34:30 +00:00
|
|
|
|
2010-03-01 22:47:12 +00:00
|
|
|
$del = '';
|
2019-08-21 02:01:06 +00:00
|
|
|
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
|
2012-06-25 16:07:51 +00:00
|
|
|
// Don't show useless checkbox to people who cannot hide log entries
|
2019-08-21 02:01:06 +00:00
|
|
|
if ( $permissionManager->userHasRight( $user, 'deletedhistory' ) ) {
|
|
|
|
|
$canHide = $permissionManager->userHasRight( $user, 'deletelogentry' );
|
|
|
|
|
$canViewSuppressedOnly = $permissionManager->userHasRight( $user, 'viewsuppressed' ) &&
|
|
|
|
|
!$permissionManager->userHasRight( $user, 'suppressrevision' );
|
2014-07-20 17:13:38 +00:00
|
|
|
$entryIsSuppressed = self::isDeleted( $row, LogPage::DELETED_RESTRICTED );
|
|
|
|
|
$canViewThisSuppressedEntry = $canViewSuppressedOnly && $entryIsSuppressed;
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $row->log_deleted || $canHide ) {
|
2013-12-03 14:58:51 +00:00
|
|
|
// Show checkboxes instead of links.
|
2015-04-29 17:34:30 +00:00
|
|
|
if ( $canHide && $this->flags & self::USE_CHECKBOXES && !$canViewThisSuppressedEntry ) {
|
2013-12-03 14:58:51 +00:00
|
|
|
// If event was hidden from sysops
|
|
|
|
|
if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
|
2012-06-05 22:58:54 +00:00
|
|
|
} else {
|
2013-12-03 14:58:51 +00:00
|
|
|
$del = Xml::check(
|
|
|
|
|
'showhiderevisions',
|
|
|
|
|
false,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'name' => 'ids[' . $row->log_id . ']' ]
|
2013-12-03 14:58:51 +00:00
|
|
|
);
|
2012-06-05 22:58:54 +00:00
|
|
|
}
|
2010-03-01 22:47:12 +00:00
|
|
|
} else {
|
2013-12-03 14:58:51 +00:00
|
|
|
// If event was hidden from sysops
|
|
|
|
|
if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) {
|
2012-06-05 22:58:54 +00:00
|
|
|
$del = Linker::revDeleteLinkDisabled( $canHide );
|
|
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$query = [
|
2012-06-05 22:58:54 +00:00
|
|
|
'target' => SpecialPage::getTitleFor( 'Log', $row->log_type )->getPrefixedDBkey(),
|
2013-04-20 15:38:24 +00:00
|
|
|
'type' => 'logging',
|
|
|
|
|
'ids' => $row->log_id,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-12-03 14:58:51 +00:00
|
|
|
$del = Linker::revDeleteLink(
|
|
|
|
|
$query,
|
2014-07-20 17:13:38 +00:00
|
|
|
$entryIsSuppressed,
|
|
|
|
|
$canHide && !$canViewThisSuppressedEntry
|
2013-12-03 14:58:51 +00:00
|
|
|
);
|
2012-06-05 22:58:54 +00:00
|
|
|
}
|
2010-03-01 22:47:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2009-01-18 21:07:09 +00:00
|
|
|
return $del;
|
2008-04-02 05:48:16 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-04-13 15:18:59 +00:00
|
|
|
/**
|
2017-12-28 15:06:10 +00:00
|
|
|
* @param stdClass $row
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param string|array $type
|
|
|
|
|
* @param string|array $action
|
2020-03-03 09:11:01 +00:00
|
|
|
* @param string $right (deprecated since 1.35)
|
2013-12-03 18:26:59 +00:00
|
|
|
* @return bool
|
2008-04-13 15:18:59 +00:00
|
|
|
*/
|
2013-02-03 18:30:03 +00:00
|
|
|
public static function typeAction( $row, $type, $action, $right = '' ) {
|
2020-02-28 06:26:18 +00:00
|
|
|
if ( $right !== '' ) {
|
2020-03-03 09:11:01 +00:00
|
|
|
wfDeprecated( __METHOD__ . ' with a right specified', '1.35' );
|
2020-02-28 06:26:18 +00:00
|
|
|
}
|
2013-02-03 18:30:03 +00:00
|
|
|
$match = is_array( $type ) ?
|
2009-10-11 19:55:56 +00:00
|
|
|
in_array( $row->log_type, $type ) : $row->log_type == $type;
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $match ) {
|
2009-10-11 19:55:56 +00:00
|
|
|
$match = is_array( $action ) ?
|
|
|
|
|
in_array( $row->log_action, $action ) : $row->log_action == $action;
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $match && $right ) {
|
2008-12-16 19:20:35 +00:00
|
|
|
global $wgUser;
|
2019-08-21 02:01:06 +00:00
|
|
|
$match = MediaWikiServices::getInstance()
|
|
|
|
|
->getPermissionManager()
|
|
|
|
|
->userHasRight( $wgUser, $right );
|
2008-12-16 19:20:35 +00:00
|
|
|
}
|
2008-04-16 18:05:54 +00:00
|
|
|
}
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2008-09-05 17:34:44 +00:00
|
|
|
return $match;
|
2008-04-13 15:18:59 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-04-02 17:11:58 +00:00
|
|
|
/**
|
|
|
|
|
* Determine if the current user is allowed to view a particular
|
2019-04-28 20:14:18 +00:00
|
|
|
* field of this log row, if it's marked as deleted and/or restricted log type.
|
2010-06-03 21:00:51 +00:00
|
|
|
*
|
2017-12-28 15:06:10 +00:00
|
|
|
* @param stdClass $row
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param int $field
|
2020-01-13 02:30:26 +00:00
|
|
|
* @param User|null $user User to check, or null to use $wgUser (deprecated since 1.35)
|
2013-12-03 18:26:59 +00:00
|
|
|
* @return bool
|
2008-04-02 17:11:58 +00:00
|
|
|
*/
|
2011-10-12 15:09:04 +00:00
|
|
|
public static function userCan( $row, $field, User $user = null ) {
|
2020-01-13 02:30:26 +00:00
|
|
|
if ( !$user ) {
|
2020-02-20 03:05:35 +00:00
|
|
|
wfDeprecated( __METHOD__ . ' without passing a $user parameter', '1.35' );
|
2020-01-13 02:30:26 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
$user = $wgUser;
|
|
|
|
|
}
|
2019-04-28 20:14:18 +00:00
|
|
|
return self::userCanBitfield( $row->log_deleted, $field, $user ) &&
|
|
|
|
|
self::userCanViewLogType( $row->log_type, $user );
|
2009-10-15 11:31:33 +00:00
|
|
|
}
|
2010-06-03 21:00:51 +00:00
|
|
|
|
2009-10-15 11:31:33 +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
|
|
|
*
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param int $bitfield Current field
|
|
|
|
|
* @param int $field
|
2020-01-13 02:30:26 +00:00
|
|
|
* @param User|null $user User to check, or null to use $wgUser (deprecated since 1.35)
|
2013-12-03 18:26:59 +00:00
|
|
|
* @return bool
|
2009-10-15 11:31:33 +00:00
|
|
|
*/
|
2011-10-12 15:09:04 +00:00
|
|
|
public static function userCanBitfield( $bitfield, $field, User $user = null ) {
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $bitfield & $field ) {
|
2011-10-12 15:09:04 +00:00
|
|
|
if ( $user === null ) {
|
2020-02-20 03:05:35 +00:00
|
|
|
wfDeprecated( __METHOD__ . ' without passing a $user parameter', '1.35' );
|
2011-10-12 15:09:04 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
$user = $wgUser;
|
|
|
|
|
}
|
2014-06-12 22:18:51 +00:00
|
|
|
if ( $bitfield & LogPage::DELETED_RESTRICTED ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$permissions = [ 'suppressrevision', 'viewsuppressed' ];
|
2014-06-12 22:18:51 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$permissions = [ 'deletedhistory' ];
|
2014-06-12 22:18:51 +00:00
|
|
|
}
|
2014-07-20 17:43:39 +00:00
|
|
|
$permissionlist = implode( ', ', $permissions );
|
|
|
|
|
wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" );
|
2019-08-21 22:42:08 +00:00
|
|
|
return MediaWikiServices::getInstance()
|
|
|
|
|
->getPermissionManager()
|
|
|
|
|
->userHasAnyRight( $user, ...$permissions );
|
2008-04-02 17:11:58 +00:00
|
|
|
}
|
2013-12-03 21:49:59 +00:00
|
|
|
return true;
|
2008-04-02 17:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-28 20:14:18 +00:00
|
|
|
/**
|
|
|
|
|
* Determine if the current user is allowed to view a particular
|
|
|
|
|
* field of this log row, if it's marked as restricted log type.
|
|
|
|
|
*
|
|
|
|
|
* @param stdClass $type
|
2020-01-13 02:30:26 +00:00
|
|
|
* @param User|null $user User to check, or null to use $wgUser (deprecated since 1.35)
|
2019-04-28 20:14:18 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function userCanViewLogType( $type, User $user = null ) {
|
|
|
|
|
if ( $user === null ) {
|
2020-02-20 03:05:35 +00:00
|
|
|
wfDeprecated( __METHOD__ . ' without passing a $user parameter', '1.35' );
|
2019-04-28 20:14:18 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
$user = $wgUser;
|
|
|
|
|
}
|
|
|
|
|
$logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( 'LogRestrictions' );
|
2019-08-21 02:01:06 +00:00
|
|
|
if ( isset( $logRestrictions[$type] ) && !MediaWikiServices::getInstance()
|
|
|
|
|
->getPermissionManager()
|
|
|
|
|
->userHasRight( $user, $logRestrictions[$type] )
|
|
|
|
|
) {
|
2019-04-28 20:14:18 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-02 17:11:58 +00:00
|
|
|
/**
|
2017-12-28 15:06:10 +00:00
|
|
|
* @param stdClass $row
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param int $field One of DELETED_* bitfield constants
|
|
|
|
|
* @return bool
|
2008-04-02 17:11:58 +00:00
|
|
|
*/
|
|
|
|
|
public static function isDeleted( $row, $field ) {
|
2009-10-11 19:55:56 +00:00
|
|
|
return ( $row->log_deleted & $field ) == $field;
|
2008-04-02 17:11:58 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-04-02 19:01:41 +00:00
|
|
|
/**
|
2009-09-13 22:21:11 +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
|
|
|
*
|
2017-08-11 00:23:16 +00:00
|
|
|
* @param OutputPage|string &$out
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string|array $types Log types to show
|
|
|
|
|
* @param string|Title $page The page title to show log entries for
|
|
|
|
|
* @param string $user The user who made the log entries
|
|
|
|
|
* @param array $param Associative Array with the following additional options:
|
2009-10-11 19:55:56 +00:00
|
|
|
* - lim Integer Limit of items to show, default is 50
|
2017-02-22 17:55:56 +00:00
|
|
|
* - conds Array Extra conditions for the query
|
|
|
|
|
* (e.g. 'log_action != ' . $dbr->addQuotes( 'revision' ))
|
2009-10-11 19:55:56 +00:00
|
|
|
* - 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
|
2012-06-16 15:33:21 +00:00
|
|
|
* that are processed with wfMessage
|
|
|
|
|
* - offset Set to overwrite offset parameter in WebRequest
|
2009-10-11 19:55:56 +00:00
|
|
|
* set to '' to unset offset
|
2010-03-01 22:47:12 +00:00
|
|
|
* - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
|
|
|
|
|
* - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
|
2013-02-02 02:17:02 +00:00
|
|
|
* - useRequestParams boolean Set true to use Pager-related parameters in the WebRequest
|
2013-11-16 22:57:33 +00:00
|
|
|
* - useMaster boolean Use master DB
|
2016-05-13 17:44:34 +00:00
|
|
|
* - extraUrlParams array|bool Additional url parameters for "full log" link (if it is shown)
|
2013-12-03 18:26:59 +00:00
|
|
|
* @return int Number of total log items (not limited by $lim)
|
2008-04-02 20:20:47 +00:00
|
|
|
*/
|
2010-03-01 22:47:12 +00:00
|
|
|
public static function showLogExtract(
|
2016-02-17 09:09:32 +00:00
|
|
|
&$out, $types = [], $page = '', $user = '', $param = []
|
2010-03-01 22:47:12 +00:00
|
|
|
) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$defaultParameters = [
|
2009-10-02 18:04:58 +00:00
|
|
|
'lim' => 25,
|
2016-02-17 09:09:32 +00:00
|
|
|
'conds' => [],
|
2009-09-18 13:57:13 +00:00
|
|
|
'showIfEmpty' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
'msgKey' => [ '' ],
|
2010-03-01 22:47:12 +00:00
|
|
|
'wrap' => "$1",
|
2013-02-02 02:17:02 +00:00
|
|
|
'flags' => 0,
|
|
|
|
|
'useRequestParams' => false,
|
2013-11-16 22:57:33 +00:00
|
|
|
'useMaster' => false,
|
2016-05-13 17:44:34 +00:00
|
|
|
'extraUrlParams' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2009-09-18 13:57:13 +00:00
|
|
|
# The + operator appends elements of remaining keys from the right
|
|
|
|
|
# handed array to the left handed, whereas duplicated keys are NOT overwritten.
|
|
|
|
|
$param += $defaultParameters;
|
2009-09-16 17:17:16 +00:00
|
|
|
# Convert $param array to individual variables
|
|
|
|
|
$lim = $param['lim'];
|
|
|
|
|
$conds = $param['conds'];
|
|
|
|
|
$showIfEmpty = $param['showIfEmpty'];
|
|
|
|
|
$msgKey = $param['msgKey'];
|
2010-01-16 11:24:23 +00:00
|
|
|
$wrap = $param['wrap'];
|
2010-03-01 22:47:12 +00:00
|
|
|
$flags = $param['flags'];
|
2016-05-13 17:44:34 +00:00
|
|
|
$extraUrlParams = $param['extraUrlParams'];
|
|
|
|
|
|
2013-02-02 02:17:02 +00:00
|
|
|
$useRequestParams = $param['useRequestParams'];
|
2010-03-01 22:47:12 +00:00
|
|
|
if ( !is_array( $msgKey ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$msgKey = [ $msgKey ];
|
2010-03-01 22:47:12 +00:00
|
|
|
}
|
2011-09-20 20:00:05 +00:00
|
|
|
|
|
|
|
|
if ( $out instanceof OutputPage ) {
|
|
|
|
|
$context = $out->getContext();
|
|
|
|
|
} else {
|
|
|
|
|
$context = RequestContext::getMain();
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-30 09:05:29 +00:00
|
|
|
// FIXME: Figure out how to inject this
|
|
|
|
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
|
|
|
|
|
2009-09-16 17:17:16 +00:00
|
|
|
# Insert list of top 50 (or top $lim) items
|
2017-06-30 09:05:29 +00:00
|
|
|
$loglist = new LogEventsList( $context, $linkRenderer, $flags );
|
2009-05-02 14:34:45 +00:00
|
|
|
$pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
|
2013-02-02 02:17:02 +00:00
|
|
|
if ( !$useRequestParams ) {
|
|
|
|
|
# Reset vars that may have been taken from the request
|
|
|
|
|
$pager->mLimit = 50;
|
|
|
|
|
$pager->mDefaultLimit = 50;
|
|
|
|
|
$pager->mOffset = "";
|
|
|
|
|
$pager->mIsBackwards = false;
|
|
|
|
|
}
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2013-11-16 22:57:33 +00:00
|
|
|
if ( $param['useMaster'] ) {
|
|
|
|
|
$pager->mDb = wfGetDB( DB_MASTER );
|
|
|
|
|
}
|
2012-06-16 15:33:21 +00:00
|
|
|
if ( isset( $param['offset'] ) ) { # Tell pager to ignore WebRequest offset
|
2009-09-20 22:07:44 +00:00
|
|
|
$pager->setOffset( $param['offset'] );
|
2010-03-01 22:47:12 +00:00
|
|
|
}
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $lim > 0 ) {
|
|
|
|
|
$pager->mLimit = $lim;
|
|
|
|
|
}
|
2014-10-31 21:16:06 +00:00
|
|
|
// Fetch the log rows and build the HTML if needed
|
2015-04-03 08:28:08 +00:00
|
|
|
$logBody = $pager->getBody();
|
|
|
|
|
$numRows = $pager->getNumRows();
|
2014-10-31 21:16:06 +00:00
|
|
|
|
2009-09-14 02:17:31 +00:00
|
|
|
$s = '';
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $logBody ) {
|
2009-09-16 17:17:16 +00:00
|
|
|
if ( $msgKey[0] ) {
|
2013-12-19 14:20:24 +00:00
|
|
|
$dir = $context->getLanguage()->getDir();
|
2014-11-06 13:22:02 +00:00
|
|
|
$lang = $context->getLanguage()->getHtmlCode();
|
2013-12-19 14:20:24 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$s = Xml::openElement( 'div', [
|
2019-10-03 18:19:45 +00:00
|
|
|
'class' => "warningbox mw-warning-with-logexcerpt mw-content-$dir",
|
2013-12-19 14:20:24 +00:00
|
|
|
'dir' => $dir,
|
|
|
|
|
'lang' => $lang,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2009-09-14 18:58:25 +00:00
|
|
|
|
2009-09-14 19:56:22 +00:00
|
|
|
if ( count( $msgKey ) == 1 ) {
|
2012-06-16 15:33:21 +00:00
|
|
|
$s .= $context->msg( $msgKey[0] )->parseAsBlock();
|
2009-09-14 18:58:25 +00:00
|
|
|
} else { // Process additional arguments
|
|
|
|
|
$args = $msgKey;
|
2009-09-14 19:56:22 +00:00
|
|
|
array_shift( $args );
|
2012-06-16 15:33:21 +00:00
|
|
|
$s .= $context->msg( $msgKey[0], $args )->parseAsBlock();
|
2009-09-14 18:58:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-09-13 22:21:11 +00:00
|
|
|
$s .= $loglist->beginLogEventsList() .
|
2013-02-03 18:30:03 +00:00
|
|
|
$logBody .
|
|
|
|
|
$loglist->endLogEventsList();
|
2019-04-02 20:06:34 +00:00
|
|
|
// add styles for change tags
|
|
|
|
|
$context->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' );
|
2013-04-20 15:38:24 +00:00
|
|
|
} elseif ( $showIfEmpty ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$s = Html::rawElement( 'div', [ 'class' => 'mw-warning-logempty' ],
|
2013-04-20 15:38:24 +00:00
|
|
|
$context->msg( 'logempty' )->parse() );
|
2009-08-31 11:54:53 +00:00
|
|
|
}
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2014-11-20 08:22:42 +00:00
|
|
|
if ( $numRows > $pager->mLimit ) { # Show "Full log" link
|
2016-02-17 09:09:32 +00:00
|
|
|
$urlParam = [];
|
2011-09-29 19:03:57 +00:00
|
|
|
if ( $page instanceof Title ) {
|
|
|
|
|
$urlParam['page'] = $page->getPrefixedDBkey();
|
|
|
|
|
} elseif ( $page != '' ) {
|
2009-09-13 22:21:11 +00:00
|
|
|
$urlParam['page'] = $page;
|
2011-09-29 19:03:57 +00:00
|
|
|
}
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $user != '' ) {
|
2009-09-13 22:21:11 +00:00
|
|
|
$urlParam['user'] = $user;
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( !is_array( $types ) ) { # Make it an array, if it isn't
|
2016-02-17 09:09:32 +00:00
|
|
|
$types = [ $types ];
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2009-09-13 22:21:11 +00:00
|
|
|
# If there is exactly one log type, we can link to Special:Log?type=foo
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( count( $types ) == 1 ) {
|
2009-09-13 22:21:11 +00:00
|
|
|
$urlParam['type'] = $types[0];
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2016-05-13 17:44:34 +00:00
|
|
|
if ( $extraUrlParams !== false ) {
|
|
|
|
|
$urlParam = array_merge( $urlParam, $extraUrlParams );
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-30 09:05:29 +00:00
|
|
|
$s .= $linkRenderer->makeKnownLink(
|
2009-09-13 22:21:11 +00:00
|
|
|
SpecialPage::getTitleFor( 'Log' ),
|
2016-11-30 01:07:37 +00:00
|
|
|
$context->msg( 'log-fulllog' )->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
2009-09-13 22:21:11 +00:00
|
|
|
$urlParam
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-12-03 18:26:59 +00:00
|
|
|
|
2010-03-01 22:47:12 +00:00
|
|
|
if ( $logBody && $msgKey[0] ) {
|
2009-09-13 22:21:11 +00:00
|
|
|
$s .= '</div>';
|
2010-03-01 22:47:12 +00:00
|
|
|
}
|
2009-09-13 22:21:11 +00:00
|
|
|
|
2011-11-16 13:22:03 +00:00
|
|
|
if ( $wrap != '' ) { // Wrap message in html
|
2010-01-16 11:24:23 +00:00
|
|
|
$s = str_replace( '$1', $s, $wrap );
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-16 22:30:39 +00:00
|
|
|
/* hook can return false, if we don't want the message to be emitted (Wikia BugId:7093) */
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( Hooks::run( 'LogEventsListShowLogExtract', [ &$s, $types, $page, $user, $param ] ) ) {
|
2011-10-04 14:32:07 +00:00
|
|
|
// $out can be either an OutputPage object or a String-by-reference
|
2013-01-26 21:11:09 +00:00
|
|
|
if ( $out instanceof OutputPage ) {
|
2011-10-04 14:32:07 +00:00
|
|
|
$out->addHTML( $s );
|
|
|
|
|
} else {
|
|
|
|
|
$out = $s;
|
|
|
|
|
}
|
2011-09-16 22:30:39 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-20 08:22:42 +00:00
|
|
|
return $numRows;
|
2008-09-05 22:46:46 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
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
|
|
|
*
|
2015-10-04 09:07:25 +00:00
|
|
|
* @param IDatabase $db
|
2013-12-03 18:26:59 +00:00
|
|
|
* @param string $audience Public/user
|
2020-02-28 06:07:36 +00:00
|
|
|
* @param User|null $user User to check, or null to use $wgUser (deprecated since 1.35)
|
2013-12-03 18:26:59 +00:00
|
|
|
* @return string|bool String on success, false on failure.
|
2008-04-02 19:01:41 +00:00
|
|
|
*/
|
2012-12-14 14:01:32 +00:00
|
|
|
public static function getExcludeClause( $db, $audience = 'public', User $user = null ) {
|
|
|
|
|
global $wgLogRestrictions;
|
|
|
|
|
|
|
|
|
|
if ( $audience != 'public' && $user === null ) {
|
2020-02-28 06:07:36 +00:00
|
|
|
wfDeprecated(
|
|
|
|
|
__METHOD__ .
|
|
|
|
|
' using a non-public audience without passing a $user parameter',
|
|
|
|
|
'1.35'
|
|
|
|
|
);
|
2012-12-14 14:01:32 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
$user = $wgUser;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-02 19:01:41 +00:00
|
|
|
// Reset the array, clears extra "where" clauses when $par is used
|
2016-02-17 09:09:32 +00:00
|
|
|
$hiddenLogs = [];
|
2012-12-14 14:01:32 +00:00
|
|
|
|
2008-04-08 13:58:33 +00:00
|
|
|
// Don't show private logs to unprivileged users
|
2013-04-20 15:38:24 +00:00
|
|
|
foreach ( $wgLogRestrictions as $logType => $right ) {
|
2019-08-21 02:01:06 +00:00
|
|
|
if ( $audience == 'public' || !MediaWikiServices::getInstance()
|
|
|
|
|
->getPermissionManager()
|
|
|
|
|
->userHasRight( $user, $right )
|
|
|
|
|
) {
|
2012-12-14 14:01:32 +00:00
|
|
|
$hiddenLogs[] = $logType;
|
2008-04-02 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( count( $hiddenLogs ) == 1 ) {
|
2008-04-08 13:58:33 +00:00
|
|
|
return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
|
2013-04-20 15:38:24 +00:00
|
|
|
} elseif ( $hiddenLogs ) {
|
2012-12-14 14:01:32 +00:00
|
|
|
return 'log_type NOT IN (' . $db->makeList( $hiddenLogs ) . ')';
|
2008-04-02 19:01:41 +00:00
|
|
|
}
|
2013-12-03 14:36:21 +00:00
|
|
|
|
2008-04-02 19:01:41 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-02-03 18:30:03 +00:00
|
|
|
}
|