Index: trunk/extensions/SemanticForms/includes/SF_AutocompleteAPI.php |
— | — | @@ -42,10 +42,6 @@ |
43 | 43 | } elseif ( !is_null( $concept ) ) { |
44 | 44 | $data = SFUtils::getAllPagesForConcept( $concept, $substr ); |
45 | 45 | } elseif ( !is_null( $namespace ) ) { |
46 | | - // Special handling for main (blank) namespace. |
47 | | - if ( $namespace == 'main' ) { |
48 | | - $namespace = ''; |
49 | | - } |
50 | 46 | $data = SFUtils::getAllPagesForNamespace( $namespace, $substr ); |
51 | 47 | } elseif ( !is_null( $external_url ) ) { |
52 | 48 | $data = SFUtils::getValuesFromExternalURL( $external_url, $substr ); |
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -584,32 +584,59 @@ |
585 | 585 | } |
586 | 586 | |
587 | 587 | public static function getAllPagesForNamespace( $namespace_name, $substring = null ) { |
588 | | - // cycle through all the namespace names for this language, and |
589 | | - // if one matches the namespace specified in the form, add the |
590 | | - // names of all the pages in that namespace to $names_array |
591 | | - global $wgContLang; |
| 588 | + global $wgContLang, $wgLanguageCode; |
| 589 | + |
| 590 | + // Cycle through all the namespace names for this language, and |
| 591 | + // if one matches the namespace specified in the form, get the |
| 592 | + // names of all the pages in that namespace. |
| 593 | + |
| 594 | + // Switch to blank for the string 'Main'. |
| 595 | + if ( $namespace_name == 'Main' || $namespace_name == 'main' ) { |
| 596 | + $namespace_name = ''; |
| 597 | + } |
| 598 | + $matchingNamespaceCode = null; |
592 | 599 | $namespaces = $wgContLang->getNamespaces(); |
593 | | - $db = wfGetDB( DB_SLAVE ); |
594 | | - $pages = array(); |
595 | | - foreach ( $namespaces as $ns_code => $ns_name ) { |
596 | | - if ( $ns_name == $namespace_name ) { |
597 | | - $conditions = "page_namespace = $ns_code"; |
598 | | - if ( $substring != null ) { |
599 | | - $substring = str_replace( ' ', '_', strtolower( $substring ) ); |
600 | | - $substring = str_replace( '_', '\_', $substring ); |
601 | | - $substring = str_replace( "'", "\'", $substring ); |
602 | | - $conditions .= " AND (LOWER(CONVERT(`page_title` USING utf8)) LIKE '$substring%' OR LOWER(CONVERT(`page_title` USING utf8)) LIKE '%\_$substring%')"; |
| 600 | + foreach ( $namespaces as $curNSCode => $curNSName ) { |
| 601 | + if ( $curNSName == $namespace_name ) { |
| 602 | + $matchingNamespaceCode = $curNSCode; |
| 603 | + } |
| 604 | + } |
| 605 | + |
| 606 | + // If that didn't find anything, and we're in a language |
| 607 | + // other than English, check English as well. |
| 608 | + if ( is_null( $matchingNamespaceCode ) && $wgLanguageCode != 'en' ) { |
| 609 | + $englishLang = Language::factory( 'en' ); |
| 610 | + $namespaces = $englishLang->getNamespaces(); |
| 611 | + foreach ( $namespaces as $curNSCode => $curNSName ) { |
| 612 | + if ( $curNSName == $namespace_name ) { |
| 613 | + $matchingNamespaceCode = $curNSCode; |
603 | 614 | } |
604 | | - $res = $db->select( 'page', |
605 | | - 'page_title', |
606 | | - $conditions, __METHOD__, |
607 | | - array( 'ORDER BY' => 'page_title' ) ); |
608 | | - while ( $row = $db->fetchRow( $res ) ) { |
609 | | - $pages[] = str_replace( '_', ' ', $row[0] ); |
610 | | - } |
611 | | - $db->freeResult( $res ); |
612 | 615 | } |
613 | 616 | } |
| 617 | + |
| 618 | + if ( is_null( $matchingNamespaceCode ) ) { |
| 619 | + return array(); |
| 620 | + } |
| 621 | + |
| 622 | + $db = wfGetDB( DB_SLAVE ); |
| 623 | + $conditions = "page_namespace = $matchingNamespaceCode"; |
| 624 | + if ( $substring != null ) { |
| 625 | + $substring = str_replace( ' ', '_', strtolower( $substring ) ); |
| 626 | + $substring = str_replace( '_', '\_', $substring ); |
| 627 | + $substring = str_replace( "'", "\'", $substring ); |
| 628 | + $conditions .= " AND (LOWER(CONVERT(`page_title` USING utf8)) LIKE '$substring%' OR LOWER(CONVERT(`page_title` USING utf8)) LIKE '%\_$substring%')"; |
| 629 | + } |
| 630 | + $res = $db->select( 'page', |
| 631 | + 'page_title', |
| 632 | + $conditions, __METHOD__, |
| 633 | + array( 'ORDER BY' => 'page_title' ) ); |
| 634 | + |
| 635 | + $pages = array(); |
| 636 | + while ( $row = $db->fetchRow( $res ) ) { |
| 637 | + $pages[] = str_replace( '_', ' ', $row[0] ); |
| 638 | + } |
| 639 | + $db->freeResult( $res ); |
| 640 | + |
614 | 641 | return $pages; |
615 | 642 | } |
616 | 643 | |
— | — | @@ -633,9 +660,6 @@ |
634 | 661 | } elseif ( $source_type == 'concept' ) { |
635 | 662 | $names_array = self::getAllPagesForConcept( $source_name ); |
636 | 663 | } else { // i.e., $source_type == 'namespace' |
637 | | - // switch back to blank for main namespace |
638 | | - if ( $source_name == "Main" ) |
639 | | - $source_name = ""; |
640 | 664 | $names_array = self::getAllPagesForNamespace( $source_name ); |
641 | 665 | } |
642 | 666 | return $names_array; |