Page MenuHomePhabricator

ImportConstraintEntities.php should use $wgHTTPProxy when defined
Closed, ResolvedPublic

Description

I installed MediaWiki 1.33 + Wikibase in an organisation where Internet was available only through a HTTP proxy. Consequently the script ImportConstraintEntities.php was not able to download Wikidata constraints. This script should use $wgHTTPProxy when it is non-empty.

I added the following code to be able to download Wikidata constraints:

diff --git a/maintenance/ImportConstraintEntities.php b/maintenance/ImportConstraintEntities.php
index 8af9dec..da9314c 100644
--- a/maintenance/ImportConstraintEntities.php
+++ b/maintenance/ImportConstraintEntities.php
@@ -130,8 +130,16 @@ class ImportConstraintEntities extends Maintenance {
         * @return string local entity ID
         */
        private function importEntityFromWikidata( $wikidataEntityId ) {
+
+               $paramsContext = [
+                       'http' => [
+                               'proxy' => 'tcp://proxy.example.org:8080',
+                       ],
+               ];
+               $context = stream_context_create( $paramsContext );
+
                $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json";
-               $wikidataEntitiesJson = file_get_contents( $wikidataEntityUrl );
+               $wikidataEntitiesJson = file_get_contents( $wikidataEntityUrl, false, $context );
                return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson );
        }

Event Timeline

Change 576869 had a related patch set uploaded (by Seb35; owner: Seb35):
[mediawiki/extensions/WikibaseQualityConstraints@master] Use HttpRequestFactory in ImportConstraintEntities.php.

https://gerrit.wikimedia.org/r/576869

Change 576869 merged by jenkins-bot:
[mediawiki/extensions/WikibaseQualityConstraints@master] Use HttpRequestFactory in ImportConstraintEntities.php.

https://gerrit.wikimedia.org/r/576869