Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-33887

Calling $PAGE->requires->xx before require_login() + force language gives javascript language string error

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2, 2.3
    • Fix Version/s: 2.3.2
    • Component/s: Other
    • Labels:
    • Testing Instructions:
      Hide

      For developers:
      see description or create a test page with (you need Czech lang pack installed)

      <?php
      require('config.php');
      $PAGE->set_url('/xx.php');
      $PAGE->set_context(null);
      echo $OUTPUT->header();
      $SESSION->lang = 'en';
      $PAGE->requires->string_for_js('course', 'moodle', 1);
      $SESSION->lang = 'cs';
      $PAGE->requires->string_for_js('course', 'moodle', 1);
      echo $OUTPUT->footer();

      Show
      For developers: see description or create a test page with (you need Czech lang pack installed) <?php require('config.php'); $PAGE->set_url('/xx.php'); $PAGE->set_context(null); echo $OUTPUT->header(); $SESSION->lang = 'en'; $PAGE->requires->string_for_js('course', 'moodle', 1); $SESSION->lang = 'cs'; $PAGE->requires->string_for_js('course', 'moodle', 1); echo $OUTPUT->footer();
    • Affected Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      w28_MDL-33887_m24_jsstrings

      Description

      If you have a Moodle course with the language forced (e.g. to Deutsch (De)) and the user's own language is set to another language (e.g. to English (En)), then a page with a filepicker element (e.g. the 'Add blog' page of the OU Blog) causes an error.

      This is because the language strings for the filepicker form element javascript (including the 'cancel' string) are loaded before the forced course language is applied, whereas 'init_requirements_data' (also including the 'cancel' string) is called after the force course language is applied. This means that the first one loads, in my case, the English 'Cancel' and the second attempts to load the German 'Abbrechen', causing an exception, as they don't match.

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            davosmith Davo Smith added a comment -

            Actually, there seems to be a slightly different bug happening in M2.3 - similar result on the OU Blog, but different language string.

            Show
            davosmith Davo Smith added a comment - Actually, there seems to be a slightly different bug happening in M2.3 - similar result on the OU Blog, but different language string.
            Hide
            davosmith Davo Smith added a comment -

            The sequence is this:

            OU blog calls $PAGE->require->js(...)
            -> the page_requirements_manager constructor is called, which loads 'core_filepicker', which (in Moodle 2.2) loads the English 'cancel' string.

            OU blog calls require_login($course)
            -> moodle applies the forced language from the course

            OU blog calls $OUTPUT->header()
            > core_renderer>standard_head_html() calls core_renderer->get_head_code(), which calls core_renderer->init_requirements_data(), which loads the German 'cancel' string
            -> clash occurs between the language string 'cancel' being 'Cancel' (from before forced language set) and 'Abbrechen' (after forced language set).

            In 2.3 'core_filepicker' doesn't load the 'cancel' string, so that no longer clashes, however it does load the 'error' string, which is also loaded by the 'filemanager' element (see file/renderer.php - render_form_filemanager ).

            I can't work out yet why this is sometimes working, but causing an error on the OU blog editing page (it looks like it should fail on every page within a course that has a filemanager form element and course forced language settings).

            Show
            davosmith Davo Smith added a comment - The sequence is this: OU blog calls $PAGE->require->js(...) -> the page_requirements_manager constructor is called, which loads 'core_filepicker', which (in Moodle 2.2) loads the English 'cancel' string. OU blog calls require_login($course) -> moodle applies the forced language from the course OU blog calls $OUTPUT->header() > core_renderer >standard_head_html() calls core_renderer->get_head_code(), which calls core_renderer->init_requirements_data(), which loads the German 'cancel' string -> clash occurs between the language string 'cancel' being 'Cancel' (from before forced language set) and 'Abbrechen' (after forced language set). In 2.3 'core_filepicker' doesn't load the 'cancel' string, so that no longer clashes, however it does load the 'error' string, which is also loaded by the 'filemanager' element (see file/renderer.php - render_form_filemanager ). I can't work out yet why this is sometimes working, but causing an error on the OU blog editing page (it looks like it should fail on every page within a course that has a filemanager form element and course forced language settings).
            Hide
            davosmith Davo Smith added a comment -

            I've narrowed it down and updated the summary to match.

            To reproduce, you need to do the following:

            1. set 'force language' for a course
            2. set your user's language to another language
            3. visit a page that calls a $PAGE->requires->xx function before calling require_login($course) (e.g. $PAGE->requires->js())
            4. (for Moodle 2.3, this page should also contain a 'filemanager' form element which will load the 'error' string)

            I'm not sure what a sensible fix is, other than some sort of coding_exception if require_login is called after the $PAGE->requires object has already been initialised?

            (For the moment, I'll raise a separate bug against OU Blog to adjust the function calling order).

            Show
            davosmith Davo Smith added a comment - I've narrowed it down and updated the summary to match. To reproduce, you need to do the following: 1. set 'force language' for a course 2. set your user's language to another language 3. visit a page that calls a $PAGE->requires->xx function before calling require_login($course) (e.g. $PAGE->requires->js()) 4. (for Moodle 2.3, this page should also contain a 'filemanager' form element which will load the 'error' string) I'm not sure what a sensible fix is, other than some sort of coding_exception if require_login is called after the $PAGE->requires object has already been initialised? (For the moment, I'll raise a separate bug against OU Blog to adjust the function calling order).
            Hide
            skodak Petr Skoda added a comment -

            We should probably use the new lang_string class and delay the string fetching till page footer where is the JS printed to page.

            Show
            skodak Petr Skoda added a comment - We should probably use the new lang_string class and delay the string fetching till page footer where is the JS printed to page.
            Hide
            skodak Petr Skoda added a comment -

            thanks for the report

            Show
            skodak Petr Skoda added a comment - thanks for the report
            Hide
            poltawski Dan Poltawski added a comment -

            Taking integration held issues out of integration (whilst we are keeping master and 23_STABLE in sync).

            Show
            poltawski Dan Poltawski added a comment - Taking integration held issues out of integration (whilst we are keeping master and 23_STABLE in sync).
            Hide
            samhemelryk Sam Hemelryk added a comment -

            Thanks Petr, changes look sensible and have been integrated.

            Show
            samhemelryk Sam Hemelryk added a comment - Thanks Petr, changes look sensible and have been integrated.
            Hide
            salvetore Michael de Raadt added a comment -

            Test result: Success

            Tested in master only.

            Show
            salvetore Michael de Raadt added a comment - Test result: Success Tested in master only.
            Hide
            poltawski Dan Poltawski added a comment -

            Congratulations!

            You've made it into the weekly release!

            Thanks for your contribution - here are some random drummers to keep you inspired for the next week!
            http://www.youtube.com/watch?v=_QhpHUmVCmY

            Show
            poltawski Dan Poltawski added a comment - Congratulations! You've made it into the weekly release! Thanks for your contribution - here are some random drummers to keep you inspired for the next week! http://www.youtube.com/watch?v=_QhpHUmVCmY

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  10/Sep/12