jenkins-bot has submitted this change and it was merged. Change subject: Factor common string validators into common method ......................................................................
Factor common string validators into common method Change-Id: I53883a7921dea368ed8b38aa7513cbbd0f488964 --- M lib/includes/WikibaseDataTypeBuilders.php 1 file changed, 16 insertions(+), 20 deletions(-) Approvals: WikidataJenkins: Verified Thiemo Mättig (WMDE): Looks good to me, approved jenkins-bot: Verified diff --git a/lib/includes/WikibaseDataTypeBuilders.php b/lib/includes/WikibaseDataTypeBuilders.php index f170b23..8df0a49 100644 --- a/lib/includes/WikibaseDataTypeBuilders.php +++ b/lib/includes/WikibaseDataTypeBuilders.php @@ -102,12 +102,20 @@ return new DataType( $id, 'wikibase-entityid', $validators ); } - public function buildMediaType( $id ) { + protected function getCommonStringValidators( $maxLength = 400 ) { $validators = array(); $validators[] = new TypeValidator( 'string' ); - $validators[] = new StringLengthValidator( 1, 240 ); // Note: 240 is hardcoded in UploadBase + //TODO: validate UTF8 (here and elsewhere) + $validators[] = new StringLengthValidator( 1, $maxLength, 'mb_strlen' ); $validators[] = new RegexValidator( '/^\s|[\r\n\t]|\s$/', true ); // no leading/trailing whitespace, no line breaks. + + return $validators; + } + + public function buildMediaType( $id ) { + $validators = $this->getCommonStringValidators( 240 ); + $validators[] = new RegexValidator( '@[#/:\\\\]@u', true ); // no nasty chars $validators[] = new RegexValidator( '@\..+@u', false ); // must contain a file extension //TODO: add a validator that checks the rules that MediaWiki imposes on filenames for uploads. @@ -122,12 +130,7 @@ } public function buildStringType( $id ) { - $validators = array(); - - $validators[] = new TypeValidator( 'string' ); - //TODO: validate UTF8 (here and elsewhere) - $validators[] = new StringLengthValidator( 1, 400, 'mb_strlen' ); - $validators[] = new RegexValidator( '/^\s|[\r\n\t]|\s$/', true ); // no leading/trailing whitespace, no line breaks. + $validators = $this->getCommonStringValidators(); $topValidator = new DataValueValidator( //Note: validate the DataValue's native value. new CompositeValidator( $validators, true ) //Note: each validator is fatal @@ -137,24 +140,17 @@ } public function buildMonolingualTextType( $id ) { - $validators = array(); - - $validators[] = new TypeValidator( 'string' ); - //TODO: validate UTF8 (here and elsewhere) - $validators[] = new StringLengthValidator( 1, 400, 'mb_strlen' ); - $validators[] = new RegexValidator( '/^\s|[\r\n\t]|\s$/', true ); // no leading/trailing whitespace, no line breaks. - $textValidator = new DataFieldValidator( 'text', - new CompositeValidator( $validators, true ) //Note: each validator is fatal + new CompositeValidator( + $this->getCommonStringValidators(), + true //Note: each validator is fatal + ) ); - - $validators = array(); - $validators[] = new MembershipValidator( Utils::getLanguageCodes() ); $languageValidator = new DataFieldValidator( 'language', - new CompositeValidator( $validators, true ) + new MembershipValidator( Utils::getLanguageCodes() ) ); $topValidator = new CompositeValidator( -- To view, visit https://gerrit.wikimedia.org/r/133216 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I53883a7921dea368ed8b38aa7513cbbd0f488964 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Adrian Lang <adrian.l...@wikimedia.de> Gerrit-Reviewer: Hoo man <h...@online.de> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: WikidataJenkins <wikidata-servi...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits