/** * @param string $fileName * * @return string|null */ private function doLookup($fileName) { $actualPageName = $this->mediaWikiPageNameNormalizer->normalizePageName('File:' . $fileName, 'https://commons.wikimedia.org/w/api.php'); if ($actualPageName === false) { return null; } else { return str_replace('File:', '', $actualPageName); } }
/** * @dataProvider normalizePageTitleProvider */ public function testNormalizePageTitle($expected, $pageName) { $normalizer = new MediaWikiPageNameNormalizer(); $this->assertSame($expected, $normalizer->normalizePageName($pageName, 'https://www.wikidata.org/w/api.php')); }
/** * @dataProvider normalizePageTitleProvider */ public function testNormalizePageTitle($expected, $pageName, $getResponse) { MediaWikiPageNameNormalizerTestMockHttp::$response = $getResponse; $normalizer = new MediaWikiPageNameNormalizer(new MediaWikiPageNameNormalizerTestMockHttp()); $this->assertSame($expected, $normalizer->normalizePageName($pageName, 'https://www.wikidata.org/w/api.php')); }
/** * Returns the normalized form of the given page title, using the * normalization rules of the given site. If the given title is a redirect, * the redirect weill be resolved and the redirect target is returned. * * @note This actually makes an API request to the remote site, so beware * that this function is slow and depends on an external service. * * @note If MW_PHPUNIT_TEST is defined, the call to the external site is * skipped, and the title is normalized using the local normalization * rules as implemented by the Title class. * * @see Site::normalizePageName * * @since 1.21 * * @param string $pageName * * @return string * @throws MWException */ public function normalizePageName($pageName) { if (defined('MW_PHPUNIT_TEST')) { // If the code is under test, don't call out to other sites, just // normalize locally. // Note: this may cause results to be inconsistent with the actual // normalization used by the respective remote site! $t = Title::newFromText($pageName); return $t->getPrefixedText(); } else { static $mediaWikiPageNameNormalizer = null; if ($mediaWikiPageNameNormalizer === null) { $mediaWikiPageNameNormalizer = new MediaWikiPageNameNormalizer(); } return $mediaWikiPageNameNormalizer->normalizePageName($pageName, $this->getFileUrl('api.php')); } }