r99133 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99132‎ | r99133 | r99134 >
Date:20:01, 6 October 2011
Author:yaron
Status:deferred
Tags:
Comment:
Added support for 'remote autocompletion' parameter for #forminput; generally improved autocompletion code
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php
@@ -10,7 +10,8 @@
1111 * 'forminput' is called as:
1212 *
1313 * {{#forminput:form=|size=|default value=|button text=|query string=
14 - * |autocomplete on category=|autocomplete on namespace=}}
 14+ * |autocomplete on category=|autocomplete on namespace=
 15+ * |remote autocompletion}}
1516 *
1617 * This function returns HTML representing a form to let the user enter the
1718 * name of a page to be added or edited using a Semantic Forms form. All
@@ -26,6 +27,10 @@
2728 * (you can only use one). To autcomplete on all pages in the main (blank)
2829 * namespace, specify "autocomplete on namespace=main".
2930 *
 31+ * If the "remote autocompletion" parameter is added, autocompletion
 32+ * is done via an external URL, which can allow autocompletion on a much
 33+ * larger set of values.
 34+ *
3035 * Example: to create an input to add or edit a page with a form called
3136 * 'User' within a namespace also called 'User', and to have the form
3237 * preload with the page called 'UserStub', you could call the following:
@@ -255,6 +260,7 @@
256261 // set defaults
257262 $inFormName = $inValue = $inButtonStr = $inQueryStr = '';
258263 $inAutocompletionSource = '';
 264+ $inRemoteAutocompletion = false;
259265 $inSize = 25;
260266 $classStr = "";
261267 // assign params - support unlabelled params, for backwards compatibility
@@ -282,6 +288,8 @@
283289 } elseif ( $param_name == 'autocomplete on namespace' ) {
284290 $inAutocompletionSource = $value;
285291 $autocompletion_type = 'namespace';
 292+ } elseif ( $param_name == 'remote autocompletion' ) {
 293+ $inRemoteAutocompletion = true;
286294 } elseif ( $param_name == null && $value == 'popup'
287295 && version_compare( $wgVersion, '1.16', '>=' )) {
288296 self::loadScriptsForPopupForm( $parser );
@@ -299,8 +307,27 @@
300308 $inQueryStr = $param;
301309 }
302310
 311+ $fs = SpecialPage::getPage( 'FormStart' );
 312+ $fs_url = $fs->getTitle()->getLocalURL();
 313+ $str = <<<END
 314+ <form name="createbox" action="$fs_url" method="get" class="$classStr">
 315+ <p>
 316+
 317+END;
 318+ $formInputAttrs = array(
 319+ 'type' => 'text',
 320+ 'name' => 'page_name',
 321+ 'size' => $inSize,
 322+ 'value' => $inValue,
 323+ );
 324+
 325+ // Now apply the necessary settings and Javascript, depending
 326+ // on whether or not there's autocompletion (and whether the
 327+ // autocompletion is local or remote).
303328 $input_num = 1;
304 - if ( ! empty( $inAutocompletionSource ) ) {
 329+ if ( empty( $inAutocompletionSource ) ) {
 330+ $formInputAttrs['class'] = 'formInput';
 331+ } else {
305332 self::$num_autocompletion_inputs++;
306333 $input_num = self::$num_autocompletion_inputs;
307334 // place the necessary Javascript on the page, and
@@ -311,37 +338,23 @@
312339 $parser->disableCache();
313340 SFUtils::addJavascriptAndCSS();
314341 }
315 - $autocompletion_values = SFUtils::getAutocompleteValues( $inAutocompletionSource, $autocompletion_type );
316 - global $sfgAutocompleteValues;
317 - $sfgAutocompleteValues["input_$input_num"] = $autocompletion_values;
 342+
 343+ $inputID = 'input_' . $input_num;
 344+ $formInputAttrs['id'] = $inputID;
 345+ $formInputAttrs['class'] = 'autocompleteInput createboxInput formInput';
 346+ if ( $inRemoteAutocompletion ) {
 347+ $formInputAttrs['autocompletesettings'] = $inAutocompletionSource;
 348+ $formInputAttrs['autocompletedatatype'] = $autocompletion_type;
 349+ } else {
 350+ $autocompletion_values = SFUtils::getAutocompleteValues( $inAutocompletionSource, $autocompletion_type );
 351+ global $sfgAutocompleteValues;
 352+ $sfgAutocompleteValues[$inputID] = $autocompletion_values;
 353+ $formInputAttrs['autocompletesettings'] = $inputID;
 354+ }
318355 }
319356
320 - $fs = SpecialPage::getPage( 'FormStart' );
321 - $fs_url = $fs->getTitle()->getLocalURL();
322 - if ( empty( $inAutocompletionSource ) ) {
323 - $str = <<<END
324 - <form action="$fs_url" method="get" class="$classStr">
325 - <p>
 357+ $str .= "\t" . Xml::element( 'input', $formInputAttrs ) . "\n";
326358
327 -END;
328 - $str .= Xml::element( 'input',
329 - array( 'type' => 'text', 'name' => 'page_name', 'size' => $inSize, 'value' => $inValue, 'class' => 'formInput' ) );
330 - } else {
331 - $str = <<<END
332 - <form name="createbox" action="$fs_url" method="get" class="$classStr">
333 - <p>
334 -
335 -END;
336 - $str .= Xml::element( 'input', array(
337 - 'type' => 'text',
338 - 'name' => 'page_name',
339 - 'id' => 'input_' . $input_num,
340 - 'size' => $inSize,
341 - 'value' => $inValue,
342 - 'class' => 'autocompleteInput createboxInput formInput',
343 - 'autocompletesettings' => 'input_' . $input_num
344 - ) );
345 - }
346359 // if the form start URL looks like "index.php?title=Special:FormStart"
347360 // (i.e., it's in the default URL style), add in the title as a
348361 // hidden value