Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define value constraint using regular expressions #1417

Merged
merged 1 commit into from Feb 29, 2016
Merged

Define value constraint using regular expressions #1417

merged 1 commit into from Feb 29, 2016

Conversation

mwjames
Copy link
Contributor

@mwjames mwjames commented Feb 24, 2016

Similar to Allows value, the Allows pattern property is to specify a regular expression to match permissible values for an assigned property. If a value cannot be matched then a general purpose message is being displayed.

@mwjames mwjames added the new feature A new, or altered behaviour of an existing functionality that fundamentally impacts behaviour label Feb 24, 2016
@mwjames mwjames added this to the SMW 2.4 milestone Feb 24, 2016
@mwjames
Copy link
Contributor Author

mwjames commented Feb 24, 2016

@SemanticMediaWiki/testers I'd appreciate if this finds some love amongst testers to give it a run down.

@jaideraf
Copy link
Member

Cool!
@mwjames This feature applies to all datatypes (Text, Page, URL, etc.)?

Edit:
Ops, sorry, now I read:

This special property can be used with a property of any datatype to limit possible value format matches.

@jaideraf
Copy link
Member

I'd appreciate if this finds some love amongst testers to give it a run down.

Tested. It seems fine to me. 👍

@JeroenDeDauw
Copy link
Member

@mwjames
Copy link
Contributor Author

mwjames commented Feb 26, 2016

https://twitter.com/benestar_wm/status/702803623378591744

Bene* ‏@benestar_wm 14h14 hours ago
JeroenDeDauw SemanticMW github I remember we had some concerns when considering this for wikidata because of security issues

As listed in [0], " The regex modifier /e is not permitted and removed from any expression".

If users feel more comfortable we can ship this as an opt-in rather than an opt-out by removing the SMW_DV_PAVP flag from $GLOBALS['smwgDVFeatures'] in the initial deploy setting.

[0] https://www.semantic-mediawiki.org/wiki/Help:Special_property_Allows_pattern

@JeroenDeDauw
Copy link
Member

I don't remember the details of the concerns @Benestar mentioned, though have a vague notation that it was DoS by means of resource consumption.

@mwjames mwjames mentioned this pull request Feb 26, 2016
@Benestar
Copy link

Related ticket can be found here: https://phabricator.wikimedia.org/T105126

@Benestar
Copy link

Also relevant and linked from the ticket: http://www.regular-expressions.info/catastrophic.html

@mwjames
Copy link
Contributor Author

mwjames commented Feb 26, 2016

Thanks

Related ticket can be found here: https://phabricator.wikimedia.org/T105126

I did a quick read through and with "... about this for months now and it seems there is no solution. Either have regular expressions or not.", I concur that I want regex support but I also recognize the potential impact therefore I've decided (just made a rough prototype) to add an administrative level.

Instead of allowing to add a pattern directly, the property expects a reference (as shown below) with the actual regex being maintained in MediaWiki:Smw allows pattern in order to have more control over who can edit the page [0].

image

[0] https://www.mediawiki.org/wiki/Manual:$wgNamespaceProtection

Similar to `Allows value`, the `Allows pattern` property is to specify a
regular expression to match permissible values for an assigned property.
If a value cannot be matched then a general purpose message is being
displayed.

To avoid any issues with expressions that include | or [] it is suggested
to use #set (`|+pipe` indicator ensures that MW doesn't interfere with the
expression):

```
Whitelist

{{#set:
 |Allows pattern=^(Foo|Foo bar|Bar)$|+pipe
}}
```
```
IPv4

{{#set:
 |Al1lows pattern=(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|+pipe
}}
```

`$GLOBALS['smwgDVFeatures'] = SMW_DV_PAVP` is enabled by default but if removed
will disable the functionality.
@mwjames
Copy link
Contributor Author

mwjames commented Feb 29, 2016

Over the weekend, I was elaborating on the approach and as indicated above, regular expression declaration has been moved to one dedicated place MediaWiki:Smw allows pattern.

Not enough that the property Allows pattern now only excepts a reference, MediaWiki:Smw allows pattern page is also not editable by anyone, users are required to have the smw-patternedit right (see the newly created smwcurator group). By default smw-patternedit is not assigned to any user (not even the sysop) and therefore has to be given explicitly.

@kghbln FYI, PR comes with a new group/right (smwcurator/smw-patternedit) [0]

[0] https://www.semantic-mediawiki.org/wiki/Help:Permissions_and_user_rights

mwjames added a commit that referenced this pull request Feb 29, 2016
Define value constraint using regular expressions
@mwjames mwjames merged commit ad32c68 into master Feb 29, 2016
@mwjames mwjames deleted the pvap branch February 29, 2016 07:14
@mwjames
Copy link
Contributor Author

mwjames commented Feb 29, 2016

Speaking of permission, @kghbln would you mind assigning the curator group to me so I can create an example.

image

@kghbln
Copy link
Member

kghbln commented Feb 29, 2016

@mwjames Not at all and this is done now. Great to see that my setup works as indented.

@kghbln
Copy link
Member

kghbln commented Feb 29, 2016

@JeroenDeDauw So far you do not have an account on sandbox. Shame on you and currently not extra rights! ;)

@mwjames
Copy link
Contributor Author

mwjames commented Feb 29, 2016

Not at all and this is done now. Great to see that my setup works as indented.

👍

@kghbln
Copy link
Member

kghbln commented Feb 29, 2016

@kghbln
Copy link
Member

kghbln commented Feb 29, 2016

All one needs for IBANs including ref!

mwjames added a commit that referenced this pull request Mar 31, 2016
Suppress error on regex compilation, refs #1417
mwjames pushed a commit that referenced this pull request Jul 7, 2016
mwjames added a commit that referenced this pull request Jul 7, 2016
PatternConstraint to escape early, refs #1417
@kghbln
Copy link
Member

kghbln commented Aug 18, 2016

Are there more than one "Allows pattern" assignments possible per property? I would guess yes.

@mwjames
Copy link
Contributor Author

mwjames commented Aug 18, 2016

Are there more than one "Allows pattern" assignments possible per property? I would guess yes.

Yes BUT only the last will win [0].

[0] https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/src/PropertySpecificationLookup.php#L183

@mwjames
Copy link
Contributor Author

mwjames commented Aug 18, 2016

BUT only the last will win [0].

This saves a lot of headaches as we don't have to make assumptions. Regular expressions are very "stretchy", so for those who want to combine different patterns, create a new reference, merge them in a coherent way leaving SMW to not second guess the intend.

@kghbln
Copy link
Member

kghbln commented Aug 18, 2016

Yes BUT only the last will win [0].

Thanks for the info. Indeed this makes much sense. This is now documented.

@kghbln kghbln added the wikidocu missing Code changes (mostly features) what have not yet been documented label Jun 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new, or altered behaviour of an existing functionality that fundamentally impacts behaviour wikidocu missing Code changes (mostly features) what have not yet been documented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants