X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fsite%2FMediaWikiPageNameNormalizer.php;h=1a079b4295cf0009844b801ce505d5b7825cf6ab;hb=f6c8b955bd6103e3084ec609902e68599cf11f23;hp=f358bd4e69c634b123c2bab51314dda3dd3c6da3;hpb=47a052b797ef8ef650aa799261c984f6abc295d8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/site/MediaWikiPageNameNormalizer.php b/includes/site/MediaWikiPageNameNormalizer.php index f358bd4e69..1a079b4295 100644 --- a/includes/site/MediaWikiPageNameNormalizer.php +++ b/includes/site/MediaWikiPageNameNormalizer.php @@ -34,6 +34,22 @@ use UtfNormal\Validator; */ class MediaWikiPageNameNormalizer { + /** + * @var Http + */ + private $http; + + /** + * @param Http|null $http + */ + public function __construct( Http $http = null ) { + if ( !$http ) { + $http = new Http(); + } + + $this->http = $http; + } + /** * Returns the normalized form of the given page title, using the * normalization rules of the given site. If the given title is a redirect, @@ -67,7 +83,7 @@ class MediaWikiPageNameNormalizer { $pageName = Validator::cleanUp( $pageName ); // Build the args for the specific call - $args = array( + $args = [ 'action' => 'query', 'prop' => 'info', 'redirects' => true, @@ -79,13 +95,13 @@ class MediaWikiPageNameNormalizer { // but that maxage can avoid the extreme delay. On the other hand // maxage could be nice to use anyhow as it stops unnecessary requests. // Also consider smaxage if maxage is used. - ); + ]; $url = wfAppendQuery( $apiUrl, $args ); // Go on call the external site // @todo we need a good way to specify a timeout here. - $ret = Http::get( $url, array(), __METHOD__ ); + $ret = $this->http->get( $url, [], __METHOD__ ); if ( $ret === false ) { wfDebugLog( "MediaWikiSite", "call to external site failed: $url" ); @@ -146,12 +162,12 @@ class MediaWikiPageNameNormalizer { return false; } // Loop over the tree different named structures, that otherwise are similar - $structs = array( + $structs = [ 'normalized' => 'from', 'converted' => 'from', 'redirects' => 'from', 'pages' => 'title' - ); + ]; foreach ( $structs as $listId => $fieldId ) { // Check if the substructure exist at all. if ( !isset( $externalData['query'][$listId] ) ) {