function getInputHTML($value)
 {
     if (!in_array($value, $this->mParams['options'])) {
         $this->mParams['options'][$value] = $value;
     }
     return parent::getInputHTML($value);
 }
Exemple #2
0
 function validate($value, $alldata)
 {
     # HTMLSelectField forces $value to be one of the options in the select
     # field, which is not useful here.  But we do want the validation further up
     # the chain
     $p = parent::validate($value[1], $alldata);
     if ($p !== true) {
         return $p;
     }
     if (isset($this->mParams['required']) && $this->mParams['required'] !== false && $value[1] === '') {
         return $this->msg('htmlform-required')->parse();
     }
     return true;
 }
Exemple #3
0
    /**
     * Outputs a form to edit the story with. Code based on <storysubmission>.
     *
     * @param $story
     */
    private function showStoryForm($story)
    {
        global $wgOut, $wgLang, $wgRequest, $wgUser, $wgScriptPath, $wgContLanguageCode;
        global $egStoryboardScriptPath, $egStorysubmissionWidth, $egStoryboardMaxStoryLen, $egStoryboardMinStoryLen;
        $wgOut->setPageTitle($story->story_title);
        efStoryboardAddJSLocalisation();
        $wgOut->addStyle($egStoryboardScriptPath . '/storyboard.css');
        $wgOut->includeJQuery();
        $wgOut->addScriptFile($egStoryboardScriptPath . '/jquery/jquery.validate.js');
        $wgOut->addScriptFile($egStoryboardScriptPath . '/storyboard.js');
        $fieldSize = 50;
        $width = $egStorysubmissionWidth;
        $maxLen = $wgRequest->getVal('maxlength');
        if (!is_int($maxLen)) {
            $maxLen = $egStoryboardMaxStoryLen;
        }
        $minLen = $wgRequest->getVal('minlength');
        if (!is_int($minLen)) {
            $minLen = $egStoryboardMinStoryLen;
        }
        $formBody = "<table width=\"{$width}\">";
        // The current value will be selected on page load with jQuery.
        $formBody .= '<tr>' . '<td width="100%"><label for="storystate">' . htmlspecialchars(wfMsg('storyboard-storystate')) . '</label></td><td>' . Html::rawElement('select', array('name' => 'storystate', 'id' => 'storystate'), '<option value="' . Storyboard_STORY_UNPUBLISHED . '">' . htmlspecialchars(wfMsg('storyboard-option-unpublished')) . '</option>' . '<option value="' . Storyboard_STORY_PUBLISHED . '">' . htmlspecialchars(wfMsg('storyboard-option-published')) . '</option>' . '<option value="' . Storyboard_STORY_HIDDEN . '">' . htmlspecialchars(wfMsg('storyboard-option-hidden')) . '</option>') . '</td></tr>';
        $languages = Language::getLanguageNames(false);
        $currentLang = array_key_exists($story->story_lang_code, $languages) ? $story->story_lang_code : $wgContLanguageCode;
        $options = array();
        ksort($languages);
        foreach ($languages as $code => $name) {
            $display = wfBCP47($code) . ' - ' . $name;
            $options[$display] = $code;
        }
        $languageSelector = new HTMLSelectField(array('name' => 'language', 'options' => $options));
        $formBody .= '<tr>' . Html::element('td', array('width' => '100%'), wfMsg('storyboard-language')) . '<td>' . $languageSelector->getInputHTML($currentLang) . '</td></tr>';
        $formBody .= '<tr>' . Html::element('td', array('width' => '100%'), wfMsg('storyboard-authorname')) . '<td>' . Html::input('name', $story->story_author_name, 'text', array('size' => $fieldSize, 'class' => 'required', 'minlength' => 2, 'maxlength' => 255)) . '</td></tr>';
        $formBody .= '<tr>' . Html::element('td', array('width' => '100%'), wfMsg('storyboard-authorlocation')) . '<td>' . Html::input('location', $story->story_author_location, 'text', array('size' => $fieldSize, 'maxlength' => 255, 'minlength' => 2)) . '</td></tr>';
        $formBody .= '<tr>' . Html::element('td', array('width' => '100%'), wfMsg('storyboard-authoroccupation')) . '<td>' . Html::input('occupation', $story->story_author_occupation, 'text', array('size' => $fieldSize, 'maxlength' => 255, 'minlength' => 4)) . '</td></tr>';
        $formBody .= '<tr>' . Html::element('td', array('width' => '100%'), wfMsg('storyboard-authoremail')) . '<td>' . Html::input('email', $story->story_author_email, 'text', array('size' => $fieldSize, 'maxlength' => 255, 'class' => 'required email')) . '</td></tr>';
        $formBody .= '<tr>' . '<td width="100%"><label for="storytitle">' . htmlspecialchars(wfMsg('storyboard-storytitle')) . '</label></td><td>' . Html::input('storytitle', $story->story_title, 'text', array('size' => $fieldSize, 'maxlength' => 255, 'minlength' => 2, 'id' => 'storytitle', 'class' => 'required storytitle', 'remote' => "{$wgScriptPath}/api.php?format=json&action=storyexists&currentid={$story->story_id}")) . '</td></tr>';
        $formBody .= '<tr><td colspan="2">' . wfMsg('storyboard-thestory') . Html::element('div', array('class' => 'storysubmission-charcount', 'id' => 'storysubmission-charlimitinfo'), wfMsgExt('storyboard-charsneeded', 'parsemag', $minLen)) . '<br />' . Html::element('textarea', array('id' => 'storytext', 'name' => 'storytext', 'rows' => 7, 'class' => 'required', 'onkeyup' => "stbValidateStory( this, {$minLen}, {$maxLen}, 'storysubmission-charlimitinfo', 'storysubmission-button' )"), $story->story_text) . '</td></tr>';
        $returnTo = $wgRequest->getVal('returnto');
        $query = "id={$story->story_id}";
        if ($returnTo) {
            $query .= "&returnto={$returnTo}";
        }
        $formBody .= '<tr><td colspan="2">' . Html::input('', wfMsg('htmlform-submit'), 'submit', array('id' => 'storysubmission-button')) . "&#160;&#160;<span class='editHelp'>" . Html::element('a', array('href' => $this->getTitle()->getLocalURL($query)), wfMsgExt('cancel', array('parseinline'))) . '</span>' . '</td></tr>';
        $formBody .= '</table>';
        $formBody .= Html::hidden('wpEditToken', $wgUser->editToken());
        $formBody .= Html::hidden('storyId', $story->story_id);
        $formBody = '<fieldset><legend>' . htmlspecialchars(wfMsgExt('storyboard-createdandmodified', 'parsemag', $wgLang->time($story->story_created), $wgLang->date($story->story_created), $wgLang->time($story->story_modified), $wgLang->date($story->story_modified))) . '</legend>' . $formBody . '</fieldset>';
        $query = "id={$story->story_id}";
        if ($returnTo) {
            $query .= "&returnto={$returnTo}";
        }
        $formBody = Html::rawElement('form', array('id' => 'storyform', 'name' => 'storyform', 'method' => 'post', 'action' => $this->getTitle()->getLocalURL($query)), $formBody);
        $wgOut->addHTML($formBody);
        $state = htmlspecialchars($story->story_state);
        $wgOut->addInlineScript(<<<EOT
jQuery(document).ready(function() {
\tjQuery('#storystate option[value="{$state}"]').attr('selected', 'selected');

\tjQuery("#storyform").validate({
\t\tmessages: {
\t\t\tstorytitle: {
\t\t\t\tremote: jQuery.validator.format( stbMsg( 'storyboard-alreadyexistschange' ) )
\t\t\t}
\t\t}
\t});
});

\$(
\tfunction() {
\t\tstbValidateStory( document.getElementById('storytext'), {$minLen}, {$maxLen}, 'storysubmission-charlimitinfo', 'storysubmission-button' )
\t}
);
jQuery(document).ready(function(){
\tjQuery("#storyform").validate();
});
EOT
);
    }
 /**
  * Builds up an HTML select for translation memory types with the provided name.
  * The value parameter allows setting which item should be selected.
  * 
  * @since 0.4
  * 
  * @param string $name
  * @param string $value
  * 
  * @return string
  */
 protected function getTypeSelector($name, $value)
 {
     $typeSelector = new HTMLSelectField(array('fieldname' => $name, 'options' => $this->getTypeOptions()));
     return $typeSelector->getInputHTML($value);
 }