r16526 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r16525‎ | r16526 | r16527 >
Date:21:02, 15 September 2006
Author:brion
Status:old
Tags:
Comment:
reverting SerbianVariants check-in, not ready to go live yet on Wikimedia
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/SearchEngine.php (modified) (history)
  • /trunk/phase3/includes/SpecialSearch.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)
  • /trunk/phase3/languages/LanguageSr.php (modified) (history)
  • /trunk/phase3/languages/MessagesSr_ec.php (modified) (history)
  • /trunk/phase3/languages/MessagesSr_el.php (modified) (history)
  • /trunk/phase3/maintenance/archives/patch-page_no_title_convert.sql (modified) (history)
  • /trunk/phase3/maintenance/mysql5/tables.sql (modified) (history)
  • /trunk/phase3/maintenance/tables.sql (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/archives/patch-page_no_title_convert.sql
@@ -1,7 +0,0 @@
2 -
3 -ALTER TABLE /*$wgDBprefix*/page
4 - ADD page_no_title_convert bool NOT NULL default 0;
Index: trunk/phase3/maintenance/updaters.inc
@@ -57,7 +57,6 @@
5858 array( 'ipblocks', 'ipb_range_start', 'patch-ipb_range_start.sql' ),
5959 array( 'site_stats', 'ss_images', 'patch-ss_images.sql' ),
6060 array( 'ipblocks', 'ipb_anon_only', 'patch-ipb_anon_only.sql' ),
61 - array( 'page', 'page_no_title_convert','patch-page_no_title_convert.sql' ),
6261 );
6362
6463 function rename_table( $from, $to, $patch ) {
Index: trunk/phase3/maintenance/mysql5/tables.sql
@@ -218,10 +218,6 @@
219219 -- Uncompressed length in bytes of the page's current source text.
220220 page_len int(8) unsigned NOT NULL,
221221
222 - -- Set to 1 if the page contains __NOTITLECONVERT__ magic word.
223 - -- Used only for languages with variants to prevent title conversion
224 - page_no_title_convert bool NOT NULL default 0,
225 -
226222 PRIMARY KEY page_id (page_id),
227223 UNIQUE INDEX name_title (page_namespace,page_title),
228224
Index: trunk/phase3/maintenance/tables.sql
@@ -206,10 +206,6 @@
207207 -- Uncompressed length in bytes of the page's current source text.
208208 page_len int(8) unsigned NOT NULL,
209209
210 - -- Set to 1 if the page contains __NOTITLECONVERT__ magic word.
211 - -- Used only for languages with variants to prevent title conversion
212 - page_no_title_convert bool NOT NULL default 0,
213 -
214210 PRIMARY KEY page_id (page_id),
215211 UNIQUE INDEX name_title (page_namespace,page_title),
216212
Index: trunk/phase3/includes/Article.php
@@ -30,8 +30,6 @@
3131 var $mGoodAdjustment; //!<
3232 var $mLatest; //!<
3333 var $mMinorEdit; //!<
34 - var $mNoTitleConvert; //!<
35 - var $mNoTitleConvertParser; //!<
3634 var $mOldId; //!<
3735 var $mRedirectedFrom; //!<
3836 var $mRedirectUrl; //!<
@@ -132,8 +130,6 @@
133131 $this->mRevIdFetched = 0;
134132 $this->mRedirectUrl = false;
135133 $this->mLatest = false;
136 - $this->mNoTitleConvert = false;
137 - $this->mNoTitleConvertParser = false;
138134 }
139135
140136 /**
@@ -271,8 +267,7 @@
272268 'page_random',
273269 'page_touched',
274270 'page_latest',
275 - 'page_len',
276 - 'page_no_title_convert') ;
 271+ 'page_len' ) ;
277272 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
278273 $row = $dbr->selectRow( 'page',
279274 $fields,
@@ -308,8 +303,6 @@
309304 * @private
310305 */
311306 function loadPageData( $data = 'fromdb' ) {
312 - global $wgContLang;
313 -
314307 if ( $data === 'fromdb' ) {
315308 $dbr =& $this->getDB();
316309 $data = $this->pageDataFromId( $dbr, $this->getId() );
@@ -327,10 +320,6 @@
328321 $this->mTouched = wfTimestamp( TS_MW, $data->page_touched );
329322 $this->mIsRedirect = $data->page_is_redirect;
330323 $this->mLatest = $data->page_latest;
331 - $this->mNoTitleConvert = $data->page_no_title_convert;
332 -
333 - if($this->mNoTitleConvert)
334 - $wgContLang->setNoTitleConvert();
335324 } else {
336325 if ( is_object( $this->mTitle ) ) {
337326 $lc->addBadLinkObj( $this->mTitle );
@@ -995,7 +984,6 @@
996985 'page_touched' => $dbw->timestamp(),
997986 'page_latest' => 0, # Fill this in shortly...
998987 'page_len' => 0, # Fill this in shortly...
999 - 'page_no_title_convert' => 0,
1000988 ), __METHOD__ );
1001989 $newid = $dbw->insertId();
1002990
@@ -1035,21 +1023,12 @@
10361024 'page_is_new' => ($lastRevision === 0) ? 1 : 0,
10371025 'page_is_redirect' => Article::isRedirect( $text ) ? 1 : 0,
10381026 'page_len' => strlen( $text ),
1039 - 'page_no_title_convert' => ($this->mNoTitleConvertParser)? 1 : 0,
10401027 ),
10411028 $conditions,
10421029 __METHOD__ );
10431030
1044 - $succ = $dbw->affectedRows() != 0;
1045 -
1046 - // check if no title magic word has been changed
1047 - if($succ && $this->mNoTitleConvert != $this->mNoTitleConvertParser){
1048 - // Clear caches
1049 - Article::onArticleCreate( $this->mTitle );
1050 - }
1051 -
10521031 wfProfileOut( __METHOD__ );
1053 - return $succ;
 1032+ return ( $dbw->affectedRows() != 0 );
