7namespace MediaWiki\Specials;
9use MediaWiki\ChangeTags\ChangeTags;
10use MediaWiki\Exception\PermissionsError;
11use MediaWiki\HookContainer\HookRunner;
12use MediaWiki\Html\FormOptions;
13use MediaWiki\Html\Html;
14use MediaWiki\Html\ListToggle;
15use MediaWiki\Logging\LogEventsList;
16use MediaWiki\Logging\LogFormatterFactory;
17use MediaWiki\Logging\LogPage;
18use MediaWiki\Logging\Pager\LogPager;
19use MediaWiki\MainConfigNames;
20use MediaWiki\MediaWikiServices;
21use MediaWiki\Page\LinkBatchFactory;
22use MediaWiki\SpecialPage\SpecialPage;
23use MediaWiki\Title\Title;
24use MediaWiki\User\ActorNormalization;
25use MediaWiki\User\TempUser\TempUserConfig;
26use MediaWiki\User\UserIdentityLookup;
27use MediaWiki\User\UserNameUtils;
28use MediaWiki\Utils\MWTimestamp;
30use Wikimedia\Rdbms\IConnectionProvider;
31use Wikimedia\Rdbms\IExpression;
32use Wikimedia\Timestamp\TimestampException;
52 parent::__construct(
'Log' );
54 $this->tempUserConfig = $tempUserConfig;
65 $out->addModuleStyles(
'mediawiki.interface.helpers.styles' );
69 $opts->
add(
'type',
'' );
70 $opts->add(
'user',
'' );
71 $opts->add(
'page', [] );
72 $opts->add(
'pattern',
false );
73 $opts->add(
'year',
null, FormOptions::INTNULL );
74 $opts->add(
'month',
null, FormOptions::INTNULL );
75 $opts->add(
'day',
null, FormOptions::INTNULL );
76 $opts->add(
'tagfilter',
'' );
77 $opts->add(
'tagInvert',
false );
78 $opts->add(
'offset',
'' );
79 $opts->add(
'dir',
'' );
80 $opts->add(
'offender',
'' );
81 $opts->add(
'subtype',
'' );
82 $opts->add(
'logid',
'' );
85 if ( $par !==
null ) {
86 $this->parseParams( (
string)$par );
88 $opts->fetchValuesFromRequest( $this->
getRequest() );
91 $dateString = $this->
getRequest()->getVal(
'wpdate' );
94 $dateStamp = MWTimestamp::getInstance( $dateString .
' 00:00:00' );
95 }
catch ( TimestampException ) {
101 $opts->setValue(
'year', (
int)$dateStamp->format(
'Y' ) );
102 $opts->setValue(
'month', (
int)$dateStamp->format(
'm' ) );
103 $opts->setValue(
'day', (
int)$dateStamp->format(
'd' ) );
110 $type = $opts->getValue(
'type' );
111 if ( isset( $logRestrictions[$type] )
112 && !$this->
getAuthority()->isAllowed( $logRestrictions[$type] )
117 # TODO: Move this into LogPager like other query conditions.
118 # Handle type-specific inputs
120 $offenderName = $opts->getValue(
'offender' );
121 if ( $opts->getValue(
'type' ) ==
'suppress' && $offenderName !==
'' ) {
122 $dbr = $this->dbProvider->getReplicaDatabase();
123 $offenderId = $this->actorNormalization->findActorIdByName( $offenderName, $dbr );
125 $qc = [
'ls_field' =>
'target_author_actor',
'ls_value' => strval( $offenderId ) ];
131 if ( $this->tempUserConfig->isKnown() ) {
142 $formWasSubmitted = $this->
getRequest()->getVal(
'wpFormIdentifier' ) ===
'logeventslist';
145 !$formWasSubmitted &&
147 !$this->
getRequest()->getVal(
'excludetempacct' ) &&
148 !$this->tempUserConfig->isTempName( $opts->getValue(
'user' ) )
152 !$this->getRequest()->getVal(
'logid' ) &&
153 $this->getRequest()->getVal(
'excludetempacct' )
156 $dbr = $this->dbProvider->getReplicaDatabase();
157 if ( $opts->getValue(
'type' ) ===
'' ) {
160 $dbr->expr(
'log_type',
'!=',
'newusers' )->orExpr(
161 $dbr->expr(
'log_type',
'=',
'newusers' )
162 ->andExpr( $this->tempUserConfig
163 ->getMatchCondition( $dbr,
'logging_actor.actor_name', IExpression::NOT_LIKE ) )
166 } elseif ( $opts->getValue(
'type' ) ===
'newusers' ) {
168 $this->tempUserConfig
169 ->getMatchCondition( $dbr,
'logging_actor.actor_name', IExpression::NOT_LIKE )
177 $opts->getValue(
'type' ), $this->getRequest(), $qc );
180 # TODO: Move this into LogEventList and use it as filter-callback in the field descriptor.
181 # Some log types are only for a 'User:' title but we might have been given
182 # only the username instead of the full title 'User:username'. This part try
183 # to lookup for a user by that name and eventually fix user input. See T3697.
184 if ( in_array( $opts->getValue(
'type' ), self::getLogTypesOnUser( $this->getHookRunner() ) ) ) {
186 foreach ( $opts->getValue(
'page' ) as $page ) {
187 $page = $this->normalizeUserPage( $page );
188 if ( $page !==
null ) {
189 $pages[] = $page->getPrefixedText();
192 $opts->setValue(
'page', $pages );
195 $this->show( $opts, $qc );
204 private function normalizeUserPage( $page ) {
205 $target = Title::newFromText( $page );
206 if ( $target && $target->getNamespace() ===
NS_MAIN ) {
207 if ( IPUtils::isValidRange( $target->getText() ) ) {
208 $page = IPUtils::sanitizeRange( $target->getText() );
210 # User forgot to add 'User:', we are adding it for them
211 $target = Title::makeTitleSafe(
NS_USER, $page );
212 } elseif ( $target && $target->getNamespace() ===
NS_USER
213 && IPUtils::isValidRange( $target->getText() )
215 $ipOrRange = IPUtils::sanitizeRange( $target->getText() );
216 if ( $ipOrRange !== $target->getText() ) {
217 $target = Title::makeTitleSafe(
NS_USER, $ipOrRange );
235 static $types =
null;
236 if ( $types !==
null ) {
247 ->onGetLogTypesOnUser( $types );
257 $subpages = LogPage::validTypes();
261 $this->
getHookRunner()->onSpecialLogGetSubpagesForPrefixSearch(
269 $subpages = array_unique( $subpages );
282 private function parseParams(
string $par ) {
283 $params = explode(
'/', $par, 2 );
284 $logType = $this->resolveLogType( $params );
287 $this->
getRequest()->setVal(
'type', $logType );
288 if ( count( $params ) === 2 ) {
289 $this->
getRequest()->setVal(
'user', $params[1] );
291 } elseif ( $par !==
'' ) {
312 private function resolveLogType( array $params ): string {
322 if ( $logType !==
'' ) {
323 $symsForAll = [
'*',
'all' ];
324 $allowedTypes = array_merge( LogPage::validTypes(), $symsForAll );
326 if ( in_array( $logType, $allowedTypes ) ) {
335 # Create a LogPager item to get the results and a LogEventsList item to format them...
338 $this->getLinkRenderer(),
339 LogEventsList::USE_CHECKBOXES
343 $opts->getValue(
'type' ),
344 $opts->getValue(
'user' ),
345 $opts->getValue(
'page' ),
346 $opts->getValue(
'pattern' ),
348 $opts->getValue(
'year' ),
349 $opts->getValue(
'month' ),
350 $opts->getValue(
'day' ),
351 $opts->getValue(
'tagfilter' ),
352 $opts->getValue(
'subtype' ),
353 $opts->getValue(
'logid' ),
354 $this->linkBatchFactory,
355 $this->actorNormalization,
356 $this->logFormatterFactory,
357 $opts->getValue(
'tagInvert' )
361 $performer = $pager->getPerformer();
363 $performerUser = $this->userIdentityLookup->getUserIdentityByName( $performer );
366 if ( $performerUser && !IPUtils::isValidRange( $performer ) &&
367 ( $this->userNameUtils->isIP( $performer ) || $performerUser->isRegistered() )
369 $this->
getSkin()->setRelevantUser( $performerUser );
374 $succeed = $loglist->showOptions(
375 $opts->getValue(
'type' ),
376 $opts->getValue(
'year' ),
377 $opts->getValue(
'month' ),
378 $opts->getValue(
'day' ),
379 $opts->getValue(
'user' ),
390 $logBody = $pager->getBody();
393 $pager->getNavigationBar() .
394 $this->getActionButtons(
395 $loglist->beginLogEventsList() .
397 $loglist->endLogEventsList()
399 $pager->getNavigationBar()
402 $this->
getOutput()->addWikiMsg(
'logempty' );
406 private function getActionButtons(
string $formcontents ): string {
410 # If the user doesn't have the ability to delete log entries nor edit tags,
411 # don't bother showing them the button(s).
413 return $formcontents;
416 # Show button to hide log entries and/or edit change tags
417 $s = Html::openElement(
419 [
'action' =>
wfScript(),
'id' =>
'mw-log-deleterevision-submit' ]
421 $s .= Html::hidden(
'type',
'logging' ) .
"\n";
424 if ( $canRevDelete ) {
431 'class' =>
"deleterevision-log-submit mw-log-deleterevision-button mw-ui-button"
433 $this->
msg(
'showhideselectedlogentries' )->
text()
443 'class' =>
"editchangetags-log-submit mw-log-editchangetags-button mw-ui-button"
445 $this->
msg(
'log-edit-tags' )->
text()
451 $s .= $buttons . $formcontents . $buttons;
452 $s .= Html::closeElement(
'form' );
465class_alias( SpecialLog::class,
'SpecialLog' );
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
Class to simplify the use of log pages.
const LogRestrictions
Name constant for the LogRestrictions setting, for use with Config\get().
Factory for LinkBatch objects to batch query page metadata.
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
getOutput()
Get the OutputPage being used for this instance.
getAuthority()
Shortcut to get the Authority executing this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.