From 16577746564269b5587fe3d8955622aa0b46c192 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 15 Sep 2006 20:08:21 +0000 Subject: [PATCH] Merge from SerbianVariants branch, trunk 16500 vs SerbianVariants 16523 --- RELEASE-NOTES | 2 + includes/Article.php | 36 ++++++++- includes/Parser.php | 100 ++++++++++++++++++++++-- includes/SearchEngine.php | 15 ++-- includes/SpecialSearch.php | 15 ++++ languages/Language.php | 131 +++++++++++++++++++++++++++++--- languages/LanguageConverter.php | 74 ++++++++++++++---- languages/LanguageSr.php | 45 +++++++++-- languages/MessagesSr_ec.php | 2 +- languages/MessagesSr_el.php | 2 +- maintenance/mysql5/tables.sql | 4 + maintenance/tables.sql | 4 + maintenance/updaters.inc | 1 + 13 files changed, 374 insertions(+), 57 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 19723edd7e..0dbd206951 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -206,6 +206,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN preferences don't get stuck in proxy caches for other people * (bug 7324) Fix error message for failure of Database::sourceFile() * (bug 7309) Plurals: use singular form for zero in French and Brazilian Portuguese +* Add page_no_title_convert field to support language variant conversion + for page titles which shouldn't be converted on display/linking == Languages updated == diff --git a/includes/Article.php b/includes/Article.php index f32e15e73c..c3da94067a 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -30,6 +30,8 @@ class Article { var $mGoodAdjustment; //!< var $mLatest; //!< var $mMinorEdit; //!< + var $mNoTitleConvert; //!< + var $mNoTitleConvertParser; //!< var $mOldId; //!< var $mRedirectedFrom; //!< var $mRedirectUrl; //!< @@ -130,6 +132,8 @@ class Article { $this->mRevIdFetched = 0; $this->mRedirectUrl = false; $this->mLatest = false; + $this->mNoTitleConvert = false; + $this->mNoTitleConvertParser = false; } /** @@ -267,7 +271,8 @@ class Article { 'page_random', 'page_touched', 'page_latest', - 'page_len' ) ; + 'page_len', + 'page_no_title_convert') ; wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ; $row = $dbr->selectRow( 'page', $fields, @@ -303,6 +308,8 @@ class Article { * @private */ function loadPageData( $data = 'fromdb' ) { + global $wgContLang; + if ( $data === 'fromdb' ) { $dbr =& $this->getDB(); $data = $this->pageDataFromId( $dbr, $this->getId() ); @@ -320,6 +327,10 @@ class Article { $this->mTouched = wfTimestamp( TS_MW, $data->page_touched ); $this->mIsRedirect = $data->page_is_redirect; $this->mLatest = $data->page_latest; + $this->mNoTitleConvert = $data->page_no_title_convert; + + if($this->mNoTitleConvert) + $wgContLang->setNoTitleConvert(); } else { if ( is_object( $this->mTitle ) ) { $lc->addBadLinkObj( $this->mTitle ); @@ -984,6 +995,7 @@ class Article { 'page_touched' => $dbw->timestamp(), 'page_latest' => 0, # Fill this in shortly... 'page_len' => 0, # Fill this in shortly... + 'page_no_title_convert' => 0, ), __METHOD__ ); $newid = $dbw->insertId(); @@ -1023,12 +1035,21 @@ class Article { 'page_is_new' => ($lastRevision === 0) ? 1 : 0, 'page_is_redirect' => Article::isRedirect( $text ) ? 1 : 0, 'page_len' => strlen( $text ), + 'page_no_title_convert' => ($this->mNoTitleConvertParser)? 1 : 0, ), $conditions, __METHOD__ ); + $succ = $dbw->affectedRows() != 0; + + // check if no title magic word has been changed + if($succ && $this->mNoTitleConvert != $this->mNoTitleConvertParser){ + // Clear caches + Article::onArticleCreate( $this->mTitle ); + } + wfProfileOut( __METHOD__ ); - return ( $dbw->affectedRows() != 0 ); + return $succ; } /** @@ -1194,7 +1215,7 @@ class Article { * @return bool success */ function doEdit( $text, $summary, $flags = 0 ) { - global $wgUser, $wgDBtransactions; + global $wgUser, $wgDBtransactions, $wgContLang; wfProfileIn( __METHOD__ ); $good = true; @@ -1221,6 +1242,15 @@ class Article { $isminor = ( $flags & EDIT_MINOR ) && $wgUser->isAllowed('minoredit'); $bot = $wgUser->isAllowed( 'bot' ) || ( $flags & EDIT_FORCE_BOT ); + // process the notitleconvert magic for languages with variants + $this->mNoTitleConvertParser = false; + if(sizeof($wgContLang->getVariants())>1){ + $mw =& MagicWord::get( 'notitleconvert' ); + if( $mw->match( $text ) ){ + $this->mNoTitleConvertParser = true; + } + } + $text = $this->preSaveTransform( $text ); $dbw =& wfGetDB( DB_MASTER ); diff --git a/includes/Parser.php b/includes/Parser.php index e099144154..12ec5d1900 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1507,7 +1507,6 @@ class Parser } $selflink = $this->mTitle->getPrefixedText(); - $checkVariantLink = sizeof($wgContLang->getVariants())>1; $useSubpages = $this->areSubpagesAllowed(); wfProfileOut( $fname.'-setup' ); @@ -1602,13 +1601,6 @@ class Parser continue; } - #check other language variants of the link - #if the article does not exist - if( $checkVariantLink - && $nt->getArticleID() == 0 ) { - $wgContLang->findVariantLink($link, $nt); - } - $ns = $nt->getNamespace(); $iw = $nt->getInterWiki(); wfProfileOut( "$fname-title" ); @@ -3897,6 +3889,7 @@ class Parser function replaceLinkHolders( &$text, $options = 0 ) { global $wgUser; global $wgOutputReplace; + global $wgContLang, $wgLanguageCode; $fname = 'Parser::replaceLinkHolders'; wfProfileIn( $fname ); @@ -3987,6 +3980,97 @@ class Parser } wfProfileOut( $fname.'-check' ); + # Do a second query for different language variants of links (if needed) + if($wgContLang->hasVariants()){ + $linkBatch = new LinkBatch(); + $variantMap = array(); // maps $pdbkey_Variant => $pdbkey_original + + // Add variants of links to link batch + foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) { + $title = $this->mLinkHolders['titles'][$key]; + if ( is_null( $title ) ) + continue; + + $pdbk = $title->getPrefixedDBkey(); + + // add the original text into query to check for notitleconvert pages + $variantTitle = Title::makeTitle( $ns, $title->getText() ); + $linkBatch->addObj( $variantTitle ); + $variantMap[$variantTitle->getPrefixedDBkey()][] = $key; + + // generate all variants of the link title text + $allTextVariants = $wgContLang->convertLinkToAllVariants($title->getText()); + + // 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; + } + } + } + + # construct query + $titleClause = $linkBatch->constructSet('page', $dbr); + $variantQuery = "SELECT page_id, page_namespace, page_title"; + if ( $threshold > 0 ) { + $variantQuery .= ', page_len, page_is_redirect'; + } + $variantQuery .= ", page_no_title_convert FROM $page WHERE $titleClause"; + if ( $options & RLH_FOR_UPDATE ) { + $query .= ' FOR UPDATE'; + } + + $varRes = $dbr->query( $variantQuery, $fname ); + + # for each found variants, figure out link holders and replace + while ( $s = $dbr->fetchObject($varRes) ) { + + $variantTitle = Title::makeTitle( $s->page_namespace, $s->page_title ); + $varPdbk = $variantTitle->getPrefixedDBkey(); + $linkCache->addGoodLinkObj( $s->page_id, $variantTitle ); + $this->mOutput->addLink( $variantTitle, $s->page_id ); + + $noTitleConvert = $s->page_no_title_convert; + + $holderKeys = $variantMap[$varPdbk]; + + // loop over link holders + foreach($holderKeys as $key){ + $title = $this->mLinkHolders['titles'][$key]; + if ( is_null( $title ) ) continue; + + $pdbk = $title->getPrefixedDBkey(); + + if(!isset($colours[$pdbk]) || ($noTitleConvert && $colours[$pdbk] == 1)){ + // found link in some of the variants, replace the link holder data + $this->mLinkHolders['titles'][$key] = $variantTitle; + $this->mLinkHolders['dbkeys'][$key] = $variantTitle->getDBkey(); + + // prevent link conversion if needed + if($noTitleConvert) + $this->mLinkHolders['texts'][$key] = $wgContLang->markNoConversion($variantTitle->getText(),true); + + // set pdbk and colour + $pdbks[$key] = $varPdbk; + if ( $threshold > 0 ) { + $size = $s->page_len; + if ( $s->page_is_redirect || $s->page_namespace != 0 || $size >= $threshold ) { + $colours[$varPdbk] = 1; + } else { + $colours[$varPdbk] = 2; + } + } + else { + $colours[$varPdbk] = 1; + } + } + } + } + } + # Construct search and replace arrays wfProfileIn( $fname.'-construct' ); $wgOutputReplace = array(); diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index c3b38519a7..6af1e41596 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -51,6 +51,7 @@ class SearchEngine { * @private */ function getNearMatch( $term ) { + global $wgContLang; # Exact match? No need to look further. $title = Title::newFromText( $term ); if (is_null($title)) @@ -62,33 +63,27 @@ class SearchEngine { # Now try all lower case (i.e. first letter capitalized) # - $title = Title::newFromText( strtolower( $term ) ); + $title = Title::newFromText( $wgContLang->lc( $term ) ); if ( $title->exists() ) { return $title; } # Now try capitalized string # - $title = Title::newFromText( ucwords( strtolower( $term ) ) ); + $title = Title::newFromText( $wgContLang->ucwords( $term ) ); if ( $title->exists() ) { return $title; } # Now try all upper case # - $title = Title::newFromText( strtoupper( $term ) ); + $title = Title::newFromText( $wgContLang->uc( $term ) ); if ( $title->exists() ) { return $title; } # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc - $title = Title::newFromText( preg_replace_callback( - '/\b([\w\x80-\xff]+)\b/', - create_function( '$matches', ' - global $wgContLang; - return $wgContLang->ucfirst($matches[1]); - ' ), - $term ) ); + $title = Title::newFromText( $wgContLang->ucwordbreaks($term) ); if ( $title->exists() ) { return $title; } diff --git a/includes/SpecialSearch.php b/includes/SpecialSearch.php index 4667bd68b6..0c767ede4a 100644 --- a/includes/SpecialSearch.php +++ b/includes/SpecialSearch.php @@ -77,6 +77,7 @@ class SpecialSearch { function goResult( $term ) { global $wgOut; global $wgGoToEdit; + global $wgContLang; $this->setupPage( $term ); @@ -96,6 +97,20 @@ class SpecialSearch { return; } + # if language supports variants, search in all variants + if($wgContLang->hasVariants()){ + $allTermVariants = $wgContLang->convertLinkToAllVariants($term); + + foreach($allTermVariants as $termVariant){ + $t = SearchEngine::getNearMatch( $termVariant ); + if( !is_null( $t ) ) { + $wgOut->redirect( $t->getFullURL() ); + wfProfileOut( $fname ); + return; + } + } + } + # No match, generate an edit URL $t = Title::newFromText( $term ); if( is_null( $t ) ) { diff --git a/languages/Language.php b/languages/Language.php index c1f46ccbb6..bbd3bb08ee 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -49,9 +49,10 @@ class FakeConverter { function findVariantLink(&$l, &$n) {} function getExtraHashOptions() {return '';} function getParsedTitle() {return '';} - function markNoConversion($text) {return $text;} + function markNoConversion($text, $noParse=false) {return $text;} function convertCategoryKey( $key ) {return $key; } - + function convertLinkToAllVariants($text){ return array( $this->mLang->getCode() => $text); } + function setNoTitleConvert(){} } #-------------------------------------------------------------------------- @@ -712,6 +713,34 @@ class Language { return iconv( $in, $out, $string ); } + // callback functions for uc(), lc(), ucwords(), ucwordbreaks() + function ucwordbreaksCallbackAscii($matches){ + return $this->ucfirst($matches[1]); + } + + function ucwordbreaksCallbackMB($matches){ + return mb_strtoupper($matches[0]); + } + + function ucCallback($matches){ + global $wikiUpperChars; + return strtr( $matches[1] , $wikiUpperChars ); + } + + function lcCallback($matches){ + global $wikiLowerChars; + return strtr( $matches[1] , $wikiLowerChars ); + } + + function ucwordsCallbackMB($matches){ + return mb_strtoupper($matches[0]); + } + + function ucwordsCallbackWiki($matches){ + global $wikiUpperChars; + return strtr( $matches[0] , $wikiUpperChars ); + } + function ucfirst( $str ) { return self::uc( $str, true ); } @@ -729,9 +758,9 @@ class Language { if ( self::isMultibyte( $str ) ) { list( $wikiUpperChars ) = $this->getCaseMaps(); $x = $first ? '^' : ''; - return preg_replace( - "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e", - "strtr( \"\$1\" , \$wikiUpperChars )", + return preg_replace_callback( + "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/", + array($this,"ucCallback"), $str ); } else @@ -755,9 +784,9 @@ class Language { if ( self::isMultibyte( $str ) ) { list( , $wikiLowerChars ) = self::getCaseMaps(); $x = $first ? '^' : ''; - return preg_replace( - "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e", - "strtr( \"\$1\" , \$wikiLowerChars )", + return preg_replace_callback( + "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/", + array($this,"lcCallback"), $str ); } else @@ -768,6 +797,66 @@ class Language { return (bool)preg_match( '/[\x80-\xff]/', $str ); } + function ucwords($str) { + global $wikiUpperChars; + + if ( self::isMultibyte( $str ) ) { + $str = self::lc($str); + + // regexp to find first letter in each word (i.e. after each space) + $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)| ([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/"; + + // function to use to capitalize a single char + if ( function_exists( 'mb_strtoupper' ) ) + return preg_replace_callback( + $replaceRegexp, + array($this,"ucwordsCallbackMB"), + $str + ); + else + return preg_replace_callback( + $replaceRegexp, + array($this,"ucwordsCallbackWiki"), + $str + ); + } + else + return ucwords( strtolower( $str ) ); + } + + # capitalize words at word breaks + function ucwordbreaks($str){ + global $wikiUpperChars; + + if (self::isMultibyte( $str ) ) { + $str = self::lc($str); + + // since \b doesn't work for UTF-8, we explicitely define word break chars + $breaks= "[ \-\(\)\}\{\.,\?!]"; + + // find first letter after word break + $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/"; + + if ( function_exists( 'mb_strtoupper' ) ) + return preg_replace_callback( + $replaceRegexp, + array($this,"ucwordbreaksCallbackMB"), + $str + ); + else + return preg_replace_callback( + $replaceRegexp, + array($this,"ucwordsCallbackWiki"), + $str + ); + } + else + return preg_replace_callback( + '/\b([\w\x80-\xff]+)\b/', + array($this,"ucwordbreaksCallbackAscii"), + $str ); + } + function checkTitleEncoding( $s ) { if( is_array( $s ) ) { wfDebugDieBacktrace( 'Given array to checkTitleEncoding.' ); @@ -1169,6 +1258,17 @@ class Language { 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; + } + + /** * Perform output conversion on a string, and encode for safe HTML output. * @param string $text @@ -1213,6 +1313,17 @@ class Language { $this->mConverter->findVariantLink($link, $nt); } + /** + * If a language supports multiple variants, converts text + * into an array of all possible variants of the text: + * 'variant' => text in that variant + */ + + function convertLinkToAllVariants($text){ + return $this->mConverter->convertLinkToAllVariants($text); + } + + /** * returns language specific options used by User::getPageRenderHash() * for example, the preferred language variant @@ -1242,8 +1353,8 @@ class Language { * @param string $text text to be tagged for no conversion * @return string the tagged text */ - function markNoConversion( $text ) { - return $this->mConverter->markNoConversion( $text ); + function markNoConversion( $text, $noParse=false ) { + return $this->mConverter->markNoConversion( $text, $noParse ); } /** diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 2e504360a9..86283198d6 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -22,6 +22,7 @@ class LanguageConverter { var $mMarkup; var $mFlags; var $mUcfirst = false; + var $mNoTitleConvert = false; /** * Constructor * @@ -38,6 +39,7 @@ class LanguageConverter { $markup=array(), $flags = array()) { global $wgDBname; + global $wgLegalTitleChars; $this->mLangObj = $langobj; $this->mMainLanguageCode = $maincode; $this->mVariants = $variants; @@ -155,14 +157,17 @@ class LanguageConverter { $marker = ""; // this one is needed when the text is inside an html markup - $htmlfix = '|<[^>]+=\"[^(>=)]*$|^[^(<>=\")]*\"[^>]*>'; + $htmlfix = '|<[^>]+$|^[^<>]*>'; - $reg = '/<[^>]+>|&[a-z#][a-z0-9]+;' . $marker . $htmlfix . '/'; + // disable convert to variants between tags + $codefix = '.+?<\/code>|'; + + $reg = '/'.$codefix.'<[^>]+>|&[a-z#][a-z0-9]+;' . $marker . $htmlfix . '/s'; $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE); - $m = array_shift($matches); + $ret = $this->translate($m[0], $toVariant); $mstart = $m[1]+strlen($m[0]); foreach($matches as $m) { @@ -197,7 +202,7 @@ class LanguageConverter { * * @param string $text the text to be converted * @return array of string - * @private + * @public */ function autoConvertToAllVariants($text) { $fname="LanguageConverter::autoConvertToAllVariants"; @@ -209,10 +214,44 @@ class LanguageConverter { foreach($this->mVariants as $variant) { $ret[$variant] = $this->translate($text, $variant); } + wfProfileOut( $fname ); return $ret; } + /** + * convert link text to all supported variants + * + * @param string $text the text to be converted + * @return array of string + * @public + */ + function convertLinkToAllVariants($text) { + if( !$this->mTablesLoaded ) + $this->loadTables(); + + $ret = array(); + $tarray = explode($this->mMarkup['begin'], $text); + $tfirst = array_shift($tarray); + + foreach($this->mVariants as $variant) + $ret[$variant] = $this->translate($tfirst,$variant); + + foreach($tarray as $txt) { + $marked = explode($this->mMarkup['end'], $txt, 2); + + foreach($this->mVariants as $variant){ + $ret[$variant] .= $this->mMarkup['begin'].$marked[0].$this->mMarkup['end']; + if(array_key_exists(1, $marked)) + $ret[$variant] .= $this->translate($marked[1],$variant); + } + + } + + return $ret; + } + + /** * Convert text using a parser object for context */ @@ -220,7 +259,7 @@ class LanguageConverter { global $wgDisableLangConversion; /* don't do anything if this is the conversion table */ if ( $parser->mTitle->getNamespace() == NS_MEDIAWIKI && - strpos($parser->mTitle->getText, "Conversiontable") !== false ) + strpos($parser->mTitle->getText(), "Conversiontable") !== false ) { return $text; } @@ -264,6 +303,11 @@ class LanguageConverter { return $text; if( $isTitle ) { + if($this->mNoTitleConvert){ + $this->mTitleDisplay = $text; + return $text; + } + if( !$this->mDoTitleConvert ) { $this->mTitleDisplay = $text; return $text; @@ -278,7 +322,7 @@ class LanguageConverter { return $text; } else { - $this->mTitleDisplay = $this->autoConvert($text); + $this->mTitleDisplay = $this->convert($text); return $this->mTitleDisplay; } } @@ -315,7 +359,7 @@ class LanguageConverter { else $rules = $marked[0]; -#FIXME: may cause trouble here... + //FIXME: may cause trouble here... //strip   since it interferes with the parsing, plus, //all spaces should be stripped in this tag anyway. $rules = str_replace(' ', '', $rules); @@ -410,23 +454,16 @@ class LanguageConverter { * @access public */ function findVariantLink( &$link, &$nt ) { - static $count=0; //used to limit this operation - static $cache=array(); global $wgDisableLangConversion; $pref = $this->getPreferredVariant(); $ns=0; if(is_object($nt)) $ns = $nt->getNamespace(); - if( $count > 50 && $ns != NS_CATEGORY ) - return; - $count++; + $variants = $this->autoConvertToAllVariants($link); if($variants == false) //give up return; foreach( $variants as $v ) { - if(isset($cache[$v])) - continue; - $cache[$v] = 1; $varnt = Title::newFromText( $v, $ns ); if( $varnt && $varnt->getArticleID() > 0 ) { $nt = $varnt; @@ -655,7 +692,7 @@ class LanguageConverter { * @param string $text text to be tagged for no conversion * @return string the tagged text */ - function markNoConversion($text) { + function markNoConversion($text, $noParse=false) { # don't mark if already marked if(strpos($text, $this->mMarkup['begin']) || strpos($text, $this->mMarkup['end'])) @@ -696,6 +733,11 @@ class LanguageConverter { } return true; } + + function setNoTitleConvert(){ + $this->mNoTitleConvert = true; + } + } ?> diff --git a/languages/LanguageSr.php b/languages/LanguageSr.php index 4258322bfb..d295adfb5f 100644 --- a/languages/LanguageSr.php +++ b/languages/LanguageSr.php @@ -169,8 +169,8 @@ class SrConverter extends LanguageConverter { * We want our external link captions to be converted in variants, * so we return the original text instead -{$text}-, except for URLs */ - function markNoConversion($text) { - if(preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text)) + function markNoConversion($text, $noParse=false) { + if($noParse || preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text)) return parent::markNoConversion($text); return $text; } @@ -188,22 +188,51 @@ class SrConverter extends LanguageConverter { return parent::autoConvert($text,$toVariant); } + /** + * It translates text into variant, specials: + * - ommiting roman numbers + */ + function translate($text, $toVariant){ + $breaks = '[^\w\x80-\xff]'; + + // regexp for roman numbers + $roman = 'M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})'; + + $reg = '/^'.$roman.'$|^'.$roman.$breaks.'|'.$breaks.$roman.'$|'.$breaks.$roman.$breaks.'/'; + + $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE); + + $m = array_shift($matches); + $ret = strtr($m[0], $this->mTables[$toVariant]); + $mstart = $m[1]+strlen($m[0]); + foreach($matches as $m) { + $ret .= substr($text, $mstart, $m[1]-$mstart); + $ret .= parent::translate($m[0], $toVariant); + $mstart = $m[1] + strlen($m[0]); + } + + return $ret; + } + } class LanguageSr extends LanguageSr_ec { function __construct() { global $wgHooks; + parent::__construct(); - $variants = array('sr', 'sr-ec', 'sr-jc', 'sr-el', 'sr-jl'); + // these variants are currently UNUSED: + // 'sr-jc', 'sr-jl' + $variants = array('sr', 'sr-ec', 'sr-el'); $variantfallbacks = array( 'sr' => 'sr-ec', - 'sr-ec' => 'sr-jc', - 'sr-jc' => 'sr-ec', - 'sr-el' => 'sr-jl', - 'sr-jl' => 'sr-el' - ); + 'sr-ec' => 'sr-ec', + 'sr-el' => 'sr-el', + ); + + $marker = array();//don't mess with these, leave them as they are $flags = array( 'S' => 'S', 'писмо' => 'S', 'pismo' => 'S', diff --git a/languages/MessagesSr_ec.php b/languages/MessagesSr_ec.php index 75d8279340..6bdc46000f 100644 --- a/languages/MessagesSr_ec.php +++ b/languages/MessagesSr_ec.php @@ -173,7 +173,7 @@ $magicWords = array( 'servername' => array( 0, 'SERVERNAME', 'ИМЕСЕРВЕРА' ), 'scriptpath' => array( 0, 'SCRIPTPATH', 'СКРИПТА' ), 'grammar' => array( 0, 'GRAMMAR:', 'ГРАМАТИКА:' ), - 'notitleconvert' => array( 0, '__NOTITLECONVERT__', '__NOTC__', '__БЕЗТЦ__' ), + 'notitleconvert' => array( 0, '__NOTITLECONVERT__', '__NOTC__', '__БЕЗКН__', '__BEZKN__' ), 'nocontentconvert' => array( 0, '__NOCONTENTCONVERT__', '__NOCC__', '__БЕЗЦЦ__' ), 'currentweek' => array( 1, 'CURRENTWEEK', 'ТРЕНУТНАНЕДЕЉА' ), 'currentdow' => array( 1, 'CURRENTDOW', 'ТРЕНУТНИДОВ' ), diff --git a/languages/MessagesSr_el.php b/languages/MessagesSr_el.php index c8bcf375c5..fad7ddb012 100644 --- a/languages/MessagesSr_el.php +++ b/languages/MessagesSr_el.php @@ -175,7 +175,7 @@ $magicWords = array( 'servername' => array( 0, 'SERVERNAME', 'IMESERVERA' ), 'scriptpath' => array( 0, 'SCRIPTPATH', 'SKRIPTA' ), 'grammar' => array( 0, 'GRAMMAR:', 'GRAMATIKA:' ), - 'notitleconvert' => array( 0, '__NOTITLECONVERT__', '__NOTC__', '__BEZTC__' ), + 'notitleconvert' => array( 0, '__NOTITLECONVERT__', '__NOTC__', '__БЕЗКН__', '__BEZKN__' ), 'nocontentconvert' => array( 0, '__NOCONTENTCONVERT__', '__NOCC__', '__BEZCC__' ), 'currentweek' => array( 1, 'CURRENTWEEK', 'TRENUTNANEDELjA' ), 'currentdow' => array( 1, 'CURRENTDOW', 'TRENUTNIDOV' ), diff --git a/maintenance/mysql5/tables.sql b/maintenance/mysql5/tables.sql index 81a4690adc..db65cb8f75 100644 --- a/maintenance/mysql5/tables.sql +++ b/maintenance/mysql5/tables.sql @@ -218,6 +218,10 @@ CREATE TABLE /*$wgDBprefix*/page ( -- Uncompressed length in bytes of the page's current source text. page_len int(8) unsigned NOT NULL, + -- Set to 1 if the page contains __NOTITLECONVERT__ magic word. + -- Used only for languages with variants to prevent title conversion + page_no_title_convert bool NOT NULL default 0, + PRIMARY KEY page_id (page_id), UNIQUE INDEX name_title (page_namespace,page_title), diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 3ffa5e5f66..7c2099b634 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -206,6 +206,10 @@ CREATE TABLE /*$wgDBprefix*/page ( -- Uncompressed length in bytes of the page's current source text. page_len int(8) unsigned NOT NULL, + -- Set to 1 if the page contains __NOTITLECONVERT__ magic word. + -- Used only for languages with variants to prevent title conversion + page_no_title_convert bool NOT NULL default 0, + PRIMARY KEY page_id (page_id), UNIQUE INDEX name_title (page_namespace,page_title), diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 9acf302b6f..cc47fd4e52 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -57,6 +57,7 @@ $wgNewFields = array( array( 'ipblocks', 'ipb_range_start', 'patch-ipb_range_start.sql' ), array( 'site_stats', 'ss_images', 'patch-ss_images.sql' ), array( 'ipblocks', 'ipb_anon_only', 'patch-ipb_anon_only.sql' ), + array( 'page', 'page_no_title_convert','patch-page_no_title_convert.sql' ), ); function rename_table( $from, $to, $patch ) { -- 2.20.1