37 callable $blacklistCallback,
42 $this->blacklistCallback = $blacklistCallback;
44 $this->repoGroup = $repoGroup;
45 $this->titleParser = $titleParser;
64 $file = $this->repoGroup->findFile( $name );
68 $name =
$file->getTitle()->getDBkey();
73 if ( !
Hooks::run(
'BadImage', [ $name, &$bad ] ) ) {
77 if ( $this->badFiles ===
null ) {
79 $blacklist = ( $this->blacklistCallback )();
80 $key = $this->cache->makeKey(
'bad-image-list', sha1( $blacklist ) );
81 $this->badFiles = $this->cache->get( $key ) ?:
null;
84 if ( $this->badFiles ===
null ) {
87 $lines = explode(
"\n", $blacklist );
90 if ( substr(
$line, 0, 1 ) !==
'*' ) {
97 if ( !preg_match_all(
'/\[\[:?(.*?)\]\]/',
$line, $m ) ) {
103 foreach ( $m[1] as $i => $titleText ) {
105 $title = $this->titleParser->parseTitle( $titleText );
110 $fileDBkey =
$title->getDBkey();
112 $exceptions[
$title->getNamespace()][
$title->getDBkey()] =
true;
116 if ( $fileDBkey !==
null ) {
117 $this->badFiles[$fileDBkey] = $exceptions;
120 $this->cache->set( $key, $this->badFiles, 24 * 60 * 60 );
123 return isset( $this->badFiles[$name] ) && ( !$contextTitle ||
124 !isset( $this->badFiles[$name][$contextTitle->getNamespace()]
125 [$contextTitle->getDBkey()] ) );