? Success

User tests: Successful: Unsuccessful:

avatar smz
smz
26 Jun 2015

Description

This is a code review of the "Language Filter" system plugin.

The main objective was code simplification and optimization.
At the same time some small issues/bugs have been solved.

The major differences can be found in the parseRule() method where, I think, the logic is also better documented. getLanguageCookie() too has some major mods.

Less important modifications have been introduced in onUserBeforeSave(), onUserAfterSave(), onUserLogin() and onAfterDispatch()

Testing instructions

  • Have a multilingual site with at least three languages installed
  • Test front-end multilingual functionalities (including logging in with users that have a specific language assigned)
  • Verify correct browser language detection
  • Verify correct menu items and component association
  • Verify that everything else is OK, no regression exist and some small glitches are gone

Potentially solved issues (please test...)

  • #7047 Cookie-based Redirect to 404s in language filter
  • #7419 Wrong language prefix automatically added
avatar smz smz - open - 26 Jun 2015
avatar smz smz - change - 26 Jun 2015
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 26 Jun 2015
Labels Added: ?
avatar smz
smz - comment - 26 Jun 2015

... pinging @infograf768! :smile:

avatar smz smz - change - 26 Jun 2015
The description was changed
avatar smz
smz - comment - 26 Jun 2015

Do we have problems with Travis and PHP 5.5?

Updating dependencies (including require-dev)
  - Installing squizlabs/php_codesniffer (1.5.6)
    Downloading: connection...    Failed to download squizlabs/php_codesniffer from dist: Could not authenticate against github.com
    Now trying to download from source
  - Installing squizlabs/php_codesniffer (1.5.6)
    Cloning 6f3e42d311b882b25b4d409d23a289f4d3b803d5

and also:

No output has been received in the last 10 minutes, this potentially indicates a stalled build or something wrong with the build itself
avatar mbabker
mbabker - comment - 26 Jun 2015

No. Travis has just been really flaky as of late.

avatar smz
smz - comment - 26 Jun 2015

OK, Thanks!
Will it retest automatically or have I to make some changes to trigger it?

avatar mbabker
mbabker - comment - 26 Jun 2015

Someone with permission has to reset the job. I just did it.

avatar smz
smz - comment - 26 Jun 2015

Great! Thanks, Michael! :smile:

avatar rdeutz
rdeutz - comment - 26 Jun 2015

