/** * This is a hacky way how to populate a forum at lang.moodle.org with commits into the core * * @param mlang_stage $stage * @param string $commitmsg * @param string $committer * @param string $committeremail * @param string $commithash * @param string $fullcommitmsg * @return void */ function amos_core_commit_notify(mlang_stage $stage, $commitmsg, $committer, $committeremail, $commithash, $fullcommitmsg) { global $CFG; $DB; require_once $CFG->dirroot . '/mod/forum/lib.php'; if ($CFG->wwwroot !== 'http://lang.moodle.org') { // this is intended for lang.moodle.org portal only return; } if (!$stage->has_component()) { // nothing to commit return; } // these are hard-coded values of a forum to inject commit messages into $courseid = 2; // course 'Translating Moodle' $cmid = 7; // forum 'Notification of string changes' $userid = 2; // user 'AMOS bot' $cm = get_coursemodule_from_id('forum', $cmid); $discussion = new stdclass(); $discussion->course = $courseid; $discussion->forum = $cm->instance; $discussion->name = substr(s('[AMOS commit] ' . $commitmsg), 0, 255); $discussion->message = 'Author: ' . $committer . "\n"; $discussion->message .= $fullcommitmsg . "\n\n"; $discussion->message .= 'http://git.moodle.org/gw?p=moodle.git;a=commit;h=' . $commithash . "\n"; $discussion->message .= 'http://github.com/moodle/moodle/commit/' . $commithash . "\n\n"; $standardplugins = local_amos_standard_plugins(); foreach ($stage->get_iterator() as $component) { foreach ($component->get_iterator() as $string) { if ($string->deleted) { $sign = '- '; } else { $sign = '+ '; } if (isset($standardplugins[$component->version->dir][$component->name])) { $name = $standardplugins[$component->version->dir][$component->name]; } else { $name = $component->name; } $discussion->message .= $sign . $component->version->dir . ' en [' . $string->id . ',' . $name . "]\n"; } } $discussion->message = s($discussion->message); $discussion->messageformat = FORMAT_MOODLE; $discussion->messagetrust = 0; $discussion->attachments = null; $discussion->mailnow = 1; $message = null; forum_add_discussion($discussion, null, $message, $userid); }
function definition() { global $USER; $mform = $this->_form; // Commits filter $mform->addElement('header', 'logfiltercommits', get_string('logfiltercommits', 'local_amos')); // Committed after $mform->addElement('date_time_selector', 'committedafter', get_string('logfiltercommittedafter', 'local_amos'), array('optional' => true, 'timezone' => 'UTC', 'applydst' => false)); $mform->setDefault('committedafter', $USER->lastlogin); // Committed before $mform->addElement('date_time_selector', 'committedbefore', get_string('logfiltercommittedbefore', 'local_amos'), array('optional' => true, 'timezone' => 'UTC', 'applydst' => false)); $mform->setAdvanced('committedbefore'); // Committer $committers = get_users_by_capability(get_system_context(), 'local/amos:commit', user_picture::fields('u'), 'lastname, firstname'); $users = array('' => ''); foreach ($committers as $committer) { $users[$committer->id] = s(fullname($committer) . ' <' . $committer->email . '>'); } $usergrp[] = $mform->createElement('select', 'userid', '', $users); $usergrp[] = $mform->createElement('text', 'userinfo', ''); $mform->setType('userinfo', PARAM_NOTAGS); $mform->addGroup($usergrp, 'usergrp', get_string('logfilterusergrp', 'local_amos'), get_string('logfilterusergrpor', 'local_amos'), false); $mform->setAdvanced('usergrp'); // Source $sources = array('' => '', 'git' => get_string('logfiltersourcegit', 'local_amos'), 'amos' => get_string('logfiltersourceamos', 'local_amos'), 'revclean' => get_string('logfiltersourcerevclean', 'local_amos'), 'commitscript' => get_string('logfiltersourcecommitscript', 'local_amos'), 'fixdrift' => get_string('logfiltersourcefixdrift', 'local_amos'), 'bot' => get_string('logfiltersourcebot', 'local_amos')); $mform->addElement('select', 'source', get_string('logfiltersource', 'local_amos'), $sources); $mform->setAdvanced('source'); // Commit message $mform->addElement('text', 'commitmsg', get_string('logfiltercommitmsg', 'local_amos')); $mform->setAdvanced('commitmsg'); // Commit hash $mform->addElement('text', 'commithash', get_string('logfiltercommithash', 'local_amos')); $mform->setAdvanced('commithash'); // Strings filter $mform->addElement('header', 'logfilterstrings', get_string('logfilterstrings', 'local_amos')); // Branch $branchgrp = array(); foreach (mlang_version::list_all() as $version) { $branchgrp[] = $mform->createElement('checkbox', $version->code, '', $version->label); } $mform->addGroup($branchgrp, 'branch', get_string('logfilterbranch', 'local_amos'), ' '); foreach (mlang_version::list_all() as $version) { if ($version->current) { $mform->setDefault('branch[' . $version->code . ']', 1); } } // Lang $langgrp = array(); $langgrp[] = $mform->createElement('checkbox', 'langenabled', '', get_string('enable')); $langgrp[] = $mform->createElement('select', 'lang', '', mlang_tools::list_languages(), array('multiple' => 'multiple', 'size' => 5)); $mform->addGroup($langgrp, 'langgrp', get_string('logfilterlang', 'local_amos'), '<br />', false); $mform->setDefault('lang', array('en', current_language())); $mform->disabledIf('lang', 'langenabled'); // does not seem to work for multiple selects :-/ $mform->setAdvanced('langgrp'); // Components $optionscore = array(); $optionsstandard = array(); $optionscontrib = array(); $standard = array(); foreach (local_amos_standard_plugins() as $plugins) { $standard = array_merge($standard, $plugins); } foreach (mlang_tools::list_components() as $componentname => $undefined) { if (isset($standard[$componentname])) { if ($standard[$componentname] === 'core' or substr($standard[$componentname], 0, 5) === 'core_') { $optionscore[$componentname] = $standard[$componentname]; } else { $optionsstandard[$componentname] = $standard[$componentname]; } } else { $optionscontrib[$componentname] = $componentname; } } asort($optionscore); asort($optionsstandard); asort($optionscontrib); $options = array(get_string('pluginclasscore', 'local_amos') => $optionscore, get_string('pluginclassstandard', 'local_amos') => $optionsstandard, get_string('pluginclassnonstandard', 'local_amos') => $optionscontrib); $componentgrp = array(); $componentgrp[] = $mform->createElement('checkbox', 'componentenabled', '', get_string('enable')); $componentgrp[] = $mform->createElement('selectgroups', 'component', '', $options, array('multiple' => 'multiple', 'size' => 5)); $mform->addGroup($componentgrp, 'componentgrp', get_string('logfiltercomponent', 'local_amos'), '<br />', false); $mform->disabledIf('component', 'componentenabled'); // does not seem to work for multiple selects :-/ $mform->setAdvanced('componentgrp'); // Stringid $mform->addElement('text', 'stringid', get_string('logfilterstringid', 'local_amos')); $mform->setType('stringid', PARAM_STRINGID); $mform->setAdvanced('stringid'); // Submit $mform->addElement('submit', 'submit', get_string('logfiltershow', 'local_amos')); $mform->closeHeaderBefore('submit'); }
* Parameters: * --execute - execute required steps to make AMOS and Git repo synced * * @package local * @subpackage amos * @copyright 2011 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('CLI_SCRIPT', true); require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php'; require_once $CFG->dirroot . '/local/amos/cli/config.php'; require_once $CFG->dirroot . '/local/amos/mlanglib.php'; require_once $CFG->dirroot . '/local/amos/locallib.php'; require_once $CFG->libdir . '/clilib.php'; list($options, $unrecognized) = cli_get_params(array('execute' => false)); $plugins = local_amos_standard_plugins(); $stage = new mlang_stage(); foreach ($plugins as $versionnumber => $plugintypes) { $version = mlang_version::by_dir($versionnumber); if ($version->branch == 'MOODLE_23_STABLE') { $gitbranch = 'origin/master'; } else { $gitbranch = 'origin/' . $version->branch; } foreach ($plugintypes as $legacyname => $frankenstylename) { // moodle.org was replaced with a local plugin and strings were dropped from 2.0 and 2.1 if ($legacyname == 'moodle.org') { continue; } // prepare an empty component containing the fixes $fixcomponent = new mlang_component($legacyname, 'en', $version);
/** * Initialize data * * @param mlang_version $version we are generating page for * @param array $packinfo data structure prepared by cli/export-zip.php */ public function __construct(mlang_version $version, array $packinfo) { $this->version = $version; $this->packinfo = fullclone($packinfo); $this->timemodified = time(); $this->percents = array('0' => 0, '40' => 0, '60' => 0, '80' => 0); // percents => number of langpacks // get the number of strings for standard plugins // only the standard plugins are taken into statistics calculation $standard = local_amos_standard_plugins(); $english = array(); // holds the number of English strings per component $nontranslatable = array(); // holds the number of strings per component that can not be translated via AMOS // and therefore we should consider them as translated when calculating the ratio foreach ($standard[$this->version->dir] as $componentname => $unused) { $component = mlang_component::from_snapshot($componentname, 'en', $this->version); $english[$componentname] = $component->get_number_of_strings(); $this->totalenglish += $english[$componentname]; foreach ($component->get_iterator() as $string) { if (substr($string->id, -5) === '_link') { if (isset($nontranslatable[$componentname])) { $nontranslatable[$componentname]++; } else { $nontranslatable[$componentname] = 1; } } } $component->clear(); } foreach ($this->packinfo as $langcode => $info) { if ($langcode !== 'en') { $this->numoflangpacks++; } $langpack = new stdclass(); $langpack->langname = $info['langname']; $langpack->filename = $langcode . '.zip'; $langpack->filesize = $info['filesize']; $langpack->modified = $info['modified']; if (!empty($info['parent'])) { $langpack->parent = $info['parent']; } else { $langpack->parent = 'en'; } // calculate the translation statistics if ($langpack->parent == 'en') { $langpack->totaltranslated = 0; foreach ($info['numofstrings'] as $component => $translated) { if (!empty($nontranslatable[$component])) { $translated += $nontranslatable[$component]; } if (isset($standard[$this->version->dir][$component])) { $langpack->totaltranslated += min($translated, $english[$component]); } } if ($this->totalenglish == 0) { $langpack->ratio = null; } else { $langpack->ratio = $langpack->totaltranslated / $this->totalenglish; if ($langpack->ratio > 0.8) { $this->percents['80']++; } elseif ($langpack->ratio > 0.6) { $this->percents['60']++; } elseif ($langpack->ratio > 0.4) { $this->percents['40']++; } else { $this->percents['0']++; } } } else { $langpack->totaltranslated = 0; foreach ($info['numofstrings'] as $component => $translated) { $langpack->totaltranslated += $translated; } $langpack->ratio = null; } $this->langpacks[$langcode] = $langpack; } }
/** * Render repository records * * @param local_amos_log $records of stdclass full amos repository records * @return string HTML */ protected function render_local_amos_log(local_amos_log $log) { if ($log->numofcommits == 0) { return $this->heading(get_string('nologsfound', 'local_amos')); } $a = (object) array('found' => $log->numofcommits, 'limit' => local_amos_log::LIMITCOMMITS); if ($log->numofcommits > local_amos_log::LIMITCOMMITS) { $output = $this->heading(get_string('numofcommitsabovelimit', 'local_amos', $a)); } else { $output = $this->heading(get_string('numofcommitsunderlimit', 'local_amos', $a)); } $a = (object) array('strings' => $log->numofstrings, 'commits' => count($log->commits)); $output .= $this->heading(get_string('numofmatchingstrings', 'local_amos', $a)); $standard = array(); foreach (local_amos_standard_plugins() as $plugins) { $standard = array_merge($standard, $plugins); } foreach ($log->commits as $commit) { $o = ''; $o .= "Date: " . self::commit_datetime($commit->timecommitted) . "\n"; $o .= "Author: " . s($commit->userinfo) . "\n"; $o .= "Source: " . $commit->source . "\n"; if ($commit->source == 'git') { $o .= "Commit: " . $commit->commithash . "\n"; } $o .= "\n"; $o .= s($commit->commitmsg); $o .= "\n"; $o .= "\n"; foreach ($commit->strings as $string) { if ($string->deleted) { $o .= "- "; } else { $o .= "+ "; } if (isset($standard[$string->component])) { $component = $standard[$string->component]; } else { $component = $string->component; } $o .= sprintf('%4s', $string->branch) . ' '; $o .= sprintf('%-8s', $string->lang) . ' '; $o .= ' [' . $string->stringid . ',' . $component . "]\n"; } $output .= html_writer::tag('pre', $o, array('class' => 'preformatted logrecord')); } return $output; }