Merge branch 'wip-MDL-46585-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Dan Poltawski 2014-09-15 13:00:24 +01:00
commit 0908fb4221
11 changed files with 166 additions and 7 deletions

View File

@ -263,7 +263,6 @@ $string['externalbadges'] = 'My badges from other web sites';
$string['externalbadgesp'] = 'Badges from other web sites:';
$string['externalbadges_help'] = 'This area displays badges from your external backpack.';
$string['fixed'] = 'Fixed date';
$string['hidden'] = 'Hidden';
$string['hiddenbadge'] = 'Unfortunately, the badge owner has not made this information available.';
$string['issuedbadge'] = 'Issued badge information';
$string['issuancedetails'] = 'Badge expiry';
@ -389,3 +388,7 @@ $string['viewbadge'] = 'View issued badge';
$string['visible'] = 'Visible';
$string['warnexpired'] = ' (This badge has expired!)';
$string['year'] = 'Year(s)';
// Deprecated since Moodle 2.8.
$string['hidden'] = 'Hidden';

View File

@ -111,7 +111,6 @@ $string['gotocalendar'] = 'Go to calendar';
$string['group'] = 'Group';
$string['groupevent'] = 'Group event';
$string['groupevents'] = 'Group events';
$string['hidden'] = 'hidden';
$string['hidecourseevents'] = 'Hide course events';
$string['hideglobalevents'] = 'Hide global events';
$string['hidegroupsevents'] = 'Hide group events';
@ -217,3 +216,7 @@ $string['weeknext'] = 'Next week';
$string['weekthis'] = 'This week';
$string['yesterday'] = 'Yesterday';
$string['youcandeleteallrepeats'] = 'This event is part of a repeating event series. You can delete this event only, or all {$a} events in the series at once.';
// Deprecated since Moodle 2.8.
$string['hidden'] = 'hidden';

6
lang/en/deprecated.txt Normal file
View File

@ -0,0 +1,6 @@
hidden,core_badges
hidden,core_calendar
hidden,core_portfolio
hidden,core_question
hidden,core_repository
hidden,core_role

View File

@ -83,7 +83,6 @@ $string['format_richhtml'] = 'HTML with attachments';
$string['format_spreadsheet'] = 'Spreadsheet';
$string['format_text'] = 'Plain text';
$string['format_video'] = 'Video';
$string['hidden'] = 'Hidden';
$string['highdbsizethreshold'] = 'High transfer dbsize';
$string['highdbsizethresholddesc'] = 'Number of db records over which will be considered to take a high amount of time to transfer';
$string['highfilesizethreshold'] = 'High transfer filesize';
@ -181,3 +180,7 @@ $string['unknownplugin'] = 'Unknown (may have since been removed by an administr
$string['wait'] = 'Wait';
$string['wanttowait_high'] = 'It is not recommended that you wait for this transfer to complete, but you can if you\'re sure and know what you\'re doing';
$string['wanttowait_moderate'] = 'Do you want to wait for this transfer? It might take a few minutes';
// Deprecated since Moodle 2.8.
$string['hidden'] = 'Hidden';

View File

@ -333,7 +333,6 @@ $string['generalfeedback'] = 'General feedback';
$string['generalfeedback_help'] = 'General feedback is shown to the student after they have completed the question. Unlike specific feedback, which depends on the question type and what response the student gave, the same general feedback text is shown to all students.
You can use the general feedback to give students a fully worked answer and perhaps a link to more information they can use if they did not understand the questions.';
$string['hidden'] = 'Hidden';
$string['hintn'] = 'Hint {no}';
$string['hintnoptions'] = 'Hint {no} options';
$string['hinttext'] = 'Hint text';
@ -436,3 +435,7 @@ $string['whichtries'] = 'Which tries';
$string['withselected'] = 'With selected';
$string['xoutofmax'] = '{$a->mark} out of {$a->max}';
$string['yougotnright'] = 'You have correctly selected {$a->num}.';
// Deprecated since Moodle 2.8.
$string['hidden'] = 'Hidden';

View File

