public static function uploadableHTML($input_id, $delimiter = null, $default_filename = null, $cur_value = '', $other_args = array()) { $upload_window_page = SFUtils::getSpecialPage('UploadWindow'); $query_string = "sfInputID={$input_id}"; if ($delimiter != null) { $query_string .= "&sfDelimiter={$delimiter}"; } if ($default_filename != null) { $query_string .= "&wpDestFile={$default_filename}"; } $upload_window_url = $upload_window_page->getTitle()->getFullURL($query_string); $upload_label = wfMsg('upload'); // We need to set the size by default. $style = "width:650 height:500"; $cssClasses = array('sfFancyBox', 'sfUploadable'); $showPreview = array_key_exists('image preview', $other_args); if ($showPreview) { $cssClasses[] = 'sfImagePreview'; } $linkAttrs = array('href' => $upload_window_url, 'class' => implode(' ', $cssClasses), 'title' => $upload_label, 'rev' => $style, 'data-input-id' => $input_id); $text = "\t" . Html::element('a', $linkAttrs, $upload_label) . "\n"; if ($showPreview) { $text .= Html::rawElement('div', array('id' => $input_id . '_imagepreview', 'class' => 'sfImagePreviewWrapper'), self::getPreviewImage($cur_value)); } return $text; }
function createMarkup() { $title = Title::makeTitle(SF_NS_FORM, $this->mFormName); $fs = SFUtils::getSpecialPage('FormStart'); $form_start_url = SFUtils::titleURLString($fs->getTitle()) . "/" . $title->getPartialURL(); $form_description = wfMsgForContent('sf_form_docu', $this->mFormName, $form_start_url); $form_input = "{{#forminput:form=" . $this->mFormName; if (!is_null($this->mAssociatedCategory)) { $form_input .= "|autocomplete on category=" . $this->mAssociatedCategory; } $form_input .= "}}\n"; $text = <<<END <noinclude> {$form_description} {$form_input} </noinclude><includeonly> END; if (!empty($this->mPageNameFormula) || !empty($this->mCreateTitle) || !empty($this->mEditTitle)) { $text .= "{{{info"; if (!empty($this->mPageNameFormula)) { $text .= "|page name=" . $this->mPageNameFormula; } if (!empty($this->mCreateTitle)) { $text .= "|create title=" . $this->mCreateTitle; } if (!empty($this->mEditTitle)) { $text .= "|edit title=" . $this->mEditTitle; } $text .= "}}}\n"; } $text .= <<<END <div id="wikiPreview" style="display: none; padding-bottom: 25px; margin-bottom: 25px; border-bottom: 1px solid #AAAAAA;"></div> END; foreach ($this->mTemplates as $template) { $text .= $template->createMarkup() . "\n"; } $free_text_label = wfMsgForContent('sf_form_freetextlabel'); $text .= <<<END '''{$free_text_label}:''' {{{standard input|free text|rows=10}}} {{{standard input|summary}}} {{{standard input|minor edit}}} {{{standard input|watch}}} {{{standard input|save}}} {{{standard input|preview}}} {{{standard input|changes}}} {{{standard input|cancel}}} </includeonly> END; return $text; }
static function printAltFormsList( $alt_forms, $target_name ) { $text = ""; $fe = SFUtils::getSpecialPage( 'FormEdit' ); $fe_url = $fe->getTitle()->getFullURL(); $i = 0; foreach ( $alt_forms as $alt_form ) { if ( $i++ > 0 ) { $text .= ', '; } $text .= "<a href=\"$fe_url/$alt_form/$target_name\">" . str_replace( '_', ' ', $alt_form ) . '</a>'; } return $text; }
static function printAltFormsList($alt_forms, $target_name) { $text = ""; $fe = SFUtils::getSpecialPage('FormEdit'); $fe_url = $fe->getTitle()->getFullURL(); $i = 0; foreach ($alt_forms as $alt_form) { if ($i++ > 0) { $text .= ', '; } $altFormURL = $fe_url . '/' . rawurlencode($alt_form) . '/' . rawurlencode($target_name); $text .= Html::element('a', array('href' => $altFormURL), str_replace('_', ' ', $alt_form)); } return $text; }
/** * Helper function for formEditLink() - gets the 'default form' and * 'alternate form' properties for a page, and creates the * corresponding Special:FormEdit link, if any such properties are * defined */ static function getFormEditLinkForPage( $target_page_title, $page_name, $page_namespace ) { $default_forms = self::getFormsThatPagePointsTo( $page_name, $page_namespace, self::DEFAULT_FORM ); $alt_forms = self::getFormsThatPagePointsTo( $page_name, $page_namespace, self::ALTERNATE_FORM ); if ( ( count( $default_forms ) == 0 ) && ( count( $alt_forms ) == 0 ) ) { return null; } $fe = SFUtils::getSpecialPage( 'FormEdit' ); $fe_url = $fe->getTitle()->getLocalURL(); if ( count( $default_forms ) > 0 ) { $form_edit_url = $fe_url . "/" . $default_forms[0] . "/" . SFUtils::titleURLString( $target_page_title ); } else { $form_edit_url = $fe_url . "/" . SFUtils::titleURLString( $target_page_title ); } foreach ( $alt_forms as $i => $alt_form ) { $form_edit_url .= ( strpos( $form_edit_url, "?" ) ) ? "&" : "?"; $form_edit_url .= "alt_form[$i]=$alt_form"; } return $form_edit_url; }
static function createFormLink(&$parser, $specialPageName, $params) { // Set defaults. $inFormName = $inLinkStr = $inLinkType = $inTooltip = $inQueryStr = $inTargetName = ''; if ($specialPageName == 'RunQuery') { $inLinkStr = wfMessage('runquery')->text(); } $classStr = ""; $inQueryArr = array(); $positionalParameters = false; // assign params // - support unlabelled params, for backwards compatibility // - parse and sanitize all parameter values 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 == 'link text') { $inLinkStr = $value; } elseif ($param_name == 'link type') { $inLinkType = $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); parse_str($inQueryStr, $arr); $inQueryArr = self::array_merge_recursive_distinct($inQueryArr, $arr); } elseif ($param_name == 'tooltip') { $inTooltip = Sanitizer::decodeCharReferences($value); } elseif ($param_name == 'target') { $inTargetName = $value; } elseif ($param_name == null && $value == 'popup') { self::loadScriptsForPopupForm($parser); $classStr = 'popupformlink'; } elseif ($param_name !== null && !$positionalParameters) { $value = urlencode($value); parse_str("{$param_name}={$value}", $arr); $inQueryArr = self::array_merge_recursive_distinct($inQueryArr, $arr); } elseif ($i == 0) { $inFormName = $value; $positionalParameters = true; } elseif ($i == 1) { $inLinkStr = $value; } elseif ($i == 2) { $inLinkType = $value; } elseif ($i == 3) { // 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 = self::array_merge_recursive_distinct($inQueryArr, $arr); } } $ad = SFUtils::getSpecialPage($specialPageName); $link_url = $ad->getTitle()->getLocalURL() . "/{$inFormName}"; if (!empty($inTargetName)) { $link_url .= "/{$inTargetName}"; } $link_url = str_replace(' ', '_', $link_url); $hidden_inputs = ""; if (!empty($inQueryArr)) { // Special handling for the buttons - query string // has to be turned into hidden inputs. if ($inLinkType == 'button' || $inLinkType == 'post button') { $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) { $hidden_inputs .= Html::hidden(urldecode($var_and_val[0]), urldecode($var_and_val[1])); } } } else { $link_url .= strstr($link_url, '?') ? '&' : '?'; $link_url .= str_replace('+', '%20', http_build_query($inQueryArr, '', '&')); } } if ($inLinkType == 'button' || $inLinkType == 'post button') { $formMethod = $inLinkType == 'button' ? 'get' : 'post'; $str = Html::rawElement('form', array('action' => $link_url, 'method' => $formMethod, 'class' => $classStr), '<button ' . Html::expandAttributes(array('type' => 'submit', 'value' => $inLinkStr)) . '>' . $inLinkStr . '</button>' . $hidden_inputs); } else { // If a target page has been specified but it doesn't // exist, make it a red link. if (!empty($inTargetName)) { $targetTitle = Title::newFromText($inTargetName); if (is_null($targetTitle) || !$targetTitle->exists()) { $classStr .= " new"; } } $str = Html::rawElement('a', array('href' => $link_url, 'class' => $classStr, 'title' => $inTooltip), $inLinkStr); } return $str; }
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 = ""; $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); 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 = SFUtils::getSpecialPage('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; } // 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'; 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 .= 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}" /></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); }
/** * Helper function - returns a URL that includes Special:FormEdit. */ static function getFormEditURL($formName, $targetName) { $fe = SFUtils::getSpecialPage('FormEdit'); // Special handling for forms whose name contains a slash. if (strpos($formName, '/') !== false) { return $fe->getTitle()->getLocalURL(array('form' => $formName, 'target' => $targetName)); } return $fe->getTitle("{$formName}/{$targetName}")->getLocalURL(); }
/** * Helper function for formEditLink() - gets the 'default form' and * 'alternate form' properties for a page, and creates the * corresponding Special:FormEdit link, if any such properties are * defined */ static function getFormEditLinkForPage($target_page_title, $page_name, $page_namespace) { $default_forms = self::getFormsThatPagePointsTo($page_name, $page_namespace, self::DEFAULT_FORM); $alt_forms = self::getFormsThatPagePointsTo($page_name, $page_namespace, self::ALTERNATE_FORM); if (count($default_forms) == 0 && count($alt_forms) == 0) { return null; } $fe = SFUtils::getSpecialPage('FormEdit'); $fe_url = $fe->getTitle()->getLocalURL(); if (count($default_forms) > 0) { $form_edit_url = $fe_url . "/" . $default_forms[0] . "/" . SFUtils::titleURLString($target_page_title); } else { $form_edit_url = $fe_url . "/" . SFUtils::titleURLString($target_page_title); } foreach ($alt_forms as $i => $alt_form) { $form_edit_url .= strpos($form_edit_url, "?") ? "&" : "?"; $form_edit_url .= "alt_form[{$i}]={$alt_form}"; } // Add "redlink=1" to the query string, so that the user will // go to the actual page if it now exists. $form_edit_url .= strpos($form_edit_url, "?") ? "&" : "?"; $form_edit_url .= "redlink=1"; return $form_edit_url; }
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 ); }