r76310 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76309‎ | r76310 | r76311 >
Date:16:02, 8 November 2010
Author:yaron
Status:deferred
Tags:
Comment:
Moved two static helper functions, getAutocompleteValues() and getValuesArray(), here from SF_FormInputs.php
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_Utils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_Utils.php
@@ -425,6 +425,42 @@
426426 return $pages;
427427 }
428428
 429+ /**
 430+ * Creates an array of values that match the specified source name and type,
 431+ * for use by both Javascript autocompletion and comboboxes.
 432+ */
 433+ static function getAutocompleteValues( $source_name, $source_type ) {
 434+ $names_array = array();
 435+ // the query depends on whether this is a property, category, concept
 436+ // or namespace
 437+ if ( $source_type == 'property' || $source_type == 'attribute' || $source_type == 'relation' ) {
 438+ $names_array = self::getAllValuesForProperty( $source_name );
 439+ } elseif ( $source_type == 'category' ) {
 440+ $names_array = self::getAllPagesForCategory( $source_name, 10 );
 441+ } elseif ( $source_type == 'concept' ) {
 442+ $names_array = self::getAllPagesForConcept( $source_name );
 443+ } else { // i.e., $source_type == 'namespace'
 444+ // switch back to blank for main namespace
 445+ if ( $source_name == "Main" )
 446+ $source_name = "";
 447+ $names_array = self::getAllPagesForNamespace( $source_name );
 448+ }
 449+ return $names_array;
 450+ }
 451+
 452+ /**
 453+ * Helper function to get an array of values out of what may be either
 454+ * an array or a delimited string
 455+ */
 456+ static function getValuesArray( $value, $delimiter ) {
 457+ if ( is_array( $value ) ) {
 458+ return $value;
 459+ } else {
 460+ // remove extra spaces
 461+ return array_map( 'trim', explode( $delimiter, $value ) );
 462+ }
 463+ }
 464+
429465 static function getValuesFromExternalURL( $external_url_alias, $substring ) {
430466 global $sfgAutocompletionURLs;
431467 if ( empty( $sfgAutocompletionURLs ) ) return array();

Status & tagging log