@ -126,7 +126,6 @@ $string['foldernotfound'] = 'Folder not found';
$string['folderrecurse'] = 'Folder can not be moved to it\'s own subfolder';
$string['getfile'] = 'Select this file';
$string['getfiletimeout'] = 'Get file timeout';
$string['hidden'] = 'Hidden';
$string['help'] = 'Help';
$string['choosealink'] = 'Choose a link...';
$string['chooselicense'] = 'Choose license';
@ -238,3 +237,7 @@ $string['unzipped'] = 'Unzipped successfully';
$string['wrongcontext'] = 'You cannot access to this context';
$string['xhtmlerror'] = 'You are probably using XHTML strict header, some YUI Component doesn\'t work in this mode, please turn it off in moodle';
$string['ziped'] = 'Compress folder successfully';
// Deprecated since Moodle 2.8.
$string['hidden'] = 'Hidden';

View File

@ -218,7 +218,6 @@ $string['grade:unlock'] = 'Unlock grades or items';
$string['grade:view'] = 'View own grades';
$string['grade:viewall'] = 'View grades of other users';
$string['grade:viewhidden'] = 'View hidden grades for owner';
$string['hidden'] = 'Hidden';
$string['highlightedcellsshowdefault'] = 'The permissions highlighted in the table below are the defaults for the role archetype currently selected above.';
$string['highlightedcellsshowinherit'] = 'The highlighted cells in the table below show the permission (if any) that will be inherited. Apart from the capabilities whose permission you actually want to alter, you should leave everything set to Inherit.';
$string['checkglobalpermissions'] = 'Check system permissions';
@ -423,3 +422,7 @@ $string['whydoesuserhavecap'] = 'Why does {$a->fullname} have capability {$a->ca
$string['whydoesusernothavecap'] = 'Why does {$a->fullname} not have capability {$a->capability} in context {$a->context}?';
$string['xroleassignments'] = '{$a}\'s role assignments';
$string['xuserswiththerole'] = 'Users with the role "{$a->role}"';
// Deprecated since Moodle 2.8.
$string['hidden'] = 'Hidden';

View File

