Example #1
0
 /**
  * Returns the form data as set by explicit permalink
  *
  * @see self::set_permalink()
  * @return object|null
  */
 protected function get_data_permalink()
 {
     $ispermalink = optional_param('t', false, PARAM_INT);
     if (empty($ispermalink)) {
         return null;
     }
     $data = new stdclass();
     $data->version = array();
     $fver = optional_param('v', '', PARAM_RAW);
     $fver = explode(',', $fver);
     $fver = clean_param($fver, PARAM_INT);
     if (!empty($fver) and is_array($fver)) {
         foreach (mlang_version::list_all() as $version) {
             if (in_array($version->code, $fver)) {
                 $data->version[] = $version->code;
             }
         }
     }
     $data->language = array();
     $flng = optional_param('l', '', PARAM_RAW);
     if ($flng == '*') {
         // all languages
         foreach (mlang_tools::list_languages(false) as $langcode => $langname) {
             $data->language[] = $langcode;
         }
     } else {
         $flng = explode(',', $flng);
         $flng = clean_param($flng, PARAM_SAFEDIR);
         if (!empty($flng) and is_array($flng)) {
             foreach ($flng as $language) {
                 // todo if valid language code
                 $data->language[] = $language;
             }
         }
     }
     $data->component = array();
     $fcmp = optional_param('c', '', PARAM_RAW);
     if ($fcmp == '*') {
         // all components
         foreach (mlang_tools::list_components() as $component => $undefined) {
             $data->component[] = $component;
         }
     } else {
         $fcmp = explode(',', $fcmp);
         $fcmp = clean_param($fcmp, PARAM_FILE);
         if (!empty($fcmp) and is_array($fcmp)) {
             foreach ($fcmp as $component) {
                 // todo if valid component
                 $data->component[] = $component;
             }
         }
     }
     $data->missing = optional_param('m', false, PARAM_BOOL);
     $data->helps = optional_param('h', false, PARAM_BOOL);
     $data->substring = optional_param('s', '', PARAM_RAW);
     $data->substringregex = optional_param('r', false, PARAM_BOOL);
     $data->substringcs = optional_param('i', false, PARAM_BOOL);
     $data->stringidpartial = optional_param('p', false, PARAM_BOOL);
     if ($data->stringidpartial) {
         // in this case, the stringid can start with a non a-z
         $data->stringid = trim(optional_param('d', '', PARAM_NOTAGS));
     } else {
         $data->stringid = trim(optional_param('d', '', PARAM_STRINGID));
     }
     $data->stagedonly = optional_param('g', false, PARAM_BOOL);
     $data->greylistedonly = optional_param('o', false, PARAM_BOOL);
     $data->withoutgreylisted = optional_param('w', false, PARAM_BOOL);
     // reset the paginator to the first page for permalinks
     $data->page = 1;
     return $data;
 }
Example #2
0
 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');
 }
