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

MBS-9515: Block anchors in new Wikipedia URLs #562

Merged
merged 2 commits into from Oct 19, 2017

Conversation

yvanzo
Copy link
Contributor

@yvanzo yvanzo commented Oct 17, 2017

MBS-9515: Block adding Wikipedia relationships to anchors

@yvanzo yvanzo requested a review from mwiencek October 17, 2017 18:20
} else if ((!isPositiveInteger(link.relationship) || (oldLink && link.url !== oldLink.url)) && /^(https?:\/\/)?([^.\/]+\.)?wikipedia\.org\/.*#/.test(link.url)) {
// Kludge for MBS-9515 to be replaced with the more general MBS-9516
error = l('Anchor (#Example_section) Wikipedia links are not allowed, see the {url|guidelines for URL}.', {
url: { href: '/doc/Style/Relationships/URLs', target: '_blank' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably link to something like https://musicbrainz.org/relationship/29651736-fa6d-48e4-aadc-a557c6add1cb

It's kind of annoying that we don't have a central "Wikipedia page" rel to link to, but only one per entity type :/ But linking to a specific one, like artist, might be better than nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

46feadc links to the specific relationship page for the current URL.
Besides, I reported the lack of central page for similar relationship types in MBS-9517.

@@ -196,6 +196,12 @@ class ExternalLinksEditor extends React.Component<LinksEditorProps, LinksEditorS
error = l('This relationship type is deprecated and should not be used.');
} else if ((!isPositiveInteger(link.relationship) || (oldLink && link.url !== oldLink.url)) && checker && !checker(link.url)) {
error = l('This URL is not allowed for the selected link type, or is incorrectly formatted.');
} else if ((!isPositiveInteger(link.relationship) || (oldLink && link.url !== oldLink.url)) && /^(https?:\/\/)?([^.\/]+\.)?wikipedia\.org\/.*#/.test(link.url)) {
// Kludge for MBS-9515 to be replaced with the more general MBS-9516
error = l('Anchors Wikipedia links are not allowed, please remove {fragment} if still appropriate, see the {url|guidelines}.', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will some users know what an anchor is? I guess it's fine, but I wonder if something like "Wikipedia links to specific sections of the page are not allowed, ..." would make more sense.

The comma splice at the end sounds slightly unnatural so I'd replace "appropriate, see" with "appropriate. See" too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost applied in 46feadc

} else if ((!isPositiveInteger(link.relationship) || (oldLink && link.url !== oldLink.url)) && /^(https?:\/\/)?([^.\/]+\.)?wikipedia\.org\/.*#/.test(link.url)) {
// Kludge for MBS-9515 to be replaced with the more general MBS-9516
error = l('Anchors Wikipedia links are not allowed, please remove {fragment} if still appropriate, see the {url|guidelines}.', {
fragment: '<i>' + _.escape(link.url.replace(/^(?:https?:\/\/)?(?:[^.\/]+\.)?wikipedia\.org\/[^#]*#(.*)$/, '#$1')) + '</i>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's much safer to pass __react: true here and pass in a React element directly, like fragment: <i>{link.url.replace(...)}</li>. Then you can revert the dangerouslySetInnerHTML below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that for the URL syntax you don't need to pass in an <a>, the i18n module will do that for you with __react: true. So the url: {...} part can stay as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 46feadc, with extra style in 4007afd that wraps the quoted URL fragment in order to break it if longer than line.

@yvanzo
Copy link
Contributor Author

yvanzo commented Oct 18, 2017

Selenium tests seem to deadlock build #631.

@yvanzo yvanzo merged commit f4c765f into metabrainz:master Oct 19, 2017
@yvanzo yvanzo deleted the mbs-9515-block-wp-anchor branch July 26, 2018 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants