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 ) { global $wgVersion; $params = func_get_args(); array_shift( $params ); // don't need the parser // set defaults $inFormName = $inValue = $inButtonStr = $inQueryStr = ''; $inAutocompletionSource = ''; $inRemoteAutocompletion = false; $inSize = 25; $classStr = ""; // assign params - support unlabelled params, for backwards compatibility foreach ( $params as $i => $param ) { $elements = explode( '=', $param, 2 ); $param_name = null; $value = trim( $param ); if ( count( $elements ) > 1 ) { $param_name = trim( $elements[0] ); $value = trim( $parser->recursiveTagParse( $elements[1] ) ); } 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' ) $inQueryStr = $value; 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 == null && $value == 'popup' ) { self::loadScriptsForPopupForm( $parser ); $classStr = 'popupforminput'; } elseif ( $i == 0 ) $inFormName = $param; elseif ( $i == 1 ) $inSize = $param; elseif ( $i == 2 ) $inValue = $param; elseif ( $i == 3 ) $inButtonStr = $param; elseif ( $i == 4 ) $inQueryStr = $param; } $fs = SFUtils::getSpecialPage( 'FormStart' ); $fs_url = $fs->getTitle()->getLocalURL(); $str = <<<END <form name="createbox" action="$fs_url" method="get" class="$classStr"> <p> END; $formInputAttrs = array( 'size' => $inSize ); // 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(); } $inputID = 'input_' . $input_num; $formInputAttrs['id'] = $inputID; $formInputAttrs['class'] = 'autocompleteInput createboxInput formInput'; if ( $inRemoteAutocompletion ) { $formInputAttrs['autocompletesettings'] = $inAutocompletionSource; $formInputAttrs['autocompletedatatype'] = $autocompletion_type; } else { $autocompletion_values = SFUtils::getAutocompleteValues( $inAutocompletionSource, $autocompletion_type ); 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 .= SFFormUtils::hiddenFieldHTML( "title", urldecode( substr( $fs_url, $pos + 6 ) ) ); } if ( $inFormName == '' ) { $str .= SFUtils::formDropdownHTML(); } else { $str .= SFFormUtils::hiddenFieldHTML( "form", $inFormName ); } // Recreate the passed-in query string as a set of hidden // variables. // Change HTML-encoded ampersands to URL-encoded ampersands, so // that the string doesn't get split up on the '&'. $inQueryStr = str_replace( '&', '%26', $inQueryStr ); $query_components = explode( '&', $inQueryStr ); foreach ( $query_components as $component ) { // change URL-encoded ampersands back $component = str_replace( '%26', '&', $component ); $subcomponents = explode( '=', $component, 2 ); $key = ( isset( $subcomponents[0] ) ) ? $subcomponents[0] : ''; $val = ( isset( $subcomponents[1] ) ) ? $subcomponents[1] : ''; if ( ! empty( $key ) ) { $str .= '\t\t\t' . Html::hidden( $key, $val ) . "\n"; } } $button_str = ( $inButtonStr != '' ) ? $inButtonStr : wfMsg( 'sf_formstart_createoredit' ); $str .= <<<END <input type="submit" value="$button_str" /></p> </form> END; if ( ! empty( $inAutocompletionSource ) ) { $str .= "\t\t\t" . Html::element( 'div', array( 'class' => 'page_name_auto_complete', 'id' => "div_$input_num", ), // it has to be <div></div>, not // <div />, to work properly - stick // in a space as the content ' ' ) . "\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 ); }
function execute($query) { global $wgOut, $wgRequest; $this->setHeaders(); $form_name = $wgRequest->getVal('form'); $target_namespace = $wgRequest->getVal('namespace'); $super_page = $wgRequest->getVal('super_page'); $params = $wgRequest->getVal('params'); // If the query string did not contain a form name, try the URL if (!$form_name) { $queryparts = explode('/', $query, 2); $form_name = isset($queryparts[0]) ? $queryparts[0] : ''; // If a target was specified, it means we should // redirect to 'FormEdit' for this target page. if (isset($queryparts[1])) { $target_name = $queryparts[1]; $this->doRedirect($form_name, $target_name, $params); } // Get namespace from the URL, if it's there. if ($namespace_label_loc = strpos($form_name, "/Namespace:")) { $target_namespace = substr($form_name, $namespace_label_loc + 11); $form_name = substr($form_name, 0, $namespace_label_loc); } } // Remove forbidden characters from the form name. $forbidden_chars = array('"', "'", '<', '>', '{', '}', '(', ')', '[', ']', '='); $form_name = str_replace($forbidden_chars, "", $form_name); // Get title of form. $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); // Handle submission of this form. $form_submitted = $wgRequest->getCheck('page_name'); if ($form_submitted) { $page_name = $wgRequest->getVal('page_name'); // This form can be used to create a sub-page for an // existing page if (!is_null($super_page) && $super_page !== '') { $page_name = "{$super_page}/{$page_name}"; } if ($page_name !== '') { // Append the namespace prefix to the page name, // if this namespace was not already entered. if (strpos($page_name, $target_namespace . ':') === false && !is_null($target_namespace)) { $page_name = $target_namespace . ':' . $page_name; } // If there was no page title, it's probably an // invalid page name, containing forbidden // characters - in that case, display an error // message. $page_title = Title::newFromText($page_name); if (!$page_title) { $wgOut->addHTML(htmlspecialchars(wfMsg('sf_formstart_badtitle', $page_name))); return; } else { $this->doRedirect($form_name, $page_name, $params); return; } } } if ((!$form_title || !$form_title->exists()) && $form_name !== '') { $text = Html::rawElement('p', array('class' => 'error'), wfMsgExt('sf_formstart_badform', 'parseinline', SFUtils::linkText(SF_NS_FORM, $form_name))) . "\n"; } else { if ($form_name === '') { $description = htmlspecialchars(wfMsg('sf_formstart_noform_docu', $form_name)); } else { $description = htmlspecialchars(wfMsg('sf_formstart_docu', $form_name)); } $text = <<<END \t<form action="" method="post"> \t<p>{$description}</p> \t<p><input type="text" size="40" name="page_name" /> END; // If no form was specified, display a dropdown letting // the user choose the form. if ($form_name === '') { $text .= SFUtils::formDropdownHTML(); } $text .= "\t</p>\n"; $text .= Html::hidden('namespace', $target_namespace); $text .= Html::hidden('super_page', $super_page); $text .= Html::hidden('params', $params); $text .= "\n\t" . Html::input(null, wfMsg('sf_formstart_createoredit'), 'submit') . "\n"; $text .= "\t</form>\n"; } $wgOut->addHTML($text); }
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); }