Index: trunk/extensions/SphinxSearch/SphinxSearch_body.php |
— | — | @@ -1,14 +1,14 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * SphinxSearch extension code for MediaWiki |
| 5 | + * Class file for the SphinxSearch extension |
6 | 6 | * |
7 | 7 | * http://www.mediawiki.org/wiki/Extension:SphinxSearch |
8 | 8 | * |
9 | | - * Developed by Paul Grinberg and Svemir Brkic |
10 | | - * |
11 | 9 | * Released under GNU General Public License (see http://www.fsf.org/licenses/gpl.html) |
12 | 10 | * |
| 11 | + * @addtogroup Extensions |
| 12 | + * @author Svemir Brkic <svemir@deveblog.com> and Paul Grinberg |
13 | 13 | */ |
14 | 14 | |
15 | 15 | class SphinxSearch extends SpecialPage { |
— | — | @@ -19,27 +19,33 @@ |
20 | 20 | var $exc_categories = array(); // categories to exclude |
21 | 21 | var $page = 1; // results page we are on |
22 | 22 | |
| 23 | + /** |
| 24 | + * Build a set of next/previous links for a given title |
| 25 | + * |
| 26 | + * @param Title $title |
| 27 | + * @return string |
| 28 | + */ |
23 | 29 | function SphinxSearch() { |
24 | 30 | global $wgDisableInternalSearch, $wgSphinxSuggestMode, $wgAutoloadClasses; |
25 | 31 | |
26 | | - if ($wgDisableInternalSearch) { |
| 32 | + if ( $wgDisableInternalSearch ) { |
27 | 33 | SpecialPage::SpecialPage( 'Search' ); |
28 | 34 | } else { |
29 | 35 | SpecialPage::SpecialPage( 'SphinxSearch' ); |
30 | 36 | } |
31 | 37 | |
32 | | - if ($wgSphinxSuggestMode) { |
| 38 | + if ( $wgSphinxSuggestMode ) { |
33 | 39 | $wgAutoloadClasses['SphinxSearch_spell'] = dirname( __FILE__ ) . '/SphinxSearch_spell.php'; |
34 | 40 | } |
35 | 41 | |
36 | | - if (function_exists('wfLoadExtensionMessages')) { |
| 42 | + if ( function_exists( 'wfLoadExtensionMessages' ) ) { |
37 | 43 | wfLoadExtensionMessages( 'SphinxSearch' ); |
38 | 44 | } else { |
39 | 45 | static $messagesLoaded = false; |
40 | 46 | global $wgMessageCache; |
41 | | - if (!$messagesLoaded) { |
| 47 | + if ( !$messagesLoaded ) { |
42 | 48 | $messagesLoaded = true; |
43 | | - include dirname(__FILE__) . '/SphinxSearch.i18n.php'; |
| 49 | + include dirname( __FILE__ ) . '/SphinxSearch.i18n.php'; |
44 | 50 | foreach ( $messages as $lang => $langMessages ) { |
45 | 51 | $wgMessageCache->addMessages( $langMessages, $lang ); |
46 | 52 | } |
— | — | @@ -48,65 +54,88 @@ |
49 | 55 | return true; |
50 | 56 | } |
51 | 57 | |
| 58 | + /** |
| 59 | + * Determine which namespaces may be included in a search |
| 60 | + * |
| 61 | + * @return array |
| 62 | + */ |
52 | 63 | function searchableNamespaces() { |
53 | 64 | $namespaces = SearchEngine::searchableNamespaces(); |
54 | | - wfRunHooks('SphinxSearchFilterSearchableNamespaces', array(&$namespaces)); |
| 65 | + |
| 66 | + wfRunHooks( 'SphinxSearchFilterSearchableNamespaces', array( &$namespaces ) ); |
| 67 | + |
55 | 68 | return $namespaces; |
56 | 69 | } |
57 | 70 | |
| 71 | + /** |
| 72 | + * Determine which categories may be included in a search |
| 73 | + * |
| 74 | + * @return array |
| 75 | + */ |
58 | 76 | function searchableCategories() { |
59 | 77 | global $wgSphinxTopSearchableCategory; |
60 | 78 | |
61 | | - if ($wgSphinxTopSearchableCategory) { |
62 | | - $categories = self::getChildrenCategories($wgSphinxTopSearchableCategory); |
| 79 | + if ( $wgSphinxTopSearchableCategory ) { |
| 80 | + $categories = self::getChildrenCategories( $wgSphinxTopSearchableCategory ); |
63 | 81 | } else { |
64 | 82 | $categories = array(); |
65 | 83 | } |
66 | | - wfRunHooks('SphinxSearchGetSearchableCategories', array(&$categories)); |
| 84 | + |
| 85 | + wfRunHooks( 'SphinxSearchGetSearchableCategories', array( &$categories ) ); |
| 86 | + |
67 | 87 | return $categories; |
68 | 88 | } |
69 | 89 | |
70 | | - function getChildrenCategories($parent) { |
| 90 | + /** |
| 91 | + * Determine sub-categories of a given category |
| 92 | + * |
| 93 | + * @param string $parent |
| 94 | + * @return array |
| 95 | + */ |
| 96 | + function getChildrenCategories( $parent ) { |
71 | 97 | global $wgMemc, $wgDBname; |
72 | 98 | |
73 | 99 | $categories = null; |
74 | | - if (is_object($wgMemc)) { |
75 | | - $cache_key = $wgDBname . ':sphinx_cats:' . md5($parent); |
| 100 | + if ( is_object( $wgMemc ) ) { |
| 101 | + $cache_key = $wgDBname . ':sphinx_cats:' . md5( $parent ); |
76 | 102 | $categories = $wgMemc->get( $cache_key ); |
77 | 103 | } |
78 | | - if (!is_array($categories)) { |
| 104 | + if ( !is_array( $categories ) ) { |
79 | 105 | $categories = array(); |
80 | | - $dbr =& wfGetDB( DB_SLAVE ); |
| 106 | + $dbr = wfGetDB( DB_SLAVE ); |
81 | 107 | $res = $dbr->select( |
82 | 108 | array( 'categorylinks', 'page' ), |
83 | 109 | array( 'cl_from', 'cl_sortkey', 'page_title' ), |
84 | 110 | array( '1', |
85 | 111 | 'cl_from = page_id', |
86 | 112 | 'cl_to' => $parent, |
87 | | - 'page_namespace' => NS_CATEGORY), |
| 113 | + 'page_namespace' => NS_CATEGORY ), |
88 | 114 | 'epSearchableCategories', |
89 | 115 | array( 'ORDER BY' => 'cl_sortkey' ) |
90 | 116 | ); |
91 | | - while( $x = $dbr->fetchObject ( $res ) ) { |
| 117 | + while ( $x = $dbr->fetchObject ( $res ) ) { |
92 | 118 | $categories[$x->cl_from] = $x->cl_sortkey; |
93 | 119 | } |
94 | | - if ($cache_key) { |
| 120 | + if ( $cache_key ) { |
| 121 | + # cache query results for a day |
95 | 122 | $wgMemc->set( $cache_key, $categories, 86400 ); |
96 | 123 | } |
97 | | - $dbr->freeResult($res); |
| 124 | + $dbr->freeResult( $res ); |
98 | 125 | } |
99 | 126 | return $categories; |
100 | 127 | } |
101 | 128 | |
102 | | - function ajaxGetCategoryChildren($parent_id) { |
| 129 | + function ajaxGetCategoryChildren( $parent_id ) { |
103 | 130 | |
104 | 131 | $title = Title::newFromID( $parent_id ); |
105 | 132 | |
106 | | - if ( ! $title ) return false; |
| 133 | + if ( !$title ) { |
| 134 | + return false; |
| 135 | + } |
107 | 136 | |
108 | 137 | # Retrieve page_touched for the category |
109 | 138 | $dbkey = $title->getDBkey(); |
110 | | - $dbr =& wfGetDB( DB_SLAVE ); |
| 139 | + $dbr = wfGetDB( DB_SLAVE ); |
111 | 140 | $touched = $dbr->selectField( |
112 | 141 | 'page', 'page_touched', |
113 | 142 | array( |
— | — | @@ -124,14 +153,14 @@ |
125 | 154 | |
126 | 155 | $categories = self::getChildrenCategories( $dbkey ); |
127 | 156 | |
128 | | - $html = self::getCategoryCheckboxes($categories, $parent_id); |
| 157 | + $html = self::getCategoryCheckboxes( $categories, $parent_id ); |
129 | 158 | |
130 | 159 | $response->addText( $html ); |
131 | 160 | |
132 | 161 | return $response; |
133 | 162 | } |
134 | 163 | |
135 | | - function execute($par) { |
| 164 | + function execute( $par ) { |
136 | 165 | global $wgRequest, $wgOut, $wgUser, $wgSphinxMatchAll, $wgSphinxSearch_index_list; |
137 | 166 | |
138 | 167 | # extract the options from the GET query |
— | — | @@ -144,51 +173,54 @@ |
145 | 174 | # thn try to go to title directly). This is needed because IE has a |
146 | 175 | # different behavior when the <ENTER> button is pressed in a form - |
147 | 176 | # it does not send the name of the default button! |
148 | | - if( ! $wgRequest->getVal( 'fulltext' )) { |
| 177 | + if ( !$wgRequest->getVal( 'fulltext' ) ) { |
149 | 178 | $this->goResult( $term ); |
150 | 179 | } |
151 | 180 | |
152 | 181 | $this->setHeaders(); |
153 | | - $wgOut->setPagetitle(wfMsg('sphinxsearch')); |
| 182 | + $wgOut->setPagetitle( wfMsg( 'sphinxsearch' ) ); |
154 | 183 | |
155 | 184 | $this->namespaces = array(); |
156 | 185 | $all_namespaces = self::searchableNamespaces(); |
157 | | - foreach( $all_namespaces as $ns => $name ) { |
158 | | - if ($wgRequest->getCheck("ns{$ns}")) { |
| 186 | + foreach ( $all_namespaces as $ns => $name ) { |
| 187 | + if ( $wgRequest->getCheck( "ns{$ns}" ) ) { |
159 | 188 | $this->namespaces[] = $ns; |
160 | 189 | } |
161 | 190 | } |
162 | | - if (!count($this->namespaces)) { |
163 | | - foreach( $all_namespaces as $ns => $name ) { |
164 | | - if ($wgUser->getOption('searchNs' . $ns)) { |
| 191 | + if ( !count( $this->namespaces ) ) { |
| 192 | + foreach ( $all_namespaces as $ns => $name ) { |
| 193 | + if ( $wgUser->getOption( 'searchNs' . $ns ) ) { |
165 | 194 | $this->namespaces[] = $ns; |
166 | 195 | } |
167 | 196 | } |
168 | 197 | } |
169 | 198 | |
170 | | - $this->categories = $wgRequest->getIntArray("cat", array()); |
171 | | - $this->exc_categories = $wgRequest->getIntArray("exc", array()); |
| 199 | + $this->categories = $wgRequest->getIntArray( "cat", array() ); |
| 200 | + $this->exc_categories = $wgRequest->getIntArray( "exc", array() ); |
172 | 201 | |
173 | | - $this->page = $wgRequest->getInt('page', 1); |
174 | | - $wgSphinxMatchAll = $wgRequest->getInt('match_all', intval($wgSphinxMatchAll)); |
175 | | - $match_titles_only = ($wgRequest->getInt('match_titles') == 1); |
| 202 | + $this->page = $wgRequest->getInt( 'page', 1 ); |
| 203 | + $wgSphinxMatchAll = $wgRequest->getInt( 'match_all', intval( $wgSphinxMatchAll ) ); |
| 204 | + $match_titles_only = ( $wgRequest->getInt( 'match_titles' ) == 1 ); |
176 | 205 | |
177 | 206 | # do the actual search |
178 | 207 | $found = 0; |
179 | 208 | $cl = $this->prepareSphinxClient( $term, $match_titles_only ); |
180 | 209 | if ( $cl ) { |
181 | | - $res = $cl->Query( addcslashes($this->search_term, '/()[]"!'), $wgSphinxSearch_index_list ); |
| 210 | + $res = $cl->Query( |
| 211 | + addcslashes( $this->search_term, '/()[]"!' ), |
| 212 | + $wgSphinxSearch_index_list |
| 213 | + ); |
182 | 214 | if ( $res === false ) { |
183 | | - $wgOut->addWikiText( wfMsg('sphinxSearchFailed') . wfMsg( 'word-separator' ) . $cl->GetLastError() . ".\n" ); |
| 215 | + $wgOut->addWikiText( wfMsg( 'sphinxSearchFailed', $cl->GetLastError() ) . "\n" ); |
184 | 216 | } else { |
185 | 217 | $found = $this->wfSphinxDisplayResults( $term, $res, $cl ); |
186 | 218 | } |
187 | 219 | } else { |
188 | | - $wgOut->addWikiText( wfMsg('sphinxClientFailed') . ".\n" ); |
| 220 | + $wgOut->addWikiText( wfMsg( 'sphinxClientFailed' ) . "\n" ); |
189 | 221 | } |
190 | 222 | |
191 | 223 | # prepare for the next search |
192 | | - if ($found) { |
| 224 | + if ( $found ) { |
193 | 225 | $this->createNextPageBar( $found, $term ); |
194 | 226 | } |
195 | 227 | |
— | — | @@ -202,21 +234,21 @@ |
203 | 235 | $t = Title::newFromText( $term ); |
204 | 236 | |
205 | 237 | # If the string cannot be used to create a title |
206 | | - if( is_null( $t ) ){ |
| 238 | + if ( is_null( $t ) ) { |
207 | 239 | return; |
208 | 240 | } |
209 | 241 | |
210 | 242 | # If there's an exact or very near match, jump right there. |
211 | 243 | $t = SearchEngine::getNearMatch( $term ); |
212 | | - wfRunHooks('SphinxSearchGetNearMatch', array(&$term, &$t)); |
213 | | - if( !is_null( $t ) ) { |
| 244 | + wfRunHooks( 'SphinxSearchGetNearMatch', array( &$term, &$t ) ); |
| 245 | + if ( !is_null( $t ) ) { |
214 | 246 | $wgOut->redirect( $t->getFullURL() ); |
215 | 247 | return; |
216 | 248 | } |
217 | 249 | |
218 | 250 | # No match, generate an edit URL |
219 | 251 | $t = Title::newFromText( $term ); |
220 | | - if( ! is_null( $t ) ) { |
| 252 | + if ( !is_null( $t ) ) { |
221 | 253 | # If the feature is enabled, go straight to the edit page |
222 | 254 | if ( $wgGoToEdit ) { |
223 | 255 | $wgOut->redirect( $t->getFullURL( 'action=edit' ) ); |
— | — | @@ -268,7 +300,10 @@ |
269 | 301 | |
270 | 302 | $cl = $this->prepareSphinxClient( $term, $titles_only ); |
271 | 303 | if ( $cl ) { |
272 | | - $res = $cl->Query( addcslashes($this->search_term, '/()[]"!'), $wgSphinxSearch_index_list ); |
| 304 | + $res = $cl->Query( |
| 305 | + addcslashes( $this->search_term, '/()[]"!' ), |
| 306 | + $wgSphinxSearch_index_list |
| 307 | + ); |
273 | 308 | } else { |
274 | 309 | $res = false; |
275 | 310 | } |
— | — | @@ -296,22 +331,28 @@ |
297 | 332 | * Display the results of the search one page at a time. |
298 | 333 | * Returns the number of matches. |
299 | 334 | */ |
300 | | - function prepareSphinxClient($term, $match_titles_only = false) { |
| 335 | + function prepareSphinxClient( $term, $match_titles_only = false ) { |
301 | 336 | global $wgSphinxSearch_sortmode, $wgSphinxSearch_sortby, |
302 | 337 | $wgSphinxSearch_host, $wgSphinxSearch_port, $wgSphinxSearch_index_weights, |
303 | 338 | $wgSphinxSearch_index, $wgSphinxSearch_matches, $wgSphinxSearch_mode, $wgSphinxSearch_weights, |
304 | 339 | $wgSphinxMatchAll, $wgSphinxSearch_maxmatches, $wgSphinxSearch_cutoff; |
305 | 340 | |
306 | 341 | # don't do anything for blank searches |
307 | | - if (trim($term) === '') { |
| 342 | + if ( trim( $term ) === '' ) { |
308 | 343 | return false; |
309 | 344 | } |
310 | 345 | |
311 | | - wfRunHooks( 'SphinxSearchBeforeResults', array( &$term, &$this->page, &$this->namespaces, &$this->categories, &$this->exc_categories ) ); |
| 346 | + wfRunHooks( 'SphinxSearchBeforeResults', array( |
| 347 | + &$term, |
| 348 | + &$this->page, |
| 349 | + &$this->namespaces, |
| 350 | + &$this->categories, |
| 351 | + &$this->exc_categories |
| 352 | + ) ); |
312 | 353 | |
313 | 354 | if ( $wgSphinxSearch_mode == SPH_MATCH_EXTENDED && $wgSphinxMatchAll != '1' ) { |
314 | 355 | # make OR the default in extended mode |
315 | | - $this->search_term = preg_replace( '/[\s_\-&]+/', '|', trim($term) ); |
| 356 | + $this->search_term = preg_replace( '/[\s_\-&]+/', '|', trim( $term ) ); |
316 | 357 | } else { |
317 | 358 | $this->search_term = $term; |
318 | 359 | } |
— | — | @@ -319,97 +360,107 @@ |
320 | 361 | $cl = new SphinxClient(); |
321 | 362 | |
322 | 363 | # setup the options for searching |
323 | | - if ( isset($wgSphinxSearch_host) && isset($wgSphinxSearch_port) ) { |
324 | | - $cl->SetServer($wgSphinxSearch_host, $wgSphinxSearch_port); |
| 364 | + if ( isset( $wgSphinxSearch_host ) && isset( $wgSphinxSearch_port ) ) { |
| 365 | + $cl->SetServer( $wgSphinxSearch_host, $wgSphinxSearch_port ); |
325 | 366 | } |
326 | | - if (count($wgSphinxSearch_weights)) { |
327 | | - if (is_string(key($wgSphinxSearch_weights))) { |
328 | | - $cl->SetFieldWeights($wgSphinxSearch_weights); |
| 367 | + if ( count( $wgSphinxSearch_weights ) ) { |
| 368 | + if ( is_string( key( $wgSphinxSearch_weights ) ) ) { |
| 369 | + $cl->SetFieldWeights( $wgSphinxSearch_weights ); |
329 | 370 | } else { |
330 | | - $cl->SetWeights($wgSphinxSearch_weights); |
| 371 | + $cl->SetWeights( $wgSphinxSearch_weights ); |
331 | 372 | } |
332 | 373 | } |
333 | | - if (is_array($wgSphinxSearch_index_weights)) { |
334 | | - $cl->SetIndexWeights($wgSphinxSearch_index_weights); |
| 374 | + if ( is_array( $wgSphinxSearch_index_weights ) ) { |
| 375 | + $cl->SetIndexWeights( $wgSphinxSearch_index_weights ); |
335 | 376 | } |
336 | | - if (isset($wgSphinxSearch_mode)) { |
337 | | - $cl->SetMatchMode($wgSphinxSearch_mode); |
| 377 | + if ( isset( $wgSphinxSearch_mode ) ) { |
| 378 | + $cl->SetMatchMode( $wgSphinxSearch_mode ); |
338 | 379 | } |
339 | | - if (count($this->namespaces)) { |
340 | | - $cl->SetFilter('page_namespace', $this->namespaces); |
| 380 | + if ( count( $this->namespaces ) ) { |
| 381 | + $cl->SetFilter( 'page_namespace', $this->namespaces ); |
341 | 382 | } |
342 | 383 | |
343 | | - if (count($this->categories)) { |
344 | | - $cl->SetFilter('category', $this->categories); |
| 384 | + if ( count( $this->categories ) ) { |
| 385 | + $cl->SetFilter( 'category', $this->categories ); |
345 | 386 | } |
346 | 387 | |
347 | | - if (count($this->exc_categories)) { |
348 | | - $cl->SetFilter('category', $this->exc_categories, true); |
| 388 | + if ( count( $this->exc_categories ) ) { |
| 389 | + $cl->SetFilter( 'category', $this->exc_categories, true ); |
349 | 390 | } |
350 | 391 | |
351 | | - if (isset($wgSphinxSearch_groupby) && isset($wgSphinxSearch_groupsort)) { |
352 | | - $cl->SetGroupBy($wgSphinxSearch_groupby, SPH_GROUPBY_ATTR, $wgSphinxSearch_groupsort); |
| 392 | + if ( isset( $wgSphinxSearch_groupby ) && isset( $wgSphinxSearch_groupsort ) ) { |
| 393 | + $cl->SetGroupBy( $wgSphinxSearch_groupby, SPH_GROUPBY_ATTR, $wgSphinxSearch_groupsort ); |
353 | 394 | } |
354 | | - $cl->SetSortMode($wgSphinxSearch_sortmode, $wgSphinxSearch_sortby); |
355 | | - $cl->SetLimits( ($this->page - 1) * $wgSphinxSearch_matches, $wgSphinxSearch_matches, $wgSphinxSearch_maxmatches, $wgSphinxSearch_cutoff ); |
| 395 | + $cl->SetSortMode( $wgSphinxSearch_sortmode, $wgSphinxSearch_sortby ); |
| 396 | + $cl->SetLimits( |
| 397 | + ( $this->page - 1 ) * $wgSphinxSearch_matches, |
| 398 | + $wgSphinxSearch_matches, |
| 399 | + $wgSphinxSearch_maxmatches, |
| 400 | + $wgSphinxSearch_cutoff |
| 401 | + ); |
356 | 402 | |
357 | 403 | if ( $match_titles_only ) { |
358 | 404 | $this->search_term = '@page_title ' . $this->search_term; |
359 | 405 | } |
360 | 406 | |
361 | | - wfRunHooks('SphinxSearchBeforeQuery', array(&$this->search_term, &$cl)); |
| 407 | + wfRunHooks( 'SphinxSearchBeforeQuery', array( &$this->search_term, &$cl ) ); |
362 | 408 | |
363 | 409 | return $cl; |
364 | 410 | } |
365 | 411 | |
366 | | - function wfSphinxDisplayResults($term, $res, $cl) { |
| 412 | + function wfSphinxDisplayResults( $term, $res, $cl ) { |
367 | 413 | |
368 | 414 | global $wgOut, $wgSphinxSuggestMode, $wgSphinxSearch_matches, $wgSphinxSearch_index, $wgSphinxSearch_maxmatches; |
369 | 415 | |
370 | 416 | if ($cl->GetLastWarning()) { |
371 | | - // FIXME: should be one message with a parameter |
372 | | - $wgOut->addWikiText(wfMsg('sphinxSearchWarning') . wfMsg( 'word-separator' ) . $cl->GetLastWarning() . "\n\n"); |
| 417 | + $wgOut->addWikiText( wfMsg( 'sphinxSearchWarning', $cl->GetLastWarning() ) . "\n\n"); |
373 | 418 | } |
374 | 419 | $found = $res['total_found']; |
375 | 420 | |
376 | | - if ($wgSphinxSuggestMode) { |
| 421 | + if ( $wgSphinxSuggestMode ) { |
377 | 422 | $sc = new SphinxSearch_spell; |
378 | | - $didyoumean = $sc->spell($this->search_term); |
379 | | - if ($didyoumean) { |
380 | | - $wgOut->addhtml(wfMsg('sphinxSearchDidYouMean') . |
381 | | - " <b><a href='" . |
382 | | - $this->getActionURL($didyoumean, $this->namespaces) . |
383 | | - "1'>" . $didyoumean . '</a></b>?'); |
| 423 | + $didyoumean = $sc->spell( $this->search_term ); |
| 424 | + if ( $didyoumean ) { |
| 425 | + $wgOut->addhtml( wfMsg( 'sphinxSearchDidYouMean' ) . |
| 426 | + " <b><a href='" . |
| 427 | + $this->getActionURL( $didyoumean, $this->namespaces ) . |
| 428 | + "1'>" . $didyoumean . '</a></b>?' |
| 429 | + ); |
384 | 430 | } |
385 | 431 | } |
386 | 432 | |
387 | | - $preamble = sprintf(wfMsg('sphinxSearchPreamble'), |
388 | | - ( (($this->page - 1) * $wgSphinxSearch_matches) + 1 > $res['total'] ) ? $res['total'] : (($this->page - 1) * $wgSphinxSearch_matches) + 1, |
389 | | - ($this->page * $wgSphinxSearch_matches > $res['total']) ? $res['total'] : $this->page * $wgSphinxSearch_matches, |
390 | | - $res['total'], |
391 | | - $term, |
392 | | - $res['time'] |
| 433 | + $from = min( |
| 434 | + ( ( $this->page - 1 ) * $wgSphinxSearch_matches ) + 1, |
| 435 | + $res['total'] |
393 | 436 | ); |
394 | | - // FIXME: should be one message with a parameter ending on a colon |
395 | | - $wgOut->addWikiText($preamble . wfMsg( 'colon-separator' ) ); |
396 | | - if (is_array($res["words"])) { |
| 437 | + $to = min( |
| 438 | + $this->page * $wgSphinxSearch_matches, |
| 439 | + $res['total'] |
| 440 | + ); |
| 441 | + $wgOut->addWikiText( wfMsg( 'sphinxSearchPreamble', |
| 442 | + $from, $to, $res['total'], $term, $res['time'] ) |
| 443 | + ); |
| 444 | + |
| 445 | + if ( is_array( $res["words"] ) ) { |
397 | 446 | $warn = false; |
398 | | - foreach ($res["words"] as $word => $info) { |
399 | | - $wgOut->addWikiText( '* ' . sprintf( wfMsg('sphinxSearchStats'), $word, $info['hits'], $info['docs'] ) ); |
| 447 | + foreach ( $res["words"] as $word => $info ) { |
| 448 | + $wgOut->addWikiText( '* ' . |
| 449 | + wfMsg( 'sphinxSearchStats', $word, $info['hits'], $info['docs'] ) |
| 450 | + ); |
400 | 451 | if ( ( $info['docs'] < $wgSphinxSearch_maxmatches ) && ( $info['docs'] > $res['total'] ) ) { |
401 | 452 | $warn = true; |
402 | 453 | } |
403 | 454 | } |
404 | 455 | if ( $warn ) { |
405 | | - $wgOut->addWikiText( "''" . wfMsg('sphinxSearchStatsInfo') . ".''" ); |
| 456 | + $wgOut->addWikiText( "''" . wfMsg( 'sphinxSearchStatsInfo' ) . "''" ); |
406 | 457 | } else { |
407 | 458 | $wgOut->addWikiText( "\n" ); |
408 | 459 | } |
409 | 460 | } |
410 | | - $start_time = microtime(true); |
| 461 | + $start_time = microtime( true ); |
411 | 462 | |
412 | | - if (isset($res["matches"]) && is_array($res["matches"])) { |
413 | | - $wgOut->addWikiText("----"); |
| 463 | + if ( isset( $res["matches"] ) && is_array( $res["matches"] ) ) { |
| 464 | + $wgOut->addWikiText( "----" ); |
414 | 465 | $db = wfGetDB( DB_SLAVE ); |
415 | 466 | $excerpts_opt = array( |
416 | 467 | "before_match" => "<span style='color:red'>", |
— | — | @@ -419,73 +470,69 @@ |
420 | 471 | "around" => 15 |
421 | 472 | ); |
422 | 473 | |
423 | | - foreach ($res["matches"] as $doc => $docinfo) { |
424 | | - $sql = "SELECT old_text FROM ".$db->tableName('text')." WHERE old_id=".$docinfo['attrs']['old_id']; |
| 474 | + foreach ( $res["matches"] as $doc => $docinfo ) { |
| 475 | + $sql = "SELECT old_text FROM " . $db->tableName( 'text' ) . " WHERE old_id=" . $docinfo['attrs']['old_id']; |
425 | 476 | $res = $db->query( $sql, __METHOD__ ); |
426 | | - if ($db->numRows($res)) { |
427 | | - $row = $db->fetchRow($res); |
| 477 | + if ( $db->numRows( $res ) ) { |
| 478 | + $row = $db->fetchRow( $res ); |
428 | 479 | $title_obj = Title::newFromID( $doc ); |
429 | | - if (is_object($title_obj)) { |
| 480 | + if ( is_object( $title_obj ) ) { |
430 | 481 | $wiki_title = $title_obj->getPrefixedText(); |
431 | 482 | $wiki_path = $title_obj->getPrefixedDBkey(); |
432 | | - $wgOut->addWikiText("* <span style='font-size:110%;'>[[:$wiki_path|$wiki_title]]</span>"); |
| 483 | + $wgOut->addWikiText( "* <span style='font-size:110%;'>[[:$wiki_path|$wiki_title]]</span>" ); |
| 484 | + |
433 | 485 | # uncomment this line to see the weights etc. as HTML comments in the source of the page |
434 | | - #$wgOut->addHTML("<!-- page_id: ".$doc."\ninfo: ".print_r($docinfo, true)." -->"); |
435 | | - $excerpts = $cl->BuildExcerpts(array($row[0]), $wgSphinxSearch_index, $term, $excerpts_opt); |
436 | | - if ( !is_array($excerpts) ) { |
437 | | - $excerpts = array( "ERROR: " . $cl->GetLastError() ); |
| 486 | + # $wgOut->addHTML("<!-- page_id: ".$doc."\ninfo: ".print_r($docinfo, true)." -->"); |
| 487 | + |
| 488 | + $excerpts = $cl->BuildExcerpts( array( $row[0] ), $wgSphinxSearch_index, $term, $excerpts_opt ); |
| 489 | + if ( !is_array( $excerpts ) ) { |
| 490 | + $excerpts = array( wfMsg( 'sphinxSearchWarning', $cl->GetLastError() ) ); |
438 | 491 | } |
439 | 492 | foreach ( $excerpts as $entry ) { |
440 | | - # add excerpt to output, removing some wiki markup, and breaking apart long strings |
441 | | - $entry = preg_replace('/([\[\]\{\}\*\#\|\!]+|==+)/', |
| 493 | + # add excerpt to output, removing some wiki markup |
| 494 | + $entry = preg_replace( '/([\[\]\{\}\*\#\|\!]+|==+)/', |
442 | 495 | ' ', |
443 | | - strip_tags($entry, '<span><br>') |
| 496 | + strip_tags( $entry, '<span><br>' ) |
444 | 497 | ); |
445 | | - # force breaks on very |
446 | | - /*$entry = join('<br>', |
447 | | - preg_split('/(\S{60})/', |
448 | | - $entry, |
449 | | - -1, |
450 | | - PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE |
451 | | - ) |
452 | | - );*/ |
453 | | - |
454 | | - $wgOut->addHTML("<div style='margin: 0.2em 1em 1em 1em;'>$entry</div>\n"); |
| 498 | + $wgOut->addHTML( "<div style='margin: 0.2em 1em 1em 1em;'>$entry</div>\n" ); |
455 | 499 | } |
456 | 500 | } |
457 | 501 | } |
458 | | - $db->freeResult($res); |
| 502 | + $db->freeResult( $res ); |
459 | 503 | } |
460 | | - $wgOut->addWikiText(sprintf(wfMsg('sphinxSearchEpilogue'), microtime(true) - $start_time)); |
| 504 | + $time = number_format( microtime( true ) - $start_time, 3); |
| 505 | + $wgOut->addWikiText( wfMsg( 'sphinxSearchEpilogue', $time ) ); |
461 | 506 | } |
462 | 507 | |
463 | | - wfRunHooks('SphinxSearchAfterResults', array($term, $this->page)); |
| 508 | + wfRunHooks( 'SphinxSearchAfterResults', array( $term, $this->page ) ); |
464 | 509 | |
465 | 510 | return $found; |
466 | 511 | } |
467 | 512 | |
468 | | - function getActionURL($term) { |
| 513 | + function getActionURL( $term ) { |
469 | 514 | global $wgDisableInternalSearch, $wgSphinxMatchAll, $wgRequest; |
470 | 515 | |
471 | | - $search_title = ($wgDisableInternalSearch ? 'Search' : 'SphinxSearch'); |
| 516 | + $search_title = ( $wgDisableInternalSearch ? 'Search' : 'SphinxSearch' ); |
472 | 517 | $titleObj = SpecialPage::getTitleFor( $search_title ); |
473 | 518 | $qry = $titleObj->getLocalUrl(); |
474 | | - $searchField = strtolower($search_title); |
475 | | - $term = urlencode($term); |
476 | | - $qry .= (strpos($qry, '?') === false ? '?' : '&').$searchField."={$term}&fulltext=".wfMsg('sphinxSearchButton')."&"; |
477 | | - if ($wgSphinxMatchAll == '1') { |
| 519 | + $searchField = strtolower( $search_title ); |
| 520 | + $term = urlencode( $term ); |
| 521 | + $qry .= ( strpos( $qry, '?' ) === false ? '?' : '&' ) . |
| 522 | + $searchField . "={$term}&fulltext=" . |
| 523 | + wfMsg( 'sphinxSearchButton' ) . "&"; |
| 524 | + if ( $wgSphinxMatchAll == '1' ) { |
478 | 525 | $qry .= "match_all=1&"; |
479 | 526 | } |
480 | | - if ($wgRequest->getInt('match_titles')) { |
| 527 | + if ( $wgRequest->getInt( 'match_titles' ) ) { |
481 | 528 | $qry .= "match_titles=1&"; |
482 | 529 | } |
483 | | - foreach ($this->namespaces as $ns) { |
| 530 | + foreach ( $this->namespaces as $ns ) { |
484 | 531 | $qry .= "ns{$ns}=1&"; |
485 | 532 | } |
486 | | - foreach ($this->categories as $c) { |
| 533 | + foreach ( $this->categories as $c ) { |
487 | 534 | $qry .= "cat[]={$c}&"; |
488 | 535 | } |
489 | | - foreach ($this->exc_categories as $c) { |
| 536 | + foreach ( $this->exc_categories as $c ) { |
490 | 537 | $qry .= "exc[]={$c}&"; |
491 | 538 | } |
492 | 539 | $qry .= "page="; |
— | — | @@ -496,144 +543,166 @@ |
497 | 544 | function createNextPageBar( $found, $term ) { |
498 | 545 | global $wgOut, $wgSphinxSearch_matches; |
499 | 546 | |
500 | | - $qry = $this->getActionURL($term); |
| 547 | + $qry = $this->getActionURL( $term ); |
501 | 548 | |
502 | 549 | $display_pages = 10; |
503 | | - $max_page = ceil($found / $wgSphinxSearch_matches); |
504 | | - $center_page = floor(($this->page + $display_pages) / 2); |
| 550 | + $max_page = ceil( $found / $wgSphinxSearch_matches ); |
| 551 | + $center_page = floor( ( $this->page + $display_pages ) / 2 ); |
505 | 552 | $first_page = $center_page - $display_pages / 2; |
506 | | - if ($first_page < 1) { |
| 553 | + if ( $first_page < 1 ) { |
507 | 554 | $first_page = 1; |
508 | 555 | } |
509 | 556 | $last_page = $first_page + $display_pages - 1; |
510 | | - if ($last_page > $max_page) { |
| 557 | + if ( $last_page > $max_page ) { |
511 | 558 | $last_page = $max_page; |
512 | 559 | } |
513 | | - if ($first_page != $last_page) { |
514 | | - $wgOut->addWikiText("----"); |
515 | | - $wgOut->addHTML("<center><table border='0' cellpadding='0' width='1%' cellspacing='0'><tr align='center' valign='top'><td valign='bottom' nowrap='1'>" . wfMsg('sphinxResultPage') . ":</td>"); |
| 560 | + if ( $first_page != $last_page ) { |
| 561 | + $wgOut->addWikiText( "----" ); |
| 562 | + $wgOut->addHTML( "<center> |
| 563 | + <table border='0' cellpadding='0' width='1%' cellspacing='0'> |
| 564 | + <tr align='center' valign='top'> |
| 565 | + <td valign='bottom' nowrap='1'>" . wfMsg( 'sphinxResultPage' ) . "</td>" ); |
516 | 566 | |
517 | | - if ($first_page > 1) { |
| 567 | + if ( $first_page > 1 ) { |
518 | 568 | $prev_page = "<td> <a href='{$qry}"; |
519 | | - $prev_page .= ($this->page - 1) . "'>" . wfMsg('sphinxPreviousPage') . "</a> </td>"; |
520 | | - $wgOut->addHTML($prev_page); |
| 569 | + $prev_page .= ( $this->page - 1 ) . "'>" . wfMsg( 'sphinxPreviousPage' ) . "</a> </td>"; |
| 570 | + $wgOut->addHTML( $prev_page ); |
521 | 571 | } |
522 | | - for ($i = $first_page; $i < $this->page; $i++) { |
523 | | - $wgOut->addHTML("<td> <a href='{$qry}{$i}'>{$i}</a> </td>"); |
| 572 | + for ( $i = $first_page; $i < $this->page; $i++ ) { |
| 573 | + $wgOut->addHTML( "<td> <a href='{$qry}{$i}'>{$i}</a> </td>" ); |
524 | 574 | } |
525 | | - $wgOut->addHTML("<td> <b>{$this->page}</b> </td>"); |
526 | | - for ($i = $this->page + 1; $i <= $last_page; $i++) { |
527 | | - $wgOut->addHTML("<td> <a href='{$qry}{$i}'>{$i}</a> </td>"); |
| 575 | + $wgOut->addHTML( "<td> <b>{$this->page}</b> </td>" ); |
| 576 | + for ( $i = $this->page + 1; $i <= $last_page; $i++ ) { |
| 577 | + $wgOut->addHTML( "<td> <a href='{$qry}{$i}'>{$i}</a> </td>" ); |
528 | 578 | } |
529 | | - if ($last_page < $max_page) { |
| 579 | + if ( $last_page < $max_page ) { |
530 | 580 | $next_page = "<td> <a href='{$qry}"; |
531 | | - $next_page .= ($this->page + 1) . "'>" . wfMsg('sphinxNextPage') . "</a> </td>"; |
532 | | - $wgOut->addHTML($next_page); |
| 581 | + $next_page .= ( $this->page + 1 ) . "'>" . wfMsg( 'sphinxNextPage' ) . "</a> </td>"; |
| 582 | + $wgOut->addHTML( $next_page ); |
533 | 583 | } |
534 | 584 | |
535 | | - $wgOut->addHTML("</tr></table></center>"); |
| 585 | + $wgOut->addHTML( "</tr></table></center>" ); |
536 | 586 | } |
537 | 587 | } |
538 | 588 | |
539 | | - function createNewSearchForm($term) { |
| 589 | + function createNewSearchForm( $term ) { |
540 | 590 | global $wgOut, $wgDisableInternalSearch, $wgSphinxSearch_mode, $wgSphinxMatchAll, $wgUseExcludes; |
541 | 591 | global $wgUseAjax, $wgJsMimeType, $wgScriptPath, $wgSphinxSearchExtPath, $wgSphinxSearchJSPath, $wgRequest; |
542 | 592 | |
543 | | - $search_title = ($wgDisableInternalSearch ? 'Search' : 'SphinxSearch'); |
| 593 | + $search_title = ( $wgDisableInternalSearch ? 'Search' : 'SphinxSearch' ); |
544 | 594 | $titleObj = SpecialPage::getTitleFor( $search_title ); |
545 | 595 | $kiAction = $titleObj->getLocalUrl(); |
546 | | - $searchField = strtolower($search_title); |
547 | | - $wgOut->addHTML("<form action='$kiAction' method='GET'> |
548 | | - <input type='hidden' name='title' value='".$titleObj->getPrefixedText()."'> |
| 596 | + $searchField = strtolower( $search_title ); |
| 597 | + $wgOut->addHTML( "<form action='$kiAction' method='GET'> |
| 598 | + <input type='hidden' name='title' value='" . $titleObj->getPrefixedText() . "'> |
549 | 599 | <input type='text' name='$searchField' maxlength='100' value='$term'> |
550 | | - <input type='submit' name='fulltext' value='" . wfMsg('sphinxSearchButton') ."'>"); |
| 600 | + <input type='submit' name='fulltext' value='" . wfMsg( 'sphinxSearchButton' ) . "'>" ); |
551 | 601 | |
552 | | - $wgOut->addHTML("<div style='margin:0.5em 0 0.5em 0;'>"); |
553 | | - if ($wgSphinxSearch_mode == SPH_MATCH_EXTENDED) { |
554 | | - $wgOut->addHTML("<input type='radio' name='match_all' value='0' ".($wgSphinxMatchAll ? "" : "checked='checked'")." />".wfMsg('sphinxMatchAny')." <input type='radio' name='match_all' value='1' ".($wgSphinxMatchAll ? "checked='checked'" : "")." />".wfMsg('sphinxMatchAll')); |
| 602 | + $wgOut->addHTML( "<div style='margin:0.5em 0 0.5em 0;'>" ); |
| 603 | + if ( $wgSphinxSearch_mode == SPH_MATCH_EXTENDED ) { |
| 604 | + $wgOut->addHTML( "<input type='radio' name='match_all' value='0' " . |
| 605 | + ( $wgSphinxMatchAll ? "" : "checked='checked'" ) . " />" . |
| 606 | + wfMsg( 'sphinxMatchAny' ) . |
| 607 | + " <input type='radio' name='match_all' value='1' " . |
| 608 | + ( $wgSphinxMatchAll ? "checked='checked'" : "" ) . " />" . |
| 609 | + wfMsg( 'sphinxMatchAll' ) |
| 610 | + ); |
555 | 611 | } |
556 | | - $wgOut->addHTML(" <input type='checkbox' name='match_titles' value='1' " . ($wgRequest->getInt('match_titles') ? "checked='checked'" : ""). ">" . wfMsg('sphinxMatchTitles') . "</div>"); |
| 612 | + $wgOut->addHTML( " <input type='checkbox' name='match_titles' value='1' " . |
| 613 | + ( $wgRequest->getInt( 'match_titles' ) ? "checked='checked'" : "" ) . ">" . |
| 614 | + wfMsg( 'sphinxMatchTitles' ) . "</div>" |
| 615 | + ); |
557 | 616 | # get user settings for which namespaces to search |
558 | | - $wgOut->addHTML("<div style='width:30%; border:1px #eee solid; padding:4px; margin-right:1px; float:left;'>"); |
559 | | - $wgOut->addHTML(wfMsg('sphinxSearchInNamespaces') . '<br />'); |
| 617 | + $wgOut->addHTML( "<div style='width:30%; border:1px #eee solid; padding:4px; margin-right:1px; float:left;'>" ); |
| 618 | + $wgOut->addHTML( wfMsg( 'sphinxSearchInNamespaces' ) . '<br />' ); |
560 | 619 | $all_namespaces = self::searchableNamespaces(); |
561 | | - foreach( $all_namespaces as $ns => $name ) { |
562 | | - $checked = in_array($ns, $this->namespaces) ? ' checked="checked"' : ''; |
| 620 | + foreach ( $all_namespaces as $ns => $name ) { |
| 621 | + $checked = in_array( $ns, $this->namespaces ) ? ' checked="checked"' : ''; |
563 | 622 | $name = str_replace( '_', ' ', $name ); |
564 | | - if('' == $name) { |
565 | | - $name = wfMsg('blanknamespace'); |
| 623 | + if ( '' == $name ) { |
| 624 | + $name = wfMsg( 'blanknamespace' ); |
566 | 625 | } |
567 | | - $wgOut->addHTML("<label><input type='checkbox' value='1' name='ns$ns'$checked />$name</label><br />"); |
| 626 | + $wgOut->addHTML( "<label><input type='checkbox' value='1' name='ns$ns'$checked />$name</label><br />" ); |
568 | 627 | } |
569 | 628 | |
570 | 629 | $all_categories = self::searchableCategories(); |
571 | | - if (is_array($all_categories) && count($all_categories)) { |
572 | | - $cat_parents = $wgRequest->getIntArray("catp", array()); |
573 | | - $wgOut->addScript(Skin::makeVariablesScript(array( |
574 | | - 'sphinxLoadingMsg' => wfMsg('sphinxLoading'), |
575 | | - 'wgSphinxSearchExtPath' => ($wgSphinxSearchJSPath ? $wgSphinxSearchJSPath : $wgSphinxSearchExtPath) |
576 | | - ))); |
| 630 | + if ( is_array( $all_categories ) && count( $all_categories ) ) { |
| 631 | + $cat_parents = $wgRequest->getIntArray( "catp", array() ); |
| 632 | + $wgOut->addScript( Skin::makeVariablesScript( array( |
| 633 | + 'sphinxLoadingMsg' => wfMsg( 'sphinxLoading' ), |
| 634 | + 'wgSphinxSearchExtPath' => ( $wgSphinxSearchJSPath ? $wgSphinxSearchJSPath : $wgSphinxSearchExtPath ) |
| 635 | + ) ) ); |
577 | 636 | $wgOut->addScript( |
578 | | - "<script type='{$wgJsMimeType}' src='".($wgSphinxSearchJSPath ? $wgSphinxSearchJSPath : $wgSphinxSearchExtPath)."/SphinxSearch.js?2'></script>\n" |
579 | | - ); |
580 | | - $wgOut->addHTML("</div><div style='width:30%; border:1px #eee solid; padding:4px; margin-right:1px; float:left;'>"); |
581 | | - $wgOut->addHTML(wfMsg('sphinxSearchInCategories') ); |
582 | | - if ($wgUseExcludes) { |
| 637 | + "<script type='{$wgJsMimeType}' src='" . |
| 638 | + ( $wgSphinxSearchJSPath ? $wgSphinxSearchJSPath : $wgSphinxSearchExtPath ) . |
| 639 | + "/SphinxSearch.js?2'></script>\n" |
| 640 | + ); |
| 641 | + $wgOut->addHTML( "</div> |
| 642 | + <div style='width:30%; border:1px #eee solid; padding:4px; margin-right:1px; float:left;'>" |
| 643 | + ); |
| 644 | + $wgOut->addHTML( wfMsg('sphinxSearchInCategories') ); |
| 645 | + if ( $wgUseExcludes ) { |
583 | 646 | $wgOut->addHTML("<div style='float:right; font-size:80%;'>exclude</div>"); |
584 | 647 | } |
585 | 648 | $wgOut->addHTML('<br />'); |
586 | | - $wgOut->addHTML($this->getCategoryCheckboxes($all_categories, '', $cat_parents)); |
| 649 | + $wgOut->addHTML( $this->getCategoryCheckboxes( $all_categories, '', $cat_parents ) ); |
587 | 650 | } |
588 | | - $wgOut->addHTML("</div></form><br clear='both'>"); |
| 651 | + $wgOut->addHTML( "</div></form><br clear='both'>" ); |
589 | 652 | |
590 | 653 | # Put a Sphinx label for this search |
591 | | - $wgOut->addHTML("<div style='text-align:center'>" . sprintf(wfMsg('sphinxPowered'), "<a href='http://www.sphinxsearch.com/'>Sphinx</a>") . "</div>"); |
| 654 | + $wgOut->addHTML( "<div style='text-align:center'>" . |
| 655 | + wfMsg( 'sphinxPowered', "<a href='http://www.sphinxsearch.com/'>Sphinx</a>" ) . |
| 656 | + "</div>" |
| 657 | + ); |
592 | 658 | } |
593 | 659 | |
594 | | - function getCategoryCheckboxes($all_categories, $parent_id, $cat_parents = array()) { |
| 660 | + function getCategoryCheckboxes( $all_categories, $parent_id, $cat_parents = array() ) { |
595 | 661 | global $wgUseAjax, $wgRequest, $wgUseExcludes; |
596 | 662 | |
597 | 663 | $html = ''; |
598 | 664 | |
599 | | - foreach( $all_categories as $cat => $name ) { |
| 665 | + foreach ( $all_categories as $cat => $name ) { |
600 | 666 | $input_attrs = ''; |
601 | | - if ($this && in_array($cat, $this->categories)) { |
| 667 | + if ( $this && in_array( $cat, $this->categories ) ) { |
602 | 668 | $input_attrs .= ' checked="checked"'; |
603 | 669 | } |
604 | 670 | $name = str_replace( '_', ' ', $name ); |
605 | | - if('' == $name) { |
606 | | - $name = wfMsg('blanknamespace'); |
| 671 | + if ( '' == $name ) { |
| 672 | + $name = wfMsg( 'blanknamespace' ); |
607 | 673 | } |
608 | 674 | $children = ''; |
609 | | - if (isset($cat_parents['_'.$cat]) && ($input_attrs || $cat_parents['_'.$cat] > 0)) { |
| 675 | + if ( isset( $cat_parents['_' . $cat] ) && ( $input_attrs || $cat_parents['_' . $cat] > 0 ) ) { |
610 | 676 | $title = Title::newFromID( $cat ); |
611 | | - $children_cats = self::getChildrenCategories($title->getDBkey()); |
612 | | - if (count($children_cats)) { |
613 | | - if ($this) { |
614 | | - $children = $this->getCategoryCheckboxes($children_cats, $cat, $cat_parents); |
| 677 | + $children_cats = self::getChildrenCategories( $title->getDBkey() ); |
| 678 | + if ( count( $children_cats ) ) { |
| 679 | + if ( $this ) { |
| 680 | + $children = $this->getCategoryCheckboxes( $children_cats, $cat, $cat_parents ); |
615 | 681 | } else { |
616 | | - $children = self::getCategoryCheckboxes($children_cats, $cat, $cat_parents); |
| 682 | + $children = self::getCategoryCheckboxes( $children_cats, $cat, $cat_parents ); |
617 | 683 | } |
618 | 684 | } |
619 | 685 | } |
620 | | - if ($wgUseAjax) { |
| 686 | + if ( $wgUseAjax ) { |
621 | 687 | $input_attrs .= " onmouseup='sphinxShowCats(this)'"; |
622 | 688 | } |
623 | 689 | $html .= "<label><input type='checkbox' id='{$parent_id}_$cat' value='$cat' name='cat[]'$input_attrs />$name</label>"; |
624 | | - if ($wgUseExcludes) { |
| 690 | + if ( $wgUseExcludes ) { |
625 | 691 | $input_attrs = ''; |
626 | | - if ($this && in_array($cat, $this->exc_categories)) { |
| 692 | + if ( $this && in_array( $cat, $this->exc_categories ) ) { |
627 | 693 | $input_attrs .= ' checked="checked"'; |
628 | 694 | } |
629 | | - if ($wgUseAjax) { |
| 695 | + if ( $wgUseAjax ) { |
630 | 696 | $input_attrs .= " onmouseup='sphinxShowCats(this)'"; |
631 | 697 | } |
632 | 698 | $html .= "<input type='checkbox' id='exc_{$parent_id}_$cat' value='$cat' name='exc[]'$input_attrs style='float:right' />"; |
633 | 699 | } |
634 | 700 | $html .= "<div id='cat{$cat}_children'>$children</div>\n"; |
635 | 701 | } |
636 | | - if ($parent_id && $html) { |
637 | | - $html = "<input type='hidden' name='catp[_$parent_id]' value='".intval($cat_parents['_'.$parent_id])."' /><div style='margin-left:10px; margin-bottom:4px; padding-left:8px; border-left:1px dashed #ccc; border-bottom:1px solid #ccc;'>".$html."</div>"; |
| 702 | + if ( $parent_id && $html ) { |
| 703 | + $html = "<input type='hidden' name='catp[_$parent_id]' value='" . |
| 704 | + intval( $cat_parents['_' . $parent_id] ) . |
| 705 | + "' /><div style='margin-left:10px; margin-bottom:4px; padding-left:8px; border-left:1px dashed #ccc; border-bottom:1px solid #ccc;'>" . |
| 706 | + $html . "</div>"; |
638 | 707 | } |
639 | 708 | return $html; |
640 | 709 | } |
— | — | @@ -650,9 +719,9 @@ |
651 | 720 | global $wgSphinxSearch_index; |
652 | 721 | |
653 | 722 | $this->mResultSet = array(); |
654 | | - if (is_array($rs) && is_array($rs['matches'])) { |
| 723 | + if ( is_array( $rs ) && is_array( $rs['matches'] ) ) { |
655 | 724 | $dbr = wfGetDB( DB_SLAVE ); |
656 | | - foreach ($rs['matches'] as $id => $docinfo) { |
| 725 | + foreach ( $rs['matches'] as $id => $docinfo ) { |
657 | 726 | $res = $dbr->select( |
658 | 727 | 'page', |
659 | 728 | array( 'page_id', 'page_title', 'page_namespace' ), |
— | — | @@ -660,8 +729,8 @@ |
661 | 730 | __METHOD__, |
662 | 731 | array() |
663 | 732 | ); |
664 | | - if( $dbr->numRows( $res ) > 0 ) { |
665 | | - $this->mResultSet[] = $dbr->fetchObject($res); |
| 733 | + if ( $dbr->numRows( $res ) > 0 ) { |
| 734 | + $this->mResultSet[] = $dbr->fetchObject( $res ); |
666 | 735 | } |
667 | 736 | } |
668 | 737 | } |
— | — | @@ -678,7 +747,7 @@ |
679 | 748 | } |
680 | 749 | |
681 | 750 | function next() { |
682 | | - if( isset($this->mResultSet[$this->mNdx]) ) { |
| 751 | + if ( isset( $this->mResultSet[$this->mNdx] ) ) { |
683 | 752 | $row = $this->mResultSet[$this->mNdx]; |
684 | 753 | ++$this->mNdx; |
685 | 754 | return new SearchResult( $row ); |
Index: trunk/extensions/SphinxSearch/SphinxSearch.i18n.php |
— | — | @@ -3,29 +3,29 @@ |
4 | 4 | $messages = array(); |
5 | 5 | |
6 | 6 | /* *** English *** */ |
7 | | -$messages['en'] = array( |
| 7 | +$messages['en'] = array( |
8 | 8 | 'sphinxsearch' => 'Search wiki using Sphinx', |
9 | 9 | 'sphinxsearch-desc' => 'Replaces MediaWiki search engine with [http://www.sphinxsearch.com/ Sphinx]', |
10 | 10 | 'sphinxSearchInNamespaces' => 'Search in namespaces:', |
11 | 11 | 'sphinxSearchInCategories' => 'Search in categories:', |
12 | 12 | 'sphinxExcludeCategories' => 'Categories to exclude', |
13 | | - 'sphinxResultPage' => 'Result page', |
| 13 | + 'sphinxResultPage' => 'Result page:', |
14 | 14 | 'sphinxPreviousPage' => 'Previous', |
15 | 15 | 'sphinxNextPage' => 'Next', |
16 | | - 'sphinxSearchPreamble' => "Displaying %d-%d of %d matches for query '''<nowiki>%s</nowiki>''' retrieved in %0.3f sec with these stats", |
17 | | - 'sphinxSearchStats' => "'''%s''' found %d times in %d documents", |
18 | | - 'sphinxSearchStatsInfo' => 'Above numbers may include documents not listed due to search options', |
| 16 | + 'sphinxSearchPreamble' => 'Displaying $1—$2 of $3 matches for query "<nowiki>$4</nowiki>" retrieved in $5 sec with these stats:', |
| 17 | + 'sphinxSearchStats' => '"$1" found $2 times in $3 documents', |
| 18 | + 'sphinxSearchStatsInfo' => 'Above numbers may include documents not listed due to search options.', |
19 | 19 | 'sphinxSearchButton' => 'Search', |
20 | | - 'sphinxSearchEpilogue' => 'Additional database time was %0.3f sec.', |
| 20 | + 'sphinxSearchEpilogue' => 'Additional database time was $1 sec.', |
21 | 21 | 'sphinxSearchDidYouMean' => 'Did you mean', |
22 | 22 | 'sphinxMatchAny' => 'match any word', |
23 | 23 | 'sphinxMatchAll' => 'match all words', |
24 | 24 | 'sphinxMatchTitles' => 'match titles only', |
25 | 25 | 'sphinxLoading' => 'Loading...', |
26 | | - 'sphinxPowered' => 'Powered by %s', |
27 | | - 'sphinxClientFailed' => 'Could not instantiate SphinxClient', |
28 | | - 'sphinxSearchFailed' => 'Query failed:', |
29 | | - 'sphinxSearchWarning' => 'Warning:' |
| 26 | + 'sphinxPowered' => 'Powered by $1', |
| 27 | + 'sphinxClientFailed' => 'Could not instantiate Sphinx client.', |
| 28 | + 'sphinxSearchFailed' => 'Query failed: $1', |
| 29 | + 'sphinxSearchWarning' => 'Warning: $1' |
30 | 30 | ); |
31 | 31 | |
32 | 32 | /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
— | — | @@ -38,23 +38,23 @@ |
39 | 39 | 'sphinxSearchInNamespaces' => 'Шукаць у прасторах назваў:', |
40 | 40 | 'sphinxSearchInCategories' => 'Шукаць у катэгорыях:', |
41 | 41 | 'sphinxExcludeCategories' => 'За выключэньнем катэгорыяў', |
42 | | - 'sphinxResultPage' => 'Старонка вынікаў', |
| 42 | + 'sphinxResultPage' => 'Старонка вынікаў:', |
43 | 43 | 'sphinxPreviousPage' => 'Папярэдняя', |
44 | 44 | 'sphinxNextPage' => 'Наступная', |
45 | | - 'sphinxSearchPreamble' => "Паказ супадзеньні %d—%d з %d для запыту '''<nowiki>%s</nowiki>''', пошук склаў %0.3f с улічваючы гэтую статыстыку", |
46 | | - 'sphinxSearchStats' => "'''%s''' знойдзена %d разоў у %d дакумэнтах", |
47 | | - 'sphinxSearchStatsInfo' => 'Прыведзеныя лічбы могуць утрымліваць дакумэнты, не паказаныя з-за установак пошуку', |
| 45 | + 'sphinxSearchPreamble' => 'Паказ супадзеньні $1—$2 з $3 для запыту "<nowiki>$4</nowiki>", пошук склаў $5 с улічваючы гэтую статыстыку', |
| 46 | + 'sphinxSearchStats' => '"$1" знойдзена $2 разоў у $3 дакумэнтах', |
| 47 | + 'sphinxSearchStatsInfo' => 'Прыведзеныя лічбы могуць утрымліваць дакумэнты, не паказаныя з-за установак пошуку.', |
48 | 48 | 'sphinxSearchButton' => 'Шукаць', |
49 | | - 'sphinxSearchEpilogue' => 'Дадатковы час базы зьвестак склаў %0.3f с.', |
| 49 | + 'sphinxSearchEpilogue' => 'Дадатковы час базы зьвестак склаў $1 с.', |
50 | 50 | 'sphinxSearchDidYouMean' => 'Вы мелі на ўвазе', |
51 | 51 | 'sphinxMatchAny' => 'супадзеньне з любым словам', |
52 | 52 | 'sphinxMatchAll' => 'супадзеньне па ўсім словам', |
53 | 53 | 'sphinxMatchTitles' => 'супадзеньне толькі загалоўкаў', |
54 | 54 | 'sphinxLoading' => 'Загрузка…', |
55 | | - 'sphinxPowered' => 'Працуе на %s', |
56 | | - 'sphinxClientFailed' => 'Немагчыма стварыць экзэмпляр SphinxClient', |
57 | | - 'sphinxSearchFailed' => 'Памылка запыту:', |
58 | | - 'sphinxSearchWarning' => 'Папярэджаньне:', |
| 55 | + 'sphinxPowered' => 'Працуе на $1', |
| 56 | + 'sphinxClientFailed' => 'Немагчыма стварыць экзэмпляр SphinxClient.', |
| 57 | + 'sphinxSearchFailed' => 'Памылка запыту: $1', |
| 58 | + 'sphinxSearchWarning' => 'Папярэджаньне: $1', |
59 | 59 | ); |
60 | 60 | |
61 | 61 | /** Bulgarian (Български) */ |
— | — | @@ -70,19 +70,19 @@ |
71 | 71 | 'sphinxsearch' => 'Klask er wiki en ur implijout Sphinx', |
72 | 72 | 'sphinxsearch-desc' => "Erlec'hiañ lusker enklask MediaWiki gant [http://www.sphinxsearch.com/ Sphinx].", |
73 | 73 | 'sphinxSearchInNamespaces' => 'Klask en esaouennoù anv :', |
74 | | - 'sphinxSearchInCategories' => 'Klask er rummadoù', |
75 | | - 'sphinxResultPage' => "Pajenn an disoc'hoù", |
| 74 | + 'sphinxSearchInCategories' => 'Klask er rummadoù :', |
| 75 | + 'sphinxResultPage' => "Pajenn an disoc'hoù :", |
76 | 76 | 'sphinxPreviousPage' => 'Kent', |
77 | 77 | 'sphinxNextPage' => "War-lerc'h", |
78 | | - 'sphinxSearchStats' => "'''%s''' bet kavet %d gwech e %d teul", |
| 78 | + 'sphinxSearchStats' => '"$1" bet kavet $2 gwech e $3 teul', |
79 | 79 | 'sphinxSearchButton' => 'Klask', |
80 | 80 | 'sphinxSearchDidYouMean' => "N'hoc'h eus ket soñjet kentoc'h e", |
81 | 81 | 'sphinxMatchAny' => 'kavout forzh peseurt ger', |
82 | 82 | 'sphinxMatchAll' => 'kavout an holl gerioù', |
83 | 83 | 'sphinxMatchTitles' => 'klask en titloù hepken', |
84 | 84 | 'sphinxLoading' => 'O kargañ...', |
85 | | - 'sphinxPowered' => 'Savet diwar %s', |
86 | | - 'sphinxSearchWarning' => 'Diwallit :', |
| 85 | + 'sphinxPowered' => 'Savet diwar $1', |
| 86 | + 'sphinxSearchWarning' => 'Diwallit : $1', |
87 | 87 | ); |
88 | 88 | |
89 | 89 | /** Spanish (Español) |
— | — | @@ -97,20 +97,20 @@ |
98 | 98 | 'sphinxResultPage' => 'Página de resultados', |
99 | 99 | 'sphinxPreviousPage' => 'Anterior', |
100 | 100 | 'sphinxNextPage' => 'Siguiente', |
101 | | - 'sphinxSearchPreamble' => "Mostrando %d-%d de %d coincidencias para la búsqueda de '''<nowiki>%s</nowiki>''', recuperado en %0.3f segundo(s) incluyendo estas estadísticas", |
102 | | - 'sphinxSearchStats' => "'''%s''' fue encontrado %d veces en %d documentos", |
103 | | - 'sphinxSearchStatsInfo' => 'Los números mostrados arriba pueden incluir documentos no listados debido a las opciones de búsqueda', |
| 101 | + 'sphinxSearchPreamble' => 'Mostrando $1—$2 de $3 coincidencias para la búsqueda de "<nowiki>$4</nowiki>", recuperado en $5 segundo(s) incluyendo estas estadísticas', |
| 102 | + 'sphinxSearchStats' => '"$1" fue encontrado $2 veces en $3 documentos', |
| 103 | + 'sphinxSearchStatsInfo' => 'Los números mostrados arriba pueden incluir documentos no listados debido a las opciones de búsqueda.', |
104 | 104 | 'sphinxSearchButton' => 'Buscar', |
105 | | - 'sphinxSearchEpilogue' => 'El tiempo de base de datos adicional fue de %0.3f segundos.', |
| 105 | + 'sphinxSearchEpilogue' => 'El tiempo de base de datos adicional fue de $1 segundos.', |
106 | 106 | 'sphinxSearchDidYouMean' => 'Quizás quiso decir', |
107 | 107 | 'sphinxMatchAny' => 'coincidencia de cualquier palabra', |
108 | 108 | 'sphinxMatchAll' => 'coincidencia de todas las palabras', |
109 | 109 | 'sphinxMatchTitles' => 'coincidencia únicamente en los títulos', |
110 | 110 | 'sphinxLoading' => 'Cargando', |
111 | | - 'sphinxPowered' => 'Potenciado por %s', |
112 | | - 'sphinxClientFailed' => 'No se pudo instanciar el cliente Sphinx', |
113 | | - 'sphinxSearchFailed' => 'Falló la búsqueda', |
114 | | - 'sphinxSearchWarning' => 'ADVERTENCIA', |
| 111 | + 'sphinxPowered' => 'Potenciado por $1', |
| 112 | + 'sphinxClientFailed' => 'No se pudo instanciar el cliente Sphinx.', |
| 113 | + 'sphinxSearchFailed' => 'Falló la búsqueda $1', |
| 114 | + 'sphinxSearchWarning' => 'Advertencia $1', |
115 | 115 | ); |
116 | 116 | |
117 | 117 | /** French (Français) |
— | — | @@ -125,20 +125,20 @@ |
126 | 126 | 'sphinxResultPage' => 'Page de résultats', |
127 | 127 | 'sphinxPreviousPage' => 'Précédent', |
128 | 128 | 'sphinxNextPage' => 'Suivant', |
129 | | - 'sphinxSearchPreamble' => "Affichage des résultats %d-%d sur %d pour la requête '''<nowiki>%s</nowiki>''' accomplie en %0.3f secondes avec ces statistiques", |
130 | | - 'sphinxSearchStats' => "'''%s''' trouvé %d fois dans %d documents", |
131 | | - 'sphinxSearchStatsInfo' => 'Les valeurs ci-dessus peuvent inclure des documents masqués par les options de recherche', |
| 129 | + 'sphinxSearchPreamble' => 'Affichage des résultats $1—$2 sur $3 pour la requête "<nowiki>$4</nowiki>" accomplie en $5 secondes avec ces statistiques', |
| 130 | + 'sphinxSearchStats' => '"$1" trouvé $2 fois dans $3 documents', |
| 131 | + 'sphinxSearchStatsInfo' => 'Les valeurs ci-dessus peuvent inclure des documents masqués par les options de recherche.', |
132 | 132 | 'sphinxSearchButton' => 'Rechercher', |
133 | | - 'sphinxSearchEpilogue' => 'Le temps additionnel de la base de données était de %0.3f sec.', |
| 133 | + 'sphinxSearchEpilogue' => 'Le temps additionnel de la base de données était de $1 sec.', |
134 | 134 | 'sphinxSearchDidYouMean' => 'Vouliez-vous dire', |
135 | 135 | 'sphinxMatchAny' => "trouver n'importe quel mot", |
136 | 136 | 'sphinxMatchAll' => 'trouver tous les mots', |
137 | 137 | 'sphinxMatchTitles' => 'ne chercher que dans les titres', |
138 | 138 | 'sphinxLoading' => 'Chargement …', |
139 | | - 'sphinxPowered' => 'Propulsé par %s', |
140 | | - 'sphinxClientFailed' => "Impossible d'instancier SphinxClient", |
141 | | - 'sphinxSearchFailed' => 'Échec de la requête', |
142 | | - 'sphinxSearchWarning' => 'AVERTISSEMENT', |
| 139 | + 'sphinxPowered' => 'Propulsé par $1', |
| 140 | + 'sphinxClientFailed' => "Impossible d'instancier SphinxClient.", |
| 141 | + 'sphinxSearchFailed' => 'Échec de la requête $1', |
| 142 | + 'sphinxSearchWarning' => 'Avertissement $1', |
143 | 143 | ); |
144 | 144 | |
145 | 145 | /** Galician (Galego) |
— | — | @@ -153,48 +153,49 @@ |
154 | 154 | 'sphinxResultPage' => 'Páxina de resultados', |
155 | 155 | 'sphinxPreviousPage' => 'Anterior', |
156 | 156 | 'sphinxNextPage' => 'Seguinte', |
157 | | - 'sphinxSearchPreamble' => "Mostrando %d-%d coincidencias dun total de %d que deu a pescuda \"'''<nowiki>%s</nowiki>'''\", obtidas en %0.3f segundos coas estatísticas", |
158 | | - 'sphinxSearchStats' => "\"'''%s'''\" atopouse %d veces en %d documentos", |
159 | | - 'sphinxSearchStatsInfo' => 'Os números superiores poden incluír documentos non listados debido ás opcións de procura', |
| 157 | + 'sphinxSearchPreamble' => 'Mostrando $1—$2 coincidencias dun total de $3 que deu a pescuda "<nowiki>$4</nowiki>", obtidas en $5 segundos coas estatísticas', |
| 158 | + 'sphinxSearchStats' => '"$1" atopouse $2 veces en $3 documentos', |
| 159 | + 'sphinxSearchStatsInfo' => 'Os números superiores poden incluír documentos non listados debido ás opcións de procura.', |
160 | 160 | 'sphinxSearchButton' => 'Procurar', |
161 | | - 'sphinxSearchEpilogue' => 'O tempo adicional da base de datos foi de %0.3f segundos.', |
| 161 | + 'sphinxSearchEpilogue' => 'O tempo adicional da base de datos foi de $1 segundos.', |
162 | 162 | 'sphinxSearchDidYouMean' => 'Quizais quixo dicir', |
163 | 163 | 'sphinxMatchAny' => 'atopar calquera palabra', |
164 | 164 | 'sphinxMatchAll' => 'atopar todas as palabras', |
165 | 165 | 'sphinxMatchTitles' => 'atopar só nos títulos', |
166 | 166 | 'sphinxLoading' => 'Cargando...', |
167 | | - 'sphinxPowered' => 'Desenvolvido por %s', |
168 | | - 'sphinxClientFailed' => 'Non se puido conectar co SphinxClient', |
169 | | - 'sphinxSearchFailed' => 'Fallou a pescuda', |
170 | | - 'sphinxSearchWarning' => 'AVISO', |
| 167 | + 'sphinxPowered' => 'Desenvolvido por $1', |
| 168 | + 'sphinxClientFailed' => 'Non se puido conectar co SphinxClient.', |
| 169 | + 'sphinxSearchFailed' => 'Fallou a pescuda $1', |
| 170 | + 'sphinxSearchWarning' => 'Aviso $1', |
171 | 171 | ); |
172 | 172 | |
173 | 173 | /** Swiss German (Alemannisch) |
174 | 174 | * @author Als-Holder |
175 | 175 | */ |
176 | 176 | $messages['gsw'] = array( |
| 177 | + |
177 | 178 | 'sphinxsearch' => 'Wiki dursueche mit Sphinx', |
178 | 179 | 'sphinxsearch-desc' => 'Ersetzt d MediaWiki-Suechmahscin dur [http://www.sphinxsearch.com/ Sphinx]', |
179 | 180 | 'sphinxSearchInNamespaces' => 'Suech in Namensryym:', |
180 | 181 | 'sphinxSearchInCategories' => 'In Kategorie sueche:', |
181 | 182 | 'sphinxExcludeCategories' => 'Kategorie, wu solle uusgschlosse syy', |
182 | | - 'sphinxResultPage' => 'Ergebnissyte', |
| 183 | + 'sphinxResultPage' => 'Ergebnissyte:', |
183 | 184 | 'sphinxPreviousPage' => 'Vorigi', |
184 | 185 | 'sphinxNextPage' => 'Negschti', |
185 | | - 'sphinxSearchPreamble' => "%d-%d vu %d Ergebnis fir d Abfrog '''<nowiki>%s</nowiki>'''. Suechzyt: %0.3f Sekunde", |
186 | | - 'sphinxSearchStats' => "'''%s''' %d mol gfunde in %d Dokumänt", |
| 186 | + 'sphinxSearchPreamble' => '$1—$2 vu $3 Ergebnis fir d Abfrog "<nowiki>$4</nowiki>". Suechzyt: $5 Sekunde', |
| 187 | + 'sphinxSearchStats' => '"$1" $2 mol gfunde in $3 Dokumänt', |
187 | 188 | 'sphinxSearchStatsInfo' => 'In däre Zahl wäre villicht Dokumänt mitzellt, wu wäge bstimmte Suechyystellige nit ufglischtet wäre', |
188 | 189 | 'sphinxSearchButton' => 'Sueche', |
189 | | - 'sphinxSearchEpilogue' => 'Zuesätzligi Datebankzyt isch %0.3f Sekunde gsi.', |
| 190 | + 'sphinxSearchEpilogue' => 'Zuesätzligi Datebankzyt isch $1 Sekunde gsi.', |
190 | 191 | 'sphinxSearchDidYouMean' => 'Hesch gmeint', |
191 | 192 | 'sphinxMatchAny' => 'irged e Wort', |
192 | 193 | 'sphinxMatchAll' => 'alli Werter', |
193 | 194 | 'sphinxMatchTitles' => 'nume Sytename', |
194 | 195 | 'sphinxLoading' => 'Am Lade …', |
195 | | - 'sphinxPowered' => 'Betribe mit %s', |
| 196 | + 'sphinxPowered' => 'Betribe mit $1', |
196 | 197 | 'sphinxClientFailed' => 'Het dr SphinxClient nit chenne inizialisiere', |
197 | | - 'sphinxSearchFailed' => 'Abfrog fähl gschlaa:', |
198 | | - 'sphinxSearchWarning' => 'Warnig:', |
| 198 | + 'sphinxSearchFailed' => 'Abfrog fähl gschlaa: $1', |
| 199 | + 'sphinxSearchWarning' => 'Warnig: $1', |
199 | 200 | ); |
200 | 201 | |
201 | 202 | /** Interlingua (Interlingua) |
— | — | @@ -206,23 +207,23 @@ |
207 | 208 | 'sphinxSearchInNamespaces' => 'Cercar in spatios de nomines', |
208 | 209 | 'sphinxSearchInCategories' => 'Cercar in categorias:', |
209 | 210 | 'sphinxExcludeCategories' => 'Categorias a excluder', |
210 | | - 'sphinxResultPage' => 'Pagina de resultatos', |
| 211 | + 'sphinxResultPage' => 'Pagina de resultatos:', |
211 | 212 | 'sphinxPreviousPage' => 'Precedente', |
212 | 213 | 'sphinxNextPage' => 'Sequente', |
213 | | - 'sphinxSearchPreamble' => "Resultatos %d-%d de %d pro le recerca de '''<nowiki>%s</nowiki>''' recuperate in %0.3f secundas con iste statisticas", |
214 | | - 'sphinxSearchStats' => "'''%s''' trovate %d vices in %d documentos", |
215 | | - 'sphinxSearchStatsInfo' => 'Le numeros hic supra pote includer documentos non listate debite al optiones de recerca', |
| 214 | + 'sphinxSearchPreamble' => 'Resultatos $1—$2 de $3 pro le recerca de "<nowiki>$4</nowiki>" recuperate in $5 secundas con iste statisticas', |
| 215 | + 'sphinxSearchStats' => '"$1" trovate $2 vices in $3 documentos', |
| 216 | + 'sphinxSearchStatsInfo' => 'Le numeros hic supra pote includer documentos non listate debite al optiones de recerca.', |
216 | 217 | 'sphinxSearchButton' => 'Cercar', |
217 | | - 'sphinxSearchEpilogue' => 'Le tempore additional del base de datos esseva %0.3f secundas.', |
| 218 | + 'sphinxSearchEpilogue' => 'Le tempore additional del base de datos esseva $1 secundas.', |
218 | 219 | 'sphinxSearchDidYouMean' => 'Esque tu vole dicer', |
219 | 220 | 'sphinxMatchAny' => 'trovar qualcunque parola', |
220 | 221 | 'sphinxMatchAll' => 'trovar tote le parolas', |
221 | 222 | 'sphinxMatchTitles' => 'cercar solmente in titulos', |
222 | 223 | 'sphinxLoading' => 'Cargamento…', |
223 | | - 'sphinxPowered' => 'Actionate per %s', |
224 | | - 'sphinxClientFailed' => 'Non poteva instantiar SphinxClient', |
225 | | - 'sphinxSearchFailed' => 'Consulta fallite:', |
226 | | - 'sphinxSearchWarning' => 'Advertimento:', |
| 224 | + 'sphinxPowered' => 'Actionate per $1', |
| 225 | + 'sphinxClientFailed' => 'Non poteva instantiar SphinxClient.', |
| 226 | + 'sphinxSearchFailed' => 'Consulta fallite: $1', |
| 227 | + 'sphinxSearchWarning' => 'Advertimento: $1', |
227 | 228 | ); |
228 | 229 | |
229 | 230 | /** Japanese (日本語) |
— | — | @@ -231,14 +232,14 @@ |
232 | 233 | $messages['ja'] = array( |
233 | 234 | 'sphinxSearchInNamespaces' => '名前空間で検索:', |
234 | 235 | 'sphinxSearchInCategories' => 'カテゴリで検索:', |
235 | | - 'sphinxResultPage' => '結果ページ', |
| 236 | + 'sphinxResultPage' => '結果ページ:', |
236 | 237 | 'sphinxPreviousPage' => '前', |
237 | 238 | 'sphinxNextPage' => '次', |
238 | | - 'sphinxSearchStats' => "'''%s'''が、%dの文書で、\$dコ見つかりました", |
| 239 | + 'sphinxSearchStats' => '"$1"が、$2の文書で、$3コ見つかりました', |
239 | 240 | 'sphinxSearchButton' => '検索', |
240 | 241 | 'sphinxSearchDidYouMean' => 'もしかして', |
241 | | - 'sphinxPowered' => '%sの提供', |
242 | | - 'sphinxSearchWarning' => '警告:', |
| 242 | + 'sphinxPowered' => '$1の提供', |
| 243 | + 'sphinxSearchWarning' => '警告: $1', |
243 | 244 | ); |
244 | 245 | |
245 | 246 | /** Luxembourgish (Lëtzebuergesch) |
— | — | @@ -249,23 +250,23 @@ |
250 | 251 | 'sphinxSearchInNamespaces' => 'Sich an den Nummraim:', |
251 | 252 | 'sphinxSearchInCategories' => 'Sichen an de Kategorien:', |
252 | 253 | 'sphinxExcludeCategories' => 'Kategorien fir auszeschléissen', |
253 | | - 'sphinxResultPage' => 'Säit mat de Resultater', |
| 254 | + 'sphinxResultPage' => 'Säit mat de Resultater:', |
254 | 255 | 'sphinxPreviousPage' => 'Vireg', |
255 | 256 | 'sphinxNextPage' => 'Nächst', |
256 | | - 'sphinxSearchStats' => "'''%s''' gouf %d mol an %d Dokumenter fonnt", |
| 257 | + 'sphinxSearchStats' => '"$1" gouf $2 mol an $3 Dokumenter fonnt', |
257 | 258 | 'sphinxSearchButton' => 'Sichen', |
258 | 259 | 'sphinxSearchDidYouMean' => 'Mengt Dir', |
259 | 260 | 'sphinxMatchTitles' => 'nëmmen an den Titele sichen', |
260 | 261 | 'sphinxLoading' => 'Lueden...', |
261 | | - 'sphinxSearchFailed' => 'Ufro huet net fonctionnéiert:', |
262 | | - 'sphinxSearchWarning' => 'Warnung:', |
| 262 | + 'sphinxSearchFailed' => 'Ufro huet net fonctionnéiert: $1', |
| 263 | + 'sphinxSearchWarning' => 'Warnung: $1', |
263 | 264 | ); |
264 | 265 | |
265 | 266 | /** Macedonian (Македонски) |
266 | 267 | * @author Bjankuloski06 |
267 | 268 | */ |
268 | 269 | $messages['mk'] = array( |
269 | | - 'sphinxsearch' => 'Пребоарување по вики со Sphinx', |
| 270 | + 'sphinxsearch' => 'Пребарување по вики со Sphinx', |
270 | 271 | 'sphinxsearch-desc' => 'Замена на МедијаВики пребарувачот со [http://www.sphinxsearch.com/ Sphinx].', |
271 | 272 | 'sphinxSearchInNamespaces' => 'Барај во именски простори', |
272 | 273 | 'sphinxSearchInCategories' => 'Барај во категории', |
— | — | @@ -273,20 +274,20 @@ |
274 | 275 | 'sphinxResultPage' => 'Страница за резулати', |
275 | 276 | 'sphinxPreviousPage' => 'Претходна', |
276 | 277 | 'sphinxNextPage' => 'Следна', |
277 | | - 'sphinxSearchPreamble' => "Приказ на %d-%d од вкупно %d совпаѓања за барањето '''<nowiki>%s</nowiki>''' извршено за %0.3f сек. со следниве статистики", |
278 | | - 'sphinxSearchStats' => "'''%s''' е пронајдено %d пати во %d документи", |
279 | | - 'sphinxSearchStatsInfo' => 'Горенаведените бројки може да содржат документи кои не се наведени поради нагодувањата на пребарувањето', |
| 278 | + 'sphinxSearchPreamble' => 'Приказ на $1—$2 од вкупно $3 совпаѓања за барањето "<nowiki>$4</nowiki>" извршено за $5 сек. со следниве статистики', |
| 279 | + 'sphinxSearchStats' => '"$1" е пронајдено $2 пати во $3 документи', |
| 280 | + 'sphinxSearchStatsInfo' => 'Горенаведените бројки може да содржат документи кои не се наведени поради нагодувањата на пребарувањето.', |
280 | 281 | 'sphinxSearchButton' => 'Пребарај', |
281 | | - 'sphinxSearchEpilogue' => 'Дополнителното време за базата на податоци изнесуваше %0.3f сек.', |
| 282 | + 'sphinxSearchEpilogue' => 'Дополнителното време за базата на податоци изнесуваше $1 сек.', |
282 | 283 | 'sphinxSearchDidYouMean' => 'Дали мислевте на', |
283 | 284 | 'sphinxMatchAny' => 'барај било кој збор', |
284 | 285 | 'sphinxMatchAll' => 'барај само зборови', |
285 | 286 | 'sphinxMatchTitles' => 'барај само наслови', |
286 | 287 | 'sphinxLoading' => 'Вчитувам...', |
287 | | - 'sphinxPowered' => 'Овозможено од %s', |
288 | | - 'sphinxClientFailed' => 'Не можев да го повикам SphinxClient', |
289 | | - 'sphinxSearchFailed' => 'Барањето не успеа', |
290 | | - 'sphinxSearchWarning' => 'ПРЕДУПРЕДУВАЊЕ', |
| 288 | + 'sphinxPowered' => 'Овозможено од $1', |
| 289 | + 'sphinxClientFailed' => 'Не можев да го повикам Sphinx клиент.', |
| 290 | + 'sphinxSearchFailed' => 'Барањето не успеа $1', |
| 291 | + 'sphinxSearchWarning' => 'Предупредување $1', |
291 | 292 | ); |
292 | 293 | |
293 | 294 | /** Dutch (Nederlands) |
— | — | @@ -298,21 +299,21 @@ |
299 | 300 | 'sphinxSearchInNamespaces' => 'Zoeken in naamruimten:', |
300 | 301 | 'sphinxSearchInCategories' => 'Zoeken in categorieën:', |
301 | 302 | 'sphinxExcludeCategories' => 'Uit te sluiten categorieën', |
302 | | - 'sphinxResultPage' => 'Resultatenpagina', |
| 303 | + 'sphinxResultPage' => 'Resultatenpagina:', |
303 | 304 | 'sphinxPreviousPage' => 'Vorige', |
304 | 305 | 'sphinxNextPage' => 'Volgende', |
305 | | - 'sphinxSearchPreamble' => "Resultaten %1\$d tot %2\$d van %3\$d worden weergegeven voor zoekopdracht '''<nowiki>%s</nowiki>'''. Zoektijd: %0.3f seconden", |
| 306 | + 'sphinxSearchPreamble' => 'Resultaten $1 tot $2 van $3 worden weergegeven voor zoekopdracht "<nowiki>$4</nowiki>". Zoektijd: $5 seconden', |
306 | 307 | 'sphinxSearchButton' => 'Zoeken', |
307 | | - 'sphinxSearchEpilogue' => 'Aanvullende databasetijd was %0.3f seconden.', |
| 308 | + 'sphinxSearchEpilogue' => 'Aanvullende databasetijd was $1 seconden.', |
308 | 309 | 'sphinxSearchDidYouMean' => 'Bedoelde u', |
309 | 310 | 'sphinxMatchAny' => 'ieder woord', |
310 | 311 | 'sphinxMatchAll' => 'alle woorden', |
311 | 312 | 'sphinxMatchTitles' => 'alleen paginanamen', |
312 | 313 | 'sphinxLoading' => 'Bezig met laden...', |
313 | | - 'sphinxPowered' => 'Powered by %s', |
| 314 | + 'sphinxPowered' => 'Powered by $1', |
314 | 315 | 'sphinxClientFailed' => 'Het was niet mogelijk SphinxClient te initialiseren', |
315 | | - 'sphinxSearchFailed' => 'Zoekopdracht mislukt', |
316 | | - 'sphinxSearchWarning' => 'Waarschuwing', |
| 316 | + 'sphinxSearchFailed' => 'Zoekopdracht mislukt $1', |
| 317 | + 'sphinxSearchWarning' => 'Waarschuwing $1', |
317 | 318 | ); |
318 | 319 | |
319 | 320 | /** Norwegian (bokmål) (Norsk (bokmål)) |
— | — | @@ -327,20 +328,20 @@ |
328 | 329 | 'sphinxResultPage' => 'Resultatside', |
329 | 330 | 'sphinxPreviousPage' => 'Forrige', |
330 | 331 | 'sphinxNextPage' => 'Neste', |
331 | | - 'sphinxSearchPreamble' => "Viser %d-%d av &d treff på søket '''<nowiki>%s</nowiki>''' hentet på %0.3f sek med disse statistikkene", |
332 | | - 'sphinxSearchStats' => "'''%s''' funnet %d ganger i %d dokument", |
333 | | - 'sphinxSearchStatsInfo' => 'Tallene over kan inneholder dokumenter som ikke er oppført på grunn av søkealternativene', |
| 332 | + 'sphinxSearchPreamble' => 'Viser $1—$2 av $3 treff på søket "<nowiki>$4</nowiki>" hentet på $5 sek med disse statistikkene', |
| 333 | + 'sphinxSearchStats' => '"$1" funnet $2 ganger i $3 dokument', |
| 334 | + 'sphinxSearchStatsInfo' => 'Tallene over kan inneholder dokumenter som ikke er oppført på grunn av søkealternativene.', |
334 | 335 | 'sphinxSearchButton' => 'Søk', |
335 | | - 'sphinxSearchEpilogue' => 'Ytterligere databasetid var %0.3f sek.', |
| 336 | + 'sphinxSearchEpilogue' => 'Ytterligere databasetid var $1 sek.', |
336 | 337 | 'sphinxSearchDidYouMean' => 'Mente du', |
337 | 338 | 'sphinxMatchAny' => 'treff hvilket som helst av ordene', |
338 | 339 | 'sphinxMatchAll' => 'treff alle ordene', |
339 | 340 | 'sphinxMatchTitles' => 'treff kun titler', |
340 | 341 | 'sphinxLoading' => 'Laster...', |
341 | | - 'sphinxPowered' => 'Drevet av %s', |
| 342 | + 'sphinxPowered' => 'Drevet av $1', |
342 | 343 | 'sphinxClientFailed' => 'Kunne ikke instansiere SphinxClient', |
343 | | - 'sphinxSearchFailed' => 'Søk feilet', |
344 | | - 'sphinxSearchWarning' => 'ADVARSEL', |
| 344 | + 'sphinxSearchFailed' => 'Søk feilet $1', |
| 345 | + 'sphinxSearchWarning' => 'Advarsel $1', |
345 | 346 | ); |
346 | 347 | |
347 | 348 | /** Piedmontese (Piemontèis) |
— | — | @@ -352,23 +353,23 @@ |
353 | 354 | 'sphinxSearchInNamespaces' => 'Sërché ant jë spassi nominaj:', |
354 | 355 | 'sphinxSearchInCategories' => 'Sërché ant le categorìe:', |
355 | 356 | 'sphinxExcludeCategories' => 'Categorìe da esclude', |
356 | | - 'sphinxResultPage' => "Pàgina d'arzultà", |
| 357 | + 'sphinxResultPage' => "Pàgina d'arzultà:", |
357 | 358 | 'sphinxPreviousPage' => 'Prima', |
358 | 359 | 'sphinxNextPage' => 'Apress', |
359 | | - 'sphinxSearchPreamble' => "Visualisé %d-%d ëd %d arzultà për query '''<nowiki>%s</nowiki>''' trovà an %0.3f sec con coste statìstiche", |
360 | | - 'sphinxSearchStats' => "'''%s''' trovà %d vire an %d document", |
| 360 | + 'sphinxSearchPreamble' => 'Visualisé $1—$2 ëd $3 arzultà për query "<nowiki>$4</nowiki>" trovà an $5 sec con coste statìstiche', |
| 361 | + 'sphinxSearchStats' => '"$1" trovà $2 vire an $3 document', |
361 | 362 | 'sphinxSearchStatsInfo' => "Ij nùmer sota a peulo anclude document pa listà a motiv dj'opsion d'arserca", |
362 | 363 | 'sphinxSearchButton' => 'Sërca', |
363 | | - 'sphinxSearchEpilogue' => "Temp adissional ëd database a l'é stàit %0.3f sec.", |
| 364 | + 'sphinxSearchEpilogue' => "Temp adissional ëd database a l'é stàit \$1 sec.", |
364 | 365 | 'sphinxSearchDidYouMean' => 'Vorìi-lo pa dì', |
365 | 366 | 'sphinxMatchAny' => 'confronta minca paròla', |
366 | 367 | 'sphinxMatchAll' => 'confranta tute paròle', |
367 | 368 | 'sphinxMatchTitles' => 'confronta mach ij tìtoj', |
368 | 369 | 'sphinxLoading' => 'A caria ...', |
369 | | - 'sphinxPowered' => 'Potensià da %s', |
| 370 | + 'sphinxPowered' => 'Potensià da $1', |
370 | 371 | 'sphinxClientFailed' => 'As peul pa istansié SphinxClient', |
371 | | - 'sphinxSearchFailed' => 'Query falìa:', |
372 | | - 'sphinxSearchWarning' => 'Avis:', |
| 372 | + 'sphinxSearchFailed' => 'Query falìa: $1', |
| 373 | + 'sphinxSearchWarning' => 'Avis: $1', |
373 | 374 | ); |
374 | 375 | |
375 | 376 | /** Portuguese (Português) |
— | — | @@ -383,20 +384,20 @@ |
384 | 385 | 'sphinxResultPage' => 'Página de resultados', |
385 | 386 | 'sphinxPreviousPage' => 'Anterior', |
386 | 387 | 'sphinxNextPage' => 'Seguinte', |
387 | | - 'sphinxSearchPreamble' => "A mostrar %d-%d de %d resultados para a pesquisa'''<nowiki>%s</nowiki>''' obtidos em %0.3f seg., incluindo estas estatísticas", |
388 | | - 'sphinxSearchStats' => "'''%s''' aparece %d vezes em %d documentos", |
389 | | - 'sphinxSearchStatsInfo' => 'Os números acima podem incluir documentos que não são listados devido às opções de pesquisa', |
| 388 | + 'sphinxSearchPreamble' => 'A mostrar $1—$2 de $3 resultados para a pesquisa"<nowiki>$4</nowiki>" obtidos em $5 seg., incluindo estas estatísticas', |
| 389 | + 'sphinxSearchStats' => '"$1" aparece $2 vezes em $3 documentos', |
| 390 | + 'sphinxSearchStatsInfo' => 'Os números acima podem incluir documentos que não são listados devido às opções de pesquisa.', |
390 | 391 | 'sphinxSearchButton' => 'Pesquisar', |
391 | | - 'sphinxSearchEpilogue' => 'O tempo adicional da base de dados foi %0.3f seg.', |
| 392 | + 'sphinxSearchEpilogue' => 'O tempo adicional da base de dados foi $1 seg.', |
392 | 393 | 'sphinxSearchDidYouMean' => 'Talvez pretendesse', |
393 | 394 | 'sphinxMatchAny' => 'localizar qualquer palavra', |
394 | 395 | 'sphinxMatchAll' => 'localizar todas as palavras', |
395 | 396 | 'sphinxMatchTitles' => 'localizar somente nos títulos', |
396 | 397 | 'sphinxLoading' => 'A carregar...', |
397 | | - 'sphinxPowered' => 'Powered by %s', |
398 | | - 'sphinxClientFailed' => 'Não foi possível instanciar o cliente Sphinx', |
399 | | - 'sphinxSearchFailed' => 'Pesquisa falhou', |
400 | | - 'sphinxSearchWarning' => 'AVISO', |
| 398 | + 'sphinxPowered' => 'Powered by $1', |
| 399 | + 'sphinxClientFailed' => 'Não foi possível instanciar o cliente Sphinx.', |
| 400 | + 'sphinxSearchFailed' => 'Pesquisa falhou $1', |
| 401 | + 'sphinxSearchWarning' => 'Aviso $1', |
401 | 402 | ); |
402 | 403 | |
403 | 404 | /** Russian (Русский) |
— | — | @@ -411,19 +412,18 @@ |
412 | 413 | 'sphinxResultPage' => 'Страница результатов', |
413 | 414 | 'sphinxPreviousPage' => 'Предыдущая', |
414 | 415 | 'sphinxNextPage' => 'Следующая', |
415 | | - 'sphinxSearchPreamble' => "Отображение %d—%d результатов из %d для запроса '''<nowiki>%s</nowiki>''', поиска занял %0.3f с", |
416 | | - 'sphinxSearchStats' => "'''%s''' найдено %d раз в %d документах", |
417 | | - 'sphinxSearchStatsInfo' => 'Приведённые цифры могут включать в себя документы, не показанные из-за настроек поиска', |
| 416 | + 'sphinxSearchPreamble' => 'Отображение $1—$2 результатов из $3 для запроса "<nowiki>$4</nowiki>", поиска занял $5 с', |
| 417 | + 'sphinxSearchStats' => '"$1" найдено $2 раз в $3 документах', |
| 418 | + 'sphinxSearchStatsInfo' => 'Приведённые цифры могут включать в себя документы, не показанные из-за настроек поиска.', |
418 | 419 | 'sphinxSearchButton' => 'Найти', |
419 | | - 'sphinxSearchEpilogue' => 'Дополнительное время базы данных составило %0.3f с.', |
| 420 | + 'sphinxSearchEpilogue' => 'Дополнительное время базы данных составило $1 с.', |
420 | 421 | 'sphinxSearchDidYouMean' => 'Возможно, вы имели в виду', |
421 | 422 | 'sphinxMatchAny' => 'соответствие любому слову', |
422 | 423 | 'sphinxMatchAll' => 'соответствие всем словам', |
423 | 424 | 'sphinxMatchTitles' => 'соответствие только заголовкам', |
424 | 425 | 'sphinxLoading' => 'Загрузка…', |
425 | | - 'sphinxPowered' => 'При поддержке %s', |
426 | | - 'sphinxClientFailed' => 'Невозможно создать экземпляр SphinxClient', |
427 | | - 'sphinxSearchFailed' => 'Ошибка при выполнении запроса', |
428 | | - 'sphinxSearchWarning' => 'ПРЕДУПРЕЖДЕНИЕ', |
| 426 | + 'sphinxPowered' => 'При поддержке $1', |
| 427 | + 'sphinxClientFailed' => 'Невозможно создать экземпляр SphinxClient.', |
| 428 | + 'sphinxSearchFailed' => 'Ошибка при выполнении запроса $1', |
| 429 | + 'sphinxSearchWarning' => 'Предупреждение $1', |
429 | 430 | ); |
430 | | - |
Index: trunk/extensions/SphinxSearch/SphinxSearch_spell.php |
— | — | @@ -7,15 +7,15 @@ |
8 | 8 | var $suggestion_needed; // is the suggestion needed |
9 | 9 | var $suggestion; // the actual suggestion |
10 | 10 | |
11 | | - function spell ($string) { |
12 | | - $this->string = str_replace('"', '', $string); |
13 | | - $this->words = preg_split('/(\s+|\|)/', $this->string, -1, PREG_SPLIT_NO_EMPTY); |
14 | | - if (function_exists('pspell_check')) { |
| 11 | + function spell ( $string ) { |
| 12 | + $this->string = str_replace( '"', '', $string ); |
| 13 | + $this->words = preg_split( '/(\s+|\|)/', $this->string, - 1, PREG_SPLIT_NO_EMPTY ); |
| 14 | + if ( function_exists( 'pspell_check' ) ) { |
15 | 15 | $this->suggestion = $this->builtin_spell(); |
16 | 16 | } else { |
17 | 17 | $this->suggestion = $this->nonnative_spell(); |
18 | 18 | } |
19 | | - if ($this->suggestion_needed) |
| 19 | + if ( $this->suggestion_needed ) |
20 | 20 | return $this->suggestion; |
21 | 21 | else |
22 | 22 | return ''; |
— | — | @@ -26,41 +26,41 @@ |
27 | 27 | |
28 | 28 | $ret = ''; |
29 | 29 | $this->suggestion_needed = false; |
30 | | - foreach ($this->words as $word) { |
| 30 | + foreach ( $this->words as $word ) { |
31 | 31 | $pspell_config = pspell_config_create( |
32 | | - $wgUser->getDefaultOption('language'), |
33 | | - $wgUser->getDefaultOption('variant')); |
34 | | - if ($wgSphinxSearchPspellDictionaryDir) { |
35 | | - pspell_config_data_dir($pspell_config, $wgSphinxSearchPspellDictionaryDir); |
36 | | - pspell_config_dict_dir($pspell_config, $wgSphinxSearchPspellDictionaryDir); |
| 32 | + $wgUser->getDefaultOption( 'language' ), |
| 33 | + $wgUser->getDefaultOption( 'variant' ) ); |
| 34 | + if ( $wgSphinxSearchPspellDictionaryDir ) { |
| 35 | + pspell_config_data_dir( $pspell_config, $wgSphinxSearchPspellDictionaryDir ); |
| 36 | + pspell_config_dict_dir( $pspell_config, $wgSphinxSearchPspellDictionaryDir ); |
37 | 37 | } |
38 | | - pspell_config_mode($pspell_config, PSPELL_FAST|PSPELL_RUN_TOGETHER); |
39 | | - if ($wgSphinxSearchPersonalDictionary) |
40 | | - pspell_config_personal($pspell_config, $wgSphinxSearchPersonalDictionary); |
41 | | - $pspell_link = pspell_new_config($pspell_config); |
| 38 | + pspell_config_mode( $pspell_config, PSPELL_FAST | PSPELL_RUN_TOGETHER ); |
| 39 | + if ( $wgSphinxSearchPersonalDictionary ) |
| 40 | + pspell_config_personal( $pspell_config, $wgSphinxSearchPersonalDictionary ); |
| 41 | + $pspell_link = pspell_new_config( $pspell_config ); |
42 | 42 | |
43 | | - if (!$pspell_link) |
| 43 | + if ( !$pspell_link ) |
44 | 44 | return "Error starting pspell personal dictionary\n"; |
45 | 45 | |
46 | | - if (!pspell_check($pspell_link, $word)) { |
47 | | - $suggestions = pspell_suggest($pspell_link, $word); |
48 | | - $guess = $this->bestguess($word, $suggestions); |
49 | | - if (strtolower($word) == strtolower($guess)) { |
| 46 | + if ( !pspell_check( $pspell_link, $word ) ) { |
| 47 | + $suggestions = pspell_suggest( $pspell_link, $word ); |
| 48 | + $guess = $this->bestguess( $word, $suggestions ); |
| 49 | + if ( strtolower( $word ) == strtolower( $guess ) ) { |
50 | 50 | $ret .= "$word "; |
51 | 51 | } else { |
52 | 52 | $ret .= "$guess "; |
53 | 53 | $this->suggestion_needed = true; |
54 | 54 | } |
55 | | - unset($suggestion); |
56 | | - unset($guess); |
| 55 | + unset( $suggestion ); |
| 56 | + unset( $guess ); |
57 | 57 | } else { |
58 | 58 | $ret .= "$word "; |
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | | - unset($pspell_config); |
63 | | - unset($pspell_link); |
64 | | - return trim($ret); |
| 62 | + unset( $pspell_config ); |
| 63 | + unset( $pspell_link ); |
| 64 | + return trim( $ret ); |
65 | 65 | |
66 | 66 | } |
67 | 67 | |
— | — | @@ -69,46 +69,46 @@ |
70 | 70 | |
71 | 71 | // aspell will only return mis-spelled words, so remember all here |
72 | 72 | $word_suggestions = array(); |
73 | | - foreach ($this->words as $word) { |
| 73 | + foreach ( $this->words as $word ) { |
74 | 74 | $word_suggestions[$word] = $word; |
75 | 75 | } |
76 | 76 | |
77 | 77 | // prepare the system call with optional dictionary |
78 | | - $aspellcommand = 'echo ' . escapeshellarg($this->string) . |
79 | | - ' | ' . escapeshellarg($wgSphinxSearchAspellPath) . |
| 78 | + $aspellcommand = 'echo ' . escapeshellarg( $this->string ) . |
| 79 | + ' | ' . escapeshellarg( $wgSphinxSearchAspellPath ) . |
80 | 80 | ' -a --ignore-accents --ignore-case'; |
81 | | - if ($wgUser) { |
82 | | - $aspellcommand .= ' --lang='.$wgUser->getDefaultOption('language'); |
| 81 | + if ( $wgUser ) { |
| 82 | + $aspellcommand .= ' --lang=' . $wgUser->getDefaultOption( 'language' ); |
83 | 83 | } |
84 | | - if ($wgSphinxSearchPersonalDictionary) { |
85 | | - $aspellcommand .= ' --home-dir='.dirname($wgSphinxSearchPersonalDictionary); |
86 | | - $aspellcommand .= ' -p '.basename($wgSphinxSearchPersonalDictionary); |
| 84 | + if ( $wgSphinxSearchPersonalDictionary ) { |
| 85 | + $aspellcommand .= ' --home-dir=' . dirname( $wgSphinxSearchPersonalDictionary ); |
| 86 | + $aspellcommand .= ' -p ' . basename( $wgSphinxSearchPersonalDictionary ); |
87 | 87 | } |
88 | 88 | |
89 | 89 | // run aspell |
90 | | - $shell_return = shell_exec($aspellcommand); |
| 90 | + $shell_return = shell_exec( $aspellcommand ); |
91 | 91 | |
92 | 92 | // parse return line by line |
93 | | - $returnarray = explode("\n", $shell_return); |
| 93 | + $returnarray = explode( "\n", $shell_return ); |
94 | 94 | $this->suggestion_needed = false; |
95 | | - foreach($returnarray as $key=>$value) { |
| 95 | + foreach ( $returnarray as $key => $value ) { |
96 | 96 | // lines with suggestions start with & |
97 | | - if (substr($value, 0, 1) == "&") { |
98 | | - $correction = explode(" ",$value); |
| 97 | + if ( substr( $value, 0, 1 ) == "&" ) { |
| 98 | + $correction = explode( " ", $value ); |
99 | 99 | $word = $correction[1]; |
100 | | - $suggstart = strpos($value, ":") + 2; |
101 | | - $suggestions = substr($value, $suggstart); |
102 | | - $suggestionarray = explode(", ", $suggestions); |
103 | | - $guess = $this->bestguess($word, $suggestionarray); |
| 100 | + $suggstart = strpos( $value, ":" ) + 2; |
| 101 | + $suggestions = substr( $value, $suggstart ); |
| 102 | + $suggestionarray = explode( ", ", $suggestions ); |
| 103 | + $guess = $this->bestguess( $word, $suggestionarray ); |
104 | 104 | |
105 | | - if (strtolower($word) != strtolower($guess)) { |
| 105 | + if ( strtolower( $word ) != strtolower( $guess ) ) { |
106 | 106 | $word_suggestions[$word] = $guess; |
107 | 107 | $this->suggestion_needed = true; |
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | | - return join(' ', $word_suggestions); |
| 112 | + return join( ' ', $word_suggestions ); |
113 | 113 | } |
114 | 114 | |
115 | 115 | /* This function takes a word, and an array of suggested words |
— | — | @@ -116,15 +116,15 @@ |
117 | 117 | * the word. Thif is made possible with the use of the |
118 | 118 | * levenshtein() function. |
119 | 119 | */ |
120 | | - function bestguess($word, $suggestions) { |
121 | | - $shortest = -1; |
| 120 | + function bestguess( $word, $suggestions ) { |
| 121 | + $shortest = - 1; |
122 | 122 | |
123 | | - if (preg_match('/^[^a-zA-Z]*$/', $word)) |
| 123 | + if ( preg_match( '/^[^a-zA-Z]*$/', $word ) ) |
124 | 124 | return $word; |
125 | 125 | |
126 | | - foreach ($suggestions as $suggested) { |
127 | | - $lev = levenshtein(strtolower($word), strtolower($suggested)); |
128 | | - if ($lev == 0) { |
| 126 | + foreach ( $suggestions as $suggested ) { |
| 127 | + $lev = levenshtein( strtolower( $word ), strtolower( $suggested ) ); |
| 128 | + if ( $lev == 0 ) { |
129 | 129 | // closest word is this one (exact match) |
130 | 130 | $closest = $word; |
131 | 131 | $shortest = 0; |
— | — | @@ -135,7 +135,7 @@ |
136 | 136 | |
137 | 137 | // if this distance is less than the next found shortest |
138 | 138 | // distance, OR if a next shortest word has not yet been found |
139 | | - if ($lev <= $shortest || $shortest < 0) { |
| 139 | + if ( $lev <= $shortest || $shortest < 0 ) { |
140 | 140 | // set the closest match, and shortest distance |
141 | 141 | $closest = $suggested; |
142 | 142 | $shortest = $lev; |
Index: trunk/extensions/SphinxSearch/SphinxSearch.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | # Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly. |
5 | | -if (!defined('MEDIAWIKI')) { |
| 5 | +if ( !defined( 'MEDIAWIKI' ) ) { |
6 | 6 | echo <<<EOT |
7 | 7 | To install SphinxSearch extension, put the following line in LocalSettings.php: |
8 | 8 | require_once( "\$IP/extensions/SphinxSearch/SphinxSearch.php" ); |
— | — | @@ -15,24 +15,24 @@ |
16 | 16 | 'version' => '0.7.0', |
17 | 17 | 'name' => 'SphinxSearch', |
18 | 18 | 'author' => array( 'Svemir Brkic', 'Paul Grinberg' ), |
19 | | - 'email' => 'svemir at thirdblessing dot net, gri6507 at yahoo dot com', |
| 19 | + 'email' => 'svemir at deveblog dot com, gri6507 at yahoo dot com', |
20 | 20 | 'url' => 'http://www.mediawiki.org/wiki/Extension:SphinxSearch', |
21 | 21 | 'descriptionmsg' => 'sphinxsearch-desc' |
22 | 22 | ); |
23 | 23 | |
24 | | -$dir = dirname(__FILE__) . '/'; |
| 24 | +$dir = dirname( __FILE__ ) . '/'; |
25 | 25 | |
26 | 26 | $wgAutoloadClasses['SphinxSearch'] = $dir . 'SphinxSearch_body.php'; |
27 | 27 | $wgExtensionMessagesFiles['SphinxSearch'] = $dir . 'SphinxSearch.i18n.php'; |
28 | 28 | $wgExtensionAliasesFiles['SphinxSearch'] = $dir . 'SphinxSearch.alias.php'; |
29 | 29 | |
30 | | -########################################################## |
| 30 | +# ######################################################### |
31 | 31 | # To completely disable the default search and replace it with SphinxSearch, |
32 | 32 | # set this BEFORE including SphinxSearch.php in LocalSettings.php |
33 | 33 | # $wgSearchType = 'SphinxSearch'; |
34 | | -########################################################## |
| 34 | +# ######################################################### |
35 | 35 | |
36 | | -if ($wgSearchType == 'SphinxSearch') { |
| 36 | +if ( $wgSearchType == 'SphinxSearch' ) { |
37 | 37 | $wgDisableInternalSearch = true; |
38 | 38 | $wgDisableSearchUpdate = true; |
39 | 39 | $wgSpecialPages['Search'] = 'SphinxSearch'; |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | |
44 | 44 | # this assumes you have copied sphinxapi.php from your Sphinx |
45 | 45 | # installation folder to your SphinxSearch extension folder |
46 | | -if (!class_exists('SphinxClient')) { |
| 46 | +if ( !class_exists( 'SphinxClient' ) ) { |
47 | 47 | require_once ( $dir . "sphinxapi.php" ); |
48 | 48 | } |
49 | 49 | |
— | — | @@ -55,15 +55,15 @@ |
56 | 56 | |
57 | 57 | # By default, we search all available indexes |
58 | 58 | # You can also specify them explicitly, e.g |
59 | | -#$wgSphinxSearch_index_list = "wiki_main,wiki_incremental"; |
| 59 | +# $wgSphinxSearch_index_list = "wiki_main,wiki_incremental"; |
60 | 60 | $wgSphinxSearch_index_list = "*"; |
61 | 61 | |
62 | 62 | # If you have multiple index files, you can specify their weights like this |
63 | 63 | # See http://www.sphinxsearch.com/docs/current.html#api-func-setindexweights |
64 | | -#$wgSphinxSearch_index_weights = array( |
| 64 | +# $wgSphinxSearch_index_weights = array( |
65 | 65 | # "wiki_main" => 100, |
66 | 66 | # "wiki_incremental" => 10 |
67 | | -#); |
| 67 | +# ); |
68 | 68 | |
69 | 69 | # Default Sphinx search mode |
70 | 70 | $wgSphinxSearch_mode = SPH_MATCH_EXTENDED; |
— | — | @@ -84,43 +84,40 @@ |
85 | 85 | $wgSphinxSearch_cutoff = 0; |
86 | 86 | |
87 | 87 | # Weights of individual indexed columns. This gives page titles extra weight |
88 | | -$wgSphinxSearch_weights = array('old_text'=>1, 'page_title'=>100); |
| 88 | +$wgSphinxSearch_weights = array( 'old_text' => 1, 'page_title' => 100 ); |
89 | 89 | |
90 | 90 | # If you want to enable hierarchical category search, specify the top category of your hierarchy like this |
91 | | -#$wgSphinxTopSearchableCategory = 'Subject_areas'; |
| 91 | +# $wgSphinxTopSearchableCategory = 'Subject_areas'; |
92 | 92 | |
93 | 93 | # If you want sub-categories to be fetched as parent categories are checked, |
94 | 94 | # also set $wgUseAjax to true in your LocalSettings file, so that the following can be used: |
95 | | -#$wgAjaxExportList[] = 'SphinxSearch::ajaxGetCategoryChildren'; |
| 95 | +# $wgAjaxExportList[] = 'SphinxSearch::ajaxGetCategoryChildren'; |
96 | 96 | |
97 | 97 | # EXPERIMENTAL: allow excluding selected categories when filtering |
98 | | -#$wgUseExcludes = true; |
| 98 | +# $wgUseExcludes = true; |
99 | 99 | |
100 | 100 | # Web-accessible path to the extension's folder |
101 | 101 | $wgSphinxSearchExtPath = '/extensions/SphinxSearch'; |
102 | 102 | # Web-accessible path to the folder with SphinxSearch.js file (if different from $wgSphinxSearchExtPath) |
103 | | -#$wgSphinxSearchJSPath = ''; |
| 103 | +# $wgSphinxSearchJSPath = ''; |
104 | 104 | |
105 | | -########################################################## |
106 | | -# Use Aspell to suggest possible misspellings. This could be provided via either |
107 | | -# PHP pspell module (http://www.php.net/manual/en/ref.pspell.php) or command line |
108 | | -# insterface to ASpell |
| 105 | +# ######################################################### |
| 106 | +# Use Aspell to suggest possible misspellings. This can be provided via |
| 107 | +# PHP pspell module (http://www.php.net/manual/en/ref.pspell.php) |
| 108 | +# or command line insterface to ASpell |
109 | 109 | |
110 | 110 | # Should the suggestion mode be enabled? |
111 | | -# Should be set BEFORE SphinxSearch.php is included in LocalSettings |
112 | | -if (!isset($wgSphinxSuggestMode)) { |
113 | | - $wgSphinxSuggestMode = false; |
114 | | -} |
| 111 | +$wgSphinxSuggestMode = false; |
115 | 112 | |
116 | 113 | # Path to personal dictionary (for example personal.en.pws.) Needed only if using a personal dictionary |
117 | 114 | # Should be set BEFORE SphinxSearch.php is included in LocalSettings |
118 | | -if (!isset($wgSphinxSearchPersonalDictionary)) { |
| 115 | +if ( !isset( $wgSphinxSearchPersonalDictionary ) ) { |
119 | 116 | $wgSphinxSearchPersonalDictionary = ""; |
120 | 117 | } |
121 | 118 | |
122 | | -# Here is why some vars need to be set before SphinxSearch is included. |
| 119 | +# Here is why above var needs to be set before SphinxSearch is included. |
123 | 120 | # We setup a special page to edit the personal dictionary. |
124 | | -if ($wgSphinxSuggestMode && $wgSphinxSearchPersonalDictionary) { |
| 121 | +if ( $wgSphinxSearchPersonalDictionary ) { |
125 | 122 | $wgAutoloadClasses['SphinxSearchPersonalDict'] = $dir . 'SphinxSearch_PersonalDict.php'; |
126 | 123 | $wgSpecialPages['SphinxSearchPersonalDict'] = 'SphinxSearchPersonalDict'; |
127 | 124 | } |
— | — | @@ -129,5 +126,4 @@ |
130 | 127 | $wgSphinxSearchAspellPath = "/usr/bin/aspell"; |
131 | 128 | |
132 | 129 | # Path to aspell location and language data files. Do not set if not sure. |
133 | | -#$wgSphinxSearchPspellDictionaryDir = "/usr/lib/aspell"; |
134 | | - |
| 130 | +# $wgSphinxSearchPspellDictionaryDir = "/usr/lib/aspell"; |
Index: trunk/extensions/SphinxSearch/SphinxSearch_PersonalDict.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | class SphinxSearchPersonalDict extends SpecialPage { |
16 | 16 | |
17 | 17 | function SphinxSearchPersonalDict() { |
18 | | - SpecialPage::SpecialPage("SphinxSearchPersonalDict", 'delete'); |
| 18 | + SpecialPage::SpecialPage( "SphinxSearchPersonalDict", 'delete' ); |
19 | 19 | self::loadMessages(); |
20 | 20 | return true; |
21 | 21 | } |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | function loadMessages() { |
24 | 24 | static $messagesLoaded = false; |
25 | 25 | global $wgMessageCache; |
26 | | - if ($messagesLoaded) { |
| 26 | + if ( $messagesLoaded ) { |
27 | 27 | return; |
28 | 28 | } |
29 | 29 | $messagesLoaded = true; |
— | — | @@ -43,66 +43,66 @@ |
44 | 44 | return true; |
45 | 45 | } |
46 | 46 | |
47 | | - function execute($par) { |
| 47 | + function execute( $par ) { |
48 | 48 | global $wgRequest, $wgOut, $wgUser; |
49 | 49 | |
50 | 50 | $this->setHeaders(); |
51 | | - $wgOut->setPagetitle(wfMsg('sphinxsearchpersonaldict')); |
| 51 | + $wgOut->setPagetitle( wfMsg( 'sphinxsearchpersonaldict' ) ); |
52 | 52 | |
53 | | - if (!$wgUser->isAllowed("delete")) { |
54 | | - $wgOut->addWikiText(wfMsg('sphinxsearchcantpersonaldict')); |
55 | | - $wgOut->addWikiText('----'); |
| 53 | + if ( !$wgUser->isAllowed( "delete" ) ) { |
| 54 | + $wgOut->addWikiText( wfMsg( 'sphinxsearchcantpersonaldict' ) ); |
| 55 | + $wgOut->addWikiText( '----' ); |
56 | 56 | } |
57 | 57 | |
58 | | - $toberemoved = $wgRequest->getArray('indictionary', array()); |
59 | | - $tobeadded = $wgRequest->getVal('tobeadded',''); |
60 | | - $tobeadded = preg_split('/\s/', trim($tobeadded), -1, PREG_SPLIT_NO_EMPTY); |
| 58 | + $toberemoved = $wgRequest->getArray( 'indictionary', array() ); |
| 59 | + $tobeadded = $wgRequest->getVal( 'tobeadded', '' ); |
| 60 | + $tobeadded = preg_split( '/\s/', trim( $tobeadded ), - 1, PREG_SPLIT_NO_EMPTY ); |
61 | 61 | |
62 | | - $this->deleteFromPersonalDictionary($toberemoved); |
63 | | - $this->addToPersonalDictionary($tobeadded); |
| 62 | + $this->deleteFromPersonalDictionary( $toberemoved ); |
| 63 | + $this->addToPersonalDictionary( $tobeadded ); |
64 | 64 | |
65 | | - $this->CreateForm($wgUser->isAllowed("delete")); |
| 65 | + $this->CreateForm( $wgUser->isAllowed( "delete" ) ); |
66 | 66 | } |
67 | 67 | |
68 | | - function CreateForm($allowed_to_add) { |
| 68 | + function CreateForm( $allowed_to_add ) { |
69 | 69 | global $wgOut; |
70 | 70 | global $wgSphinxSearchPersonalDictionary; |
71 | 71 | |
72 | | - $wgOut->addHTML("<form method=post>"); |
73 | | - $wgOut->addHTML("<div style=\"border: thin solid #000000; width:90%;\"><table cellpadding=\"15\" width=\"100%\" cellspacing=\"0\" border=\"0\">"); |
74 | | - $wgOut->addHTML("<tr><td valign=top>"); |
75 | | - $wgOut->addWikiText("<center>'''" . wfMsg('sphinxsearchindictionary') . "'''</center><p>"); |
76 | | - $wgOut->addHTML('<select name="indictionary[]" size="15" multiple="multiple">'); |
| 72 | + $wgOut->addHTML( "<form method=post>" ); |
| 73 | + $wgOut->addHTML( "<div style=\"border: thin solid #000000; width:90%;\"><table cellpadding=\"15\" width=\"100%\" cellspacing=\"0\" border=\"0\">" ); |
| 74 | + $wgOut->addHTML( "<tr><td valign=top>" ); |
| 75 | + $wgOut->addWikiText( "<center>'''" . wfMsg( 'sphinxsearchindictionary' ) . "'''</center><p>" ); |
| 76 | + $wgOut->addHTML( '<select name="indictionary[]" size="15" multiple="multiple">' ); |
77 | 77 | |
78 | | - if (file_exists($wgSphinxSearchPersonalDictionary)) { |
79 | | - $this->readPersonalDictionary($langauge, $numwords, $words); |
80 | | - sort($words); |
| 78 | + if ( file_exists( $wgSphinxSearchPersonalDictionary ) ) { |
| 79 | + $this->readPersonalDictionary( $langauge, $numwords, $words ); |
| 80 | + sort( $words ); |
81 | 81 | |
82 | | - if (sizeof($words)>0) { |
83 | | - foreach ($words as $w) |
84 | | - $wgOut->addHTML("<option value='$w'>$w</option>"); |
| 82 | + if ( sizeof( $words ) > 0 ) { |
| 83 | + foreach ( $words as $w ) |
| 84 | + $wgOut->addHTML( "<option value='$w'>$w</option>" ); |
85 | 85 | } else { |
86 | | - $wgOut->addHTML("<option disabled value=''>Dictionary empty</option>"); |
| 86 | + $wgOut->addHTML( "<option disabled value=''>Dictionary empty</option>" ); |
87 | 87 | } |
88 | 88 | } else { |
89 | | - $wgOut->addHTML("<option disabled value=''>Dictionary not found</option>"); |
| 89 | + $wgOut->addHTML( "<option disabled value=''>Dictionary not found</option>" ); |
90 | 90 | } |
91 | 91 | |
92 | | - $wgOut->addHTML('</select></td><td valign=top>'); |
93 | | - if ($allowed_to_add) { |
94 | | - $wgOut->addWikiText("<center>'''" . wfMsg('sphinxsearchtobeadded') . "'''</center><p>"); |
95 | | - $wgOut->addHTML("<textarea name=\"tobeadded\" cols=\"30\" rows=\"15\"></textarea>"); |
96 | | - $wgOut->addHTML('</td></tr><tr><td colspan=2>'); |
97 | | - $wgOut->addHTML("<center><input type=\"submit\" value=\"Execute\" /></center>"); |
| 92 | + $wgOut->addHTML( '</select></td><td valign=top>' ); |
| 93 | + if ( $allowed_to_add ) { |
| 94 | + $wgOut->addWikiText( "<center>'''" . wfMsg( 'sphinxsearchtobeadded' ) . "'''</center><p>" ); |
| 95 | + $wgOut->addHTML( "<textarea name=\"tobeadded\" cols=\"30\" rows=\"15\"></textarea>" ); |
| 96 | + $wgOut->addHTML( '</td></tr><tr><td colspan=2>' ); |
| 97 | + $wgOut->addHTML( "<center><input type=\"submit\" value=\"Execute\" /></center>" ); |
98 | 98 | } |
99 | | - $wgOut->addHTML("</td></tr></table></div></form>"); |
| 99 | + $wgOut->addHTML( "</td></tr></table></div></form>" ); |
100 | 100 | } |
101 | 101 | |
102 | | - function addToPersonalDictionary($list) { |
103 | | - if (function_exists('pspell_config_create')) { |
104 | | - $this->builtin_addword($list); |
| 102 | + function addToPersonalDictionary( $list ) { |
| 103 | + if ( function_exists( 'pspell_config_create' ) ) { |
| 104 | + $this->builtin_addword( $list ); |
105 | 105 | } else { |
106 | | - $this->nonnative_addword($list); |
| 106 | + $this->nonnative_addword( $list ); |
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
— | — | @@ -110,18 +110,18 @@ |
111 | 111 | global $wgUser, $wgLanguageCode; |
112 | 112 | |
113 | 113 | // Try to read the default language from $wgUser: |
114 | | - $language = trim($wgUser->getDefaultOption('language')); |
| 114 | + $language = trim( $wgUser->getDefaultOption( 'language' ) ); |
115 | 115 | |
116 | 116 | // Use global variable: $wgLanguageCode (from LocalSettings.php) as fallback: |
117 | | - if (empty($language)) { $language = trim($wgLanguageCode); } |
| 117 | + if ( empty( $language ) ) { $language = trim( $wgLanguageCode ); } |
118 | 118 | |
119 | 119 | // If we still don't have a valid language yet, assume English: |
120 | | - if (empty($language)) { $language = 'en'; } |
| 120 | + if ( empty( $language ) ) { $language = 'en'; } |
121 | 121 | |
122 | 122 | return $language; |
123 | 123 | } |
124 | 124 | |
125 | | - function builtin_addword($list) { |
| 125 | + function builtin_addword( $list ) { |
126 | 126 | global $wgUser, $wgOut; |
127 | 127 | global $wgSphinxSearchPersonalDictionary; |
128 | 128 | global $wgSphinxSearchPspellDictionaryDir; |
— | — | @@ -130,109 +130,109 @@ |
131 | 131 | |
132 | 132 | $pspell_config = pspell_config_create( |
133 | 133 | $language, |
134 | | - $wgUser->getDefaultOption('variant')); |
135 | | - if ($wgSphinxSearchPspellDictionaryDir) { |
136 | | - pspell_config_data_dir($pspell_config, $wgSphinxSearchPspellDictionaryDir); |
137 | | - pspell_config_dict_dir($pspell_config, $wgSphinxSearchPspellDictionaryDir); |
| 134 | + $wgUser->getDefaultOption( 'variant' ) ); |
| 135 | + if ( $wgSphinxSearchPspellDictionaryDir ) { |
| 136 | + pspell_config_data_dir( $pspell_config, $wgSphinxSearchPspellDictionaryDir ); |
| 137 | + pspell_config_dict_dir( $pspell_config, $wgSphinxSearchPspellDictionaryDir ); |
138 | 138 | } |
139 | | - pspell_config_mode($pspell_config, PSPELL_FAST|PSPELL_RUN_TOGETHER); |
140 | | - if ($wgSphinxSearchPersonalDictionary) |
141 | | - pspell_config_personal($pspell_config, $wgSphinxSearchPersonalDictionary); |
142 | | - $pspell_link = pspell_new_config($pspell_config); |
| 139 | + pspell_config_mode( $pspell_config, PSPELL_FAST | PSPELL_RUN_TOGETHER ); |
| 140 | + if ( $wgSphinxSearchPersonalDictionary ) |
| 141 | + pspell_config_personal( $pspell_config, $wgSphinxSearchPersonalDictionary ); |
| 142 | + $pspell_link = pspell_new_config( $pspell_config ); |
143 | 143 | |
144 | 144 | $write_needed = false; |
145 | | - foreach ($list as $word) { |
146 | | - if ($word == '') |
| 145 | + foreach ( $list as $word ) { |
| 146 | + if ( $word == '' ) |
147 | 147 | continue; |
148 | | - if (preg_match('/[^a-zA-Z]/', $word)) { |
149 | | - $wgOut->addWikiText(sprintf(wfMsg('sphinxsearchnotadded'), $word)); |
| 148 | + if ( preg_match( '/[^a-zA-Z]/', $word ) ) { |
| 149 | + $wgOut->addWikiText( sprintf( wfMsg( 'sphinxsearchnotadded' ), $word ) ); |
150 | 150 | continue; |
151 | 151 | } |
152 | | - pspell_add_to_personal($pspell_link, $word); |
| 152 | + pspell_add_to_personal( $pspell_link, $word ); |
153 | 153 | $write_needed = true; |
154 | 154 | } |
155 | 155 | |
156 | | - if ($write_needed) { |
157 | | - pspell_save_wordlist($pspell_link); |
| 156 | + if ( $write_needed ) { |
| 157 | + pspell_save_wordlist( $pspell_link ); |
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | | - function nonnative_addword($list) { |
| 161 | + function nonnative_addword( $list ) { |
162 | 162 | global $wgUser; |
163 | 163 | global $wgSphinxSearchPersonalDictionary; |
164 | 164 | |
165 | | - if (!file_exists($wgSphinxSearchPersonalDictionary)) { |
| 165 | + if ( !file_exists( $wgSphinxSearchPersonalDictionary ) ) { |
166 | 166 | // create the personal dictionary file if it does not already exist |
167 | 167 | $language = $this->getSearchLanguage(); |
168 | 168 | $numwords = 0; |
169 | 169 | $words = array(); |
170 | 170 | } else { |
171 | | - $this->readPersonalDictionary($language, $numwords, $words); |
| 171 | + $this->readPersonalDictionary( $language, $numwords, $words ); |
172 | 172 | } |
173 | 173 | |
174 | 174 | $write_needed = false; |
175 | | - foreach ($list as $word) { |
176 | | - if (!in_array($word, $words)) { |
| 175 | + foreach ( $list as $word ) { |
| 176 | + if ( !in_array( $word, $words ) ) { |
177 | 177 | $numwords++; |
178 | | - array_push($words, $word); |
| 178 | + array_push( $words, $word ); |
179 | 179 | $write_needed = true; |
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | | - if ($write_needed) |
184 | | - $this->writePersonalDictionary($language, $numwords, $words); |
| 183 | + if ( $write_needed ) |
| 184 | + $this->writePersonalDictionary( $language, $numwords, $words ); |
185 | 185 | } |
186 | 186 | |
187 | | - function writePersonalDictionary($language, $numwords, $words) { |
| 187 | + function writePersonalDictionary( $language, $numwords, $words ) { |
188 | 188 | global $wgSphinxSearchPersonalDictionary; |
189 | 189 | |
190 | | - $handle = fopen($wgSphinxSearchPersonalDictionary, "wt"); |
191 | | - if ($handle) { |
192 | | - fwrite($handle, "personal_ws-1.1 $language $numwords\n"); |
193 | | - foreach ($words as $w) { |
194 | | - fwrite($handle, "$w\n"); |
| 190 | + $handle = fopen( $wgSphinxSearchPersonalDictionary, "wt" ); |
| 191 | + if ( $handle ) { |
| 192 | + fwrite( $handle, "personal_ws-1.1 $language $numwords\n" ); |
| 193 | + foreach ( $words as $w ) { |
| 194 | + fwrite( $handle, "$w\n" ); |
195 | 195 | } |
196 | | - fclose($handle); |
| 196 | + fclose( $handle ); |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | | - function readPersonalDictionary(&$language, &$numwords, &$words) { |
| 200 | + function readPersonalDictionary( &$language, &$numwords, &$words ) { |
201 | 201 | global $wgSphinxSearchPersonalDictionary; |
202 | 202 | |
203 | 203 | $words = array(); |
204 | | - $lines = explode("\n", file_get_contents($wgSphinxSearchPersonalDictionary)); |
205 | | - foreach ($lines as $line) { |
206 | | - trim($line); |
207 | | - if (preg_match('/\s(\w+)\s(\d+)/', $line, $matches)) { |
| 204 | + $lines = explode( "\n", file_get_contents( $wgSphinxSearchPersonalDictionary ) ); |
| 205 | + foreach ( $lines as $line ) { |
| 206 | + trim( $line ); |
| 207 | + if ( preg_match( '/\s(\w+)\s(\d+)/', $line, $matches ) ) { |
208 | 208 | $language = $matches[1]; |
209 | 209 | $numwords = $matches[2]; |
210 | 210 | } else |
211 | | - if ($line) |
212 | | - array_push($words, $line); |
| 211 | + if ( $line ) |
| 212 | + array_push( $words, $line ); |
213 | 213 | } |
214 | 214 | |
215 | 215 | // Make sure that we have a valid value for language if it wasn't in the .pws file: |
216 | | - if (empty($language)) { $language = $this->getSearchLanguage(); } |
| 216 | + if ( empty( $language ) ) { $language = $this->getSearchLanguage(); } |
217 | 217 | } |
218 | 218 | |
219 | | - function deleteFromPersonalDictionary($list) { |
| 219 | + function deleteFromPersonalDictionary( $list ) { |
220 | 220 | // there is no built in way to delete from the personal dictionary. |
| 221 | + |
| 222 | + $this->readPersonalDictionary( $language, $numwords, $words ); |
221 | 223 | |
222 | | - $this->readPersonalDictionary($language, $numwords, $words); |
223 | | - |
224 | 224 | $write_needed = false; |
225 | | - foreach ($list as $w) { |
226 | | - if ($w == '') |
| 225 | + foreach ( $list as $w ) { |
| 226 | + if ( $w == '' ) |
227 | 227 | continue; |
228 | | - if (in_array($w, $words)) { |
229 | | - $index = array_keys($words, $w); |
230 | | - unset($words[$index[0]]); |
| 228 | + if ( in_array( $w, $words ) ) { |
| 229 | + $index = array_keys( $words, $w ); |
| 230 | + unset( $words[$index[0]] ); |
231 | 231 | $numwords--; |
232 | 232 | $write_needed = true; |
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
236 | | - if ($write_needed) |
237 | | - $this->writePersonalDictionary($language, $numwords, $words); |
| 236 | + if ( $write_needed ) |
| 237 | + $this->writePersonalDictionary( $language, $numwords, $words ); |
238 | 238 | } |
239 | 239 | } |