Index: trunk/phase3/includes/SearchEngine.php |
— | — | @@ -50,62 +50,72 @@ |
51 | 51 | * @return Title |
52 | 52 | * @private |
53 | 53 | */ |
54 | | - function getNearMatch( $term ) { |
| 54 | + function getNearMatch( $searchterm ) { |
55 | 55 | global $wgContLang; |
56 | | - # Exact match? No need to look further. |
57 | | - $title = Title::newFromText( $term ); |
58 | | - if (is_null($title)) |
59 | | - return NULL; |
60 | 56 | |
61 | | - if ( $title->getNamespace() == NS_SPECIAL || $title->exists() ) { |
62 | | - return $title; |
63 | | - } |
| 57 | + $allSearchTerms = array($searchterm); |
64 | 58 | |
65 | | - # Now try all lower case (i.e. first letter capitalized) |
66 | | - # |
67 | | - $title = Title::newFromText( $wgContLang->lc( $term ) ); |
68 | | - if ( $title->exists() ) { |
69 | | - return $title; |
| 59 | + if($wgContLang->hasVariants()){ |
| 60 | + $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm)); |
70 | 61 | } |
71 | 62 | |
72 | | - # Now try capitalized string |
73 | | - # |
74 | | - $title = Title::newFromText( $wgContLang->ucwords( $term ) ); |
75 | | - if ( $title->exists() ) { |
76 | | - return $title; |
77 | | - } |
| 63 | + foreach($allSearchTerms as $term){ |
78 | 64 | |
79 | | - # Now try all upper case |
80 | | - # |
81 | | - $title = Title::newFromText( $wgContLang->uc( $term ) ); |
82 | | - if ( $title->exists() ) { |
83 | | - return $title; |
84 | | - } |
| 65 | + # Exact match? No need to look further. |
| 66 | + $title = Title::newFromText( $term ); |
| 67 | + if (is_null($title)) |
| 68 | + return NULL; |
85 | 69 | |
86 | | - # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc |
87 | | - $title = Title::newFromText( $wgContLang->ucwordbreaks($term) ); |
88 | | - if ( $title->exists() ) { |
89 | | - return $title; |
90 | | - } |
| 70 | + if ( $title->getNamespace() == NS_SPECIAL || $title->exists() ) { |
| 71 | + return $title; |
| 72 | + } |
91 | 73 | |
92 | | - global $wgCapitalLinks, $wgContLang; |
93 | | - if( !$wgCapitalLinks ) { |
94 | | - // Catch differs-by-first-letter-case-only |
95 | | - $title = Title::newFromText( $wgContLang->ucfirst( $term ) ); |
| 74 | + # Now try all lower case (i.e. first letter capitalized) |
| 75 | + # |
| 76 | + $title = Title::newFromText( $wgContLang->lc( $term ) ); |
96 | 77 | if ( $title->exists() ) { |
97 | 78 | return $title; |
98 | 79 | } |
99 | | - $title = Title::newFromText( $wgContLang->lcfirst( $term ) ); |
| 80 | + |
| 81 | + # Now try capitalized string |
| 82 | + # |
| 83 | + $title = Title::newFromText( $wgContLang->ucwords( $term ) ); |
100 | 84 | if ( $title->exists() ) { |
101 | 85 | return $title; |
102 | 86 | } |
| 87 | + |
| 88 | + # Now try all upper case |
| 89 | + # |
| 90 | + $title = Title::newFromText( $wgContLang->uc( $term ) ); |
| 91 | + if ( $title->exists() ) { |
| 92 | + return $title; |
| 93 | + } |
| 94 | + |
| 95 | + # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc |
| 96 | + $title = Title::newFromText( $wgContLang->ucwordbreaks($term) ); |
| 97 | + if ( $title->exists() ) { |
| 98 | + return $title; |
| 99 | + } |
| 100 | + |
| 101 | + global $wgCapitalLinks, $wgContLang; |
| 102 | + if( !$wgCapitalLinks ) { |
| 103 | + // Catch differs-by-first-letter-case-only |
| 104 | + $title = Title::newFromText( $wgContLang->ucfirst( $term ) ); |
| 105 | + if ( $title->exists() ) { |
| 106 | + return $title; |
| 107 | + } |
| 108 | + $title = Title::newFromText( $wgContLang->lcfirst( $term ) ); |
| 109 | + if ( $title->exists() ) { |
| 110 | + return $title; |
| 111 | + } |
| 112 | + } |
103 | 113 | } |
104 | 114 | |
105 | | - $title = Title::newFromText( $term ); |
| 115 | + $title = Title::newFromText( $searchterm ); |
106 | 116 | |
107 | 117 | # Entering an IP address goes to the contributions page |
108 | 118 | if ( ( $title->getNamespace() == NS_USER && User::isIP($title->getText() ) ) |
109 | | - || User::isIP( trim( $term ) ) ) { |
| 119 | + || User::isIP( trim( $searchterm ) ) ) { |
110 | 120 | return Title::makeTitle( NS_SPECIAL, "Contributions/" . $title->getDbkey() ); |
111 | 121 | } |
112 | 122 | |
— | — | @@ -116,7 +126,7 @@ |
117 | 127 | } |
118 | 128 | |
119 | 129 | # Quoted term? Try without the quotes... |
120 | | - if( preg_match( '/^"([^"]+)"$/', $term, $matches ) ) { |
| 130 | + if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) { |
121 | 131 | return SearchEngine::getNearMatch( $matches[1] ); |
122 | 132 | } |
123 | 133 | |
Index: trunk/phase3/includes/SpecialSearch.php |
— | — | @@ -97,19 +97,6 @@ |
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
101 | | - # if language supports variants, search in all variants |
102 | | - if($wgContLang->hasVariants()){ |
103 | | - $allTermVariants = $wgContLang->convertLinkToAllVariants($term); |
104 | | - |
105 | | - foreach($allTermVariants as $termVariant){ |
106 | | - $t = SearchEngine::getNearMatch( $termVariant ); |
107 | | - if( !is_null( $t ) ) { |
108 | | - $wgOut->redirect( $t->getFullURL() ); |
109 | | - return; |
110 | | - } |
111 | | - } |
112 | | - } |
113 | | - |
114 | 101 | # No match, generate an edit URL |
115 | 102 | $t = Title::newFromText( $term ); |
116 | 103 | if( is_null( $t ) ) { |