specsFormatter = $specsFormatter; $this->specsFormatter->setMessageLocalizer( $this->getContext() ); $this->filterLookup = $filterLookup; } /** * Shows the page */ public function show() { $show = $this->loadData(); $out = $this->getOutput(); $out->enableOOUI(); $out->addModuleStyles( [ 'oojs-ui.styles.icons-movement' ] ); $links = []; if ( $this->filter ) { $links['abusefilter-history-backedit'] = $this->getTitle( $this->filter )->getFullURL(); $links['abusefilter-diff-backhistory'] = $this->getTitle( "history/$this->filter" )->getFullURL(); } foreach ( $links as $msg => $href ) { $links[$msg] = new OOUI\ButtonWidget( [ 'label' => $this->msg( $msg )->text(), 'href' => $href ] ); } $backlinks = new OOUI\HorizontalLayout( [ 'items' => array_values( $links ) ] ); $out->addHTML( $backlinks ); if ( $show ) { $out->addHTML( $this->formatDiff() ); // Next and previous change links $buttons = []; $oldHistoryID = $this->oldVersion->getHistoryID(); if ( $this->filterLookup->getFirstFilterVersionID( $this->filter ) !== $oldHistoryID ) { // Create a "previous change" link if this isn't the first change of the given filter $href = $this->getTitle( "history/$this->filter/diff/prev/$oldHistoryID" )->getFullURL(); $buttons[] = new OOUI\ButtonWidget( [ 'label' => $this->msg( 'abusefilter-diff-prev' )->text(), 'href' => $href, 'icon' => 'previous' ] ); } if ( $this->nextHistoryId !== null ) { // Create a "next change" link if this isn't the last change of the given filter $href = $this->getTitle( "history/$this->filter/diff/prev/$this->nextHistoryId" )->getFullURL(); $buttons[] = new OOUI\ButtonWidget( [ 'label' => $this->msg( 'abusefilter-diff-next' )->text(), 'href' => $href, 'icon' => 'next' ] ); } if ( count( $buttons ) > 0 ) { $buttons = new OOUI\HorizontalLayout( [ 'items' => $buttons, 'classes' => [ 'mw-abusefilter-history-buttons' ] ] ); $out->addHTML( $buttons ); } } } /** * @return bool */ public function loadData() { $oldSpec = $this->mParams[3]; $newSpec = $this->mParams[4]; if ( !is_numeric( $this->mParams[1] ) ) { $this->getOutput()->addWikiMsg( 'abusefilter-diff-invalid' ); return false; } $this->filter = (int)$this->mParams[1]; $this->oldVersion = $this->loadSpec( $oldSpec, $newSpec ); $this->newVersion = $this->loadSpec( $newSpec, $oldSpec ); if ( $this->oldVersion === null || $this->newVersion === null ) { $this->getOutput()->addWikiMsg( 'abusefilter-diff-invalid' ); return false; } if ( !$this->afPermManager->canViewPrivateFilters( $this->getAuthority() ) && ( $this->oldVersion->isHidden() || $this->newVersion->isHidden() ) ) { $this->getOutput()->addWikiMsg( 'abusefilter-history-error-hidden' ); return false; } if ( !$this->afPermManager->canViewProtectedVariables( $this->getAuthority() ) && ( $this->oldVersion->isProtected() || $this->newVersion->isProtected() ) ) { $this->getOutput()->addWikiMsg( 'abusefilter-history-error-protected' ); return false; } try { $this->nextHistoryId = $this->filterLookup->getClosestVersion( $this->newVersion->getHistoryID(), $this->filter, FilterLookup::DIR_NEXT )->getHistoryID(); } catch ( ClosestFilterVersionNotFoundException $_ ) { $this->nextHistoryId = null; } return true; } /** * @param string $spec * @param string $otherSpec * @return HistoryFilter|null */ public function loadSpec( $spec, $otherSpec ): ?HistoryFilter { static $dependentSpecs = [ 'prev', 'next' ]; static $cache = []; if ( isset( $cache[$spec] ) ) { return $cache[$spec]; } $filterObj = null; if ( ( $spec === 'prev' || $spec === 'next' ) && !in_array( $otherSpec, $dependentSpecs ) ) { $other = $this->loadSpec( $otherSpec, $spec ); if ( !$other ) { return null; } $dir = $spec === 'prev' ? FilterLookup::DIR_PREV : FilterLookup::DIR_NEXT; try { $filterObj = $this->filterLookup->getClosestVersion( $other->getHistoryID(), $this->filter, $dir ); } catch ( ClosestFilterVersionNotFoundException $_ ) { $t = $this->getTitle( "history/$this->filter/item/" . $other->getHistoryID() ); $this->getOutput()->redirect( $t->getFullURL() ); return null; } } if ( $filterObj === null ) { try { if ( is_numeric( $spec ) ) { $filterObj = $this->filterLookup->getFilterVersion( (int)$spec ); } elseif ( $spec === 'cur' ) { $filterObj = $this->filterLookup->getLastHistoryVersion( $this->filter ); } } catch ( FilterNotFoundException | FilterVersionNotFoundException $_ ) { } } $cache[$spec] = $filterObj; return $cache[$spec]; } /** * @param HistoryFilter $filterVersion * @return string raw html for the