static function renderFormInput(&$parser) { global $wgHtml5; $params = func_get_args(); array_shift($params); // don't need the parser // set defaults $inFormName = $inValue = $inButtonStr = $inQueryStr = ''; $inQueryArr = array(); $positionalParameters = false; $inAutocompletionSource = ''; $inRemoteAutocompletion = false; $inSize = 25; $classStr = "sfFormInput"; $inPlaceholder = ""; // assign params - support unlabelled params, for backwards compatibility foreach ($params as $i => $param) { $elements = explode('=', $param, 2); // set param_name and value if (count($elements) > 1 && !$positionalParameters) { $param_name = trim($elements[0]); // parse (and sanitize) parameter values $value = trim($parser->recursiveTagParse($elements[1])); } else { $param_name = null; // parse (and sanitize) parameter values $value = trim($parser->recursiveTagParse($param)); } if ($param_name == 'form') { $inFormName = $value; } elseif ($param_name == 'size') { $inSize = $value; } elseif ($param_name == 'default value') { $inValue = $value; } elseif ($param_name == 'button text') { $inButtonStr = $value; } elseif ($param_name == 'query string') { // Change HTML-encoded ampersands directly to // URL-encoded ampersands, so that the string // doesn't get split up on the '&'. $inQueryStr = str_replace('&', '%26', $value); // "Decode" any other HTML tags. $inQueryStr = html_entity_decode($inQueryStr, ENT_QUOTES); parse_str($inQueryStr, $arr); $inQueryArr = SFUtils::array_merge_recursive_distinct($inQueryArr, $arr); } elseif ($param_name == 'autocomplete on category') { $inAutocompletionSource = $value; $autocompletion_type = 'category'; } elseif ($param_name == 'autocomplete on namespace') { $inAutocompletionSource = $value; $autocompletion_type = 'namespace'; } elseif ($param_name == 'remote autocompletion') { $inRemoteAutocompletion = true; } elseif ($param_name == 'placeholder') { $inPlaceholder = $value; } elseif ($param_name == null && $value == 'popup') { SFUtils::loadScriptsForPopupForm($parser); $classStr .= ' popupforminput'; } elseif ($param_name !== null && !$positionalParameters) { $value = urlencode($value); parse_str("{$param_name}={$value}", $arr); $inQueryArr = SFUtils::array_merge_recursive_distinct($inQueryArr, $arr); } elseif ($i == 0) { $inFormName = $value; $positionalParameters = true; } elseif ($i == 1) { $inSize = $value; } elseif ($i == 2) { $inValue = $value; } elseif ($i == 3) { $inButtonStr = $value; } elseif ($i == 4) { // Change HTML-encoded ampersands directly to // URL-encoded ampersands, so that the string // doesn't get split up on the '&'. $inQueryStr = str_replace('&', '%26', $value); parse_str($inQueryStr, $arr); $inQueryArr = SFUtils::array_merge_recursive_distinct($inQueryArr, $arr); } } $fs = SpecialPageFactory::getPage('FormStart'); $fs_url = $fs->getTitle()->getLocalURL(); $str = <<<END \t\t\t<form name="createbox" action="{$fs_url}" method="get" class="{$classStr}"> \t\t\t<p> END; $formInputAttrs = array('size' => $inSize); if ($wgHtml5) { $formInputAttrs['placeholder'] = $inPlaceholder; $formInputAttrs['autofocus'] = 'autofocus'; } // Now apply the necessary settings and Javascript, depending // on whether or not there's autocompletion (and whether the // autocompletion is local or remote). $input_num = 1; if (empty($inAutocompletionSource)) { $formInputAttrs['class'] = 'formInput'; } else { self::$num_autocompletion_inputs++; $input_num = self::$num_autocompletion_inputs; // place the necessary Javascript on the page, and // disable the cache (so the Javascript will show up) - // if there's more than one autocompleted #forminput // on the page, we only need to do this the first time if ($input_num == 1) { $parser->disableCache(); SFUtils::addJavascriptAndCSS($parser); } $inputID = 'input_' . $input_num; $formInputAttrs['id'] = $inputID; $formInputAttrs['class'] = 'autocompleteInput createboxInput formInput'; global $sfgMaxLocalAutocompleteValues; $autocompletion_values = SFUtils::getAutocompleteValues($inAutocompletionSource, $autocompletion_type); if (count($autocompletion_values) > $sfgMaxLocalAutocompleteValues || $inRemoteAutocompletion) { $formInputAttrs['autocompletesettings'] = $inAutocompletionSource; $formInputAttrs['autocompletedatatype'] = $autocompletion_type; } else { global $sfgAutocompleteValues; $sfgAutocompleteValues[$inputID] = $autocompletion_values; $formInputAttrs['autocompletesettings'] = $inputID; } } $str .= "\t" . Html::input('page_name', $inValue, 'text', $formInputAttrs) . "\n"; // if the form start URL looks like "index.php?title=Special:FormStart" // (i.e., it's in the default URL style), add in the title as a // hidden value if (($pos = strpos($fs_url, "title=")) > -1) { $str .= Html::hidden("title", urldecode(substr($fs_url, $pos + 6))); } if ($inFormName == '') { $str .= SFUtils::formDropdownHTML(); } else { $str .= Html::hidden("form", $inFormName); } // Recreate the passed-in query string as a set of hidden variables. if (!empty($inQueryArr)) { // query string has to be turned into hidden inputs. $query_components = explode('&', http_build_query($inQueryArr, '', '&')); foreach ($query_components as $query_component) { $var_and_val = explode('=', $query_component, 2); if (count($var_and_val) == 2) { $str .= Html::hidden(urldecode($var_and_val[0]), urldecode($var_and_val[1])); } } } $button_str = $inButtonStr != '' ? $inButtonStr : wfMessage('sf_formstart_createoredit')->escaped(); $str .= <<<END \t\t\t<input type="submit" value="{$button_str}" id="input_button_{$input_num}" class="forminput_button"/></p> \t\t\t</form> END; if (!empty($inAutocompletionSource)) { $str .= "\t\t\t" . Html::element('div', array('class' => 'page_name_auto_complete', 'id' => "div_{$input_num}"), ' ') . "\n"; } // hack to remove newline from beginning of output, thanks to // http://jimbojw.com/wiki/index.php?title=Raw_HTML_Output_from_a_MediaWiki_Parser_Function return $parser->insertStripItem($str, $parser->mStripState); }
static function renderFormInput(&$parser) { $params = func_get_args(); array_shift($params); // don't need the parser // Set defaults. $inFormName = $inValue = $inButtonStr = $inQueryStr = ''; $inQueryArr = array(); $inAutocompletionSource = ''; $inRemoteAutocompletion = false; $inSize = 25; $classStr = "sfFormInput"; $inPlaceholder = null; $inAutofocus = true; // Assign params. foreach ($params as $i => $param) { $elements = explode('=', $param, 2); // Set param name and value. if (count($elements) > 1) { $paramName = trim($elements[0]); // Parse (and sanitize) parameter values. // We call recursivePreprocess() and not // recursiveTagParse() so that URL values will // not be turned into links. $value = trim($parser->recursivePreprocess($elements[1])); } else { $paramName = trim($param); $value = null; } if ($paramName == 'form') { $inFormName = $value; } elseif ($paramName == 'size') { $inSize = $value; } elseif ($paramName == 'default value') { $inValue = $value; } elseif ($paramName == 'button text') { $inButtonStr = $value; } elseif ($paramName == 'query string') { // Change HTML-encoded ampersands directly to // URL-encoded ampersands, so that the string // doesn't get split up on the '&'. $inQueryStr = str_replace('&', '%26', $value); // "Decode" any other HTML tags. $inQueryStr = html_entity_decode($inQueryStr, ENT_QUOTES); parse_str($inQueryStr, $arr); $inQueryArr = SFUtils::array_merge_recursive_distinct($inQueryArr, $arr); } elseif ($paramName == 'autocomplete on category') { $inAutocompletionSource = $value; $autocompletionType = 'category'; } elseif ($paramName == 'autocomplete on namespace') { $inAutocompletionSource = $value; $autocompletionType = 'namespace'; } elseif ($paramName == 'remote autocompletion') { $inRemoteAutocompletion = true; } elseif ($paramName == 'placeholder') { $inPlaceholder = $value; } elseif ($paramName == 'popup') { SFUtils::loadScriptsForPopupForm($parser); $classStr .= ' popupforminput'; } elseif ($paramName == 'no autofocus') { $inAutofocus = false; } else { $value = urlencode($value); parse_str("{$paramName}={$value}", $arr); $inQueryArr = SFUtils::array_merge_recursive_distinct($inQueryArr, $arr); } } $formInputAttrs = array('size' => $inSize); if ($inPlaceholder != null) { $formInputAttrs['placeholder'] = $inPlaceholder; } if ($inAutofocus) { $formInputAttrs['autofocus'] = 'autofocus'; } // Now apply the necessary settings and Javascript, depending // on whether or not there's autocompletion (and whether the // autocompletion is local or remote). $input_num = 1; if (empty($inAutocompletionSource)) { $formInputAttrs['class'] = 'formInput'; } else { self::$num_autocompletion_inputs++; $input_num = self::$num_autocompletion_inputs; // Place the necessary Javascript on the page, and // disable the cache (so the Javascript will show up) - // if there's more than one autocompleted #forminput // on the page, we only need to do this the first time. if ($input_num == 1) { $parser->disableCache(); $output = $parser->getOutput(); $output->addModules('ext.semanticforms.main'); } $inputID = 'input_' . $input_num; $formInputAttrs['id'] = $inputID; $formInputAttrs['class'] = 'autocompleteInput createboxInput formInput'; global $sfgMaxLocalAutocompleteValues; $autocompletion_values = SFUtils::getAutocompleteValues($inAutocompletionSource, $autocompletionType); if (count($autocompletion_values) > $sfgMaxLocalAutocompleteValues || $inRemoteAutocompletion) { $formInputAttrs['autocompletesettings'] = $inAutocompletionSource; $formInputAttrs['autocompletedatatype'] = $autocompletionType; } else { global $sfgAutocompleteValues; $sfgAutocompleteValues[$inputID] = $autocompletion_values; $formInputAttrs['autocompletesettings'] = $inputID; } } $formContents = Html::input('page_name', $inValue, 'text', $formInputAttrs); // If the form start URL looks like "index.php?title=Special:FormStart" // (i.e., it's in the default URL style), add in the title as a // hidden value $fs = SpecialPageFactory::getPage('FormStart'); $fsURL = $fs->getTitle()->getLocalURL(); if (($pos = strpos($fsURL, "title=")) > -1) { $formContents .= Html::hidden("title", urldecode(substr($fsURL, $pos + 6))); } if ($inFormName == '') { $formContents .= SFUtils::formDropdownHTML(); } else { $formContents .= Html::hidden("form", $inFormName); } // Recreate the passed-in query string as a set of hidden // variables. if (!empty($inQueryArr)) { // Query string has to be turned into hidden inputs. $query_components = explode('&', http_build_query($inQueryArr, '', '&')); foreach ($query_components as $query_component) { $var_and_val = explode('=', $query_component, 2); if (count($var_and_val) == 2) { $formContents .= Html::hidden(urldecode($var_and_val[0]), urldecode($var_and_val[1])); } } } $buttonStr = $inButtonStr != '' ? $inButtonStr : wfMessage('sf_formstart_createoredit')->escaped(); $formContents .= " " . Html::input(null, $buttonStr, 'submit', array('id' => "input_button_{$input_num}", 'class' => 'forminput_button')); $str = "\t" . Html::rawElement('form', array('name' => 'createbox', 'action' => $fsURL, 'method' => 'get', 'class' => $classStr), '<p>' . $formContents . '</p>') . "\n"; if (!empty($inAutocompletionSource)) { $str .= "\t\t\t" . Html::element('div', array('class' => 'page_name_auto_complete', 'id' => "div_{$input_num}"), ' ') . "\n"; } // Hack to remove newline from beginning of output, thanks to // http://jimbojw.com/wiki/index.php?title=Raw_HTML_Output_from_a_MediaWiki_Parser_Function return $parser->insertStripItem($str, $parser->mStripState); }