Signed-off-by: WaitSpring <me@waitspring.com>
这个提交包含在:
WaitSpring 2024-02-07 22:20:07 +08:00
当前提交 e4131be0de
找不到此签名对应的密钥
共有 20 个文件被更改,包括 1194 次插入1307 次删除

查看文件

@ -1,7 +1,7 @@
{ {
"require-dev": { "require-dev": {
"mediawiki/mediawiki-codesniffer": "39.0.0", "mediawiki/mediawiki-codesniffer": "41.0.0",
"mediawiki/mediawiki-phan-config": "0.12.0", "mediawiki/mediawiki-phan-config": "0.12.1",
"mediawiki/minus-x": "1.1.1", "mediawiki/minus-x": "1.1.1",
"php-parallel-lint/php-console-highlighter": "1.0.0", "php-parallel-lint/php-console-highlighter": "1.0.0",
"php-parallel-lint/php-parallel-lint": "1.3.2" "php-parallel-lint/php-parallel-lint": "1.3.2"

查看文件

@ -6,13 +6,18 @@
"license-name": "GPL-2.0-or-later", "license-name": "GPL-2.0-or-later",
"type": "other", "type": "other",
"requires": { "requires": {
"MediaWiki": ">= 1.38.0" "MediaWiki": ">= 1.41"
}, },
"Hooks": { "Hooks": {
"GetExtendedMetadata": "CommonsMetadata\\HookHandler::onGetExtendedMetadata", "GetExtendedMetadata": "main",
"ValidateExtendedMetadataCache": "CommonsMetadata\\HookHandler::onValidateExtendedMetadataCache", "ValidateExtendedMetadataCache": "main",
"ContentAlterParserOutput": "CommonsMetadata\\HookHandler::onContentAlterParserOutput", "ContentAlterParserOutput": "main",
"SkinAfterBottomScripts": "CommonsMetadata\\HookHandler::onSkinAfterBottomScripts" "SkinAfterBottomScripts": "main"
},
"HookHandlers": {
"main": {
"class": "CommonsMetadata\\HookHandler"
}
}, },
"MessagesDirs": { "MessagesDirs": {
"CommonsMetadata": [ "CommonsMetadata": [

查看文件

@ -2,8 +2,8 @@
"@metadata": { "@metadata": {
"authors": [ "authors": [
"Айбикә", "Айбикә",
"Рустам Нурыев", "З. ӘЙЛЕ",
"З. ӘЙЛЕ" "Рустам Нурыев"
] ]
}, },
"commonsmetadata-desc": "Викимилектәге ҡалыптар йыш ҡулланған, һүрәтләү биттәрендә һаҡланған мәғлүмәтте индереү өсөн \"extmetadata\" һүрәтләү үҙенсәлеген API-модулгә ебәрә", "commonsmetadata-desc": "Викимилектәге ҡалыптар йыш ҡулланған, һүрәтләү биттәрендә һаҡланған мәғлүмәтте индереү өсөн \"extmetadata\" һүрәтләү үҙенсәлеген API-модулгә ебәрә",

查看文件

@ -2,8 +2,8 @@
"@metadata": { "@metadata": {
"authors": [ "authors": [
"Aftabuzzaman", "Aftabuzzaman",
"আফতাবুজ্জামান", "Tahmid",
"Tahmid" "আফতাবুজ্জামান"
] ]
}, },
"commonsmetadata-desc": "ছবি বর্ণনা পাতায় সঞ্চিত তথ্য অন্তর্ভুক্ত করতে চিত্রের তথ্য এপিআই মডিউলের \"extmetadata\" বৈশিষ্ট্য প্রসারিত করে যা সাধারণভাবে উইকিমিডিয়া কমন্সে ব্যবহার করা টেমপ্লেটে ব্যবহার করা হয়", "commonsmetadata-desc": "ছবি বর্ণনা পাতায় সঞ্চিত তথ্য অন্তর্ভুক্ত করতে চিত্রের তথ্য এপিআই মডিউলের \"extmetadata\" বৈশিষ্ট্য প্রসারিত করে যা সাধারণভাবে উইকিমিডিয়া কমন্সে ব্যবহার করা টেমপ্লেটে ব্যবহার করা হয়",

查看文件

@ -1,7 +1,8 @@
{ {
"@metadata": { "@metadata": {
"authors": [ "authors": [
"Chase me ladies, I'm the Cavalry" "Chase me ladies, I'm the Cavalry",
"Piano1forte2"
] ]
}, },
"commonsmetadata-trackingcategory-no-license": "Files with no machine-readable licence", "commonsmetadata-trackingcategory-no-license": "Files with no machine-readable licence",

查看文件

@ -1,8 +1,8 @@
{ {
"@metadata": { "@metadata": {
"authors": [ "authors": [
"Akakiiri", "Baba Ayɛ'ɛra",
"Baba Ayɛ'ɛra" "Akakiiri"
] ]
}, },
"commonsmetadata-desc": "Ba malum vurege \"extimatadata\" foote lɔgerɔ yɛla yelesum n de API lɔkɔ tole nɛŋa la yelesum sebo n pa'alɛ foote la pɛgera n doose se'em dee zo'e zo'e puan ti a bɔna Wikimedia fɔɔra zi'an la", "commonsmetadata-desc": "Ba malum vurege \"extimatadata\" foote lɔgerɔ yɛla yelesum n de API lɔkɔ tole nɛŋa la yelesum sebo n pa'alɛ foote la pɛgera n doose se'em dee zo'e zo'e puan ti a bɔna Wikimedia fɔɔra zi'an la",

查看文件

@ -6,8 +6,8 @@
"Kwj2772", "Kwj2772",
"Namoroka", "Namoroka",
"Priviet", "Priviet",
"아라", "Ykhwong",
"Ykhwong" "아라"
] ]
}, },
"commonsmetadata-desc": "그림 정보 API 모듈의 \"extmetadata\" 속성을, 위키미디어 공용에서 공용으로 사용되는 틀을 사용하는 그림 설명 문서에 담긴 정보를 포함하도록 확장합니다", "commonsmetadata-desc": "그림 정보 API 모듈의 \"extmetadata\" 속성을, 위키미디어 공용에서 공용으로 사용되는 틀을 사용하는 그림 설명 문서에 담긴 정보를 포함하도록 확장합니다",

查看文件

@ -1,6 +1,7 @@
{ {
"@metadata": { "@metadata": {
"authors": [ "authors": [
"Msz2001",
"WTM", "WTM",
"Woytecr", "Woytecr",
"Msz2001" "Msz2001"

查看文件

@ -1,18 +0,0 @@
{
"@metadata": {
"authors": [
"Vlad5250"
]
},
"commonsmetadata-desc": "Proširuje osobinu za informiranje „extmetadata“ u API-modul sa informacijama što stoje na opisnima stranicama slika koje koriste šabloni zastupljeni na Ostavi",
"commonsmetadata-trackingcategory-no-license": "Datoteke bez mašinski čitljive licence",
"commonsmetadata-trackingcategory-no-license-desc": "Ova datoteka nema [{{MediaWiki:Commonsmetadata-doc-url}} mašinski čitljiv] licencni šablon.",
"commonsmetadata-trackingcategory-no-description": "Datoteke bez mašinski čitljivog opisa",
"commonsmetadata-trackingcategory-no-description-desc": "Ova datoteka nema [{{MediaWiki:Commonsmetadata-doc-url}} mašinski čitljiv] informativni šablon ili pak nije mu popunjeno polje opis.",
"commonsmetadata-trackingcategory-no-author": "Datoteke bez mašinski čitljivog autora",
"commonsmetadata-trackingcategory-no-author-desc": "Ova datoteka nema [{{MediaWiki:Commonsmetadata-doc-url}} mašinski čitljiv] informativni šablon ili pak nije mu popunjeno polje autor.",
"commonsmetadata-trackingcategory-no-source": "Datoteke bez mašinski čitljivog izvora",
"commonsmetadata-trackingcategory-no-source-desc": "Ova datoteka nema [{{MediaWiki:Commonsmetadata-doc-url}} mašinski čitljiv] informativni šablon ili pak nije mu popunjeno polje izvor.",
"commonsmetadata-trackingcategory-no-patent": "Datoteke bez mašinski čitljivog patenta",
"commonsmetadata-trackingcategory-no-patent-desc": "Ova datoteka nema [{{MediaWiki:Commonsmetadata-doc-url}} mašinski čitljiv] patentni šablon."
}

2321
package-lock.json 自动生成的

文件差异内容过多而无法显示 加载差异

查看文件

@ -5,11 +5,11 @@
"test": "grunt test" "test": "grunt test"
}, },
"devDependencies": { "devDependencies": {
"eslint-config-wikimedia": "0.22.1", "eslint-config-wikimedia": "0.25.0",
"grunt": "1.5.3", "grunt": "1.6.1",
"grunt-banana-checker": "0.10.0", "grunt-banana-checker": "0.11.0",
"grunt-eslint": "24.0.0", "grunt-eslint": "24.0.1",
"grunt-stylelint": "0.17.0", "grunt-stylelint": "0.18.0",
"stylelint-config-wikimedia": "0.13.0" "stylelint-config-wikimedia": "0.15.0"
} }
} }

查看文件

@ -4,10 +4,10 @@ namespace CommonsMetadata;
use File; use File;
use ForeignAPIFile; use ForeignAPIFile;
use InvalidArgumentException;
use Language; use Language;
use LocalFile; use LocalFile;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use MWException;
use ParserOutput; use ParserOutput;
use WikiFilePage; use WikiFilePage;
@ -286,8 +286,10 @@ class DataCollector {
$page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $file->getOriginalTitle() ); $page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $file->getOriginalTitle() );
if ( !$page instanceof WikiFilePage ) { if ( !$page instanceof WikiFilePage ) {
throw new MWException( 'Cannot instance WikiFilePage to get categories for ' . $file->getName() throw new InvalidArgumentException(
. ', got instance of ' . get_class( $page ) ); 'Cannot instance WikiFilePage to get categories for ' . $file->getName()
. ', got instance of ' . get_class( $page )
);
} }
$page->setFile( $file ); $page->setFile( $file );

查看文件

@ -23,16 +23,13 @@ class DomNavigator {
* @param string $html * @param string $html
*/ */
public function __construct( $html ) { public function __construct( $html ) {
// libxml mutilates UTF-8 chars unless they are encoded as entities
$html = mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' );
$oldLoaderState = false; $oldLoaderState = false;
if ( LIBXML_VERSION < 20900 ) { if ( LIBXML_VERSION < 20900 ) {
$oldLoaderState = libxml_disable_entity_loader( true ); $oldLoaderState = libxml_disable_entity_loader( true );
} }
$oldHandlerState = libxml_use_internal_errors( true ); $oldHandlerState = libxml_use_internal_errors( true );
$dom = new DOMDocument(); $dom = new DOMDocument();
$dom->loadHTML( $html ); $dom->loadHTML( '<!doctype html><html><head><meta charset="UTF-8"/></head><body>' . $html . '</body></html>' );
$this->domx = new DOMXPath( $dom ); $this->domx = new DOMXPath( $dom );
if ( LIBXML_VERSION < 20900 ) { if ( LIBXML_VERSION < 20900 ) {
libxml_disable_entity_loader( $oldLoaderState ); libxml_disable_entity_loader( $oldLoaderState );

查看文件

@ -10,15 +10,24 @@ use FormatMetadata;
use IContextSource; use IContextSource;
use Language; use Language;
use LocalRepo; use LocalRepo;
use MediaWiki\Content\Hook\ContentAlterParserOutputHook;
use MediaWiki\Hook\GetExtendedMetadataHook;
use MediaWiki\Hook\SkinAfterBottomScriptsHook;
use MediaWiki\Hook\ValidateExtendedMetadataCacheHook;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use MediaWiki\Title\Title;
use ParserOutput; use ParserOutput;
use Skin; use Skin;
use Title;
/** /**
* Hook handler * Hook handler
*/ */
class HookHandler { class HookHandler implements
GetExtendedMetadataHook,
ValidateExtendedMetadataCacheHook,
ContentAlterParserOutputHook,
SkinAfterBottomScriptsHook
{
/** /**
* Metadata version. When getting metadata of a remote file via the API, sometimes * Metadata version. When getting metadata of a remote file via the API, sometimes
* we get the data generated by a CommonsMetadata extension installed at the remote, * we get the data generated by a CommonsMetadata extension installed at the remote,
@ -36,10 +45,9 @@ class HookHandler {
* @param IContextSource $context Context. Used to select language * @param IContextSource $context Context. Used to select language
* @param bool $singleLang Get only target language, or all translations * @param bool $singleLang Get only target language, or all translations
* @param int &$maxCache How many seconds to cache the result * @param int &$maxCache How many seconds to cache the result
* @return bool This hook handler always returns true
*/ */
public static function onGetExtendedMetadata( public function onGetExtendedMetadata(
&$combinedMeta, File $file, IContextSource $context, $singleLang, &$maxCache &$combinedMeta, $file, $context, $singleLang, &$maxCache
) { ) {
global $wgCommonsMetadataForceRecalculate; global $wgCommonsMetadataForceRecalculate;
@ -50,7 +58,7 @@ class HookHandler {
) { ) {
// This is a file from a remote API repo, and CommonsMetadata is installed on // This is a file from a remote API repo, and CommonsMetadata is installed on
// the remote as well, and generates the same metadata format. We have nothing to do. // the remote as well, and generates the same metadata format. We have nothing to do.
return true; return;
} else { } else {
$combinedMeta['CommonsMetadataExtension'] = [ $combinedMeta['CommonsMetadataExtension'] = [
'value' => self::VERSION, 'value' => self::VERSION,
@ -62,7 +70,7 @@ class HookHandler {
$templateParser = new TemplateParser(); $templateParser = new TemplateParser();
$templateParser->setMultiLanguage( !$singleLang ); $templateParser->setMultiLanguage( !$singleLang );
$fallbacks = Language::getFallbacksFor( $lang->getCode() ); $fallbacks = MediaWikiServices::getInstance()->getLanguageFallback()->getAll( $lang->getCode() );
array_unshift( $fallbacks, $lang->getCode() ); array_unshift( $fallbacks, $lang->getCode() );
$templateParser->setPriorityLanguages( $fallbacks ); $templateParser->setPriorityLanguages( $fallbacks );
@ -79,8 +87,6 @@ class HookHandler {
// If that's the case, just cache blindly for a shorter period. // If that's the case, just cache blindly for a shorter period.
$maxCache = 60 * 60 * 12; $maxCache = 60 * 60 * 12;
} }
return true;
} }
/** /**
@ -90,7 +96,7 @@ class HookHandler {
* @param File $file The file metadata is for * @param File $file The file metadata is for
* @return bool Is metadata still valid * @return bool Is metadata still valid
*/ */
public static function onValidateExtendedMetadataCache( $timestamp, File $file ) { public function onValidateExtendedMetadataCache( $timestamp, $file ) {
return // use cached value if... return // use cached value if...
// we don't know when the file was last updated // we don't know when the file was last updated
!$file->getDescriptionTouched() !$file->getDescriptionTouched()
@ -105,10 +111,9 @@ class HookHandler {
* @param Content $content * @param Content $content
* @param Title $title * @param Title $title
* @param ParserOutput $parserOutput * @param ParserOutput $parserOutput
* @return bool this hook handler always returns true.
*/ */
public static function onContentAlterParserOutput( public function onContentAlterParserOutput(
Content $content, Title $title, ParserOutput $parserOutput $content, $title, $parserOutput
) { ) {
global $wgCommonsMetadataSetTrackingCategories; global $wgCommonsMetadataSetTrackingCategories;
@ -118,7 +123,7 @@ class HookHandler {
|| !$parserOutput->hasText() || !$parserOutput->hasText()
|| $content->getModel() !== CONTENT_MODEL_WIKITEXT || $content->getModel() !== CONTENT_MODEL_WIKITEXT
) { ) {
return true; return;
} }
/* /*
@ -137,13 +142,13 @@ class HookHandler {
$trackingCategories = $services->getTrackingCategories(); $trackingCategories = $services->getTrackingCategories();
$repo = $services->getRepoGroup()->getLocalRepo(); $repo = $services->getRepoGroup()->getLocalRepo();
if ( $title->isRedirect() ) { if ( $title->isRedirect() ) {
return true; return;
} }
$file = $repo->findFile( $title, [ 'ignoreRedirect' => true ] ); $file = $repo->findFile( $title, [ 'ignoreRedirect' => true ] );
if ( $file === false ) { if ( $file === false ) {
$file = $repo->findFile( $title, [ 'ignoreRedirect' => true, 'latest' => true ] ); $file = $repo->findFile( $title, [ 'ignoreRedirect' => true, 'latest' => true ] );
if ( $file === false ) { if ( $file === false ) {
return true; return;
} }
} }
@ -158,8 +163,6 @@ class HookHandler {
$title $title
); );
} }
return true;
} }
/** /**
@ -170,7 +173,7 @@ class HookHandler {
private static function getDataCollector( Language $lang, $singleLang ) { private static function getDataCollector( Language $lang, $singleLang ) {
$templateParser = new TemplateParser(); $templateParser = new TemplateParser();
$templateParser->setMultiLanguage( !$singleLang ); $templateParser->setMultiLanguage( !$singleLang );
$fallbacks = Language::getFallbacksFor( $lang->getCode() ); $fallbacks = MediaWikiServices::getInstance()->getLanguageFallback()->getAll( $lang->getCode() );
array_unshift( $fallbacks, $lang->getCode() ); array_unshift( $fallbacks, $lang->getCode() );
$templateParser->setPriorityLanguages( $fallbacks ); $templateParser->setPriorityLanguages( $fallbacks );
@ -191,10 +194,8 @@ class HookHandler {
* *
* @param Skin $skin * @param Skin $skin
* @param string &$html * @param string &$html
*
* @return bool Always true.
*/ */
public static function onSkinAfterBottomScripts( Skin $skin, &$html ) { public function onSkinAfterBottomScripts( $skin, &$html ) {
$title = $skin->getOutput()->getTitle(); $title = $skin->getOutput()->getTitle();
$isFilePage = $title->inNamespace( NS_FILE ); $isFilePage = $title->inNamespace( NS_FILE );
@ -203,7 +204,7 @@ class HookHandler {
!$title->exists() || !$title->exists() ||
!$isFilePage !$isFilePage
) { ) {
return true; return;
} }
$localRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo(); $localRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
@ -222,14 +223,11 @@ class HookHandler {
$handler = new SkinAfterBottomScriptsHandler( $format, $publicDomainPageUrl ); $handler = new SkinAfterBottomScriptsHandler( $format, $publicDomainPageUrl );
$hooksObject = new self(); $html .= $this->doSkinAfterBottomScripts(
$html .= $hooksObject->doSkinAfterBottomScripts(
$localRepo, $localRepo,
$handler, $handler,
$title $title
); );
return true;
} }
/** /**

查看文件

@ -5,7 +5,7 @@ namespace CommonsMetadata\Hooks;
use File; use File;
use FormatMetadata; use FormatMetadata;
use Html; use Html;
use Title; use MediaWiki\Title\Title;
/** /**
* @license GPL-2.0-or-later * @license GPL-2.0-or-later

查看文件

@ -4,9 +4,9 @@ namespace CommonsMetadata;
use File; use File;
use Language; use Language;
use MediaWiki\Title\Title;
use ParserOutput; use ParserOutput;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Title;
/** /**
* @group Database * @group Database

查看文件

@ -5,8 +5,8 @@ namespace CommonsMetadata;
use CommonsMetadata\Hooks\SkinAfterBottomScriptsHandler; use CommonsMetadata\Hooks\SkinAfterBottomScriptsHandler;
use File; use File;
use LocalRepo; use LocalRepo;
use MediaWiki\Title\Title;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Title;
require_once __DIR__ . "/ParserTestHelper.php"; require_once __DIR__ . "/ParserTestHelper.php";
@ -33,7 +33,7 @@ class HookHandlerTest extends TestCase {
$file = $this->parserTestHelper->getLocalFile( $description, $categories ); $file = $this->parserTestHelper->getLocalFile( $description, $categories );
$context = $this->parserTestHelper->getContext( 'en' ); $context = $this->parserTestHelper->getContext( 'en' );
HookHandler::onGetExtendedMetadata( $metadata, $file, $context, true, $maxCache ); ( new HookHandler )->onGetExtendedMetadata( $metadata, $file, $context, true, $maxCache );
// cache interval was not changed // cache interval was not changed
$this->assertEquals( 3600, $maxCache ); $this->assertEquals( 3600, $maxCache );
@ -53,7 +53,7 @@ class HookHandlerTest extends TestCase {
$file = $this->parserTestHelper->getForeignApiFile( $description ); $file = $this->parserTestHelper->getForeignApiFile( $description );
$context = $this->parserTestHelper->getContext( 'en' ); $context = $this->parserTestHelper->getContext( 'en' );
HookHandler::onGetExtendedMetadata( $metadata, $file, $context, true, $maxCache ); ( new HookHandler )->onGetExtendedMetadata( $metadata, $file, $context, true, $maxCache );
// cache interval was not changed // cache interval was not changed
$this->assertEquals( 3600, $maxCache ); $this->assertEquals( 3600, $maxCache );
@ -74,7 +74,7 @@ class HookHandlerTest extends TestCase {
$file = $this->parserTestHelper->getForeignDbFile( $description, $categories ); $file = $this->parserTestHelper->getForeignDbFile( $description, $categories );
$context = $this->parserTestHelper->getContext( 'en' ); $context = $this->parserTestHelper->getContext( 'en' );
HookHandler::onGetExtendedMetadata( $metadata, $file, $context, true, $maxCache ); ( new HookHandler )->onGetExtendedMetadata( $metadata, $file, $context, true, $maxCache );
// cache interval is 12 hours for all remote files // cache interval is 12 hours for all remote files
$this->assertEquals( 3600 * 12, $maxCache ); $this->assertEquals( 3600 * 12, $maxCache );
@ -98,7 +98,7 @@ class HookHandlerTest extends TestCase {
$file = $this->parserTestHelper->getLocalFile( $description, [] ); $file = $this->parserTestHelper->getLocalFile( $description, [] );
$context = $this->parserTestHelper->getContext( 'en' ); $context = $this->parserTestHelper->getContext( 'en' );
HookHandler::onGetExtendedMetadata( $actualMetadata, $file, $context, true, $maxCache ); ( new HookHandler )->onGetExtendedMetadata( $actualMetadata, $file, $context, true, $maxCache );
$expectedMetadata = $this->parserTestHelper->getMetadata( $testName ); $expectedMetadata = $this->parserTestHelper->getMetadata( $testName );
foreach ( $expectedMetadata as $key => $val ) { foreach ( $expectedMetadata as $key => $val ) {
@ -108,7 +108,7 @@ class HookHandlerTest extends TestCase {
} }
} }
public function provideDescriptionData() { public static function provideDescriptionData() {
return [ return [
[ 'noinfo' ], [ 'noinfo' ],
[ 'simple' ], [ 'simple' ],

查看文件

@ -4,7 +4,7 @@ namespace CommonsMetadata\Hooks;
use File; use File;
use FormatMetadata; use FormatMetadata;
use Title; use MediaWiki\Title\Title;
/** /**
* @covers \CommonsMetadata\Hooks\SkinAfterBottomScriptsHandler * @covers \CommonsMetadata\Hooks\SkinAfterBottomScriptsHandler
@ -35,7 +35,7 @@ class SkinAfterBottomScriptsHandlerTest extends \MediaWikiIntegrationTestCase {
$this->assertEquals( $expectedSchema, $actualSchema ); $this->assertEquals( $expectedSchema, $actualSchema );
} }
public function provideImageWithLicenseData() { public static function provideImageWithLicenseData() {
$metadata = [ $metadata = [
'LicenseUrl' => [ 'LicenseUrl' => [
'value' => 'https://creativecommons.org/licenses/by-sa/4.0', 'value' => 'https://creativecommons.org/licenses/by-sa/4.0',
@ -70,7 +70,8 @@ class SkinAfterBottomScriptsHandlerTest extends \MediaWikiIntegrationTestCase {
/** /**
* @dataProvider provideInvalidFiles * @dataProvider provideInvalidFiles
*/ */
public function testGetSchemaElementWithInvalidFiles( $file ) { public function testGetSchemaElementWithInvalidFiles( $mockExists, $mockMediaType ) {
$file = $mockExists === null ? null : $this->getMockFile( $mockExists, $mockMediaType );
// We'll set up the mock format's fetchExtendedMetadata method to return // We'll set up the mock format's fetchExtendedMetadata method to return
// an empty array so we can test the scenario of a valid file that gets // an empty array so we can test the scenario of a valid file that gets
// back no extended metadata. // back no extended metadata.
@ -83,16 +84,12 @@ class SkinAfterBottomScriptsHandlerTest extends \MediaWikiIntegrationTestCase {
$this->assertSame( '', $result ); $this->assertSame( '', $result );
} }
public function provideInvalidFiles() { public static function provideInvalidFiles() {
$nonexistentFile = $this->getMockFile( false, null );
$wrongMediaTypeFile = $this->getMockFile( true, MEDIATYPE_AUDIO );
$validFile = $this->getMockFile( true, MEDIATYPE_BITMAP );
return [ return [
'Null value' => [ null ], 'Null value' => [ null, null ],
'Nonexistent file' => [ $nonexistentFile ], 'Nonexistent file' => [ false, null ],
'Wrong media type' => [ $wrongMediaTypeFile ] , 'Wrong media type' => [ true, MEDIATYPE_AUDIO ] ,
'No extended metadata' => [ $validFile ] 'No extended metadata' => [ true, MEDIATYPE_BITMAP ]
]; ];
} }
@ -113,7 +110,7 @@ class SkinAfterBottomScriptsHandlerTest extends \MediaWikiIntegrationTestCase {
$this->assertEquals( $expected, $actual ); $this->assertEquals( $expected, $actual );
} }
public function providePublicDomainImageData() { public static function providePublicDomainImageData() {
$metadata = [ $metadata = [
'License' => [ 'License' => [
'value' => 'pd', 'value' => 'pd',
@ -140,7 +137,7 @@ class SkinAfterBottomScriptsHandlerTest extends \MediaWikiIntegrationTestCase {
]; ];
} }
public function provideImageWithMissingUploadDateData() { public static function provideImageWithMissingUploadDateData() {
$metadata = [ $metadata = [
'LicenseUrl' => [ 'LicenseUrl' => [
'value' => 'https://creativecommons.org/licenses/by-sa/4.0', 'value' => 'https://creativecommons.org/licenses/by-sa/4.0',

查看文件

@ -123,7 +123,7 @@ class LicenseParserTest extends \MediaWikiIntegrationTestCase {
$this->assertLicenseHasGreaterPriority( $greaterLicenseData, $smallerLicenseData ); $this->assertLicenseHasGreaterPriority( $greaterLicenseData, $smallerLicenseData );
} }
public function provideGetLicensePriorityData() { public static function provideGetLicensePriorityData() {
return [ return [
[ // PD wins over CC [ // PD wins over CC
[ // this should have higher priority... [ // this should have higher priority...

查看文件

@ -6,6 +6,7 @@ use ForeignAPIFile;
use ForeignDBFile; use ForeignDBFile;
use IContextSource; use IContextSource;
use LocalFile; use LocalFile;
use MediaWiki\MediaWikiServices;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ParserTestHelper { class ParserTestHelper {
@ -189,7 +190,7 @@ class ParserTestHelper {
* @return IContextSource * @return IContextSource
*/ */
public function getContext( $languageCode ) { public function getContext( $languageCode ) {
$language = \Language::factory( $languageCode ); $language = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $languageCode );
$context = $this->testCase->getMockBuilder( IContextSource::class ) $context = $this->testCase->getMockBuilder( IContextSource::class )
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();