mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
MDL-21696 Added new admin report for language customization
- Loading branch information
Showing
12 changed files
with
1,234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Defines the capabilities used by the Language customization admin report | ||
* | ||
* @package report | ||
* @subpackage customlang | ||
* @copyright 2010 David Mudrak <david@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
$capabilities = array( | ||
|
||
/* allows the user to view the current language customization */ | ||
'report/customlang:view' => array( | ||
'riskbitmask' => RISK_CONFIG, | ||
'captype' => 'read', | ||
'contextlevel' => CONTEXT_SYSTEM, | ||
'archetypes' => array( | ||
'manager' => CAP_ALLOW | ||
), | ||
), | ||
|
||
/* allows the user to edit the current language customization */ | ||
'report/customlang:edit' => array( | ||
'riskbitmask' => RISK_CONFIG | RISK_XSS, | ||
'captype' => 'write', | ||
'contextlevel' => CONTEXT_SYSTEM, | ||
'archetypes' => array( | ||
'manager' => CAP_ALLOW | ||
), | ||
), | ||
|
||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<XMLDB PATH="admin/report/customlang/db" VERSION="20100825" COMMENT="XMLDB file for Moodle admin/report/customlang" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd" | ||
> | ||
<TABLES> | ||
<TABLE NAME="customlang" COMMENT="Contains the working checkout of all strings and their customization" NEXT="customlang_components"> | ||
<FIELDS> | ||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="lang"/> | ||
<FIELD NAME="lang" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" COMMENT="The code of the language this string belongs to. Like en, cs or es" PREVIOUS="id" NEXT="componentid"/> | ||
<FIELD NAME="componentid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The id of the component" PREVIOUS="lang" NEXT="stringid"/> | ||
<FIELD NAME="stringid" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The identifier of the string" PREVIOUS="componentid" NEXT="original"/> | ||
<FIELD NAME="original" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false" COMMENT="English original of the string" PREVIOUS="stringid" NEXT="master"/> | ||
<FIELD NAME="master" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="Master translation of the string as is distributed in the official lang pack, null if not translated" PREVIOUS="original" NEXT="local"/> | ||
<FIELD NAME="local" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="Local customization of the string, null if not customized" PREVIOUS="master" NEXT="timemodified"/> | ||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The timestamp of when the original or master was recently modified" PREVIOUS="local" NEXT="timecustomized"/> | ||
<FIELD NAME="timecustomized" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The timestamp of when the value of the local translation was recently modified, null if not customized yet" PREVIOUS="timemodified" NEXT="outdated"/> | ||
<FIELD NAME="outdated" TYPE="int" LENGTH="3" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Either the English original or the master translation changed and the customization may be outdated" PREVIOUS="timecustomized" NEXT="modified"/> | ||
<FIELD NAME="modified" TYPE="int" LENGTH="3" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Has the string been modified via the translator?" PREVIOUS="outdated"/> | ||
</FIELDS> | ||
<KEYS> | ||
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="fk_component"/> | ||
<KEY NAME="fk_component" TYPE="foreign" FIELDS="componentid" REFTABLE="customlang_components" REFFIELDS="id" PREVIOUS="primary"/> | ||
</KEYS> | ||
<INDEXES> | ||
<INDEX NAME="uq_lang_component_string" UNIQUE="true" FIELDS="lang, componentid, stringid" COMMENT="For a given language and component, string identifiers must be unique"/> | ||
</INDEXES> | ||
</TABLE> | ||
<TABLE NAME="customlang_components" COMMENT="Contains the list of all installed plugins that provide their own language pack" PREVIOUS="customlang"> | ||
<FIELDS> | ||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/> | ||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The normalized name of the plugin" PREVIOUS="id" NEXT="version"/> | ||
<FIELD NAME="version" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The checked out version of the plugin, null of the version is unknown" PREVIOUS="name"/> | ||
</FIELDS> | ||
<KEYS> | ||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> | ||
</KEYS> | ||
</TABLE> | ||
</TABLES> | ||
</XMLDB> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* @package report | ||
* @subpackage customlang | ||
* @copyright 2010 David Mudrak <david@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); | ||
require_once($CFG->dirroot.'/'.$CFG->admin.'/report/customlang/locallib.php'); | ||
require_once($CFG->dirroot.'/'.$CFG->admin.'/report/customlang/filter_form.php'); | ||
|
||
require_login(SITEID, false); | ||
require_capability('report/customlang:edit', get_system_context()); | ||
|
||
$currentpage = optional_param('p', 0, PARAM_INT); | ||
$translatorsubmitted = optional_param('translatorsubmitted', 0, PARAM_BOOL); | ||
|
||
$PAGE->set_pagelayout('standard'); | ||
$PAGE->set_url('/admin/report/customlang/edit.php'); | ||
navigation_node::override_active_url(new moodle_url('/admin/report/customlang/index.php')); | ||
$PAGE->set_title(get_string('pluginname', 'report_customlang')); | ||
$PAGE->set_heading(get_string('pluginname', 'report_customlang')); | ||
//$PAGE->requires->js_init_call('M.report_customlang.init_translator', array(), true); | ||
|
||
// pre-output processing | ||
$filter = new report_customlang_filter_form($PAGE->url, null, 'post', '', array('class'=>'filterform')); | ||
$filterdata = report_customlang_utils::load_filter($USER); | ||
$filter->set_data($filterdata); | ||
|
||
if ($filter->is_cancelled()) { | ||
redirect($PAGE->url); | ||
|
||
} elseif ($submitted = $filter->get_data()) { | ||
report_customlang_utils::save_filter($submitted, $USER); | ||
redirect(new moodle_url($PAGE->url, array('p'=>0))); | ||
} | ||
|
||
if ($translatorsubmitted) { | ||
$strings = optional_param('cust', array(), PARAM_RAW); | ||
$updates = optional_param('updates', array(), PARAM_INT); | ||
$checkin = optional_param('savecheckin', false, PARAM_RAW); | ||
|
||
if ($checkin === false) { | ||
$nexturl = $PAGE->url; | ||
} else { | ||
$nexturl = new moodle_url('/admin/report/customlang/index.php', array('action'=>'checkin', 'sesskey'=>sesskey())); | ||
} | ||
|
||
if (!is_array($strings)) { | ||
$strings = array(); | ||
} | ||
$current = $DB->get_records_list('customlang', 'id', array_keys($strings)); | ||
$now = time(); | ||
|
||
foreach ($strings as $recordid => $customization) { | ||
$customization = trim($customization); | ||
|
||
if (empty($customization) and !is_null($current[$recordid]->local)) { | ||
$current[$recordid]->local = null; | ||
$current[$recordid]->modified = 1; | ||
$current[$recordid]->outdated = 0; | ||
$current[$recordid]->timecustomized = null; | ||
$DB->update_record('customlang', $current[$recordid]); | ||
continue; | ||
} | ||
|
||
if (empty($customization)) { | ||
continue; | ||
} | ||
|
||
if ($customization !== $current[$recordid]->local) { | ||
$current[$recordid]->local = $customization; | ||
$current[$recordid]->modified = 1; | ||
$current[$recordid]->outdated = 0; | ||
$current[$recordid]->timecustomized = $now; | ||
$DB->update_record('customlang', $current[$recordid]); | ||
continue; | ||
} | ||
} | ||
|
||
if (!is_array($updates)) { | ||
$updates = array(); | ||
} | ||
if (!empty($updates)) { | ||
list($sql, $params) = $DB->get_in_or_equal($updates); | ||
$DB->set_field_select('customlang', 'outdated', 0, "local IS NOT NULL AND id $sql", $params); | ||
} | ||
|
||
redirect($nexturl); | ||
} | ||
|
||
$translator = new report_customlang_translator($PAGE->url, current_language(), $filterdata, $currentpage); | ||
|
||
// output starts here | ||
$output = $PAGE->get_renderer('report_customlang'); | ||
$paginator = $output->paging_bar($translator->numofrows, $currentpage, report_customlang_translator::PERPAGE, $PAGE->url, 'p'); | ||
|
||
echo $output->header(); | ||
$filter->display(); | ||
echo $paginator; | ||
echo $output->render($translator); | ||
echo $paginator; | ||
echo $output->footer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* @package report | ||
* @subpackage customlang | ||
* @copyright 2010 David Mudrak <david@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot . '/lib/formslib.php'); | ||
|
||
/** | ||
* Form for filtering the strings to customize | ||
*/ | ||
class report_customlang_filter_form extends moodleform { | ||
|
||
function definition() { | ||
$mform = $this->_form; | ||
$current = $this->_customdata['current']; | ||
|
||
$mform->addElement('header', 'filtersettings', get_string('filter', 'report_customlang')); | ||
|
||
// Component | ||
$options = array(); | ||
foreach (report_customlang_utils::list_components() as $component => $normalized) { | ||
list($type, $plugin) = normalize_component($normalized); | ||
if ($type == 'core' and is_null($plugin)) { | ||
$plugin = 'moodle'; | ||
} | ||
$options[$type][$normalized] = $component.'.php'; | ||
} | ||
$mform->addElement('selectgroups', 'component', get_string('filtercomponent', 'report_customlang'), $options, | ||
array('multiple'=>'multiple', 'size'=>7)); | ||
|
||
// Customized only | ||
$mform->addElement('advcheckbox', 'customized', get_string('filtercustomized', 'report_customlang')); | ||
$mform->setType('customized', PARAM_BOOL); | ||
$mform->setDefault('customized', 0); | ||
|
||
// Only helps | ||
$mform->addElement('advcheckbox', 'helps', get_string('filteronlyhelps', 'report_customlang')); | ||
$mform->setType('helps', PARAM_BOOL); | ||
$mform->setDefault('helps', 0); | ||
|
||
// Modified only | ||
$mform->addElement('advcheckbox', 'modified', get_string('filtermodified', 'report_customlang')); | ||
$mform->setType('filtermodified', PARAM_BOOL); | ||
$mform->setDefault('filtermodified', 0); | ||
|
||
// Substring | ||
$mform->addElement('text', 'substring', get_string('filtersubstring', 'report_customlang')); | ||
$mform->setType('substring', PARAM_RAW); | ||
|
||
// String identifier | ||
$mform->addElement('text', 'stringid', get_string('filterstringid', 'report_customlang')); | ||
$mform->setType('stringid', PARAM_STRINGID); | ||
|
||
// Show strings - submit button | ||
$mform->addElement('submit', 'submit', get_string('filtershowstrings', 'report_customlang')); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Performs checkout of the strings into the translation table | ||
* | ||
* @package report | ||
* @subpackage customlang | ||
* @copyright 2010 David Mudrak <david@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); | ||
require_once($CFG->dirroot.'/'.$CFG->admin.'/report/customlang/locallib.php'); | ||
require_once($CFG->libdir.'/adminlib.php'); | ||
|
||
require_login(SITEID, false); | ||
require_capability('report/customlang:view', get_system_context()); | ||
|
||
$action = optional_param('action', '', PARAM_ALPHA); | ||
$confirm = optional_param('confirm', false, PARAM_BOOL); | ||
|
||
admin_externalpage_setup('reportcustomlang'); | ||
|
||
// pre-output actions | ||
if ($action === 'checkout') { | ||
require_sesskey(); | ||
require_capability('report/customlang:edit', get_system_context()); | ||
report_customlang_utils::checkout(current_language()); | ||
redirect(new moodle_url('/admin/report/customlang/edit.php')); | ||
} | ||
|
||
if ($action === 'checkin') { | ||
require_sesskey(); | ||
require_capability('report/customlang:edit', get_system_context()); | ||
|
||
if (!$confirm) { | ||
$output = $PAGE->get_renderer('report_customlang'); | ||
echo $output->header(); | ||
echo $output->heading(get_string('pluginname', 'report_customlang')); | ||
$numofmodified = report_customlang_utils::get_count_of_modified(current_language()); | ||
if ($numofmodified != 0) { | ||
echo $output->heading(get_string('modifiednum', 'report_customlang', $numofmodified), 3); | ||
echo $output->confirm(get_string('confirmcheckin', 'report_customlang'), | ||
new moodle_url($PAGE->url, array('action'=>'checkin', 'confirm'=>1)), $PAGE->url); | ||
} else { | ||
echo $output->heading(get_string('modifiedno', 'report_customlang', $numofmodified), 3); | ||
echo $output->continue_button($PAGE->url); | ||
} | ||
echo $output->footer(); | ||
die(); | ||
|
||
} else { | ||
report_customlang_utils::checkin(current_language()); | ||
redirect($PAGE->url); | ||
} | ||
} | ||
|
||
$output = $PAGE->get_renderer('report_customlang'); | ||
|
||
// output starts here | ||
echo $output->header(); | ||
echo $output->heading(get_string('pluginname', 'report_customlang')); | ||
|
||
echo $output->box($output->lang_menu(), 'langmenubox'); | ||
|
||
$numofmodified = report_customlang_utils::get_count_of_modified(current_language()); | ||
|
||
if ($numofmodified != 0) { | ||
echo $output->heading(get_string('modifiednum', 'report_customlang', $numofmodified), 3); | ||
} | ||
|
||
$menu = array(); | ||
if (has_capability('report/customlang:edit', get_system_context())) { | ||
$menu['checkout'] = array( | ||
'title' => get_string('checkout', 'report_customlang'), | ||
'url' => new moodle_url($PAGE->url, array('action' => 'checkout')), | ||
'method' => 'post', | ||
); | ||
if ($numofmodified != 0) { | ||
$menu['checkin'] = array( | ||
'title' => get_string('checkin', 'report_customlang'), | ||
'url' => new moodle_url($PAGE->url, array('action' => 'checkin')), | ||
'method' => 'post', | ||
); | ||
} | ||
} | ||
echo $output->render(new report_customlang_menu($menu)); | ||
|
||
echo $output->footer(); |
Oops, something went wrong.