* @private
*/
function strip( $text, $state, $stripcomments = false , $dontstrip = array () ) {
+ global $wgContLang;
wfProfileIn( __METHOD__ );
$render = ($this->mOutputType == OT_HTML);
$output = Xml::escapeTagsOnly( $content );
break;
case 'math':
- $output = MathRenderer::renderMath( $content );
+ $output = $wgContLang->armourMath( MathRenderer::renderMath( $content ) );
break;
case 'gallery':
$output = $this->renderImageGallery( $content, $params );
if ( !is_null( $title ) ) {
$titleText = $title->getPrefixedText();
- $checkVariantLink = sizeof($wgContLang->getVariants())>1;
# Check for language variants if the template is not found
- if($checkVariantLink && $title->getArticleID() == 0){
+ if($wgContLang->hasVariants() && $title->getArticleID() == 0){
$wgContLang->findVariantLink($part1, $title);
}
}
wfProfileOut( $fname.'-check' );
- # Do a second query for different language variants of links (if needed)
+ # Do a second query for different language variants of links and categories
if($wgContLang->hasVariants()){
$linkBatch = new LinkBatch();
- $variantMap = array(); // maps $pdbkey_Variant => $pdbkey_original
+ $variantMap = array(); // maps $pdbkey_Variant => $keys (of link holders)
+ $categoryMap = array(); // maps $category_variant => $category (dbkeys)
+ $varCategories = array(); // category replacements oldDBkey => newDBkey
+
+ $categories = $this->mOutput->getCategoryLinks();
// Add variants of links to link batch
foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) {
continue;
$pdbk = $title->getPrefixedDBkey();
+ $titleText = $title->getText();
// generate all variants of the link title text
- $allTextVariants = $wgContLang->convertLinkToAllVariants($title->getText());
+ $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){
- $variantTitle = Title::makeTitle( $ns, $textVariant );
- if(is_null($variantTitle)) continue;
- $linkBatch->addObj( $variantTitle );
- $variantMap[$variantTitle->getPrefixedDBkey()][] = $key;
+ if($textVariant != $titleText){
+ $variantTitle = Title::makeTitle( $ns, $textVariant );
+ if(is_null($variantTitle)) continue;
+ $linkBatch->addObj( $variantTitle );
+ $variantMap[$variantTitle->getPrefixedDBkey()][] = $key;
+ }
}
}
}
+ // process categories, check if a category exists in some variant
+ foreach( $categories as $category){
+ $variants = $wgContLang->convertLinkToAllVariants($category);
+ foreach($variants as $variant){
+ $variantTitle = Title::newFromDBkey( Title::makeName(NS_CATEGORY,$variant) );
+ if(is_null($variantTitle)) continue;
+ $linkBatch->addObj( $variantTitle );
+ $categoryMap[$variant] = $category;
+ }
+ }
+
if(!$linkBatch->isEmpty()){
// construct query
$variantTitle = Title::makeTitle( $s->page_namespace, $s->page_title );
$varPdbk = $variantTitle->getPrefixedDBkey();
+ $vardbk = $variantTitle->getDBkey();
$linkCache->addGoodLinkObj( $s->page_id, $variantTitle );
$this->mOutput->addLink( $variantTitle, $s->page_id );
- $holderKeys = $variantMap[$varPdbk];
+ $holderKeys = array();
+ if(isset($variantMap[$varPdbk]))
+ $holderKeys = $variantMap[$varPdbk];
// loop over link holders
foreach($holderKeys as $key){
}
}
}
+
+ // check if the object is a variant of a category
+ if(isset($categoryMap[$vardbk])){
+ $oldkey = $categoryMap[$vardbk];
+ if($oldkey != $vardbk)
+ $varCategories[$oldkey]=$vardbk;
+ }
+ }
+
+ // rebuild the categories in original order (if there are replacements)
+ if(count($varCategories)>0){
+ $newCats = array();
+ $originalCats = $this->mOutput->getCategories();
+ foreach($originalCats as $cat => $sortkey){
+ // make the replacement
+ if( array_key_exists($cat,$varCategories) )
+ $newCats[$varCategories[$cat]] = $sortkey;
+ else $newCats[$cat] = $sortkey;
+ }
+ $this->mOutput->setCategoryLinks($newCats);
}
}
}
function markNoConversion($text, $noParse=false) {return $text;}
function convertCategoryKey( $key ) {return $key; }
function convertLinkToAllVariants($text){ return array( $this->mLang->getCode() => $text); }
- function setNoTitleConvert(){}
+ function armourMath($text){ return $text; }
}
#--------------------------------------------------------------------------
return $this->mConverter->parserConvert( $text, $parser );
}
- # Tell the converter that it shouldn't convert titles
- function setNoTitleConvert(){
- $this->mConverter->setNotitleConvert();
- }
-
# Check if this is a language with variants
function hasVariants(){
return sizeof($this->getVariants())>1;
}
+ # Put custom tags (e.g. -{ }-) around math to prevent conversion
+ function armourMath($text){
+ return $this->mConverter->armourMath($text);
+ }
+
/**
* Perform output conversion on a string, and encode for safe HTML output.
var $mMarkup;
var $mFlags;
var $mUcfirst = false;
- var $mNoTitleConvert = false;
/**
* Constructor
*
return $text;
if( $isTitle ) {
- if($this->mNoTitleConvert){
- $this->mTitleDisplay = $text;
- return $text;
- }
-
if( !$this->mDoTitleConvert ) {
$this->mTitleDisplay = $text;
return $text;
*/
function findVariantLink( &$link, &$nt ) {
global $wgDisableLangConversion;
- $pref = $this->getPreferredVariant();
- $ns=0;
+ $linkBatch = new LinkBatch();
+
+ $ns=NS_MAIN;
+
if(is_object($nt))
$ns = $nt->getNamespace();
$variants = $this->autoConvertToAllVariants($link);
if($variants == false) //give up
return;
+
+ $titles = array();
+
foreach( $variants as $v ) {
- $varnt = Title::newFromText( $v, $ns );
- if( $varnt && $varnt->getArticleID() > 0 ) {
+ if($v != $link){
+ $varnt = Title::newFromText( $v, $ns );
+ if(!is_null($varnt)){
+ $linkBatch->addObj($varnt);
+ $titles[]=$varnt;
+ }
+ }
+ }
+
+ // fetch all variants in single query
+ $linkBatch->execute();
+
+ foreach( $titles as $varnt ) {
+ if( $varnt->getArticleID() > 0 ) {
$nt = $varnt;
if( !$wgDisableLangConversion )
$link = $v;
return true;
}
- function setNoTitleConvert(){
- $this->mNoTitleConvert = true;
+ /**
+ * Armour rendered math against conversion
+ * Default is do nothing, since the process can interfere with
+ * parseManualRule() if format -{ alter1 ; alter2 }- is enabled
+ */
+ function armourMath($text){
+ return $text;
}
+
}
?>
'Nj' => 'Њ', 'n!j' => 'нј', 'N!j'=> 'Нј', 'N!J'=> 'НЈ'
);
+ var $mParsingContent=false;
+
function loadDefaultTables() {
$this->mTables = array(
'sr-ec' => new ReplacementArray( $this->mToCyrillics ),
return $carray;
}
+ // Set a flag when parsing content, this is used to prevent
+ // conversion of content within talk pages
+ function parserConvert( $text, &$parser ){
+ $this->mParsingContent = true;
+ $output = parent::parserConvert($text, $parser );
+ $this->mParsingContent = false;
+ return $output;
+
+ }
+
/*
* Override function from LanguageConvertor
* Additional checks:
* - There should be no conversion for Talk pages
*/
- function getPreferredVariant(){
+ function getPreferredVariant( $fromUser=true ){
global $wgTitle;
- if($wgTitle!=NULL && $wgTitle->isTalkPage()){
+ if(is_object($wgTitle) && $wgTitle->isTalkPage() && $this->mParsingContent){
return $this->mMainLanguageCode;
}
- return parent::getPreferredVariant();
+ return parent::getPreferredVariant($fromUser);
}
$link=$oldlink;
}
-
/*
* We want our external link captions to be converted in variants,
* so we return the original text instead -{$text}-, except for URLs
*/
function autoConvert($text, $toVariant=false) {
global $wgTitle;
- if($wgTitle->getNameSpace()==NS_IMAGE){
+ if(is_object($wgTitle) && $wgTitle->getNameSpace()==NS_IMAGE){
$imagename = $wgTitle->getNsText();
if(preg_match("/^$imagename:/",$text)) return $text;
}
return $ret;
}
+
+ function armourMath($text){
+ return parent::markNoConversion($text);
+ }
+
}
class LanguageSr extends LanguageSr_ec {