@ -61,6 +61,17 @@ interface core_string_manager {
*/
public function string_exists($identifier, $component);
/**
* Has string been deprecated?
*
* Usually checked only inside get_string() to display debug warnings.
*
* @param string $identifier The identifier of the string to search for
* @param string $component The module the string is associated with
* @return bool true if deprecated
*/
public function string_deprecated($identifier, $component);
/**
* Returns a localised list of all country names, sorted by country keys.
* @param bool $returnall return all or just enabled

View File

@ -79,6 +79,19 @@ class core_string_manager_install implements core_string_manager {
return (strpos($str, '[[') === false);
}
/**
* Has string been deprecated?
*
* No deprecated string in installation, unused strings are simply removed.
*
* @param string $identifier The identifier of the string to search for
* @param string $component The module the string is associated with
* @return bool true if deprecated
*/
public function string_deprecated($identifier, $component) {
return false;
}
/**
* Get String returns a requested string
*

View File

@ -47,6 +47,8 @@ class core_string_manager_standard implements core_string_manager {
protected $translist;
/** @var cache stores list of available translations */
protected $menucache;
/** @var array list of cached deprecated strings */
protected $cacheddeprecated;
/**
* Create new instance of string manager
@ -206,6 +208,57 @@ class core_string_manager_standard implements core_string_manager {
return $string;
}
/**
* Parses all deprecated.txt in all plugins lang locations and returns the list of deprecated strings.
*
* Static variable is used for caching, this function is only called in dev environment.
*
* @return array of deprecated strings in the same format they appear in deprecated.txt files: "identifier,component"
* where component is a normalised component (i.e. "core_moodle", "mod_assign", etc.)
*/
protected function load_deprecated_strings() {
global $CFG;
if ($this->cacheddeprecated !== null) {
return $this->cacheddeprecated;
}
$this->cacheddeprecated = array();
$content = '';
$filename = $CFG->dirroot . '/lang/en/deprecated.txt';
if (file_exists($filename)) {
$content .= file_get_contents($filename);
}
foreach (core_component::get_plugin_types() as $plugintype => $plugintypedir) {
foreach (core_component::get_plugin_list($plugintype) as $pluginname => $plugindir) {
$filename = $plugindir.'/lang/en/deprecated.txt';
if (file_exists($filename)) {
$content .= "\n". file_get_contents($filename);
}
}
}
$strings = preg_split('/\s*\n\s*/', $content, -1, PREG_SPLIT_NO_EMPTY);
$this->cacheddeprecated = array_flip($strings);
return $this->cacheddeprecated;
}
/**
* Has string been deprecated?
*
* Usually checked only inside get_string() to display debug warnings.
*
* @param string $identifier The identifier of the string to search for
* @param string $component The module the string is associated with
* @return bool true if deprecated
*/
public function string_deprecated($identifier, $component) {
$deprecated = $this->load_deprecated_strings();
list($plugintype, $pluginname) = core_component::normalize_component($component);
return isset($deprecated[$identifier . ',' . $plugintype . '_' . $pluginname]);
}
/**
* Does the string actually exist?
*
@ -234,6 +287,8 @@ class core_string_manager_standard implements core_string_manager {
* @return string The String !
*/
public function get_string($identifier, $component = '', $a = null, $lang = null) {
global $CFG;
$this->countgetstring++;
// There are very many uses of these time formatting strings without the 'langconfig' component,
// it would not be reasonable to expect that all of them would be converted during 2.0 migration.
@ -279,7 +334,7 @@ class core_string_manager_standard implements core_string_manager {
// Devs need to learn to purge all caches after any change or disable $CFG->langstringcache.
if (!isset($string[$identifier])) {
// The string is still missing - should be fixed by developer.
if (debugging('', DEBUG_DEVELOPER)) {
if ($CFG->debugdeveloper) {
list($plugintype, $pluginname) = core_component::normalize_component($component);
if ($plugintype === 'core') {
$file = "lang/en/{$component}.php";
@ -324,6 +379,16 @@ class core_string_manager_standard implements core_string_manager {
}
}
if ($CFG->debugdeveloper) {
// Display a debugging message if sting exists but was deprecated.
if ($this->string_deprecated($identifier, $component)) {
list($plugintype, $pluginname) = core_component::normalize_component($component);
debugging("String [{$identifier},{$plugintype}_{$pluginname}] is deprecated. ".
'Either you should no longer be using that string, or the string has been incorrectly deprecated, in which case you should report this as a bug. '.
'Please refer to https://docs.moodle.org/dev/String_deprecation', DEBUG_DEVELOPER);
}
}
return $string;
}

View File

@ -67,6 +67,48 @@ class core_string_manager_standard_testcase extends advanced_testcase {
// Descendant of an orphaned language (N/A < bb < bc).
$this->assertSame(array('bb', 'bc'), $stringman->get_language_dependencies('bc'));
}
public function test_deprecated_strings() {
$stringman = get_string_manager();
// Check non-deprecated string.
$this->assertFalse($stringman->string_deprecated('hidden', 'grades'));
// Check deprecated string.
$this->assertTrue($stringman->string_deprecated('hidden', 'repository'));
$this->assertTrue($stringman->string_exists('hidden', 'repository'));
$this->assertDebuggingNotCalled();
$this->assertEquals('Hidden', get_string('hidden', 'repository'));
$this->assertDebuggingCalled('String [hidden,core_repository] is deprecated. '.
'Either you should no longer be using that string, or the string has been incorrectly deprecated, in which case you should report this as a bug. '.
'Please refer to https://docs.moodle.org/dev/String_deprecation');
}
/**
* This test is a built-in validation of deprecated.txt files in lang locations.
*
* It will fail if the string in the wrong format or non-existing (mistyped) string was deprecated.
*/
public function test_validate_deprecated_strings_files() {
global $CFG;
$stringman = get_string_manager();
$teststringman = testable_core_string_manager::instance($CFG->langotherroot, $CFG->langlocalroot, array());
$allstrings = $teststringman->get_all_deprecated_strings();
foreach ($allstrings as $string) {
if (!preg_match('/^(.*),(.*)$/', $string, $matches) ||
clean_param($matches[2], PARAM_COMPONENT) !== $matches[2]) {
$this->fail('String "'.$string.'" appearing in one of the lang/en/deprecated.txt files does not have correct syntax');
}
list($pluginttype, $pluginname) = core_component::normalize_component($matches[2]);
if ($matches[2] !== $pluginttype . '_' . $pluginname) {
$this->fail('String "'.$string.'" appearing in one of the lang/en/deprecated.txt files does not have normalised component name');
}
if (!$stringman->string_exists($matches[1], $matches[2])) {
$this->fail('String "'.$string.'" appearing in one of the lang/en/deprecated.txt files does not exist');
}
}
}
}
@ -101,4 +143,8 @@ class testable_core_string_manager extends core_string_manager_standard {
return new testable_core_string_manager($otherroot, $localroot, $usecache, $translist, $menucache);
}
public function get_all_deprecated_strings() {
return array_flip($this->load_deprecated_strings());
}
}