15 private $listCallback;
35 callable $listCallback,
41 $this->listCallback = $listCallback;
42 $this->cache = $cache;
43 $this->repoGroup = $repoGroup;
44 $this->titleParser = $titleParser;
45 $this->hookRunner =
new HookRunner( $hookContainer );
64 $file = $this->repoGroup->findFile( $name );
68 $name = $file->getTitle()->getDBkey();
73 if ( !$this->hookRunner->onBadImage( $name, $bad ) ) {
77 if ( $this->badFiles ===
null ) {
78 $list = ( $this->listCallback )();
79 $key = $this->cache->makeKey(
'bad-image-list', sha1( $list ) );
80 $this->badFiles = $this->cache->getWithSetCallback(
83 function () use ( $list ) {
84 return $this->buildBadFilesList( $list );
89 return isset( $this->badFiles[$name] ) && ( !$contextTitle ||
90 !isset( $this->badFiles[$name][$contextTitle->getNamespace()][$contextTitle->getDBkey()] ) );
97 private function buildBadFilesList(
string $list ): array {
99 $lines = explode(
"\n", $list );
100 foreach (
$lines as $line ) {
102 if ( substr( $line, 0, 1 ) !==
'*' ) {
109 if ( !preg_match_all(
'/\[\[:?(.*?)\]\]/', $line, $m ) ) {
115 foreach ( $m[1] as $i => $titleText ) {
117 $title = $this->titleParser->parseTitle( $titleText );
118 }
catch ( MalformedTitleException $e ) {
122 $fileDBkey = $title->getDBkey();
124 $exceptions[$title->getNamespace()][$title->getDBkey()] =
true;
128 if ( $fileDBkey !==
null ) {
129 $ret[$fileDBkey] = $exceptions;
137class_alias( BadFileLookup::class,
'MediaWiki\\BadFileLookup' );
__construct(callable $listCallback, BagOStuff $cache, RepoGroup $repoGroup, TitleParser $titleParser, HookContainer $hookContainer)
Do not call directly.
isBadFile( $name, ?LinkTarget $contextTitle=null)
Determine if a file exists on the 'bad image list'.
Prioritized list of file repositories.
if(!file_exists( $CREDITS)) $lines