I did a code restructure on the language plugin a while ago, was not merged (don't ask why), maybe there is something in it you can use #6428

avatar smz
smz - comment - 26 Jun 2015

Thanks Robert! I missed that, and I will surely look at it and see if there is anything I can bring in!

As you're familiar with languagefilter.php you'll probably may also give a look at my code and see if it looks all-right to you (if you have some time, of course...).

avatar rdeutz
rdeutz - comment - 26 Jun 2015

A bit busy atm but sure will do.

avatar zero-24 zero-24 - change - 26 Jun 2015
Category Multilanguage
avatar infograf768
infograf768 - comment - 27 Jun 2015

Although it looks like a simplification, I am not sure that checking browser language in the private function getLanguageCookie() is very semantic...

avatar smz
smz - comment - 27 Jun 2015

Although it looks like a simplification, I am not sure that checking browser language in the private function getLanguageCookie() is very semantic...

Agreed! :smile:
What could be a better name for that function?

  • getPreferredLanguage ()
  • guessLanguage()
  • getLanguage()
  • getCookieOrBrowserLanguage()
  • getClientLanguage()
  • ...................................................
avatar smz
smz - comment - 28 Jun 2015

Ouch... I made some mods but Travis got stuck again with PHP 5.5...
Can someone, please, re-submit the job?
Thanks! :smile:

avatar rdeutz
rdeutz - comment - 28 Jun 2015

done

avatar smz
smz - comment - 28 Jun 2015

Thanks, Robert!

Apparently good 'ol Travis now got stuck on PHP:5.3, but don't worry: I'll have a minor commit for tonight and that will re-trigger it. I'll just be sure to cross my finger while committing... :smile:

avatar smz
smz - comment - 29 Jun 2015

In theory I have some more small mods to push, but as they are limited to code style and comments fixing, and Travis finally got through with all PHP versions, I'll defer those minor mods to a second time, if and when there will be consensus that this is valid code worth merging.

Is that OK?

avatar infograf768
infograf768 - comment - 29 Jun 2015

As it is now, code looks like working for me.

avatar smz
smz - comment - 29 Jun 2015

With latest commit I fix an unreported (I think) issue:

While in non-SEF mode there were several cases in which home pages were not detected and as a consequence the rel='alternate' links were not generated.

I also modified those links to be of the form /index.php?lang=sef, without any redundant reference to item IDs. For consistency, I also plan to apply a similar patch to the "Language Switcher"

I think this PR solves issue #7047 too. If testers will confirm this, that issue could be closed

avatar smz
smz - comment - 29 Jun 2015

I just pushed a PR (#7286) that modifies the Language Switcher to better adhere to the rel=alternate links generated by this PR...

avatar smz
smz - comment - 29 Jun 2015

@infograf768 a question: are there cases in which we want the language switcher filter to function for languages that do not have an associated home page? If not, I can make further simplifications...

avatar infograf768
infograf768 - comment - 30 Jun 2015

@infograf768 a question: are there cases in which we want the language switcher filter to function for languages that do not have an associated home page? If not, I can make further simplifications...

No. A content language without a home page is like a bicycle without a saddle...
Will look at your last iteration of the PR as soon as possible, but

While in non-SEF mode there were several cases in which home pages were not detected and as a consequence the rel='alternate' links were not generated.

I first would have to be able to reproduce this.

avatar smz
smz - comment - 30 Jun 2015

Easiest way to reproduce the issue with rel='alternate' links in home pages, non-SEF mode, is to go to the naked domain (default language, cookie language or browser detected language do not matter): you will not find alternates in there. Now switch to another language and then back to the original one: alternates will be there (and ugly...).

avatar smz
smz - comment - 30 Jun 2015

@infograf768 I forgot to mention that if you test this for fixing the non-SEF home page rel=alternate issue, it would be better if you test it together with #7286

This is not a requirement, but then there will be two kinds of links to home pages, the "short ones" in the rel=alternate links and the "long ones" in the Language Switcher. Those links will be both "seen" by crawlers and I think it will be unpredictable which one will be indexed by search engines.

Having the "short form" indexed would be a lot better as this will not change even if you'll change the home pages menu itemid (or even component) at a second time.

avatar infograf768
infograf768 - comment - 30 Jun 2015

Easiest way to reproduce the issue with rel='alternate' links in home pages, non-SEF mode, is to go to the naked domain (default language, cookie language or browser detected language do not matter): you will not find alternates in there.

This does not change with your patch.

Now switch to another language and then back to the original one: alternates will be there (and ugly...).

They are changed indeed but is it B/C ?
Also how is sef concerned by the language switcher when no SEF?

Looks like we need to add htmlspecialchars here btw:

                    // Current language link
                    case ($i == $this->current_lang):
                        $language->link = htmlspecialchars(JUri::getInstance()->toString(array('path', 'query')));
                        break;

Otherwise we get this for associated items (below for it-IT)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it-it" lang="it-it" dir="ltr">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta name="generator" content="Joomla! - Open Source Content Management" />
  <title>Italiano - Multilingua passo dopo passo</title>
  <link href="/testwindows/trunkgitnew/index.php?option=com_content&amp;view=category&amp;id=32&amp;Itemid=151&amp;lang=it&amp;format=feed&amp;type=rss" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
  <link href="/testwindows/trunkgitnew/index.php?option=com_content&amp;view=category&amp;id=32&amp;Itemid=151&amp;lang=it&amp;format=feed&amp;type=atom" rel="alternate" type="application/atom+xml" title="Atom 1.0" />
  <link href="http://localhost:8888/testwindows/trunkgitnew/index.php?option=com_content&amp;view=category&amp;id=12&amp;lang=en&amp;Itemid=122" rel="alternate" hreflang="en-GB" />
  <link href="http://localhost:8888/testwindows/trunkgitnew/index.php?option=com_content&amp;view=category&amp;id=11&amp;lang=fr&amp;Itemid=121" rel="alternate" hreflang="fr-FR" />
  <link href="http://localhost:8888/testwindows/trunkgitnew/index.php?option=com_content&amp;view=category&amp;id=27&amp;lang=de&amp;Itemid=143" rel="alternate" hreflang="de-DE" />
  <link href="http://localhost:8888/testwindows/trunkgitnew/index.php?option=com_content&view=category&id=32&Itemid=151&lang=it" rel="alternate" hreflang="it-IT" />
  <link href="http://localhost:8888/testwindows/trunkgitnew/index.php?option=com_content&amp;view=category&amp;id=21&amp;lang=es&amp;Itemid=131" rel="alternate" hreflang="es-ES" />
  <link href="http://localhost:8888/testwindows/trunkgitnew/index.php?option=com_content&amp;view=category&amp;id=36&amp;Itemid=180&amp;lang=mk" rel="alternate" hreflang="mk-MK" />
  <link href="http://localhost:8888/testwindows/trunkgitnew/index.php?option=com_content&amp;view=category&amp;id=41&amp;Itemid=192&amp;lang=ta" rel="alternate" hreflang="ta-IN" />

Now, to be honest: it took ages to get the regressions out of the languagefilter. I am frightened by your changes.

avatar smz
smz - comment - 30 Jun 2015

@infograf768

I can't reproduce the fact that you can't reproduce... :smile: Honestly, I consistently get the issue w/o this patch and consistently don't get it when the patch is applied... That's curious... How can we get out of this?

I don't think we have a B/C commitment for non-SEF URLs (but I may be wrong...). In any case I sincerely think that the short-form URLs for home pages are a lot preferable for search engines, for the reasons I explained above.

You're right that there is a dis-alignment between current link and "other links" (the htmlspecialchars thing...), but I think we should fix it the other way around: it is having HTML entities in URI that is wrong. Unsure about this, but will check...

Changes are always a little bit frightening, but if you give an impartial look at my code you'll see (or at least that's my opinion) that it is much more structured than the current one and this will be a big plus also for future enhancements/modifications...

avatar mbabker
mbabker - comment - 30 Jun 2015

Depends what the before/after URL is and if it breaks functionality. If it gave a 200 before it should work after. See the B/C statement for URLs.

avatar smz
smz - comment - 30 Jun 2015

@mbabker no functionality is broken here: where you used to get a 200 you'll still get a 200

@infograf768 I'm checking the htmlentities thing and indeed it is wrong to have those in URLs. URL encoding is different from HTML enconding and the right function to use in PHP is urlencode() (http://php.net/manual/en/function.urlencode.php)

As the wrong URLs comes from JRoute::_ I'm afraid we have a problem there... will check.

avatar infograf768
infograf768 - comment - 30 Jun 2015

it is having HTML entities in URI that is wrong. Unsure about this, but will check...

As you can see in source for rss, atom, opensearch, form actions, etc., we usually use html entities in urls in Joomla.

avatar smz
smz - comment - 30 Jun 2015

yes, but I'm not sure this is correct (per RFCs and w3.org standards)...

avatar smz
smz - comment - 30 Jun 2015

from a practical point of view it seems there is no problem: browsers do interpret those &amp; and we are using them since ages, but... will check...

avatar smz
smz - comment - 30 Jun 2015

hmmm...

$string = this&that
htmlspecialchars($string) = this&that
htmlentities($string) = this&that
urlencode($string) = this%26that
avatar smz
smz - comment - 30 Jun 2015

It seems there are different point of view on this:

  • commonly ampersand is encoded as &amp; in URLs
  • according to PHP and other sources it should be encoded as %26

For sure a simple & is wrong: will fix that (with our current convention of using &amp;)!

Note that we have this issue in current code too: no big issues but the generated HTML will not pass HTML validators

avatar smz
smz - comment - 30 Jun 2015

&amp; is OK according to w3.org: http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2

Actually they recommend that:

...HTTP server implementors, and in particular, CGI implementors support the use of ";" in place of "&" to save authors the trouble of escaping "&" characters in this manner

.. but this is of course out of question!

avatar smz
smz - comment - 1 Jul 2015

Latest commit fix ampersand encoding issue for current language URLs in onAfterDispatch()

I'm anyway dubious if this shouldn't be directly fixed in AbstractUri::toString() and, obviously, assure we don't make a double encoding elsewhere. [OK, I know the answer: B/C... :stuck_out_tongue_winking_eye: ]

avatar smz smz - reference | c2369a8 - 1 Jul 15
avatar smz
smz - comment - 12 Jul 2015

Added #7419 to the list of the potentially solved issues.

If this is deemed correct, I can also modify the code to always give 404 if (while in SEF mode and without the option to remove the default language code) the language code is missing

avatar smz smz - change - 13 Jul 2015
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2015-07-13 08:09:05
Closed_By smz
avatar smz smz - close - 13 Jul 2015
avatar smz smz - close - 13 Jul 2015
avatar infograf768
infograf768 - comment - 13 Jul 2015

Please do not close, @smz

We found out that the cookie issue also exists when url language code is not removed.

avatar smz smz - change - 13 Jul 2015
Status Closed New
Closed_Date 2015-07-13 08:09:04
Closed_By smz
avatar smz smz - reopen - 13 Jul 2015
avatar smz smz - reopen - 13 Jul 2015
avatar smz smz - close - 13 Jul 2015
avatar smz smz - close - 13 Jul 2015
avatar infograf768
infograf768 - comment - 13 Jul 2015

I have updated #7427

I also discovered (not patched) at the same time that the alternate were not displayed for the home pages when sef was off when we use short urls of the type http://mysite.com/index.php?lang=xx while long home page urls (The ones from the Home menu item) the get the alternate fine.

Add a Comment

Login with GitHub to post a comment