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

Add support for language variant filter #1005

Merged
merged 5 commits into from
Jun 19, 2018

Conversation

Pchelolo
Copy link
Contributor

WIP: Pending actual parsoid transformations support.

cc @wikimedia/services

@Pchelolo Pchelolo force-pushed the siteinfo_langvariants branch 2 times, most recently from 09f3fda to 12862d2 Compare June 18, 2018 15:48
Change-Id: Ia7fbafe8abc73e96b391e77176d3873be962471b
@d00rman d00rman changed the title WIP: Add support for language variant filter Add support for language variant filter Jun 19, 2018
Copy link
Contributor

@d00rman d00rman left a comment

Choose a reason for hiding this comment

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

Very nice and compact! Some comments/questions in-lined, but overall LGTM

lib/mwUtil.js Outdated
return false;
}
// Second, if the requested language variant exist for page language
return pageLangVariants.indexOf(acceptLanguage) !== -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good if the check were case-insensitive.

if (/\/page\/html\//.test(specInfo.path)) {
// It's HTML, hit Parsoid for conversion
return next(hyper, req)
.then(html => hyper.post({
Copy link
Contributor

Choose a reason for hiding this comment

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

All this block looks like it belongs in the Parsoid module rather than here since we keep all Parsoid-related interfaces and logic there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's basically just making a request to the parsoid module here. We can probably move a bit more logic in there, but not too much..

// We can skip setting Vary: accept-language as Parsoid sets it.
} else {
// TODO: It's something else, so just forward to MCS
return next(hyper, req);
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now this will also store the result while forwarding the A-L header, won't it?

sys/action.js Outdated
Object.keys(origVariants).forEach((lang) => {
variants[lang] = Object.keys(origVariants[lang])
// Filter out non-specific variants like `en`, `zh` etc.
.filter(variant => /-/.test(variant));
Copy link
Contributor

Choose a reason for hiding this comment

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

What about multi-lang wikis? Wouldn't en be a valid "variant" for commons, e.g.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case of commons/wikidata it's all pretty different - this is just about conversion, commons actually would return a completely different response. I don't think parsoid even supports that case.

@@ -735,6 +735,7 @@ class ParsoidService {
headers: {
'content-type': 'application/json',
'user-agent': req['user-agent'],
'content-language': req.headers['content-language']
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean accept-language ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, I meant content-language - parsoid requires that header to be set for the conversion request.

Change-Id: Icf42fca39e9691ecf92d39017f63482e0d0716f1
Change-Id: I3c22de412c8735021daf97db465cd6455c57e33f
Change-Id: Id0d6d2868c9cef5f6526d9129ff0f12b165a1f7e
Change-Id: Icc9818b299cb0f5233529cdb15e98510bd550abc
@d00rman d00rman merged commit 988c18b into wikimedia:master Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants