Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/261186
Change subject: Merge and expand RegexValidator for Commons media files
......................................................................
Merge and expand RegexValidator for Commons media files
1. I merged the two regular expressions into one that does the exact
same.
2. I added []{}| to the list of disallowed characters. See the
documentation of $wgLegalTitleChars in DefaultSettings.php. These
characters are never allowed in file names.
3. A single character extension is now disallowed.
The intent of these changes is to avoid possibly expensive API
requests, when they are introduced in I65507d6.
Change-Id: I488abe3c13cb899e66b3e555d13a1142fd0c8f78
---
M repo/includes/ValidatorBuilders.php
M repo/tests/phpunit/includes/ValidatorBuildersTest.php
2 files changed, 11 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/86/261186/1
diff --git a/repo/includes/ValidatorBuilders.php
b/repo/includes/ValidatorBuilders.php
index 15fbf65..05cf3d8 100644
--- a/repo/includes/ValidatorBuilders.php
+++ b/repo/includes/ValidatorBuilders.php
@@ -154,9 +154,10 @@
// so restrict file name to 240 bytes (see
UploadBase::getTitle).
$validators = $this->getCommonStringValidators( 240 );
- $validators[] = new RegexValidator( '@[#/:\\\\]@u', true ); //
no nasty chars
- // Must contain a non-empty file name and a non-empty,
character-only file extension.
- $validators[] = new RegexValidator( '/.\.\w+$/u' );
+ // Must contain a non-empty file name with no nasty characters
(see documentation of
+ // $wgLegalTitleChars as well as $wgIllegalFileChars). File
name extensions with digits
+ // (e.g. ".jp2") are possible, as well as two characters (e.g.
".ai").
+ $validators[] = new RegexValidator(
'/^[^#\/:[\\\\\]{|}]+\.\w{2,}$/u' );
//TODO: add a validator that checks the rules that MediaWiki
imposes on filenames for uploads.
// $wgLegalTitleChars and $wgIllegalFileChars define this,
but we need these for the *target* wiki.
//TODO: add a validator that uses a foreign DB query to check
whether the file actually exists on commons.
diff --git a/repo/tests/phpunit/includes/ValidatorBuildersTest.php
b/repo/tests/phpunit/includes/ValidatorBuildersTest.php
index 66b328e..af924d4 100644
--- a/repo/tests/phpunit/includes/ValidatorBuildersTest.php
+++ b/repo/tests/phpunit/includes/ValidatorBuildersTest.php
@@ -88,7 +88,14 @@
array( 'commonsMedia', new StringValue( '' ), false,
'empty string should be invalid' ),
array( 'commonsMedia', new StringValue( str_repeat(
'x', 237 ) . '.jpg' ), false, 'name too long' ),
array( 'commonsMedia', new StringValue( 'Foo' ), false,
'no file extension' ),
+ array( 'commonsMedia', new StringValue( 'Foo.a' ),
false, 'file extension to short' ),
array( 'commonsMedia', new StringValue( 'Foo.jpg' ),
true, 'this should be good' ),
+ array( 'commonsMedia', new StringValue( "a\na.jpg" ),
false, 'illegal character: newline' ),
+ array( 'commonsMedia', new StringValue( 'a[a.jpg' ),
false, 'illegal character: square bracket' ),
+ array( 'commonsMedia', new StringValue( 'a]a.jpg' ),
false, 'illegal character: square bracket' ),
+ array( 'commonsMedia', new StringValue( 'a{a.jpg' ),
false, 'illegal character: curly bracket' ),
+ array( 'commonsMedia', new StringValue( 'a}a.jpg' ),
false, 'illegal character: curly bracket' ),
+ array( 'commonsMedia', new StringValue( 'a|a.jpg' ),
false, 'illegal character: pipe' ),
array( 'commonsMedia', new StringValue( 'Foo#bar.jpg'
), false, 'illegal character: hash' ),
array( 'commonsMedia', new StringValue( 'Foo:bar.jpg'
), false, 'illegal character: colon' ),
array( 'commonsMedia', new StringValue( 'Foo/bar.jpg'
), false, 'illegal character: slash' ),
--
To view, visit https://gerrit.wikimedia.org/r/261186
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I488abe3c13cb899e66b3e555d13a1142fd0c8f78
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits