Jeroen De Dauw has submitted this change and it was merged.
Change subject: (bug 54103) allow ftp links
......................................................................
(bug 54103) allow ftp links
added support for ftp links
added tests
added documentation
Change-Id: I898e2a8330923f5f32809c9485a83d71546c1c65
---
M docs/options.wiki
M lib/config/WikibaseLib.default.php
M lib/includes/Validators/UrlSchemeValidators.php
M lib/tests/phpunit/Validators/UrlSchemeValidatorsTest.php
M lib/tests/phpunit/WikibaseDataTypeBuildersTest.php
5 files changed, 24 insertions(+), 6 deletions(-)
Approvals:
Jeroen De Dauw: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/options.wiki b/docs/options.wiki
index 41a658f..77eeb85 100644
--- a/docs/options.wiki
+++ b/docs/options.wiki
@@ -18,7 +18,7 @@
:* NOTE: The default may change in order to use the repo's database name
automatically.
;sharedCacheDuration: The default duration of entries in the shared object
cache, in seconds. Default is 3600 seconds = 1 hour.
;sharedCacheType: The type of cache to use for the shared object cache.
Defaults to $wgMainCacheType. Use CACHE_XXX constants.
-;urlSchemes: Which URL schemes should be allowed in URL data values. The
default is array( 'http', 'https' ). Schemes (protocols) added here will only
have any effect if validation is supported for that protocol; that is, adding
'mailto' will work, while adding 'gopher' will do nothing.
+;urlSchemes: Which URL schemes should be allowed in URL data values. The
default is array( 'http', 'https' ). Other supported schemes are 'ftp' and
'mailto'. Schemes (protocols) added here will only have any effect if
validation is supported for that protocol; that is, adding 'mailto' will work,
while adding 'gopher' will do nothing.
:* NOTE: This setting is only really meaningful for the repository, it's
shared with the client extension for technical reasons.
;entityPrefixes: ID prefixes to use for the different entity types, as an
associative array mapping prefixes to entity type constants. Default:
<poem>
diff --git a/lib/config/WikibaseLib.default.php
b/lib/config/WikibaseLib.default.php
index 7b63972..f53d7ab 100644
--- a/lib/config/WikibaseLib.default.php
+++ b/lib/config/WikibaseLib.default.php
@@ -121,7 +121,7 @@
),
// URL schemes allowed for values of the URL type.
- // Supported types include 'http', 'https', and 'mailto'.
+ // Supported types include 'http', 'https', 'ftp', and 'mailto'.
'urlSchemes' => array( 'http', 'https' ),
);
diff --git a/lib/includes/Validators/UrlSchemeValidators.php
b/lib/includes/Validators/UrlSchemeValidators.php
index 4b5a808..5d51c2f 100644
--- a/lib/includes/Validators/UrlSchemeValidators.php
+++ b/lib/includes/Validators/UrlSchemeValidators.php
@@ -76,6 +76,15 @@
}
/**
+ * Returns a ValueValidator that will match URLs using the FTP scheme.
+ *
+ * @return RegexValidator
+ */
+ public function ftp() {
+ return $this->httpish( 'ftp' );
+ }
+
+ /**
* Returns a ValueValidator that will match URLS using the mailto
scheme.
*
* @return RegexValidator
diff --git a/lib/tests/phpunit/Validators/UrlSchemeValidatorsTest.php
b/lib/tests/phpunit/Validators/UrlSchemeValidatorsTest.php
index d1b83c9..1938855 100644
--- a/lib/tests/phpunit/Validators/UrlSchemeValidatorsTest.php
+++ b/lib/tests/phpunit/Validators/UrlSchemeValidatorsTest.php
@@ -51,6 +51,8 @@
array( 'http',
'http://foo:[email protected]/stuff/thingy.php?foo=bar#part' ),
array( 'https', 'https://acme.com' ),
array( 'https',
'https://foo:[email protected]/stuff/thingy.php?foo=bar#part' ),
+ array( 'ftp', 'ftp://acme.com' ),
+ array( 'ftp',
'ftp://foo:[email protected]/stuff/thingy.php?foo=bar#part' ),
array( 'mailto', 'mailto:foo@bar' ),
array( 'mailto',
'mailto:[email protected]?Subject=test' ),
array( 'any', 'http://acme.com' ),
@@ -73,6 +75,11 @@
array( 'https', 'https://' ),
array( 'https', 'https://acme.com/foo' . "\n" . 'bar' ),
array( 'https', '*https://acme.com/foo' ),
+ array( 'ftp', 'yadda' ),
+ array( 'ftp', 'ftp:' ),
+ array( 'ftp', 'ftp://' ),
+ array( 'ftp', 'ftp://acme.com/foo' . "\n" . 'bar' ),
+ array( 'ftp', '*ftp://acme.com/foo' ),
array( 'mailto', 'yadda' ),
array( 'mailto', 'mailto:stuff' ),
array( 'mailto', 'mailto:james@thingy' . "\n" . '.com'
),
@@ -104,6 +111,7 @@
$this->assertNotNull( $fatory->getValidator( 'http' ), 'http' );
$this->assertNotNull( $fatory->getValidator( 'https' ), 'https'
);
+ $this->assertNotNull( $fatory->getValidator( 'ftp' ), 'ftp' );
$this->assertNotNull( $fatory->getValidator( 'mailto' ),
'mailto' );
$this->assertNull( $fatory->getValidator( 'notaprotocol' ),
'notaprotocol' );
@@ -112,10 +120,10 @@
public function testGetValidators() {
$fatory = new UrlSchemeValidators();
- $schemes = array( 'http', 'https', 'dummy' );
+ $schemes = array( 'http', 'https', 'ftp', 'dummy' );
$validators = $fatory->getValidators( $schemes );
- $this->assertEquals( array( 'http', 'https' ), array_keys(
$validators ) );
+ $this->assertEquals( array( 'http', 'https', 'ftp' ),
array_keys( $validators ) );
foreach ( $validators as $validator ) {
$this->assertInstanceOf(
'ValueValidators\ValueValidator', $validator );
diff --git a/lib/tests/phpunit/WikibaseDataTypeBuildersTest.php
b/lib/tests/phpunit/WikibaseDataTypeBuildersTest.php
index 89a97ae..311cd94 100644
--- a/lib/tests/phpunit/WikibaseDataTypeBuildersTest.php
+++ b/lib/tests/phpunit/WikibaseDataTypeBuildersTest.php
@@ -39,7 +39,7 @@
$entityLookup = new MockRepository();
$entityLookup->putEntity( $q8 );
- $urlSchemes = array( 'http', 'https', 'mailto' );
+ $urlSchemes = array( 'http', 'https', 'ftp', 'mailto' );
$builders = new WikibaseDataTypeBuilders( $entityLookup,
$entityIdParser, $urlSchemes );
$dataTypeFactory = new DataTypeFactory(
$builders->getDataTypeBuilders() );
@@ -143,7 +143,8 @@
array( 'url', new NumberValue( 7 ), false, 'StringValue
expected' ),
array( 'url', new StringValue( 'http://acme.com' ),
true, 'Simple HTTP URL' ),
- array( 'url', new StringValue( 'https://acme.com/' ),
true, 'Simple HTTPS URL' ),
+ array( 'url', new StringValue( 'https://acme.com' ),
true, 'Simple HTTPS URL' ),
+ array( 'url', new StringValue( 'ftp://acme.com' ),
true, 'Simple FTP URL' ),
array( 'url', new StringValue(
'http://acme.com/foo/bar?some=stuff#fragment' ), true, 'Complex HTTP URL' ),
// evil url
--
To view, visit https://gerrit.wikimedia.org/r/89513
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I898e2a8330923f5f32809c9485a83d71546c1c65
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Michał Łazowik <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits