| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use ChangeTags; |
| 24 |
use LogEventsList; |
| 25 |
use LogFormatterFactory; |
| 26 |
use LogPage; |
| 27 |
use MediaWiki\Cache\LinkBatchFactory; |
| 28 |
use MediaWiki\HookContainer\HookRunner; |
| 29 |
use MediaWiki\Html\FormOptions; |
| 30 |
use MediaWiki\Html\Html; |
| 31 |
use MediaWiki\Html\ListToggle; |
| 32 |
use MediaWiki\MainConfigNames; |
| 33 |
use MediaWiki\MediaWikiServices; |
| 34 |
use MediaWiki\Pager\LogPager; |
| 35 |
use MediaWiki\SpecialPage\SpecialPage; |
| 36 |
use MediaWiki\Title\Title; |
| 37 |
use MediaWiki\User\ActorNormalization; |
| 38 |
use MediaWiki\User\UserIdentityLookup; |
| 39 |
use MediaWiki\User\UserNameUtils; |
| 40 |
use MediaWiki\Utils\MWTimestamp; |
| 41 |
use PermissionsError; |
| 42 |
use Wikimedia\IPUtils; |
| 43 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 44 |
use Wikimedia\Timestamp\TimestampException; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
class SpecialLog extends SpecialPage { |
| 52 |
|
| 53 |
private LinkBatchFactory $linkBatchFactory; |
| 54 |
|
| 55 |
private IConnectionProvider $dbProvider; |
| 56 |
|
| 57 |
private ActorNormalization $actorNormalization; |
| 58 |
|
| 59 |
private UserIdentityLookup $userIdentityLookup; |
| 60 |
|
| 61 |
private UserNameUtils $userNameUtils; |
| 62 |
|
| 63 |
private LogFormatterFactory $logFormatterFactory; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public function __construct( |
| 74 |
LinkBatchFactory $linkBatchFactory, |
| 75 |
IConnectionProvider $dbProvider, |
| 76 |
ActorNormalization $actorNormalization, |
| 77 |
UserIdentityLookup $userIdentityLookup, |
| 78 |
UserNameUtils $userNameUtils, |
| 79 |
LogFormatterFactory $logFormatterFactory |
| 80 |
) { |
| 81 |
parent::__construct( 'Log' ); |
| 82 |
$this->linkBatchFactory = $linkBatchFactory; |
| 83 |
$this->dbProvider = $dbProvider; |
| 84 |
$this->actorNormalization = $actorNormalization; |
| 85 |
$this->userIdentityLookup = $userIdentityLookup; |
| 86 |
$this->userNameUtils = $userNameUtils; |
| 87 |
$this->logFormatterFactory = $logFormatterFactory; |
| 88 |
} |
| 89 |
|
| 90 |
public function execute( $par ) { |
| 91 |
$this->setHeaders(); |
| 92 |
$this->outputHeader(); |
| 93 |
$out = $this->getOutput(); |
| 94 |
$out->addModules( 'mediawiki.userSuggest' ); |
| 95 |
$out->addModuleStyles( 'mediawiki.interface.helpers.styles' ); |
| 96 |
$this->addHelpLink( 'Help:Log' ); |
| 97 |
|
| 98 |
$opts = new FormOptions; |
| 99 |
$opts->add( 'type', '' ); |
| 100 |
$opts->add( 'user', '' ); |
| 101 |
$opts->add( 'page', '' ); |
| 102 |
$opts->add( 'pattern', false ); |
| 103 |
$opts->add( 'year', null, FormOptions::INTNULL ); |
| 104 |
$opts->add( 'month', null, FormOptions::INTNULL ); |
| 105 |
$opts->add( 'day', null, FormOptions::INTNULL ); |
| 106 |
$opts->add( 'tagfilter', '' ); |
| 107 |
$opts->add( 'tagInvert', false ); |
| 108 |
$opts->add( 'offset', '' ); |
| 109 |
$opts->add( 'dir', '' ); |
| 110 |
$opts->add( 'offender', '' ); |
| 111 |
$opts->add( 'subtype', '' ); |
| 112 |
$opts->add( 'logid', '' ); |
| 113 |
|
| 114 |
|
| 115 |
if ( $par !== null ) { |
| 116 |
$this->parseParams( (string)$par ); |
| 117 |
} |
| 118 |
$opts->fetchValuesFromRequest( $this->getRequest() ); |
| 119 |
|
| 120 |
|
| 121 |
$dateString = $this->getRequest()->getVal( 'wpdate' ); |
| 122 |
if ( $dateString ) { |
| 123 |
try { |
| 124 |
$dateStamp = MWTimestamp::getInstance( $dateString . ' 00:00:00' ); |
| 125 |
} catch ( TimestampException $e ) { |
| 126 |
|
| 127 |
|
| 128 |
$dateStamp = false; |
| 129 |
} |
| 130 |
if ( $dateStamp ) { |
| 131 |
$opts->setValue( 'year', (int)$dateStamp->format( 'Y' ) ); |
| 132 |
$opts->setValue( 'month', (int)$dateStamp->format( 'm' ) ); |
| 133 |
$opts->setValue( 'day', (int)$dateStamp->format( 'd' ) ); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
$logRestrictions = $this->getConfig()->get( MainConfigNames::LogRestrictions ); |
| 140 |
$type = $opts->getValue( 'type' ); |
| 141 |
if ( isset( $logRestrictions[$type] ) |
| 142 |
&& !$this->getAuthority()->isAllowed( $logRestrictions[$type] ) |
| 143 |
) { |
| 144 |
throw new PermissionsError( $logRestrictions[$type] ); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
$qc = []; |
| 150 |
$offenderName = $opts->getValue( 'offender' ); |
| 151 |
if ( $opts->getValue( 'type' ) == 'suppress' && $offenderName !== '' ) { |
| 152 |
$dbr = $this->dbProvider->getReplicaDatabase(); |
| 153 |
$offenderId = $this->actorNormalization->findActorIdByName( $offenderName, $dbr ); |
| 154 |
if ( $offenderId ) { |
| 155 |
$qc = [ 'ls_field' => 'target_author_actor', 'ls_value' => strval( $offenderId ) ]; |
| 156 |
} else { |
| 157 |
|
| 158 |
$qc = [ '1=0' ]; |
| 159 |
} |
| 160 |
} else { |
| 161 |
|
| 162 |
$this->getHookRunner()->onSpecialLogAddLogSearchRelations( |
| 163 |
$opts->getValue( 'type' ), $this->getRequest(), $qc ); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
if ( in_array( $opts->getValue( 'type' ), self::getLogTypesOnUser( $this->getHookRunner() ) ) ) { |
| 171 |
|
| 172 |
$page = $opts->getValue( 'page' ); |
| 173 |
$target = Title::newFromText( $page ); |
| 174 |
if ( $target && $target->getNamespace() === NS_MAIN ) { |
| 175 |
if ( IPUtils::isValidRange( $target->getText() ) ) { |
| 176 |
$page = IPUtils::sanitizeRange( $target->getText() ); |
| 177 |
} |
| 178 |
|
| 179 |
$target = Title::makeTitleSafe( NS_USER, $page ); |
| 180 |
} elseif ( $target && $target->getNamespace() === NS_USER |
| 181 |
&& IPUtils::isValidRange( $target->getText() ) |
| 182 |
) { |
| 183 |
$ipOrRange = IPUtils::sanitizeRange( $target->getText() ); |
| 184 |
if ( $ipOrRange !== $target->getText() ) { |
| 185 |
$target = Title::makeTitleSafe( NS_USER, $ipOrRange ); |
| 186 |
} |
| 187 |
} |
| 188 |
if ( $target !== null ) { |
| 189 |
$page = $target->getPrefixedText(); |
| 190 |
$opts->setValue( 'page', $page ); |
| 191 |
$this->getRequest()->setVal( 'page', $page ); |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
$this->show( $opts, $qc ); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
public static function getLogTypesOnUser( ?HookRunner $runner = null ) { |
| 210 |
static $types = null; |
| 211 |
if ( $types !== null ) { |
| 212 |
return $types; |
| 213 |
} |
| 214 |
$types = [ |
| 215 |
'block', |
| 216 |
'newusers', |
| 217 |
'rights', |
| 218 |
'renameuser', |
| 219 |
]; |
| 220 |
|
| 221 |
( $runner ?? new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) ) |
| 222 |
->onGetLogTypesOnUser( $types ); |
| 223 |
return $types; |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
public function getSubpagesForPrefixSearch() { |
| 232 |
$subpages = LogPage::validTypes(); |
| 233 |
$subpages[] = 'all'; |
| 234 |
sort( $subpages ); |
| 235 |
return $subpages; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
private function parseParams( string $par ) { |
| 247 |
|
| 248 |
$parms = explode( '/', $par, 2 ); |
| 249 |
$symsForAll = [ '*', 'all' ]; |
| 250 |
if ( $parms[0] !== '' && |
| 251 |
( in_array( $parms[0], LogPage::validTypes() ) || in_array( $parms[0], $symsForAll ) ) |
| 252 |
) { |
| 253 |
$this->getRequest()->setVal( 'type', $parms[0] ); |
| 254 |
if ( count( $parms ) === 2 ) { |
| 255 |
$this->getRequest()->setVal( 'user', $parms[1] ); |
| 256 |
} |
| 257 |
} elseif ( $par !== '' ) { |
| 258 |
$this->getRequest()->setVal( 'user', $par ); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
private function show( FormOptions $opts, array $extraConds ) { |
| 263 |
|
| 264 |
$loglist = new LogEventsList( |
| 265 |
$this->getContext(), |
| 266 |
$this->getLinkRenderer(), |
| 267 |
LogEventsList::USE_CHECKBOXES |
| 268 |
); |
| 269 |
$pager = new LogPager( |
| 270 |
$loglist, |
| 271 |
$opts->getValue( 'type' ), |
| 272 |
$opts->getValue( 'user' ), |
| 273 |
$opts->getValue( 'page' ), |
| 274 |
$opts->getValue( 'pattern' ), |
| 275 |
$extraConds, |
| 276 |
$opts->getValue( 'year' ), |
| 277 |
$opts->getValue( 'month' ), |
| 278 |
$opts->getValue( 'day' ), |
| 279 |
$opts->getValue( 'tagfilter' ), |
| 280 |
$opts->getValue( 'subtype' ), |
| 281 |
$opts->getValue( 'logid' ), |
| 282 |
$this->linkBatchFactory, |
| 283 |
$this->actorNormalization, |
| 284 |
$this->logFormatterFactory, |
| 285 |
$opts->getValue( 'tagInvert' ) |
| 286 |
); |
| 287 |
|
| 288 |
|
| 289 |
$performer = $pager->getPerformer(); |
| 290 |
if ( $performer ) { |
| 291 |
$performerUser = $this->userIdentityLookup->getUserIdentityByName( $performer ); |
| 292 |
|
| 293 |
|
| 294 |
if ( $performerUser && !IPUtils::isValidRange( $performer ) && |
| 295 |
( $this->userNameUtils->isIP( $performer ) || $performerUser->isRegistered() ) |
| 296 |
) { |
| 297 |
$this->getSkin()->setRelevantUser( $performerUser ); |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
$succeed = $loglist->showOptions( |
| 303 |
$opts->getValue( 'type' ), |
| 304 |
$opts->getValue( 'year' ), |
| 305 |
$opts->getValue( 'month' ), |
| 306 |
$opts->getValue( 'day' ) |
| 307 |
); |
| 308 |
if ( !$succeed ) { |
| 309 |
return; |
| 310 |
} |
| 311 |
|
| 312 |
$this->getOutput()->setPageTitleMsg( |
| 313 |
( new LogPage( $opts->getValue( 'type' ) ) )->getName() |
| 314 |
); |
| 315 |
|
| 316 |
|
| 317 |
$logBody = $pager->getBody(); |
| 318 |
if ( $logBody ) { |
| 319 |
$this->getOutput()->addHTML( |
| 320 |
$pager->getNavigationBar() . |
| 321 |
$this->getActionButtons( |
| 322 |
$loglist->beginLogEventsList() . |
| 323 |
$logBody . |
| 324 |
$loglist->endLogEventsList() |
| 325 |
) . |
| 326 |
$pager->getNavigationBar() |
| 327 |
); |
| 328 |
} else { |
| 329 |
$this->getOutput()->addWikiMsg( 'logempty' ); |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
private function getActionButtons( $formcontents ) { |
| 334 |
$canRevDelete = $this->getAuthority() |
| 335 |
->isAllowedAll( 'deletedhistory', 'deletelogentry' ); |
| 336 |
$showTagEditUI = ChangeTags::showTagEditingUI( $this->getAuthority() ); |
| 337 |
|
| 338 |
|
| 339 |
if ( !$canRevDelete && !$showTagEditUI ) { |
| 340 |
return $formcontents; |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
$s = Html::openElement( |
| 345 |
'form', |
| 346 |
[ 'action' => wfScript(), 'id' => 'mw-log-deleterevision-submit' ] |
| 347 |
) . "\n"; |
| 348 |
$s .= Html::hidden( 'type', 'logging' ) . "\n"; |
| 349 |
|
| 350 |
$buttons = ''; |
| 351 |
if ( $canRevDelete ) { |
| 352 |
$buttons .= Html::element( |
| 353 |
'button', |
| 354 |
[ |
| 355 |
'type' => 'submit', |
| 356 |
'name' => 'title', |
| 357 |
'value' => SpecialPage::getTitleFor( 'Revisiondelete' )->getPrefixedDBkey(), |
| 358 |
'class' => "deleterevision-log-submit mw-log-deleterevision-button mw-ui-button" |
| 359 |
], |
| 360 |
$this->msg( 'showhideselectedlogentries' )->text() |
| 361 |
) . "\n"; |
| 362 |
} |
| 363 |
if ( $showTagEditUI ) { |
| 364 |
$buttons .= Html::element( |
| 365 |
'button', |
| 366 |
[ |
| 367 |
'type' => 'submit', |
| 368 |
'name' => 'title', |
| 369 |
'value' => SpecialPage::getTitleFor( 'EditTags' )->getPrefixedDBkey(), |
| 370 |
'class' => "editchangetags-log-submit mw-log-editchangetags-button mw-ui-button" |
| 371 |
], |
| 372 |
$this->msg( 'log-edit-tags' )->text() |
| 373 |
) . "\n"; |
| 374 |
} |
| 375 |
|
| 376 |
$buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML(); |
| 377 |
|
| 378 |
$s .= $buttons . $formcontents . $buttons; |
| 379 |
$s .= Html::closeElement( 'form' ); |
| 380 |
|
| 381 |
return $s; |
| 382 |
} |
| 383 |
|
| 384 |
protected function getGroupName() { |
| 385 |
return 'changes'; |
| 386 |
} |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
class_alias( SpecialLog::class, 'SpecialLog' ); |