r55733 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55732‎ | r55733 | r55734 >
Date:21:18, 1 September 2009
Author:yaron
Status:deferred
Tags:
Comment:
Version 0.9 - added URL "whitelist" for #get_external_data
Modified paths:
  • /trunk/extensions/ExternalData/ED_ParserFunctions.php (modified) (history)
  • /trunk/extensions/ExternalData/ExternalData.php (modified) (history)
  • /trunk/extensions/ExternalData/README (modified) (history)

Diff [purge]

Index: trunk/extensions/ExternalData/ExternalData.php
@@ -12,7 +12,7 @@
1313 $wgExtensionCredits['parserhook'][]= array(
1414 'path' => __FILE__,
1515 'name' => 'External Data',
16 - 'version' => '0.8.1',
 16+ 'version' => '0.9',
1717 'author' => array( 'Yaron Koren', 'Michael Dale', 'David Macdonald' ),
1818 'url' => 'http://www.mediawiki.org/wiki/Extension:External_Data',
1919 'description' => 'Allows for retrieving data in CSV, JSON and XML formats from both external URLs and local wiki pages',
Index: trunk/extensions/ExternalData/ED_ParserFunctions.php
@@ -27,8 +27,32 @@
2828 array_shift( $params ); // we already know the $parser ...
2929 $url = array_shift( $params );
3030 $url = str_replace( ' ', '%20', $url ); // do some minor URL-encoding
 31+ // check whether this URL is allowed - code based on
 32+ // Parser::maybeMakeExternalImage()
 33+ global $edgAllowExternalDataFrom;
 34+ $data_from = $edgAllowExternalDataFrom;
 35+ $text = false;
 36+ if ( empty($data_from) ) {
 37+ $url_match = true;
 38+ } elseif ( is_array( $data_from ) ) {
 39+ $url_match = false;
 40+ foreach( $data_from as $match ) {
 41+ if( strpos( $url, $match ) === 0 ) {
 42+ $url_match = true;
 43+ break;
 44+ }
 45+ }
 46+ } else {
 47+ $url_match = (strpos( $url, $data_from ) === 0);
 48+ }
 49+ if ( ! $url_match )
 50+ return;
3151
 52+ // now, get the contents of the URL - exit if there's nothing
 53+ // there
3254 $url_contents = EDUtils::fetchURL( $url );
 55+ if ( empty( $url_contents ) )
 56+ return;
3357
3458 $format = strtolower( array_shift( $params ) ); // make case-insensitive
3559 $external_values = array();
Index: trunk/extensions/ExternalData/README
@@ -1,6 +1,6 @@
22 External Data extension
33
4 - Version 0.8.1
 4+ Version 0.9
55 Yaron Koren, Michael Dale and David Macdonald
66
77 This is free software licensed under the GNU General Public License. Please
@@ -66,6 +66,13 @@
6767
6868 $edgStringReplacements['MY_API_KEY'] = 'abcd1324';
6969
 70+You can create a "whitelist" to allow retrieval of data only from trusted
 71+sites, in the manner of MediaWiki's $wgAllowExternalImagesFrom - if you
 72+are hiding API keys, it is very much recommended to create such a
 73+whitelist, to prevent users from being able to discover theire values:
 74+
 75+ $edgAllowExternalDataFrom = array('http://example.com/api');
 76+
7077 Finally, to use the database or LDAP retrieval capabilities, you need to
7178 set connection settings as well - see the online documentation for more
7279 information.

Status & tagging log