Index: trunk/phase3/includes/parser/LinkHolderArray.php |
— | — | @@ -296,37 +296,57 @@ |
297 | 297 | $linkCache = LinkCache::singleton(); |
298 | 298 | $sk = $this->parent->getOptions()->getSkin(); |
299 | 299 | $threshold = $this->getStubThreshold(); |
300 | | - |
301 | | - // Add variants of links to link batch |
| 300 | + $titlesToBeConverted = ''; |
| 301 | + $titlesAttrs = array(); |
| 302 | + |
| 303 | + // Concatenate titles to a single string, thus we only need auto convert the |
| 304 | + // single string to all variants. This would improve parser's performance |
| 305 | + // significantly. |
302 | 306 | foreach ( $this->internals as $ns => $entries ) { |
303 | 307 | foreach ( $entries as $index => $entry ) { |
304 | | - $key = "$ns:$index"; |
305 | 308 | $pdbk = $entry['pdbk']; |
306 | | - $title = $entry['title']; |
307 | | - $titleText = $title->getText(); |
308 | | - |
309 | | - // generate all variants of the link title text |
310 | | - $allTextVariants = $wgContLang->convertLinkToAllVariants($titleText); |
311 | | - |
312 | | - // if link was not found (in first query), add all variants to query |
313 | | - if ( !isset($colours[$pdbk]) ){ |
314 | | - foreach($allTextVariants as $textVariant){ |
315 | | - if($textVariant != $titleText){ |
316 | | - $variantTitle = Title::makeTitle( $ns, $textVariant ); |
317 | | - if(is_null($variantTitle)) continue; |
318 | | - $linkBatch->addObj( $variantTitle ); |
319 | | - $variantMap[$variantTitle->getPrefixedDBkey()][] = $key; |
320 | | - } |
321 | | - } |
| 309 | + // we only deal with new links (in its first query) |
| 310 | + if ( !isset( $colours[$pdbk] ) ) { |
| 311 | + $title = $entry['title']; |
| 312 | + $titleText = $title->getText(); |
| 313 | + $titlesAttrs[] = array( |
| 314 | + 'ns' => $ns, |
| 315 | + 'key' => "$ns:$index", |
| 316 | + 'titleText' => $titleText, |
| 317 | + ); |
| 318 | + // separate titles with \0 because it would never appears |
| 319 | + // in a valid title |
| 320 | + $titlesToBeConverted .= $title . '\0'; |
322 | 321 | } |
323 | 322 | } |
324 | 323 | } |
| 324 | + |
| 325 | + // Now do the conversion and explode string to text of titles |
| 326 | + $titlesAllVariants = $wgContLang->convertLinkToAllVariants( $titlesToBeConverted ); |
| 327 | + $allVariantsName = array_keys( $titlesAllVariants ); |
| 328 | + foreach ( $titlesAllVariants as &$titlesVariant ) { |
| 329 | + $titlesVariant = explode( '\0', $titlesVariant ); |
| 330 | + } |
| 331 | + |
| 332 | + // Then add variants of links to link batch |
| 333 | + for ( $i = 0; $l = count( $titlesAttrs ), $i < $l; $i ++ ) { |
| 334 | + foreach ( $allVariantsName as $variantName ) { |
| 335 | + $textVariant = $titlesAllVariants[$variantName][$i]; |
| 336 | + extract( $titlesAttrs[$i] ); |
| 337 | + if($textVariant != $titleText){ |
| 338 | + $variantTitle = Title::makeTitle( $ns, $textVariant ); |
| 339 | + if( is_null( $variantTitle ) ) { continue; } |
| 340 | + $linkBatch->addObj( $variantTitle ); |
| 341 | + $variantMap[$variantTitle->getPrefixedDBkey()][] = $key; |
| 342 | + } |
| 343 | + } |
| 344 | + } |
325 | 345 | |
326 | 346 | // process categories, check if a category exists in some variant |
327 | 347 | $categoryMap = array(); // maps $category_variant => $category (dbkeys) |
328 | 348 | $varCategories = array(); // category replacements oldDBkey => newDBkey |
329 | 349 | foreach( $output->getCategoryLinks() as $category ){ |
330 | | - $variants = $wgContLang->convertLinkToAllVariants($category); |
| 350 | + $variants = $wgContLang->convertLinkToAllVariants( $category ); |
331 | 351 | foreach($variants as $variant){ |
332 | 352 | if($variant != $category){ |
333 | 353 | $variantTitle = Title::newFromDBkey( Title::makeName(NS_CATEGORY,$variant) ); |