10541033 }
10551034
10561035 /**
@@ -1215,7 +1194,7 @@
12161195 * @return bool success
12171196 */
12181197 function doEdit( $text, $summary, $flags = 0 ) {
1219 - global $wgUser, $wgDBtransactions, $wgContLang;
 1198+ global $wgUser, $wgDBtransactions;
12201199
12211200 wfProfileIn( __METHOD__ );
12221201 $good = true;
@@ -1242,15 +1221,6 @@
12431222 $isminor = ( $flags & EDIT_MINOR ) && $wgUser->isAllowed('minoredit');
12441223 $bot = $wgUser->isAllowed( 'bot' ) || ( $flags & EDIT_FORCE_BOT );
12451224
1246 - // process the notitleconvert magic for languages with variants
1247 - $this->mNoTitleConvertParser = false;
1248 - if(sizeof($wgContLang->getVariants())>1){
1249 - $mw =& MagicWord::get( 'notitleconvert' );
1250 - if( $mw->match( $text ) ){
1251 - $this->mNoTitleConvertParser = true;
1252 - }
1253 - }
1254 -
12551225 $text = $this->preSaveTransform( $text );
12561226
12571227 $dbw =& wfGetDB( DB_MASTER );
Index: trunk/phase3/includes/SearchEngine.php
@@ -51,7 +51,6 @@
5252 * @private
5353 */
5454 function getNearMatch( $term ) {
55 - global $wgContLang;
5655 # Exact match? No need to look further.
5756 $title = Title::newFromText( $term );
5857 if (is_null($title))
@@ -63,27 +62,33 @@
6463
6564 # Now try all lower case (i.e. first letter capitalized)
6665 #
67 - $title = Title::newFromText( $wgContLang->lc( $term ) );
 66+ $title = Title::newFromText( strtolower( $term ) );
6867 if ( $title->exists() ) {
6968 return $title;
7069 }
7170
7271 # Now try capitalized string
7372 #
74 - $title = Title::newFromText( $wgContLang->ucwords( $term ) );
 73+ $title = Title::newFromText( ucwords( strtolower( $term ) ) );
7574 if ( $title->exists() ) {
7675 return $title;
7776 }
7877
7978 # Now try all upper case
8079 #
81 - $title = Title::newFromText( $wgContLang->uc( $term ) );
 80+ $title = Title::newFromText( strtoupper( $term ) );
8281 if ( $title->exists() ) {
8382 return $title;
8483 }
8584
8685 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
87 - $title = Title::newFromText( $wgContLang->ucwordbreaks($term) );
 86+ $title = Title::newFromText( preg_replace_callback(
 87+ '/\b([\w\x80-\xff]+)\b/',
 88+ create_function( '$matches', '
 89+ global $wgContLang;
 90+ return $wgContLang->ucfirst($matches[1]);
 91+ ' ),
 92+ $term ) );
8893 if ( $title->exists() ) {
8994 return $title;
9095 }
Index: trunk/phase3/includes/Parser.php
@@ -1507,6 +1507,7 @@
15081508 }
15091509
15101510 $selflink = $this->mTitle->getPrefixedText();
 1511+ $checkVariantLink = sizeof($wgContLang->getVariants())>1;
15111512 $useSubpages = $this->areSubpagesAllowed();
15121513 wfProfileOut( $fname.'-setup' );
15131514
@@ -1601,6 +1602,13 @@
16021603 continue;
16031604 }
16041605
 1606+ #check other language variants of the link
 1607+ #if the article does not exist
 1608+ if( $checkVariantLink
 1609+ && $nt->getArticleID() == 0 ) {
 1610+ $wgContLang->findVariantLink($link, $nt);
 1611+ }
 1612+
16051613 $ns = $nt->getNamespace();
16061614 $iw = $nt->getInterWiki();
16071615 wfProfileOut( "$fname-title" );
@@ -3889,7 +3897,6 @@
38903898 function replaceLinkHolders( &$text, $options = 0 ) {
38913899 global $wgUser;
38923900 global $wgOutputReplace;
3893 - global $wgContLang, $wgLanguageCode;
38943901
38953902 $fname = 'Parser::replaceLinkHolders';
38963903 wfProfileIn( $fname );
@@ -3980,97 +3987,6 @@
39813988 }
39823989 wfProfileOut( $fname.'-check' );
39833990
3984 - # Do a second query for different language variants of links (if needed)
3985 - if($wgContLang->hasVariants()){
3986 - $linkBatch = new LinkBatch();
3987 - $variantMap = array(); // maps $pdbkey_Variant => $pdbkey_original
3988 -
3989 - // Add variants of links to link batch
3990 - foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) {
3991 - $title = $this->mLinkHolders['titles'][$key];
3992 - if ( is_null( $title ) )
3993 - continue;
3994 -
3995 - $pdbk = $title->getPrefixedDBkey();
3996 -
3997 - // add the original text into query to check for notitleconvert pages
3998 - $variantTitle = Title::makeTitle( $ns, $title->getText() );
3999 - $linkBatch->addObj( $variantTitle );
4000 - $variantMap[$variantTitle->getPrefixedDBkey()][] = $key;
4001 -
4002 - // generate all variants of the link title text
4003 - $allTextVariants = $wgContLang->convertLinkToAllVariants($title->getText());
4004 -
4005 - // if link was not found (in first query), add all variants to query
4006 - if ( !isset($colours[$pdbk]) ){
4007 - foreach($allTextVariants as $textVariant){
4008 - $variantTitle = Title::makeTitle( $ns, $textVariant );
4009 - if(is_null($variantTitle)) continue;
4010 - $linkBatch->addObj( $variantTitle );
4011 - $variantMap[$variantTitle->getPrefixedDBkey()][] = $key;
4012 - }
4013 - }
4014 - }
4015 -
4016 - # construct query
4017 - $titleClause = $linkBatch->constructSet('page', $dbr);
4018 - $variantQuery = "SELECT page_id, page_namespace, page_title";
4019 - if ( $threshold > 0 ) {
4020 - $variantQuery .= ', page_len, page_is_redirect';
4021 - }
4022 - $variantQuery .= ", page_no_title_convert FROM $page WHERE $titleClause";
4023 - if ( $options & RLH_FOR_UPDATE ) {
4024 - $query .= ' FOR UPDATE';
4025 - }
4026 -
4027 - $varRes = $dbr->query( $variantQuery, $fname );
4028 -
4029 - # for each found variants, figure out link holders and replace
4030 - while ( $s = $dbr->fetchObject($varRes) ) {
4031 -
4032 - $variantTitle = Title::makeTitle( $s->page_namespace, $s->page_title );
4033 - $varPdbk = $variantTitle->getPrefixedDBkey();
4034 - $linkCache->addGoodLinkObj( $s->page_id, $variantTitle );
4035 - $this->mOutput->addLink( $variantTitle, $s->page_id );
4036 -
4037 - $noTitleConvert = $s->page_no_title_convert;
4038 -
4039 - $holderKeys = $variantMap[$varPdbk];
4040 -
4041 - // loop over link holders
4042 - foreach($holderKeys as $key){
4043 - $title = $this->mLinkHolders['titles'][$key];
4044 - if ( is_null( $title ) ) continue;
4045 -
4046 - $pdbk = $title->getPrefixedDBkey();
4047 -
4048 - if(!isset($colours[$pdbk]) || ($noTitleConvert && $colours[$pdbk] == 1)){
4049 - // found link in some of the variants, replace the link holder data
4050 - $this->mLinkHolders['titles'][$key] = $variantTitle;
4051 - $this->mLinkHolders['dbkeys'][$key] = $variantTitle->getDBkey();
4052 -
4053 - // prevent link conversion if needed
4054 - if($noTitleConvert)
4055 - $this->mLinkHolders['texts'][$key] = $wgContLang->markNoConversion($variantTitle->getText(),true);
4056 -
4057 - // set pdbk and colour
4058 - $pdbks[$key] = $varPdbk;
4059 - if ( $threshold > 0 ) {
4060 - $size = $s->page_len;
4061 - if ( $s->page_is_redirect || $s->page_namespace != 0 || $size >= $threshold ) {
4062 - $colours[$varPdbk] = 1;
4063 - } else {
4064 - $colours[$varPdbk] = 2;
4065 - }
4066 - }
4067 - else {
4068 - $colours[$varPdbk] = 1;
4069 - }
4070 - }
4071 - }
4072 - }
4073 - }
4074 -
40753991 # Construct search and replace arrays
40763992 wfProfileIn( $fname.'-construct' );
40773993 $wgOutputReplace = array();
Index: trunk/phase3/includes/SpecialSearch.php
@@ -77,7 +77,6 @@
7878 function goResult( $term ) {
7979 global $wgOut;
8080 global $wgGoToEdit;
81 - global $wgContLang;
8281
8382 $this->setupPage( $term );
8483
@@ -97,20 +96,6 @@
9897 return;
9998 }
10099
101 - # if language supports variants, search in all variants
102 - if($wgContLang->hasVariants()){
103 - $allTermVariants = $wgContLang->convertLinkToAllVariants($term);
104 -
105 - foreach($allTermVariants as $termVariant){
106 - $t = SearchEngine::getNearMatch( $termVariant );
107 - if( !is_null( $t ) ) {
108 - $wgOut->redirect( $t->getFullURL() );
109 - wfProfileOut( $fname );
110 - return;
111 - }
112 - }
113 - }
114 -
115100 # No match, generate an edit URL
116101 $t = Title::newFromText( $term );
117102 if( is_null( $t ) ) {
Index: trunk/phase3/languages/MessagesSr_el.php
@@ -175,7 +175,7 @@
176176 'servername' => array( 0, 'SERVERNAME', 'IMESERVERA' ),
177177 'scriptpath' => array( 0, 'SCRIPTPATH', 'SKRIPTA' ),
178178 'grammar' => array( 0, 'GRAMMAR:', 'GRAMATIKA:' ),
179 - 'notitleconvert' => array( 0, '__NOTITLECONVERT__', '__NOTC__', '__БЕЗКН__', '__BEZKN__' ),
 179+ 'notitleconvert' => array( 0, '__NOTITLECONVERT__', '__NOTC__', '__BEZTC__' ),
180180 'nocontentconvert' => array( 0, '__NOCONTENTCONVERT__', '__NOCC__', '__BEZCC__' ),
181181 'currentweek' => array( 1, 'CURRENTWEEK', 'TRENUTNANEDELjA' ),
182182 'currentdow' => array( 1, 'CURRENTDOW', 'TRENUTNIDOV' ),
Index: trunk/phase3/languages/Language.php
@@ -49,10 +49,9 @@
5050 function findVariantLink(&$l, &$n) {}
5151 function getExtraHashOptions() {return '';}
5252 function getParsedTitle() {return '';}
53 - function markNoConversion($text, $noParse=false) {return $text;}
 53+ function markNoConversion($text) {return $text;}
5454 function convertCategoryKey( $key ) {return $key; }
55 - function convertLinkToAllVariants($text){ return array( $this->mLang->getCode() => $text); }
56 - function setNoTitleConvert(){}
 55+
5756 }
5857
5958 #--------------------------------------------------------------------------
@@ -713,34 +712,6 @@
714713 return iconv( $in, $out, $string );
715714 }
716715
717 - // callback functions for uc(), lc(), ucwords(), ucwordbreaks()
718 - function ucwordbreaksCallbackAscii($matches){
719 - return $this->ucfirst($matches[1]);
720 - }
721 -
722 - function ucwordbreaksCallbackMB($matches){
723 - return mb_strtoupper($matches[0]);
724 - }
725 -
726 - function ucCallback($matches){
727 - global $wikiUpperChars;
728 - return strtr( $matches[1] , $wikiUpperChars );
729 - }
730 -
731 - function lcCallback($matches){
732 - global $wikiLowerChars;
733 - return strtr( $matches[1] , $wikiLowerChars );
734 - }
735 -
736 - function ucwordsCallbackMB($matches){
737 - return mb_strtoupper($matches[0]);
738 - }
739 -
740 - function ucwordsCallbackWiki($matches){
741 - global $wikiUpperChars;
742 - return strtr( $matches[0] , $wikiUpperChars );
743 - }
744 -
745716 function ucfirst( $str ) {
746717 return self::uc( $str, true );
747718 }
@@ -758,9 +729,9 @@
759730 if ( self::isMultibyte( $str ) ) {
760731 list( $wikiUpperChars ) = $this->getCaseMaps();
761732 $x = $first ? '^' : '';
762 - return preg_replace_callback(
763 - "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/",
764 - array($this,"ucCallback"),
 733+ return preg_replace(
 734+ "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e",
 735+ "strtr( \"\$1\" , \$wikiUpperChars )",
765736 $str
766737 );
767738 } else
@@ -784,9 +755,9 @@
785756 if ( self::isMultibyte( $str ) ) {
786757 list( , $wikiLowerChars ) = self::getCaseMaps();
787758 $x = $first ? '^' : '';
788 - return preg_replace_callback(
789 - "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/",
790 - array($this,"lcCallback"),
 759+ return preg_replace(
 760+ "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e",
 761+ "strtr( \"\$1\" , \$wikiLowerChars )",
791762 $str
792763 );
793764 } else
@@ -797,66 +768,6 @@
798769 return (bool)preg_match( '/[\x80-\xff]/', $str );
799770 }
800771
801 - function ucwords($str) {
802 - global $wikiUpperChars;
803 -
804 - if ( self::isMultibyte( $str ) ) {
805 - $str = self::lc($str);
806 -
807 - // regexp to find first letter in each word (i.e. after each space)
808 - $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)| ([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
809 -
810 - // function to use to capitalize a single char
811 - if ( function_exists( 'mb_strtoupper' ) )
812 - return preg_replace_callback(
813 - $replaceRegexp,
814 - array($this,"ucwordsCallbackMB"),
815 - $str
816 - );
817 - else
818 - return preg_replace_callback(
819 - $replaceRegexp,
820 - array($this,"ucwordsCallbackWiki"),
821 - $str
822 - );
823 - }
824 - else
825 - return ucwords( strtolower( $str ) );
826 - }
827 -
828 - # capitalize words at word breaks
829 - function ucwordbreaks($str){
830 - global $wikiUpperChars;
831 -
832 - if (self::isMultibyte( $str ) ) {
833 - $str = self::lc($str);
834 -
835 - // since \b doesn't work for UTF-8, we explicitely define word break chars
836 - $breaks= "[ \-\(\)\}\{\.,\?!]";
837 -
838 - // find first letter after word break
839 - $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
840 -
841 - if ( function_exists( 'mb_strtoupper' ) )
842 - return preg_replace_callback(
843 - $replaceRegexp,
844 - array($this,"ucwordbreaksCallbackMB"),
845 - $str
846 - );
847 - else
848 - return preg_replace_callback(
849 - $replaceRegexp,
850 - array($this,"ucwordsCallbackWiki"),
851 - $str
852 - );
853 - }
854 - else
855 - return preg_replace_callback(
856 - '/\b([\w\x80-\xff]+)\b/',
857 - array($this,"ucwordbreaksCallbackAscii"),
858 - $str );
859 - }
860 -
861772 function checkTitleEncoding( $s ) {
862773 if( is_array( $s ) ) {
863774 wfDebugDieBacktrace( 'Given array to checkTitleEncoding.' );
@@ -1258,17 +1169,6 @@
12591170 return $this->mConverter->parserConvert( $text, $parser );
12601171 }
12611172
1262 - # Tell the converter that it shouldn't convert titles
1263 - function setNoTitleConvert(){
1264 - $this->mConverter->setNotitleConvert();
1265 - }
1266 -
1267 - # Check if this is a language with variants
1268 - function hasVariants(){
1269 - return sizeof($this->getVariants())>1;
1270 - }
1271 -
1272 -
12731173 /**
12741174 * Perform output conversion on a string, and encode for safe HTML output.
12751175 * @param string $text
@@ -1314,17 +1214,6 @@
13151215 }
13161216
13171217 /**
1318 - * If a language supports multiple variants, converts text
1319 - * into an array of all possible variants of the text:
1320 - * 'variant' => text in that variant
1321 - */
1322 -
1323 - function convertLinkToAllVariants($text){
1324 - return $this->mConverter->convertLinkToAllVariants($text);
1325 - }
1326 -
1327 -
1328 - /**
13291218 * returns language specific options used by User::getPageRenderHash()
13301219 * for example, the preferred language variant
13311220 *
@@ -1353,8 +1242,8 @@
13541243 * @param string $text text to be tagged for no conversion
13551244 * @return string the tagged text
13561245 */
1357 - function markNoConversion( $text, $noParse=false ) {
1358 - return $this->mConverter->markNoConversion( $text, $noParse );
 1246+ function markNoConversion( $text ) {
 1247+ return $this->mConverter->markNoConversion( $text );
13591248 }
13601249
13611250 /**
Index: trunk/phase3/languages/MessagesSr_ec.php
@@ -173,7 +173,7 @@
174174 'servername' => array( 0, 'SERVERNAME', 'ИМЕСЕРВЕРА' ),
175175 'scriptpath' => array( 0, 'SCRIPTPATH', 'СКРИПТА' ),
176176 'grammar' => array( 0, 'GRAMMAR:', 'ГРАМАТИКА:' ),
177 - 'notitleconvert' => array( 0, '__NOTITLECONVERT__', '__NOTC__', '__БЕЗКН__', '__BEZKN__' ),
 177+ 'notitleconvert' => array( 0, '__NOTITLECONVERT__', '__NOTC__', '__БЕЗТЦ__' ),
178178 'nocontentconvert' => array( 0, '__NOCONTENTCONVERT__', '__NOCC__', '__БЕЗЦЦ__' ),
179179 'currentweek' => array( 1, 'CURRENTWEEK', 'ТРЕНУТНАНЕДЕЉА' ),
180180 'currentdow' => array( 1, 'CURRENTDOW', 'ТРЕНУТНИДОВ' ),
Index: trunk/phase3/languages/LanguageConverter.php
@@ -22,7 +22,6 @@
2323 var $mMarkup;
2424 var $mFlags;
2525 var $mUcfirst = false;
26 - var $mNoTitleConvert = false;
2726 /**
2827 * Constructor
2928 *
@@ -39,7 +38,6 @@
4039 $markup=array(),
4140 $flags = array()) {
4241 global $wgDBname;
43 - global $wgLegalTitleChars;
4442 $this->mLangObj = $langobj;
4543 $this->mMainLanguageCode = $maincode;
4644 $this->mVariants = $variants;
@@ -157,17 +155,14 @@
158156 $marker = "";
159157
160158 // this one is needed when the text is inside an html markup
161 - $htmlfix = '|<[^>]+$|^[^<>]*>';
 159+ $htmlfix = '|<[^>]+=\"[^(>=)]*$|^[^(<>=\")]*\"[^>]*>';
162160
163 - // disable convert to variants between <code></code> tags
164 - $codefix = '<code>.+?<\/code>|';
165 -
166 - $reg = '/'.$codefix.'<[^>]+>|&[a-z#][a-z0-9]+;' . $marker . $htmlfix . '/s';
 161+ $reg = '/<[^>]+>|&[a-z#][a-z0-9]+;' . $marker . $htmlfix . '/';
167162
168163 $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
169164
170 - $m = array_shift($matches);
171165
 166+ $m = array_shift($matches);
172167 $ret = $this->translate($m[0], $toVariant);
173168 $mstart = $m[1]+strlen($m[0]);
174169 foreach($matches as $m) {
@@ -202,7 +197,7 @@
203198 *
204199 * @param string $text the text to be converted
205200 * @return array of string
206 - * @public
 201+ * @private
207202 */
208203 function autoConvertToAllVariants($text) {
209204 $fname="LanguageConverter::autoConvertToAllVariants";
@@ -214,52 +209,18 @@
215210 foreach($this->mVariants as $variant) {
216211 $ret[$variant] = $this->translate($text, $variant);
217212 }
218 -
219213 wfProfileOut( $fname );
220214 return $ret;
221215 }
222216
223217 /**
224 - * convert link text to all supported variants
225 - *
226 - * @param string $text the text to be converted
227 - * @return array of string
228 - * @public
229 - */
230 - function convertLinkToAllVariants($text) {
231 - if( !$this->mTablesLoaded )
232 - $this->loadTables();
233 -
234 - $ret = array();
235 - $tarray = explode($this->mMarkup['begin'], $text);
236 - $tfirst = array_shift($tarray);
237 -
238 - foreach($this->mVariants as $variant)
239 - $ret[$variant] = $this->translate($tfirst,$variant);
240 -
241 - foreach($tarray as $txt) {
242 - $marked = explode($this->mMarkup['end'], $txt, 2);
243 -
244 - foreach($this->mVariants as $variant){
245 - $ret[$variant] .= $this->mMarkup['begin'].$marked[0].$this->mMarkup['end'];
246 - if(array_key_exists(1, $marked))
247 - $ret[$variant] .= $this->translate($marked[1],$variant);
248 - }
249 -
250 - }
251 -
252 - return $ret;
253 - }
254 -
255 -
256 - /**
257218 * Convert text using a parser object for context
258219 */
259220 function parserConvert( $text, &$parser ) {
260221 global $wgDisableLangConversion;
261222 /* don't do anything if this is the conversion table */
262223 if ( $parser->mTitle->getNamespace() == NS_MEDIAWIKI &&
263 - strpos($parser->mTitle->getText(), "Conversiontable") !== false )
 224+ strpos($parser->mTitle->getText, "Conversiontable") !== false )
264225 {
265226 return $text;
266227 }
@@ -303,11 +264,6 @@
304265 return $text;
305266
306267 if( $isTitle ) {
307 - if($this->mNoTitleConvert){
308 - $this->mTitleDisplay = $text;
309 - return $text;
310 - }
311 -
312268 if( !$this->mDoTitleConvert ) {
313269 $this->mTitleDisplay = $text;
314270 return $text;
@@ -322,7 +278,7 @@
323279 return $text;
324280 }
325281 else {
326 - $this->mTitleDisplay = $this->convert($text);
 282+ $this->mTitleDisplay = $this->autoConvert($text);
327283 return $this->mTitleDisplay;
328284 }
329285 }
@@ -359,7 +315,7 @@
360316 else
361317 $rules = $marked[0];
362318
363 - //FIXME: may cause trouble here...
 319+#FIXME: may cause trouble here...
364320 //strip &nbsp; since it interferes with the parsing, plus,
365321 //all spaces should be stripped in this tag anyway.
366322 $rules = str_replace('&nbsp;', '', $rules);
@@ -454,16 +410,23 @@
455411 * @access public
456412 */
457413 function findVariantLink( &$link, &$nt ) {
 414+ static $count=0; //used to limit this operation
 415+ static $cache=array();
458416 global $wgDisableLangConversion;
459417 $pref = $this->getPreferredVariant();
460418 $ns=0;
461419 if(is_object($nt))
462420 $ns = $nt->getNamespace();
463 -
 421+ if( $count > 50 && $ns != NS_CATEGORY )
 422+ return;
 423+ $count++;
464424 $variants = $this->autoConvertToAllVariants($link);
465425 if($variants == false) //give up
466426 return;
467427 foreach( $variants as $v ) {
 428+ if(isset($cache[$v]))
 429+ continue;
 430+ $cache[$v] = 1;
468431 $varnt = Title::newFromText( $v, $ns );
469432 if( $varnt && $varnt->getArticleID() > 0 ) {
470433 $nt = $varnt;
@@ -692,7 +655,7 @@
693656 * @param string $text text to be tagged for no conversion
694657 * @return string the tagged text
695658 */
696 - function markNoConversion($text, $noParse=false) {
 659+ function markNoConversion($text) {
697660 # don't mark if already marked
698661 if(strpos($text, $this->mMarkup['begin']) ||
699662 strpos($text, $this->mMarkup['end']))
@@ -733,11 +696,6 @@
734697 }
735698 return true;
736699 }
737 -
738 - function setNoTitleConvert(){
739 - $this->mNoTitleConvert = true;
740 - }
741 -
742700 }
743701
744702 ?>
Index: trunk/phase3/languages/LanguageSr.php
@@ -169,8 +169,8 @@
170170 * We want our external link captions to be converted in variants,
171171 * so we return the original text instead -{$text}-, except for URLs
172172 */
173 - function markNoConversion($text, $noParse=false) {
174 - if($noParse || preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text))
 173+ function markNoConversion($text) {
 174+ if(preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text))
175175 return parent::markNoConversion($text);
176176 return $text;
177177 }
@@ -188,51 +188,22 @@
189189 return parent::autoConvert($text,$toVariant);
190190 }
191191
192 - /**
193 - * It translates text into variant, specials:
194 - * - ommiting roman numbers
195 - */
196 - function translate($text, $toVariant){
197 - $breaks = '[^\w\x80-\xff]';
198192
199 - // regexp for roman numbers
200 - $roman = 'M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})';
201 -
202 - $reg = '/^'.$roman.'$|^'.$roman.$breaks.'|'.$breaks.$roman.'$|'.$breaks.$roman.$breaks.'/';
203 -
204 - $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
205 -
206 - $m = array_shift($matches);
207 - $ret = strtr($m[0], $this->mTables[$toVariant]);
208 - $mstart = $m[1]+strlen($m[0]);
209 - foreach($matches as $m) {
210 - $ret .= substr($text, $mstart, $m[1]-$mstart);
211 - $ret .= parent::translate($m[0], $toVariant);
212 - $mstart = $m[1] + strlen($m[0]);
213 - }
214 -
215 - return $ret;
216 - }
217 -
218 -
219193 }
220194
221195 class LanguageSr extends LanguageSr_ec {
222196 function __construct() {
223197 global $wgHooks;
224 -
225198 parent::__construct();
226199
227 - // these variants are currently UNUSED:
228 - // 'sr-jc', 'sr-jl'
229 - $variants = array('sr', 'sr-ec', 'sr-el');
 200+ $variants = array('sr', 'sr-ec', 'sr-jc', 'sr-el', 'sr-jl');
230201 $variantfallbacks = array(
231202 'sr' => 'sr-ec',
232 - 'sr-ec' => 'sr-ec',
233 - 'sr-el' => 'sr-el',
234 - );
235 -
236 -
 203+ 'sr-ec' => 'sr-jc',
 204+ 'sr-jc' => 'sr-ec',
 205+ 'sr-el' => 'sr-jl',
 206+ 'sr-jl' => 'sr-el'
 207+ );
237208 $marker = array();//don't mess with these, leave them as they are
238209 $flags = array(
239210 'S' => 'S', 'писмо' => 'S', 'pismo' => 'S',

Follow-up revisions

RevisionCommit summaryAuthorDate
r87306Remove empty files left by r16526, r29128 and r83029platonides22:36, 2 May 2011