Index: trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php |
— | — | @@ -10,7 +10,8 @@ |
11 | 11 | * 'forminput' is called as: |
12 | 12 | * |
13 | 13 | * {{#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}} |
15 | 16 | * |
16 | 17 | * This function returns HTML representing a form to let the user enter the |
17 | 18 | * name of a page to be added or edited using a Semantic Forms form. All |
— | — | @@ -26,6 +27,10 @@ |
27 | 28 | * (you can only use one). To autcomplete on all pages in the main (blank) |
28 | 29 | * namespace, specify "autocomplete on namespace=main". |
29 | 30 | * |
| 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 | + * |
30 | 35 | * Example: to create an input to add or edit a page with a form called |
31 | 36 | * 'User' within a namespace also called 'User', and to have the form |
32 | 37 | * preload with the page called 'UserStub', you could call the following: |
— | — | @@ -255,6 +260,7 @@ |
256 | 261 | // set defaults |
257 | 262 | $inFormName = $inValue = $inButtonStr = $inQueryStr = ''; |
258 | 263 | $inAutocompletionSource = ''; |
| 264 | + $inRemoteAutocompletion = false; |
259 | 265 | $inSize = 25; |
260 | 266 | $classStr = ""; |
261 | 267 | // assign params - support unlabelled params, for backwards compatibility |
— | — | @@ -282,6 +288,8 @@ |
283 | 289 | } elseif ( $param_name == 'autocomplete on namespace' ) { |
284 | 290 | $inAutocompletionSource = $value; |
285 | 291 | $autocompletion_type = 'namespace'; |
| 292 | + } elseif ( $param_name == 'remote autocompletion' ) { |
| 293 | + $inRemoteAutocompletion = true; |
286 | 294 | } elseif ( $param_name == null && $value == 'popup' |
287 | 295 | && version_compare( $wgVersion, '1.16', '>=' )) { |
288 | 296 | self::loadScriptsForPopupForm( $parser ); |
— | — | @@ -299,8 +307,27 @@ |
300 | 308 | $inQueryStr = $param; |
301 | 309 | } |
302 | 310 | |
| 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). |
303 | 328 | $input_num = 1; |
304 | | - if ( ! empty( $inAutocompletionSource ) ) { |
| 329 | + if ( empty( $inAutocompletionSource ) ) { |
| 330 | + $formInputAttrs['class'] = 'formInput'; |
| 331 | + } else { |
305 | 332 | self::$num_autocompletion_inputs++; |
306 | 333 | $input_num = self::$num_autocompletion_inputs; |
307 | 334 | // place the necessary Javascript on the page, and |
— | — | @@ -311,37 +338,23 @@ |
312 | 339 | $parser->disableCache(); |
313 | 340 | SFUtils::addJavascriptAndCSS(); |
314 | 341 | } |
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 | + } |
318 | 355 | } |
319 | 356 | |
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"; |
326 | 358 | |
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 | | - } |
346 | 359 | // if the form start URL looks like "index.php?title=Special:FormStart" |
347 | 360 | // (i.e., it's in the default URL style), add in the title as a |
348 | 361 | // hidden value |