/** * Returns the HTML for a storysubmission form. * * @param Parser $parser * @param array $args * * @return HTML */ private static function getFrom(Parser $parser, array $args) { global $wgUser, $wgStyleVersion, $wgScriptPath, $wgStylePath; global $egStoryboardScriptPath, $egStorysubmissionWidth, $egStoryboardMaxStoryLen, $egStoryboardMinStoryLen; $maxLen = array_key_exists('maxlength', $args) && is_int($args['maxlength']) ? $args['maxlength'] : $egStoryboardMaxStoryLen; $minLen = array_key_exists('minlength', $args) && is_int($args['minlength']) ? $args['minlength'] : $egStoryboardMinStoryLen; efStoryboardAddJSLocalisation($parser); // Loading a seperate JS file would be overkill for just these 3 lines, and be bad for performance. $parser->getOutput()->addHeadItem(Html::linkedStyle("{$egStoryboardScriptPath}/storyboard.css?{$wgStyleVersion}") . Html::linkedScript("{$egStoryboardScriptPath}/storyboard.js?{$wgStyleVersion}") . Html::linkedScript("{$wgStylePath}/common/jquery.min.js?{$wgStyleVersion}") . Html::linkedScript("{$egStoryboardScriptPath}/jquery/jquery.validate.js?{$wgStyleVersion}") . Html::inlineScript(<<<EOT \$(function() { \tdocument.getElementById( 'storysubmission-button' ).disabled = true; \tstbValidateStory( document.getElementById('storytext'), {$minLen}, {$maxLen}, 'storysubmission-charlimitinfo', 'storysubmission-button' ) \t\$("#storyform").validate({ \t\tmessages: { \t\t\tstorytitle: { \t\t\t\tremote: jQuery.validator.format( stbMsg( 'storyboard-alreadyexistschange' ) ) \t\t\t} \t\t} \t});\t\t });\t\t\t EOT )); $fieldSize = 50; $width = StoryboardUtils::getDimension($args, 'width', $egStorysubmissionWidth); $formBody = "<table width='{$width}'>"; $defaultName = ''; $defaultEmail = ''; if ($wgUser->isLoggedIn()) { $defaultName = $wgUser->getRealName() !== '' ? $wgUser->getRealName() : $wgUser->getName(); $defaultEmail = $wgUser->getEmail(); } $formBody .= '<tr>' . Html::element('td', array('width' => '100%'), wfMsg('storyboard-yourname')) . '<td>' . Html::input('name', $defaultName, 'text', array('size' => $fieldSize, 'class' => 'required', 'maxlength' => 255, 'minlength' => 2)) . '</td></tr>'; $formBody .= '<tr>' . Html::element('td', array('width' => '100%'), wfMsg('storyboard-location')) . '<td>' . Html::input('location', '', 'text', array('size' => $fieldSize, 'maxlength' => 255, 'minlength' => 2)) . '</td></tr>'; $formBody .= '<tr>' . Html::element('td', array('width' => '100%'), wfMsg('storyboard-occupation')) . '<td>' . Html::input('occupation', '', 'text', array('size' => $fieldSize, 'maxlength' => 255, 'minlength' => 4)) . '</td></tr>'; $formBody .= '<tr>' . Html::element('td', array('width' => '100%'), wfMsg('storyboard-email')) . '<td>' . Html::input('email', $defaultEmail, 'text', array('size' => $fieldSize, 'class' => 'required email', 'size' => $fieldSize, 'maxlength' => 255)) . '</td></tr>'; $formBody .= '<tr>' . Html::element('td', array('width' => '100%'), wfMsg('storyboard-storytitle')) . '<td>' . Html::input('storytitle', '', 'text', array('size' => $fieldSize, 'class' => 'required storytitle', 'maxlength' => 255, 'minlength' => 2, 'remote' => "{$wgScriptPath}/api.php?format=json&action=storyexists")) . '</td></tr>'; $formBody .= '<tr><td colspan="2">' . wfMsg('storyboard-story') . 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' )"), null) . '</td></tr>'; // TODO: add upload functionality $formBody .= '<tr><td colspan="2"><input type="checkbox" id="storyboard-agreement" /> ' . $parser->recursiveTagParse(htmlspecialchars(wfMsg('storyboard-agreement'))) . '</td></tr>'; $formBody .= '<tr><td colspan="2">' . Html::input('storysubmission-button', wfMsg('htmlform-submit'), 'submit', array('id' => 'storysubmission-button')) . '</td></tr>'; $formBody .= '</table>'; $formBody .= Html::hidden('wpStoryEditToken', $wgUser->editToken()); if (!array_key_exists('language', $args) || !array_key_exists($args['language'], Language::getLanguageNames())) { global $wgContLanguageCode; $args['language'] = $wgContLanguageCode; } $formBody .= Html::hidden('lang', $args['language']); return Html::rawElement('form', array('id' => 'storyform', 'name' => 'storyform', 'method' => 'post', 'action' => SpecialPage::getTitleFor('StorySubmission')->getFullURL(), 'onsubmit' => 'return stbValidateSubmission( "storyboard-agreement" );'), $formBody); }
private function addOutput() { global $wgOut, $wgRequest, $wgJsMimeType, $wgContLanguageCode, $wgUser; global $egStoryboardScriptPath; efStoryboardAddJSLocalisation(); $wgOut->addStyle($egStoryboardScriptPath . '/storyboard.css'); $wgOut->includeJQuery(); $wgOut->addScriptFile($egStoryboardScriptPath . "/jquery/jquery.ajaxscroll.js"); $wgOut->addScriptFile($egStoryboardScriptPath . '/storyboard.js'); // jQuery UI core and Tabs. $wgOut->addScriptFile($egStoryboardScriptPath . '/jquery/jquery-ui-1.7.2.custom.min.js'); $wgOut->addStyle($egStoryboardScriptPath . '/jquery/css/jquery-ui-1.7.2.custom.css'); $unpublished = htmlspecialchars(wfMsg('storyboard-unpublished')); $published = htmlspecialchars(wfMsg('storyboard-published')); $hidden = htmlspecialchars(wfMsg('storyboard-hidden')); $language = $wgRequest->getText('language', false); if (!$language) { $language = $wgContLanguageCode; } $canDelete = $wgUser->isAllowed('delete') ? 'true' : 'false'; $wgOut->addHTML(<<<EOT <div id="storyreview-tabs"> \t<ul> \t\t<li><a href="#{$unpublished}" id="{$unpublished}-tab">{$unpublished}</a></li> \t\t<li><a href="#{$published}" id="{$published}-tab">{$published}</a></li> \t\t<li><a href="#{$hidden}" id="{$hidden}-tab">{$hidden}</a></li> \t</ul> \t<div id="{$unpublished}"></div> \t<div id="{$published}"></div> \t<div id="{$hidden}"></div> </div> <script type="{$wgJsMimeType}"> \tvar storyboardLanguage = "{$language}"; \tvar storyboardCanDelete = {$canDelete}; \tjQuery( function() { \t\tjQuery( "#storyreview-tabs" ).tabs(); \t}); \t \tjQuery('#storyreview-tabs').bind( 'tabsshow', function( event, ui ) { \t\tstbShowReviewBoard( jQuery( ui.panel ), ui.index ); \t}); </script>\t EOT ); }
/** * Renders the storyboard tag. * * @param $input * @param array $args * @param Parser $parser * @param $frame * * @return array */ public static function render($input, array $args, Parser $parser, $frame) { global $wgScriptPath, $wgStylePath, $wgStyleVersion, $wgContLanguageCode; global $egStoryboardScriptPath, $egStoryboardWidth, $egStoryboardHeight; efStoryboardAddJSLocalisation($parser); // TODO: Combine+minfiy JS files, add switch to use combined+minified version $parser->getOutput()->addHeadItem(Html::linkedStyle("{$egStoryboardScriptPath}/storyboard.css?{$wgStyleVersion}") . Html::linkedScript("{$wgStylePath}/common/jquery.min.js?{$wgStyleVersion}") . Html::linkedScript("{$egStoryboardScriptPath}/jquery/jquery.ajaxscroll.js?{$wgStyleVersion}") . Html::linkedScript("{$egStoryboardScriptPath}/tags/Storyboard/storyboard.js?{$wgStyleVersion}") . Html::linkedScript("{$egStoryboardScriptPath}/storyboard.js?{$wgStyleVersion}")); $width = StoryboardUtils::getDimension($args, 'width', $egStoryboardWidth); $height = StoryboardUtils::getDimension($args, 'height', $egStoryboardHeight); $languages = Language::getLanguageNames(); if (array_key_exists('language', $args) && array_key_exists($args['language'], $languages)) { $language = $args['language']; } else { $language = $wgContLanguageCode; } $parser->getOutput()->addHeadItem(Html::inlineScript("var storyboardLanguage = '{$language}';")); $output = Html::element('div', array('class' => 'storyboard', 'style' => "height: {$height}; width: {$width};")); return array($output, 'noparse' => true, 'isHTML' => true); }
/** * 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¤tid={$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')) . "  <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 ); }