Example #3
0
 /**
  * Renders the stage
  *
  * @param local_amos_stage $stage
  * @return string
  */
 protected function render_local_amos_stage(local_amos_stage $stage)
 {
     global $CFG;
     $table = new html_table();
     $table->id = 'amosstage';
     $table->head = array(get_string('stagestring', 'local_amos'), get_string('stageoriginal', 'local_amos'), get_string('stagelang', 'local_amos'), get_string('stagetranslation', 'local_amos') . $this->help_icon('stagetranslation', 'local_amos'));
     $table->colclasses = array('stringinfo', 'original', 'lang', 'translation');
     $standard = array();
     foreach (local_amos_standard_plugins() as $plugins) {
         $standard = array_merge($standard, $plugins);
     }
     $committable = 0;
     foreach ($stage->strings as $string) {
         $cells = array();
         // string identification
         if (isset($standard[$string->component])) {
             $componentname = $standard[$string->component];
         } else {
             $componentname = $string->component;
         }
         $stringinfo = html_writer::tag('span', $string->version, array('class' => 'version'));
         $stringinfo .= '&nbsp;[' . html_writer::tag('span', $string->stringid, array('class' => 'stringid')) . ',' . html_writer::tag('span', $componentname, array('class' => 'component')) . ']';
         $cells[0] = new html_table_cell($stringinfo);
         // original of the string
         $cells[1] = new html_table_cell(html_writer::tag('div', self::add_breaks(s($string->original)), array('class' => 'preformatted')));
         // the language in which the original is displayed
         $cells[2] = new html_table_cell($string->language);
         // the current and the new translation
         $unstageurl = new moodle_url('/local/amos/stage.php', array('unstage' => $string->stringid, 'component' => $string->component, 'branch' => $string->branch, 'lang' => $string->language));
         $unstagebutton = $this->single_button($unstageurl, get_string('unstage', 'local_amos'), 'post', array('class' => 'singlebutton protected unstagebutton'));
         if ($string->deleted) {
             // removal of the string
             $t = self::add_breaks(s($string->current));
             $t = html_writer::tag('div', $t, array('class' => 'preformatted'));
             $cells[3] = new html_table_cell($t . $unstagebutton);
             if ($string->committable) {
                 $committable++;
                 $cells[3]->attributes['class'] .= 'committable removal';
             } else {
                 $cells[3]->attributes['class'] .= 'uncommittable removal';
             }
         } else {
             if (trim($string->current) === trim($string->new)) {
                 // no difference
                 $t = self::add_breaks(s($string->current));
                 $t = html_writer::tag('div', $t, array('class' => 'preformatted'));
                 $cells[3] = new html_table_cell($t . $unstagebutton);
                 $cells[3]->attributes['class'] .= ' uncommittable nodiff';
             } else {
                 if (is_null($string->current)) {
                     // new translation
                     $t = $t = self::add_breaks(s($string->new));
                     $t = html_writer::tag('div', $t, array('class' => 'preformatted'));
                     $cells[3] = new html_table_cell($t . $unstagebutton);
                     if ($string->committable) {
                         $cells[3]->attributes['class'] .= ' committable new';
                         $committable++;
                     }
                     if (!$string->committable) {
                         $cells[3]->attributes['class'] .= ' uncommittable new';
                     }
                 } else {
                     // there is a difference
                     $c = s($string->current);
                     $n = s($string->new);
                     $x1 = explode(' ', $c);
                     $x2 = explode(' ', $n);
                     $t = '';
                     $diff = local_amos_simplediff($x1, $x2);
                     $numd = 0;
                     $numi = 0;
                     foreach ($diff as $k) {
                         // $diff is a sequence of chunks (words) $k
                         if (is_array($k)) {
                             if (!empty($k['d'])) {
                                 $kd = implode(' ', $k['d']);
                                 if (!empty($kd)) {
                                     $t .= '<del>' . $kd . '</del> ';
                                     $numd += count($k['d']);
                                 }
                             }
                             if (!empty($k['i'])) {
                                 $ki = implode(' ', $k['i']);
                                 if (!empty($ki)) {
                                     $t .= '<ins>' . $ki . '</ins> ';
                                     $numi += count($k['i']);
                                 }
                             }
                         } else {
                             $t .= $k . ' ';
                         }
                     }
                     if ($numi == 0 or $numd == 0 or $numd == 1 and $numi == 1) {
                         $cstyle = 'display:none;';
                         $nstyle = 'display:none;';
                         $tstyle = 'display:block;';
                     } else {
                         $cstyle = 'display:block;';
                         $nstyle = 'display:block;';
                         $tstyle = 'display:none;';
                     }
                     $n = html_writer::tag('ins', $n);
                     $n = html_writer::tag('div', self::add_breaks($n), array('class' => 'preformatted stringtext new', 'style' => $nstyle));
                     $c = html_writer::tag('del', $c);
                     $c = html_writer::tag('div', self::add_breaks($c), array('class' => 'preformatted stringtext current', 'style' => $cstyle));
                     $t = html_writer::tag('div', self::add_breaks($t), array('class' => 'preformatted stringtext diff', 'style' => $tstyle));
                     $difflink = html_writer::tag('div', '', array('class' => 'diffmode'));
                     $cells[3] = new html_table_cell($difflink . $n . $c . $t . $unstagebutton);
                     if ($string->committable) {
                         $cells[3]->attributes['class'] .= ' committable diff';
                         $committable++;
                     }
                     if (!$string->committable) {
                         $cells[3]->attributes['class'] .= ' uncommittable diff';
                     }
                 }
             }
         }
         $row = new html_table_row($cells);
         $table->data[] = $row;
     }
     $table = html_writer::table($table);
     $propagateform = '';
     $propagateform .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden'));
     $propagateform .= html_writer::empty_tag('input', array('name' => 'propagate', 'value' => 1, 'type' => 'hidden'));
     foreach (mlang_version::list_all() as $version) {
         if ($version->code < 2000) {
             continue;
         }
         $checkbox = html_writer::checkbox('ver[]', $version->code, true, $version->label);
         $propagateform .= html_writer::tag('div', $checkbox, array('class' => 'labelled_checkbox'));
     }
     $propagateform .= html_writer::empty_tag('input', array('value' => get_string('propagaterun', 'local_amos'), 'type' => 'submit'));
     $propagateform = html_writer::tag('div', $propagateform);
     $propagateform = html_writer::tag('form', $propagateform, array('method' => 'post', 'action' => $CFG->wwwroot . '/local/amos/stage.php'));
     $propagateform .= html_writer::tag('legend', get_string('propagate', 'local_amos') . $this->help_icon('propagate', 'local_amos'));
     $propagateform = html_writer::tag('fieldset', $propagateform, array('class' => 'propagateformwrapper protected'));
     $commitform = html_writer::label(get_string('commitmessage', 'local_amos'), 'commitmessage', false);
     $commitform .= html_writer::empty_tag('img', array('src' => $this->pix_url('req'), 'title' => 'Required', 'alt' => 'Required', 'class' => 'req'));
     $commitform .= html_writer::empty_tag('br');
     $commitform .= html_writer::tag('textarea', s($stage->presetmessage), array('id' => 'commitmessage', 'name' => 'message'));
     $commitform .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden'));
     $button = html_writer::empty_tag('input', array('value' => get_string('commitbutton', 'local_amos'), 'type' => 'submit'));
     $button = html_writer::tag('div', $button);
     $commitform = html_writer::tag('div', $commitform . $button);
     $commitform = html_writer::tag('form', $commitform, array('method' => 'post', 'action' => $CFG->wwwroot . '/local/amos/stage.php'));
     $commitform .= html_writer::tag('legend', get_string('commitstage', 'local_amos') . $this->help_icon('commitstage', 'local_amos'));
     $commitform = html_writer::tag('fieldset', $commitform, array('class' => 'commitformwrapper protected'));
     $a = new stdClass();
     $a->time = userdate(time(), get_string('strftimedaydatetime', 'langconfig'));
     $stashtitle = get_string('stashtitledefault', 'local_amos', $a);
     $stashform = html_writer::label(get_string('stashtitle', 'local_amos'), 'stashtitle', true);
     $stashform .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden'));
     $stashform .= html_writer::empty_tag('input', array('name' => 'new', 'value' => 1, 'type' => 'hidden'));
     $stashform .= html_writer::empty_tag('input', array('name' => 'name', 'value' => $stashtitle, 'type' => 'text', 'size' => 50, 'id' => 'stashtitle', 'maxlength' => 255));
     $stashform .= html_writer::empty_tag('input', array('value' => get_string('stashpush', 'local_amos'), 'type' => 'submit'));
     $stashform = html_writer::tag('div', $stashform);
     $stashform = html_writer::tag('form', $stashform, array('method' => 'post', 'action' => $CFG->wwwroot . '/local/amos/stash.php'));
     $stashform = html_writer::tag('div', $stashform, array('class' => 'stashformwrapper'));
     $submiturl = new moodle_url('/local/amos/stage.php', array('submit' => 1));
     $submitbutton = $this->single_button($submiturl, get_string('stagesubmit', 'local_amos'), 'post', array('class' => 'singlebutton submit'));
     $pruneurl = new moodle_url('/local/amos/stage.php', array('prune' => 1));
     $prunebutton = $this->single_button($pruneurl, get_string('stageprune', 'local_amos'), 'post', array('class' => 'singlebutton protected prune'));
     $rebaseurl = new moodle_url('/local/amos/stage.php', array('rebase' => 1));
     $rebasebutton = $this->single_button($rebaseurl, get_string('stagerebase', 'local_amos'), 'post', array('class' => 'singlebutton protected rebase'));
     $unstageallurl = new moodle_url('/local/amos/stage.php', array('unstageall' => 1));
     $unstageallbutton = $this->single_button($unstageallurl, get_string('stageunstageall', 'local_amos'), 'post', array('class' => 'singlebutton protected unstageall'));
     $i = 0;
     foreach ($stage->filterfields->fver as $fver) {
         $params['fver[' . $i . ']'] = $fver;
         $i++;
     }
     $i = 0;
     foreach ($stage->filterfields->flng as $flng) {
         $params['flng[' . $i . ']'] = $flng;
         $i++;
     }
     $i = 0;
     foreach ($stage->filterfields->fcmp as $fcmp) {
         $params['fcmp[' . $i . ']'] = $fcmp;
         $i++;
     }
     $params['fstg'] = 1;
     $params['__lazyform_amosfilter'] = 1;
     $editurl = new moodle_url('/local/amos/view.php', $params);
     $editbutton = $this->single_button($editurl, get_string('stageedit', 'local_amos'), 'post', array('class' => 'singlebutton edit'));
     if (empty($stage->strings)) {
         $output = $this->heading(get_string('stagestringsnone', 'local_amos'), 2, 'main', 'numberofstagedstrings');
         if ($stage->importform) {
             $legend = html_writer::tag('legend', get_string('importfile', 'local_amos') . $this->help_icon('importfile', 'local_amos'));
             ob_start();
             $stage->importform->display();
             $importform = ob_get_contents();
             ob_end_clean();
             $output .= html_writer::tag('fieldset', $legend . $importform, array('class' => 'wrappedmform importform'));
         }
         if ($stage->mergeform) {
             $legend = html_writer::tag('legend', get_string('mergestrings', 'local_amos') . $this->help_icon('mergestrings', 'local_amos'));
             ob_start();
             $stage->mergeform->display();
             $mergeform = ob_get_contents();
             ob_end_clean();
             $output .= html_writer::tag('fieldset', $legend . $mergeform, array('class' => 'wrappedmform mergeform'));
         }
         if ($stage->diffform) {
             $legend = html_writer::tag('legend', get_string('diffstrings', 'local_amos') . $this->help_icon('diffstrings', 'local_amos'));
             ob_start();
             $stage->diffform->display();
             $diffform = ob_get_contents();
             ob_end_clean();
             $output .= html_writer::tag('fieldset', $legend . $diffform, array('class' => 'wrappedmform diffform'));
         }
         if ($stage->executeform) {
             $legend = html_writer::tag('legend', get_string('script', 'local_amos') . $this->help_icon('script', 'local_amos'));
             ob_start();
             $stage->executeform->display();
             $executeform = ob_get_contents();
             ob_end_clean();
             $output .= html_writer::tag('fieldset', $legend . $executeform, array('class' => 'wrappedmform executeform'));
         }
     } else {
         $output = '';
         if (!empty($stage->stagedcontribution)) {
             $output .= $this->heading_with_help(get_string('contribstaged', 'local_amos', $stage->stagedcontribution), 'contribstagedinfo', 'local_amos');
         }
         $a = (object) array('staged' => count($stage->strings), 'committable' => $committable);
         if ($committable) {
             $output .= $this->heading(get_string('stagestringssome', 'local_amos', $a), 2, 'main', 'numberofstagedstrings');
         } else {
             $output .= $this->heading(get_string('stagestringsnocommit', 'local_amos', $a), 2, 'main', 'numberofstagedstrings');
         }
         unset($a);
         $justpropagated = optional_param('justpropagated', null, PARAM_INT);
         // usability hack to hide the propagator just after it was used
         if (is_null($justpropagated)) {
             $output .= $propagateform;
         } else {
             if ($justpropagated == 0) {
                 $output .= $this->heading(get_string('propagatednone', 'local_amos'));
             } else {
                 $output .= $this->heading(get_string('propagatedsome', 'local_amos', $justpropagated));
             }
         }
         if ($committable) {
             $output .= $commitform;
         }
         $legend = html_writer::tag('legend', get_string('stageactions', 'local_amos') . $this->help_icon('stageactions', 'local_amos'));
         $actionbuttons = $legend . $submitbutton . $editbutton;
         if ($committable) {
             $actionbuttons .= $prunebutton . $rebasebutton;
         }
         $actionbuttons .= $unstageallbutton;
         $output .= html_writer::tag('fieldset', $actionbuttons, array('class' => 'actionbuttons'));
         $legend = html_writer::tag('legend', get_string('stashactions', 'local_amos') . $this->help_icon('stashactions', 'local_amos'));
         $output .= html_writer::tag('fieldset', $legend . $stashform, array('class' => 'actionbuttons'));
         $output .= $table;
     }
     $output = html_writer::tag('div', $output, array('class' => 'stagewrapper'));
     return $output;
 }