extensionRegistry = $extensionRegistry; if ( $this->isGlobalCheck() ) { // @phan-suppress-next-line PhanPossiblyNullTypeMismatchProperty $this->mDb = $this->getCentralReplicaDB(); } parent::__construct( $context, $linkRenderer ); $this->namespaceInfo = $namespaceInfo; $this->preliminaryCheckService = $preliminaryCheckService; $this->tokenQueryManager = $tokenQueryManager; $this->tokenData = $tokenQueryManager->getDataFromRequest( $context->getRequest() ); $this->mOffset = $this->tokenData['offset'] ?? ''; } /** * @inheritDoc */ protected function getTableClass() { return parent::getTableClass() . ' ext-checkuser-investigate-table' . ' ext-checkuser-investigate-table-preliminary-check'; } /** * @inheritDoc */ public function getCellAttrs( $field, $value ) { $attributes = parent::getCellAttrs( $field, $value ); $attributes['class'] = $attributes['class'] ?? ''; switch ( $field ) { case 'wiki': $attributes['class'] .= ' ext-checkuser-investigate-table-cell-interactive'; $attributes['class'] .= ' ext-checkuser-investigate-table-cell-pinnable'; $attributes['data-field'] = $field; $attributes['data-value'] = $value; break; case 'registration': $attributes['class'] .= ' ext-checkuser-investigate-table-cell-interactive'; $attributes['class'] .= ' ext-checkuser-investigate-table-cell-pinnable'; $date = $this->getLanguage()->userDate( $value, $this->getUser(), [ 'format' => 'ISO 8601' ] ); $attributes['data-field'] = $field; $attributes['data-value'] = $date; break; } // Add each cell to the tab index. $attributes['tabindex'] = 0; return $attributes; } /** * @param string $name * @param mixed $value * @return string */ public function formatValue( $name, $value ) { $language = $this->getLanguage(); $row = $this->mCurrentRow; $formatted = ''; switch ( $name ) { case 'name': $formatted = htmlspecialchars( $value ); break; case 'registration': $formatted = htmlspecialchars( $language->userTimeAndDate( $value, $this->getUser() ) ); break; case 'wiki': $wiki = WikiMap::getWiki( $row->wiki ); if ( $wiki ) { $formatted = Html::element( 'a', [ 'href' => $wiki->getFullUrl( $this->namespaceInfo->getCanonicalName( NS_USER ) . ':' . $row->name ), ], $wiki->getDisplayName() ); } else { $formatted = $this->msg( 'checkuser-investigate-preliminary-table-cell-wiki-nowiki' )->text(); } break; case 'editcount': $wiki = WikiMap::getWiki( $row->wiki ); if ( $wiki ) { $formatted = Html::rawElement( 'a', [ 'href' => $wiki->getFullUrl( $this->namespaceInfo->getCanonicalName( NS_SPECIAL ) . ':Contributions/' . $row->name ), ], $this->msg( 'checkuser-investigate-preliminary-table-cell-edits', $value )->parse() ); } else { $formatted = $this->getLinkRenderer()->makeKnownLink( \SpecialPage::getTitleFor( 'Contributions', $row->name ), $this->msg( 'checkuser-investigate-preliminary-table-cell-edits', $value )->text() ); } break; case 'blocked': if ( $value ) { $formatted = $this->msg( 'checkuser-investigate-preliminary-table-cell-blocked' )->parse(); } else { $formatted = $this->msg( 'checkuser-investigate-preliminary-table-cell-unblocked' )->parse(); } break; case 'groups': $formatted = htmlspecialchars( implode( ', ', $value ) ); break; } return $formatted; } /** * @inheritDoc */ public function getIndexField() { return $this->isGlobalCheck() ? [ [ 'lu_name', 'lu_wiki' ] ] : 'user_name'; } /** * @inheritDoc */ public function getFieldNames() { if ( $this->fieldNames === null ) { $fullFieldNames = [ 'name' => 'checkuser-investigate-preliminary-table-header-name', 'registration' => 'checkuser-investigate-preliminary-table-header-registration', 'wiki' => 'checkuser-investigate-preliminary-table-header-wiki', 'editcount' => 'checkuser-investigate-preliminary-table-header-editcount', 'blocked' => 'checkuser-investigate-preliminary-table-header-blocked', 'groups' => 'checkuser-investigate-preliminary-table-header-groups', ]; if ( $this->isGlobalCheck() ) { $this->fieldNames = $fullFieldNames; } else { unset( $fullFieldNames['wiki'] ); $this->fieldNames = $fullFieldNames; } foreach ( $this->fieldNames as $key => $val ) { $this->fieldNames[$key] = $this->msg( $val )->text(); } } return $this->fieldNames; } /** * @inheritDoc */ public function getQueryInfo() { $targets = $this->tokenData['targets'] ?? []; $users = array_filter( array_map( 'User::newFromName', $targets ), function ( $user ) { return (bool)$user; } ); return $this->preliminaryCheckService->getQueryInfo( $users ); } /** * @inheritDoc */ public function preprocessResults( $result ) { $this->mResult = new FakeResultWrapper( $this->preliminaryCheckService->preprocessResults( $result ) ); } /** * @return bool */ public function isGlobalCheck(): bool { return $this->extensionRegistry->isLoaded( 'CentralAuth' ) && is_callable( [ CentralAuthUtils::class, 'getCentralReplicaDB' ] ); } /** * @return IDatabase|null */ protected function getCentralReplicaDB(): ?IDatabase { if ( is_callable( [ CentralAuthUtils::class, 'getCentralReplicaDB' ] ) ) { return CentralAuthUtils::getCentralReplicaDB(); } return null; } /** * @inheritDoc */ public function isFieldSortable( $field ) { return false; } /** * @inheritDoc */ public function getDefaultSort() { return ''; } /** * @inheritDoc * * Conceal the offset which may reveal private data. */ public function getPagingQueries() { return $this->tokenQueryManager->getPagingQueries( $this->getRequest(), parent::getPagingQueries() ); } }