summaryrefslogtreecommitdiff
path: root/includes/parser/LinkHolderArray.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/parser/LinkHolderArray.php')
-rw-r--r--includes/parser/LinkHolderArray.php108
1 files changed, 74 insertions, 34 deletions
diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php
index 4f382a4f..19313b80 100644
--- a/includes/parser/LinkHolderArray.php
+++ b/includes/parser/LinkHolderArray.php
@@ -1,5 +1,13 @@
<?php
-
+/**
+ * Holder of replacement pairs for wiki links
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Parser
+ */
class LinkHolderArray {
var $internals = array(), $interwikis = array();
var $size = 0;
@@ -99,7 +107,7 @@ class LinkHolderArray {
function getStubThreshold() {
global $wgUser;
if ( !isset( $this->stubThreshold ) ) {
- $this->stubThreshold = $wgUser->getOption('stubthreshold');
+ $this->stubThreshold = $wgUser->getStubThreshold();
}
return $this->stubThreshold;
}
@@ -132,7 +140,7 @@ class LinkHolderArray {
global $wgContLang;
$colours = array();
- $sk = $this->parent->getOptions()->getSkin();
+ $sk = $this->parent->getOptions()->getSkin( $this->parent->mTitle );
$linkCache = LinkCache::singleton();
$output = $this->parent->getOutput();
@@ -144,12 +152,13 @@ class LinkHolderArray {
# Sort by namespace
ksort( $this->internals );
+ $linkcolour_ids = array();
+
# Generate query
$query = false;
$current = null;
foreach ( $this->internals as $ns => $entries ) {
- foreach ( $entries as $index => $entry ) {
- $key = "$ns:$index";
+ foreach ( $entries as $entry ) {
$title = $entry['title'];
$pdbk = $entry['pdbk'];
@@ -162,16 +171,19 @@ class LinkHolderArray {
# Check if it's a static known link, e.g. interwiki
if ( $title->isAlwaysKnown() ) {
$colours[$pdbk] = '';
+ } elseif ( $ns == NS_SPECIAL ) {
+ $colours[$pdbk] = 'new';
} elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
$colours[$pdbk] = $sk->getLinkColour( $title, $threshold );
$output->addLink( $title, $id );
+ $linkcolour_ids[$id] = $pdbk;
} elseif ( $linkCache->isBadLink( $pdbk ) ) {
$colours[$pdbk] = 'new';
} else {
# Not in the link cache, add it to the query
if ( !isset( $current ) ) {
$current = $ns;
- $query = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len";
+ $query = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len, page_latest";
$query .= " FROM $page WHERE (page_namespace=$ns AND page_title IN(";
} elseif ( $current != $ns ) {
$current = $ns;
@@ -191,11 +203,10 @@ class LinkHolderArray {
# Fetch data and form into an associative array
# non-existent = broken
- $linkcolour_ids = array();
- while ( $s = $dbr->fetchObject($res) ) {
+ foreach ( $res as $s ) {
$title = Title::makeTitle( $s->page_namespace, $s->page_title );
$pdbk = $title->getPrefixedDBkey();
- $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect );
+ $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect, $s->page_latest );
$output->addLink( $title, $s->page_id );
# FIXME: convoluted data flow
# The redirect status and length is passed to getLinkColour via the LinkCache
@@ -205,6 +216,8 @@ class LinkHolderArray {
$linkcolour_ids[$s->page_id] = $pdbk;
}
unset( $res );
+ }
+ if ( count($linkcolour_ids) ) {
//pass an array of page_ids to an extension
wfRunHooks( 'GetLinkColours', array( $linkcolour_ids, &$colours ) );
}
@@ -265,10 +278,12 @@ class LinkHolderArray {
wfProfileIn( __METHOD__ );
# Make interwiki link HTML
- $sk = $this->parent->getOptions()->getSkin();
+ $sk = $this->parent->getOptions()->getSkin( $this->parent->mTitle );
+ $output = $this->parent->getOutput();
$replacePairs = array();
foreach( $this->interwikis as $key => $link ) {
$replacePairs[$key] = $sk->link( $link['title'], $link['text'] );
+ $output->addInterwikiLink( $link['title'] );
}
$replacer = new HashtableReplacer( $replacePairs, 1 );
@@ -288,30 +303,52 @@ class LinkHolderArray {
$variantMap = array(); // maps $pdbkey_Variant => $keys (of link holders)
$output = $this->parent->getOutput();
$linkCache = LinkCache::singleton();
- $sk = $this->parent->getOptions()->getSkin();
+ $sk = $this->parent->getOptions()->getSkin( $this->parent->mTitle );
$threshold = $this->getStubThreshold();
-
- // Add variants of links to link batch
+ $titlesToBeConverted = '';
+ $titlesAttrs = array();
+
+ // Concatenate titles to a single string, thus we only need auto convert the
+ // single string to all variants. This would improve parser's performance
+ // significantly.
foreach ( $this->internals as $ns => $entries ) {
foreach ( $entries as $index => $entry ) {
- $key = "$ns:$index";
$pdbk = $entry['pdbk'];
- $title = $entry['title'];
- $titleText = $title->getText();
-
- // generate all variants of the link title text
- $allTextVariants = $wgContLang->convertLinkToAllVariants($titleText);
-
- // if link was not found (in first query), add all variants to query
- if ( !isset($colours[$pdbk]) ){
- foreach($allTextVariants as $textVariant){
- if($textVariant != $titleText){
- $variantTitle = Title::makeTitle( $ns, $textVariant );
- if(is_null($variantTitle)) continue;
- $linkBatch->addObj( $variantTitle );
- $variantMap[$variantTitle->getPrefixedDBkey()][] = $key;
- }
+ // we only deal with new links (in its first query)
+ if ( !isset( $colours[$pdbk] ) ) {
+ $title = $entry['title'];
+ $titleText = $title->getText();
+ $titlesAttrs[] = array(
+ 'ns' => $ns,
+ 'key' => "$ns:$index",
+ 'titleText' => $titleText,
+ );
+ // separate titles with \0 because it would never appears
+ // in a valid title
+ $titlesToBeConverted .= $titleText . "\0";
+ }
+ }
+ }
+
+ // Now do the conversion and explode string to text of titles
+ $titlesAllVariants = $wgContLang->autoConvertToAllVariants( $titlesToBeConverted );
+ $allVariantsName = array_keys( $titlesAllVariants );
+ foreach ( $titlesAllVariants as &$titlesVariant ) {
+ $titlesVariant = explode( "\0", $titlesVariant );
+ }
+ $l = count( $titlesAttrs );
+ // Then add variants of links to link batch
+ for ( $i = 0; $i < $l; $i ++ ) {
+ foreach ( $allVariantsName as $variantName ) {
+ $textVariant = $titlesAllVariants[$variantName][$i];
+ extract( $titlesAttrs[$i] );
+ if($textVariant != $titleText){
+ $variantTitle = Title::makeTitle( $ns, $textVariant );
+ if( is_null( $variantTitle ) ) {
+ continue;
}
+ $linkBatch->addObj( $variantTitle );
+ $variantMap[$variantTitle->getPrefixedDBkey()][] = $titlesAttrs[$i]['key'];
}
}
}
@@ -320,7 +357,7 @@ class LinkHolderArray {
$categoryMap = array(); // maps $category_variant => $category (dbkeys)
$varCategories = array(); // category replacements oldDBkey => newDBkey
foreach( $output->getCategoryLinks() as $category ){
- $variants = $wgContLang->convertLinkToAllVariants($category);
+ $variants = $wgContLang->autoConvertToAllVariants( $category );
foreach($variants as $variant){
if($variant != $category){
$variantTitle = Title::newFromDBkey( Title::makeName(NS_CATEGORY,$variant) );
@@ -343,7 +380,7 @@ class LinkHolderArray {
$linkcolour_ids = array();
// for each found variants, figure out link holders and replace
- while ( $s = $dbr->fetchObject($varRes) ) {
+ foreach ( $varRes as $s ) {
$variantTitle = Title::makeTitle( $s->page_namespace, $s->page_title );
$varPdbk = $variantTitle->getPrefixedDBkey();
@@ -403,8 +440,9 @@ class LinkHolderArray {
/**
* Replace <!--LINK--> link placeholders with plain text of links
* (not HTML-formatted).
- * @param string $text
- * @return string
+ *
+ * @param $text String
+ * @return String
*/
function replaceText( $text ) {
wfProfileIn( __METHOD__ );
@@ -419,7 +457,9 @@ class LinkHolderArray {
}
/**
- * @param array $matches
+ * Callback for replaceText()
+ *
+ * @param $matches Array
* @return string
* @private
*/