BadFile keeps a "bad file list", not a "blacklist"
Bug: T254646 Change-Id: I23c76f42d451b8d22f178efd6a3edbc822617831
This commit is contained in:
parent
9a9872e221
commit
a2d1bf79c3
1 changed files with 10 additions and 10 deletions
|
|
@ -11,8 +11,8 @@ use RepoGroup;
|
||||||
use TitleParser;
|
use TitleParser;
|
||||||
|
|
||||||
class BadFileLookup {
|
class BadFileLookup {
|
||||||
/** @var callable Returns contents of blacklist (see comment for isBadFile()) */
|
/** @var callable Returns contents of bad file list (see comment for isBadFile()) */
|
||||||
private $blacklistCallback;
|
private $listCallback;
|
||||||
|
|
||||||
/** @var BagOStuff Cache of parsed bad image list */
|
/** @var BagOStuff Cache of parsed bad image list */
|
||||||
private $cache;
|
private $cache;
|
||||||
|
|
@ -23,7 +23,7 @@ class BadFileLookup {
|
||||||
/** @var TitleParser */
|
/** @var TitleParser */
|
||||||
private $titleParser;
|
private $titleParser;
|
||||||
|
|
||||||
/** @var array|null Parsed blacklist */
|
/** @var array|null Parsed bad file list */
|
||||||
private $badFiles;
|
private $badFiles;
|
||||||
|
|
||||||
/** @var HookRunner */
|
/** @var HookRunner */
|
||||||
|
|
@ -32,20 +32,20 @@ class BadFileLookup {
|
||||||
/**
|
/**
|
||||||
* Do not call directly. Use MediaWikiServices.
|
* Do not call directly. Use MediaWikiServices.
|
||||||
*
|
*
|
||||||
* @param callable $blacklistCallback Callback that returns wikitext of a file blacklist
|
* @param callable $listCallback Callback that returns wikitext of a bad file list
|
||||||
* @param BagOStuff $cache For caching parsed versions of the blacklist
|
* @param BagOStuff $cache For caching parsed versions of the bad file list
|
||||||
* @param RepoGroup $repoGroup
|
* @param RepoGroup $repoGroup
|
||||||
* @param TitleParser $titleParser
|
* @param TitleParser $titleParser
|
||||||
* @param HookContainer $hookContainer
|
* @param HookContainer $hookContainer
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
callable $blacklistCallback,
|
callable $listCallback,
|
||||||
BagOStuff $cache,
|
BagOStuff $cache,
|
||||||
RepoGroup $repoGroup,
|
RepoGroup $repoGroup,
|
||||||
TitleParser $titleParser,
|
TitleParser $titleParser,
|
||||||
HookContainer $hookContainer
|
HookContainer $hookContainer
|
||||||
) {
|
) {
|
||||||
$this->blacklistCallback = $blacklistCallback;
|
$this->listCallback = $listCallback;
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
$this->repoGroup = $repoGroup;
|
$this->repoGroup = $repoGroup;
|
||||||
$this->titleParser = $titleParser;
|
$this->titleParser = $titleParser;
|
||||||
|
|
@ -83,15 +83,15 @@ class BadFileLookup {
|
||||||
|
|
||||||
if ( $this->badFiles === null ) {
|
if ( $this->badFiles === null ) {
|
||||||
// Not used before in this request, try the cache
|
// Not used before in this request, try the cache
|
||||||
$blacklist = ( $this->blacklistCallback )();
|
$list = ( $this->listCallback )();
|
||||||
$key = $this->cache->makeKey( 'bad-image-list', sha1( $blacklist ) );
|
$key = $this->cache->makeKey( 'bad-image-list', sha1( $list ) );
|
||||||
$this->badFiles = $this->cache->get( $key ) ?: null;
|
$this->badFiles = $this->cache->get( $key ) ?: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->badFiles === null ) {
|
if ( $this->badFiles === null ) {
|
||||||
// Cache miss, build the list now
|
// Cache miss, build the list now
|
||||||
$this->badFiles = [];
|
$this->badFiles = [];
|
||||||
$lines = explode( "\n", $blacklist );
|
$lines = explode( "\n", $list );
|
||||||
foreach ( $lines as $line ) {
|
foreach ( $lines as $line ) {
|
||||||
// List items only
|
// List items only
|
||||||
if ( substr( $line, 0, 1 ) !== '*' ) {
|
if ( substr( $line, 0, 1 ) !== '*' ) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue