die( "This file is part of MediaWiki, it is not a valid entry point" );
}
+use MediaWiki\BadFileLookup;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\ProcOpenError;
use MediaWiki\Session\SessionManager;
use MediaWiki\Shell\Shell;
-use Wikimedia\WrappedString;
use Wikimedia\AtEase\AtEase;
+use Wikimedia\WrappedString;
/**
* Load an extension
if ( isset( $ctx['forwarded_for'] ) ||
isset( $ctx['client_ip'] ) ||
isset( $ctx['from'] ) ) {
+ // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
$ctx['proxy'] = $_SERVER['REMOTE_ADDR'];
}
* including errors from limit.sh
* - profileMethod: By default this function will profile based on the calling
* method. Set this to a string for an alternative method to profile from
+ * @phan-param array{duplicateStderr?:bool,profileMethod?:string} $options
*
* @return string Collected stdout as a string
* @deprecated since 1.30 use class MediaWiki\Shell\Shell
* @param array $options Associative array of options:
* 'php': The path to the php executable
* 'wrapper': Path to a PHP wrapper to handle the maintenance script
+ * @phan-param array{php?:string,wrapper?:string} $options
* @return string
*/
function wfShellWikiCmd( $script, array $parameters = [], array $options = [] ) {
* * Any subsequent links on the same line are considered to be exceptions,
* i.e. articles where the image may occur inline.
*
+ * @deprecated since 1.34, use the BadFileLookup service directly instead
+ *
* @param string $name The image name to check
* @param Title|bool $contextTitle The page on which the image occurs, if known
* @param string|null $blacklist Wikitext of a file blacklist
* @return bool
*/
function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
- # Handle redirects; callers almost always hit wfFindFile() anyway,
- # so just use that method because it has a fast process cache.
- $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name ); // get the final name
- $name = $file ? $file->getTitle()->getDBkey() : $name;
-
- # Run the extension hook
- $bad = false;
- if ( !Hooks::run( 'BadImage', [ $name, &$bad ] ) ) {
- return (bool)$bad;
- }
-
- $cache = ObjectCache::getLocalServerInstance( 'hash' );
- $key = $cache->makeKey(
- 'bad-image-list', ( $blacklist === null ) ? 'default' : md5( $blacklist )
- );
- $badImages = $cache->get( $key );
-
- if ( $badImages === false ) { // cache miss
- if ( $blacklist === null ) {
- $blacklist = wfMessage( 'bad_image_list' )->inContentLanguage()->plain(); // site list
- }
- # Build the list now
- $badImages = [];
- $lines = explode( "\n", $blacklist );
- foreach ( $lines as $line ) {
- # List items only
- if ( substr( $line, 0, 1 ) !== '*' ) {
- continue;
- }
-
- # Find all links
- $m = [];
- if ( !preg_match_all( '/\[\[:?(.*?)\]\]/', $line, $m ) ) {
- continue;
- }
-
- $exceptions = [];
- $imageDBkey = false;
- foreach ( $m[1] as $i => $titleText ) {
- $title = Title::newFromText( $titleText );
- if ( !is_null( $title ) ) {
- if ( $i == 0 ) {
- $imageDBkey = $title->getDBkey();
- } else {
- $exceptions[$title->getPrefixedDBkey()] = true;
- }
- }
- }
-
- if ( $imageDBkey !== false ) {
- $badImages[$imageDBkey] = $exceptions;
- }
- }
- $cache->set( $key, $badImages, 60 );
- }
-
- $contextKey = $contextTitle ? $contextTitle->getPrefixedDBkey() : false;
- $bad = isset( $badImages[$name] ) && !isset( $badImages[$name][$contextKey] );
-
- return $bad;
+ $services = MediaWikiServices::getInstance();
+ if ( $blacklist !== null ) {
+ wfDeprecated( __METHOD__ . ' with $blacklist parameter', '1.34' );
+ return ( new BadFileLookup(
+ function () use ( $blacklist ) {
+ return $blacklist;
+ },
+ $services->getLocalServerObjectCache(),
+ $services->getRepoGroup(),
+ $services->getTitleParser()
+ ) )->isBadFile( $name, $contextTitle ?: null );
+ }
+ return $services->getBadFileLookup()->isBadFile( $name, $contextTitle ?: null );
}
/**