r60763 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60762‎ | r60763 | r60764 >
Date:04:13, 7 January 2010
Author:mah
Status:resolved (Comments)
Tags:
Comment:
Refactor LanguageConversion so that title conversion isn't so flimsy. Pull MagicWord detection into Parser->doDoubleUnderscore() && remove ParserConvert.
Modified paths:
  • /trunk/phase3/includes/MagicWord.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageKk.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageKu.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageSr.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -93,7 +93,7 @@
9494 var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables,
9595 $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, $mPreprocessor,
9696 $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, $mVarCache, $mConf,
97 - $mFunctionTagHooks;
 97+ $mFunctionTagHooks, $mDoTitleConvert, $mDoContentConvert;
9898
9999
100100 # Cleared with clearState():
@@ -147,6 +147,8 @@
148148 }
149149 $this->mMarkerIndex = 0;
150150 $this->mFirstCall = true;
 151+ $this->mDoTitleConvert = true;
 152+ $this->mDoContentConvert = true;
151153 }
152154
153155 /**
@@ -314,7 +316,8 @@
315317 }
316318
317319 $this->mOptions = $options;
318 - $this->setTitle( $title );
 320+ $this->setTitle( $title ); // Page title has to be set for the pre-processor
 321+
319322 $oldRevisionId = $this->mRevisionId;
320323 $oldRevisionTimestamp = $this->mRevisionTimestamp;
321324 if( $revid !== null ) {
@@ -326,6 +329,11 @@
327330 # No more strip!
328331 wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
329332 $text = $this->internalParse( $text );
 333+ // internalParse took care of the notitleconvert bit, so title conversion is here.
 334+ if ( $this->mDoTitleConvert && !$this->mTitle->isConversionTable()) {
 335+ $this->setTitle( Title::newFromText( $wgContLang->convert( $title ) ) );
 336+ }
 337+
330338 $text = $this->mStripState->unstripGeneral( $text );
331339
332340 # Clean up special characters, only run once, next-to-last before doBlockLevels
@@ -343,11 +351,12 @@
344352
345353 $this->replaceLinkHolders( $text );
346354
347 - # the position of the parserConvert() call should not be changed. it
 355+ # the position of the convert() call should not be changed. it
348356 # assumes that the links are all replaced and the only thing left
349357 # is the <nowiki> mark.
350 - # Side-effects: this calls $this->mOutput->setTitleText()
351 - $text = $wgContLang->parserConvert( $text, $this );
 358+ if ( $this->mDoContentConvert && !$this->mTitle->isConversionTable()) {
 359+ $text = $wgContLang->convert( $text );
 360+ }
352361
353362 $text = $this->mStripState->unstripNoWiki( $text );
354363
@@ -654,14 +663,14 @@
655664 $this->mStripState->general->setPair( $rnd, $text );
656665 return $rnd;
657666 }
658 -
 667+
659668 /**
660669 * Interface with html tidy
661670 * @deprecated Use MWTidy::tidy()
662671 */
663672 public static function tidy( $text ) {
664673 wfDeprecated( __METHOD__ );
665 - return MWTidy::tidy( $text );
 674+ return MWTidy::tidy( $text );
666675 }
667676
668677 /**
@@ -870,7 +879,7 @@
871880 */
872881 function internalParse( $text, $isMain = true, $frame=false ) {
873882 wfProfileIn( __METHOD__ );
874 -
 883+
875884 $origText = $text;
876885
877886 # Hook to suspend the parser in this state
@@ -883,7 +892,7 @@
884893 if ($frame) {
885894 // use frame depth to infer how include/noinclude tags should be handled
886895 // depth=0 means this is the top-level document; otherwise it's an included document
887 - if( !$frame->depth )
 896+ if( !$frame->depth )
888897 $flag = 0;
889898 else
890899 $flag = Parser::PTD_FOR_INCLUSION;
@@ -907,6 +916,7 @@
908917 $text = preg_replace( '/(^|\n)-----*/', '\\1<hr />', $text );
909918
910919 $text = $this->doDoubleUnderscore( $text );
 920+
911921 $text = $this->doHeadings( $text );
912922 if( $this->mOptions->getUseDynamicDates() ) {
913923 $df = DateFormatter::getInstance();
@@ -930,7 +940,7 @@
931941 /**
932942 * Replace special strings like "ISBN xxx" and "RFC xxx" with
933943 * magic external links.
934 - *
 944+ *
935945 * DML
936946 * @private
937947 */
@@ -940,7 +950,7 @@
941951 $urlChar = self::EXT_LINK_URL_CLASS;
942952 $text = preg_replace_callback(
943953 '!(?: # Start cases
944 - (<a.*?</a>) | # m[1]: Skip link text
 954+ (<a.*?</a>) | # m[1]: Skip link text
945955 (<.*?>) | # m[2]: Skip stuff inside HTML elements' . "
946956 (\\b(?:$prots)$urlChar+) | # m[3]: Free external links" . '
947957 (?:RFC|PMID)\s+([0-9]+) | # m[4]: RFC or PMID, capture number
@@ -1042,7 +1052,7 @@
10431053 $text = $this->maybeMakeExternalImage( $url );
10441054 if ( $text === false ) {
10451055 # Not an image, make a link
1046 - $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free',
 1056+ $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free',
10471057 $this->getExternalLinkAttribs( $url ) );
10481058 # Register it in the output object...
10491059 # Replace unnecessary URL escape codes with their equivalent characters
@@ -1482,7 +1492,7 @@
14831493 wfProfileIn( __METHOD__.'-setup' );
14841494 static $tc = FALSE, $e1, $e1_img;
14851495 # the % is needed to support urlencoded titles as well
1486 - if ( !$tc ) {
 1496+ if ( !$tc ) {
14871497 $tc = Title::legalChars() . '#%';
14881498 # Match a link having the form [[namespace:link|alternate]]trail
14891499 $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
@@ -2016,7 +2026,7 @@
20172027 }
20182028 } elseif( $prefixLength || $lastPrefixLength ) {
20192029 // We need to open or close prefixes, or both.
2020 -
 2030+
20212031 # Either open or close a level...
20222032 $commonPrefixLength = $this->getCommon( $prefix, $lastPrefix );
20232033 $paragraphStack = false;
@@ -2026,12 +2036,12 @@
20272037 $output .= $this->closeList( $lastPrefix[$lastPrefixLength-1] );
20282038 --$lastPrefixLength;
20292039 }
2030 -
 2040+
20312041 // Continue the current prefix if appropriate.
20322042 if ( $prefixLength <= $commonPrefixLength && $commonPrefixLength > 0 ) {
20332043 $output .= $this->nextItem( $prefix[$commonPrefixLength-1] );
20342044 }
2035 -
 2045+
20362046 // Open prefixes where appropriate.
20372047 while ( $prefixLength > $commonPrefixLength ) {
20382048 $char = substr( $prefix, $commonPrefixLength, 1 );
@@ -2048,7 +2058,7 @@
20492059 }
20502060 $lastPrefix = $prefix2;
20512061 }
2052 -
 2062+
20532063 // If we have no prefixes, go to paragraph mode.
20542064 if( 0 == $prefixLength ) {
20552065 wfProfileIn( __METHOD__."-paragraph" );
@@ -2592,7 +2602,7 @@
25932603 return null;
25942604 }
25952605
2596 - if ( $index )
 2606+ if ( $index )
25972607 $this->mVarCache[$index] = $value;
25982608
25992609 return $value;
@@ -2665,7 +2675,7 @@
26662676 * self::OT_HTML: all templates and extension tags
26672677 *
26682678 * @param string $tex The text to transform
2669 - * @param PPFrame $frame Object describing the arguments passed to the template.
 2679+ * @param PPFrame $frame Object describing the arguments passed to the template.
26702680 * Arguments may also be provided as an associative array, as was the usual case before MW1.12.
26712681 * Providing arguments this way may be useful for extensions wishing to perform variable replacement explicitly.
26722682 * @param bool $argsOnly Only do argument (triple-brace) expansion, not double-brace expansion
@@ -2729,7 +2739,7 @@
27302740 */
27312741 function limitationWarn( $limitationType, $current=null, $max=null) {
27322742 //does no harm if $current and $max are present but are unnecessary for the message
2733 - $warning = wfMsgExt( "$limitationType-warning", array( 'parsemag', 'escape' ), $current, $max );
 2743+ $warning = wfMsgExt( "$limitationType-warning", array( 'parsemag', 'escape' ), $current, $max );
27342744 $this->mOutput->addWarning( $warning );
27352745 $this->addTrackingCategory( "$limitationType-category" );
27362746 }
@@ -2870,7 +2880,7 @@
28712881 $found = true;
28722882 $noparse = true;
28732883 $preprocessFlags = 0;
2874 -
 2884+
28752885 if ( is_array( $result ) ) {
28762886 if ( isset( $result[0] ) ) {
28772887 $text = $result[0];
@@ -3376,7 +3386,9 @@
33773387 * Fills $this->mDoubleUnderscores, returns the modified text
33783388 */
33793389 function doDoubleUnderscore( $text ) {
 3390+ global $wgDisableLangConversion;
33803391 wfProfileIn( __METHOD__ );
 3392+
33813393 // The position of __TOC__ needs to be recorded
33823394 $mw = MagicWord::get( 'toc' );
33833395 if( $mw->match( $text ) ) {
@@ -3416,10 +3428,23 @@
34173429 $this->mOutput->setIndexPolicy( 'index' );
34183430 $this->addTrackingCategory( 'index-category' );
34193431 }
 3432+
 3433+ if ( !$wgDisableLangConversion ) {
 3434+ if( isset( $this->mDoubleUnderscores['notitleconvert'] ) ){
 3435+ $this->mDoTitleConvert = false;
 3436+ }
 3437+
 3438+ // Don't convert talk pages
 3439+ if( isset( $this->mDoubleUnderscores['nocontentconvert'] )
 3440+ && !$this->mTitle->isTalkPage() ){
 3441+ $this->mDoContentConvert = false;
 3442+ }
 3443+ }
 3444+
34203445 wfProfileOut( __METHOD__ );
34213446 return $text;
3422 - }
3423 -
 3447+ }
 3448+
34243449 /**
34253450 * Add a tracking category, getting the title from a system message,
34263451 * or print a debug message if the title is invalid.
@@ -3428,10 +3453,10 @@
34293454 */
34303455 protected function addTrackingCategory( $msg ){
34313456 $cat = wfMsgForContent( $msg );
3432 -
 3457+
34333458 # Allow tracking categories to be disabled by setting them to "-"
34343459 if( $cat === '-' ) return false;
3435 -
 3460+
34363461 $containerCategory = Title::makeTitleSafe( NS_CATEGORY, $cat );
34373462 if ( $containerCategory ) {
34383463 $this->mOutput->addCategory( $containerCategory->getDBkey(), $this->getDefaultSort() );
@@ -3707,7 +3732,7 @@
37083733 $toc .= $sk->tocLine($anchor, $tocline,
37093734 $numbering, $toclevel, ($isTemplate ? false : $sectionIndex));
37103735 }
3711 -
 3736+
37123737 # Add the section to the section tree
37133738 # Find the DOM node for this header
37143739 while ( $node && !$isTemplate ) {
@@ -3716,11 +3741,11 @@
37173742 if ( $bits['i'] == $sectionIndex )
37183743 break;
37193744 }
3720 - $byteOffset += mb_strlen( $this->mStripState->unstripBoth(
 3745+ $byteOffset += mb_strlen( $this->mStripState->unstripBoth(
37213746 $frame->expand( $node, PPFrame::RECOVER_ORIG ) ) );
37223747 $node = $node->getNextSibling();
37233748 }
3724 - $tocraw[] = array(
 3749+ $tocraw[] = array(
37253750 'toclevel' => $toclevel,
37263751 'level' => $level,
37273752 'line' => $tocline,
@@ -3730,7 +3755,7 @@
37313756 'byteoffset' => ( $isTemplate ? null : $byteOffset ),
37323757 'anchor' => $anchor,
37333758 );
3734 -
 3759+
37353760 # give headline the correct <h#> tag
37363761 if( $showEditLink && $sectionIndex !== false ) {
37373762 if( $isTemplate ) {
@@ -3764,7 +3789,7 @@
37653790 $toc = $sk->tocList( $toc );
37663791 $this->mOutput->setTOCHTML( $toc );
37673792 }
3768 -
 3793+
37693794 if ( $isMain ) {
37703795 $this->mOutput->setSections( $tocraw );
37713796 }
@@ -3773,7 +3798,7 @@
37743799
37753800 $blocks = preg_split( '/<H[1-6].*?' . '>.*?<\/H[1-6]>/i', $text );
37763801 $i = 0;
3777 -
 3802+
37783803 foreach( $blocks as $block ) {
37793804 if( $showEditLink && $headlineCount > 0 && $i == 0 && $block !== "\n" ) {
37803805 # This is the [edit] link that appears for the top block of text when
@@ -3800,7 +3825,7 @@
38013826 return $full;
38023827 }
38033828 }
3804 -
 3829+
38053830 /**
38063831 * Merge $tree2 into $tree1 by replacing the section with index
38073832 * $section in $tree1 and its descendants with the sections in $tree2.
@@ -3823,7 +3848,7 @@
38243849 $numbering = array( 0 );
38253850 $titletext = $title->getPrefixedDBkey();
38263851 foreach ( $tree1 as $s ) {
3827 - if ( $targetLevel !== false ) {
 3852+ if ( $targetLevel !== false ) {
38283853 if ( $s['level'] <= $targetLevel )
38293854 // We've skipped enough
38303855 $targetLevel = false;
@@ -3834,7 +3859,7 @@
38353860 $s['fromtitle'] != $titletext ) {
38363861 self::incrementNumbering( $numbering,
38373862 $s['toclevel'], $lastLevel );
3838 -
 3863+
38393864 // Rewrite index, byteoffset and number
38403865 if ( $s['fromtitle'] == $titletext ) {
38413866 $s['index'] = $nextIndex++;
@@ -3856,7 +3881,7 @@
38573882 $s2['level'] += $s['level'] - 1;
38583883 $s2['index'] = $nextIndex++;
38593884 $s2['byteoffset'] += $s['byteoffset'];
3860 -
 3885+
38613886 self::incrementNumbering( $numbering,
38623887 $s2['toclevel'], $lastLevel );
38633888 $s2['number'] = implode( '.', array_map(
@@ -3872,7 +3897,7 @@
38733898 }
38743899 return $newTree;
38753900 }
3876 -
 3901+
38773902 /**
38783903 * Increment a section number. Helper function for mergeSectionTrees()
38793904 * @param $number array Array representing a section number
@@ -3890,7 +3915,7 @@
38913916 } else
38923917 $number[$level - 1]++;
38933918 }
3894 -
 3919+
38953920 /**
38963921 * Transform wiki markup when saving a page by doing \r\n -> \n
38973922 * conversion, substitting signatures, {{subst:}} templates, etc.
@@ -4015,14 +4040,14 @@
40164041 global $wgMaxSigChars;
40174042
40184043 $username = $user->getName();
4019 -
 4044+
40204045 // If not given, retrieve from the user object.
40214046 if ( $nickname === false )
40224047 $nickname = $user->getOption( 'nickname' );
4023 -
 4048+
40244049 if ( is_null( $fancySig ) )
40254050 $fancySig = $user->getBoolOption( 'fancysig' );
4026 -
 4051+
40274052 $nickname = $nickname == null ? $username : $nickname;
40284053
40294054 if( mb_strlen( $nickname ) > $wgMaxSigChars ) {
@@ -4221,23 +4246,23 @@
42224247 * @param integer $flags a combination of the following flags:
42234248 * SFH_NO_HASH No leading hash, i.e. {{plural:...}} instead of {{#if:...}}
42244249 *
4225 - * SFH_OBJECT_ARGS Pass the template arguments as PPNode objects instead of text. This
 4250+ * SFH_OBJECT_ARGS Pass the template arguments as PPNode objects instead of text. This
42264251 * allows for conditional expansion of the parse tree, allowing you to eliminate dead
4227 - * branches and thus speed up parsing. It is also possible to analyse the parse tree of
 4252+ * branches and thus speed up parsing. It is also possible to analyse the parse tree of
42284253 * the arguments, and to control the way they are expanded.
42294254 *
42304255 * The $frame parameter is a PPFrame. This can be used to produce expanded text from the
42314256 * arguments, for instance:
42324257 * $text = isset( $args[0] ) ? $frame->expand( $args[0] ) : '';
42334258 *
4234 - * For technical reasons, $args[0] is pre-expanded and will be a string. This may change in
 4259+ * For technical reasons, $args[0] is pre-expanded and will be a string. This may change in
42354260 * future versions. Please call $frame->expand() on it anyway so that your code keeps
42364261 * working if/when this is changed.
42374262 *
42384263 * If you want whitespace to be trimmed from $args, you need to do it yourself, post-
42394264 * expansion.
42404265 *
4241 - * Please read the documentation in includes/parser/Preprocessor.php for more information
 4266+ * Please read the documentation in includes/parser/Preprocessor.php for more information
42424267 * about the methods available in PPFrame and PPNode.
42434268 *
42444269 * @return The old callback function for this name, if any
@@ -4354,7 +4379,7 @@
43554380 unset( $params[ 'href' ] );
43564381 } else {
43574382 # Non-link <a> tag
4358 - return Xml::openElement( 'a', $params ) . $content . Xml::closeElement( 'a' );
 4383+ return Xml::openElement( 'a', $params ) . $content . Xml::closeElement( 'a' );
43594384 }
43604385
43614386 $sk = $this->mOptions->getSkin();
@@ -4411,7 +4436,7 @@
44124437 if ( count( $matches ) == 0 ) {
44134438 continue;
44144439 }
4415 -
 4440+
44164441 if ( strpos( $matches[0], '%' ) !== false )
44174442 $matches[1] = urldecode( $matches[1] );
44184443 $tp = Title::newFromText( $matches[1]/*, NS_FILE*/ );
@@ -4499,7 +4524,7 @@
45004525 # * upright reduce width for upright images, rounded to full __0 px
45014526 # * border draw a 1px border around the image
45024527 # * alt Text for HTML alt attribute (defaults to empty)
4503 - # * link Set the target of the image link. Can be external, interwiki, or local
 4528+ # * link Set the target of the image link. Can be external, interwiki, or local
45044529 # vertical-align values (no % or length right now):
45054530 # * baseline
45064531 # * sub
@@ -4684,7 +4709,7 @@
46854710
46864711 return $ret;
46874712 }
4688 -
 4713+
46894714 protected function stripAltText( $caption, $holders ) {
46904715 # Strip bad stuff out of the title (tooltip). We can't just use
46914716 # replaceLinkHoldersText() here, because if this function is called
@@ -4700,7 +4725,7 @@
47014726 # remove the tags
47024727 $tooltip = $this->mStripState->unstripBoth( $tooltip );
47034728 $tooltip = Sanitizer::stripAllTags( $tooltip );
4704 -
 4729+
47054730 return $tooltip;
47064731 }
47074732
@@ -5136,7 +5161,7 @@
51375162 $links['interwiki'][] = $this->mLinkHolders->interwiki[$key];
51385163 $pos = $start_pos + strlen( "<!--IWLINK $key-->" );
51395164 }
5140 -
 5165+
51415166 $data['linkholder'] = $links;
51425167
51435168 return $data;
@@ -5145,7 +5170,7 @@
51465171 function unserialiseHalfParsedText( $data, $intPrefix = null /* Unique identifying prefix */ ) {
51475172 if (!$intPrefix)
51485173 $intPrefix = $this->getRandomString();
5149 -
 5174+
51505175 // First, extract the strip state.
51515176 $stripState = $data['stripstate'];
51525177 $this->mStripState->general->merge( $stripState->general );
Index: trunk/phase3/includes/OutputPage.php
@@ -349,7 +349,7 @@
350350 */
351351 public function setPageTitle( $name ) {
352352 global $wgContLang;
353 - $name = $wgContLang->convert( $name, true );
 353+
354354 # change "<script>foo&bar</script>" to "&lt;script&gt;foo&amp;bar&lt;/script&gt;"
355355 # but leave "<i>foobar</i>" alone
356356 $nameWithTags = Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags( $name ) );
@@ -611,10 +611,14 @@
612612 }
613613 }
614614 // Page title
615 - if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
 615+ $dt = $parserOutput->getDisplayTitle();
 616+ $title = $parserOutput->getTitleText();
 617+ if ( $dt !== false ) {
616618 $this->setPageTitle( $dt );
617 - else if ( ( $title = $parserOutput->getTitleText() ) != '' )
 619+ }
 620+ else if ( $title != '' ) {
618621 $this->setPageTitle( $title );
 622+ }
619623
620624 // Hooks registered in the object
621625 global $wgParserOutputHooks;
Index: trunk/phase3/includes/MagicWord.php
@@ -161,6 +161,8 @@
162162 'index',
163163 'noindex',
164164 'staticredirect',
 165+ 'notitleconvert',
 166+ 'nocontentconvert',
165167 );
166168
167169
Index: trunk/phase3/includes/Title.php
@@ -987,6 +987,19 @@
988988 }
989989
990990 /**
 991+ * Is this a conversion table for the LanguageConverter?
 992+ * @return \type{\bool}
 993+ */
 994+ public function isConversionTable() {
 995+ if($this->getNamespace() == NS_MEDIAWIKI
 996+ && strpos( $this->getText(), 'Conversiontable' ) !== false ) {
 997+ return true;
 998+ }
 999+
 1000+ return false;
 1001+ }
 1002+
 1003+ /**
9911004 * Is $wgUser watching this page?
9921005 * @return \type{\bool}
9931006 */
Index: trunk/phase3/languages/LanguageConverter.php
@@ -22,19 +22,14 @@
2323 var $mTablesLoaded = false;
2424 var $mTables;
2525 var $mNamespaceTables;
26 - var $mDoTitleConvert = true, $mDoContentConvert = true;
2726 // 'bidirectional' 'unidirectional' 'disable' for each variant
2827 var $mManualLevel;
29 - var $mTitleFromFlag = false;
3028 var $mCacheKey;
3129 var $mLangObj;
3230 var $mMarkup;
3331 var $mFlags;
3432 var $mDescCodeSep = ':', $mDescVarSep = ';';
3533 var $mUcfirst = false;
36 - var $mTitleOriginal = '';
37 - var $mTitleDisplay = '';
38 - var $mHeaderVariant = null;
3934
4035 const CACHE_VERSION_KEY = 'VERSION 6';
4136
@@ -465,10 +460,6 @@
466461 // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom
467462 // conversion in title
468463 $title = $convRule->getTitle();
469 - if ( $title ) {
470 - $this->mTitleFromFlag = true;
471 - $this->mTitleDisplay = $title;
472 - }
473464
474465 // apply manual conversion table to global table
475466 $convTable = $convRule->getConvTable();
@@ -494,31 +485,6 @@
495486 }
496487
497488 /**
498 - * Convert text using a parser object for context.
499 - * @public
500 - */
501 - function parserConvert( $text, &$parser ) {
502 - global $wgDisableLangConversion;
503 - /* don't do anything if this is the conversion table */
504 - if ( $parser->getTitle()->getNamespace() == NS_MEDIAWIKI
505 - && strpos( $parser->mTitle->getText(),
506 - 'Conversiontable' ) !== false ) {
507 - return $text;
508 - }
509 -
510 - if ( $wgDisableLangConversion ) {
511 - return $text;
512 - }
513 -
514 - $text = $this->convert( $text );
515 -
516 - $this->convertTitle();
517 - $parser->mOutput->setTitleText( $this->mTitleDisplay );
518 -
519 - return $text;
520 - }
521 -
522 - /**
523489 * Convert namespace.
524490 * @param string $title the title included namespace
525491 * @return array of string
@@ -537,37 +503,35 @@
538504 }
539505
540506 /**
541 - * Pre convert title. Store the original title $this->mTitleOrginal;
542 - * store the default converted title to $this->mTitleDisplay.
 507+ * Convert a text fragment.
 508+ *
 509+ * @param string $text text to be converted
 510+ * @param string $plang preferred variant
 511+ * @return string converted text
543512 * @private
544513 */
545 - function preConvertTitle( $text, $variant ) {
546 - $this->mTitleOriginal = $text;
 514+ function convertFragment( $text, $plang ) {
 515+ $marked = explode( $this->mMarkup['begin'], $text, 2 );
 516+ $converted = '';
547517
548 - $text = $this->convertNamespace( $text, $variant );
549 - $this->mTitleDisplay = $this->convert( $text );
550 - }
 518+ if ( $this->mDoContentConvert ) {
 519+ // Bug 19620: should convert a string immediately after a
 520+ // new rule added.
 521+ $converted .= $this->autoConvert( $marked[0], $plang );
 522+ } else {
 523+ $converted .= $marked[0];
 524+ }
551525
552 - /**
553 - * Convert title.
554 - * @private
555 - */
556 - function convertTitle() {
557 - global $wgDisableTitleConversion, $wgUser, $wgRequest;
558 - $isredir = $wgRequest->getText( 'redirect', 'yes' );
559 - $action = $wgRequest->getText( 'action' );
560 - $linkconvert = $wgRequest->getText( 'linkconvert', 'yes' );
561 -
562 - // check for the global variable, __NOTC__ magic word, and user setting
563 - if ( $wgDisableTitleConversion || !$this->mDoTitleConvert ||
564 - $wgUser->getOption( 'noconvertlink' ) == 1 ) {
565 - $this->mTitleDisplay = $this->mTitleOriginal;
566 - } elseif ( $isredir == 'no'
567 - || $action == 'edit'
568 - || $linkconvert == 'no' ) {
569 - // check for GET params
570 - $this->mTitleDisplay = $this->mTitleOriginal;
 526+ if ( array_key_exists( 1, $marked ) ) {
 527+ $crule = new ConverterRule( $marked[1], $this );
 528+ $crule->parse( $plang );
 529+ $converted .= $crule->getDisplay();
 530+ $this->applyManualConv( $crule );
 531+ } else {
 532+ $converted .= $this->mMarkup['end'];
571533 }
 534+
 535+ return $converted;
572536 }
573537
574538 /**
@@ -582,63 +546,27 @@
583547 * -{text}- in which case no conversion should take place for text
584548 *
585549 * @param string $text text to be converted
586 - * @param bool $isTitle whether this conversion is for the article title
587550 * @return string converted text
588551 * @public
589552 */
590 - function convert( $text, $isTitle = false ) {
 553+ function convert( $text ) {
 554+ if ( $wgDisableLangConversion ) return $text;
591555
592 - $mw =& MagicWord::get( 'notitleconvert' );
593 - if ( $mw->matchAndRemove( $text ) ) {
594 - $this->mDoTitleConvert = false;
595 - }
596 - $mw =& MagicWord::get( 'nocontentconvert' );
597 - if ( $mw->matchAndRemove( $text ) ) {
598 - $this->mDoContentConvert = false;
599 - }
600 -
601 - // no conversion if redirecting
602 - $mw =& MagicWord::get( 'redirect' );
603 - if ( $mw->matchStart( $text ) ) {
604 - return $text;
605 - }
606 -
607556 $plang = $this->getPreferredVariant();
608 -
609 - // for title convertion
610 - if ( $isTitle ) {
611 - $this->preConvertTitle( $text, $plang );
612 - return $text;
613 - }
614 -
615557 $tarray = StringUtils::explode( $this->mMarkup['end'], $text );
616 - $text = '';
 558+ $converted = '';
617559
618560 foreach ( $tarray as $txt ) {
619 -
620 - $marked = explode( $this->mMarkup['begin'], $txt, 2 );
621 -
622 - if ( $this->mDoContentConvert ) {
623 - // Bug 19620: should convert a string immediately after a
624 - // new rule added.
625 - $text .= $this->autoConvert( $marked[0], $plang );
626 - } else {
627 - $text .= $marked[0];
628 - }
629 -
630 - if ( array_key_exists( 1, $marked ) ) {
631 - $crule = new ConverterRule( $marked[1], $this );
632 - $crule->parse( $plang );
633 - $text .= $crule->getDisplay();
634 - $this->applyManualConv( $crule );
635 - } else {
636 - $text .= $this->mMarkup['end'];
637 - }
 561+ $converted .= $this->convertFragment( $txt, $plang );
638562 }
639563
640564 // Remove the last delimiter (wasn't real)
641 - $text = substr( $text, 0, - strlen( $this->mMarkup['end'] ) );
642 - return $text;
 565+ $converted = substr( $converted, 0, - strlen( $this->mMarkup['end'] ) );
 566+ if ( $isTitle ) {
 567+ error_log("title2: $converted\n");
 568+ $this->mConvertedTitle = $converted;
 569+ }
 570+ return $converted;
643571 }
644572
645573 /**
@@ -725,15 +653,6 @@
726654 return '!' . $variant ;
727655 }
728656
729 - /**
730 - * Get title text as defined in the body of the article text.
731 - *
732 - * @public
733 - */
734 - function getParsedTitle() {
735 - return $this->mTitleDisplay;
736 - }
737 -
738657 /**
739658 * Load default conversion tables.
740659 * This method must be implemented in derived class.
@@ -1356,15 +1275,15 @@
13571276 // proces H,- flag or T only: output nothing
13581277 $this->mRuleDisplay = '';
13591278 } elseif ( in_array( 'S', $flags ) ) {
1360 - $this->mRuleDisplay = $this->getRuleConvertedStr( $variant,
1361 - $this->mConverter->mDoContentConvert );
 1279+ // true hard-coded now since we shouldn't be called if we're not converting
 1280+ $this->mRuleDisplay = $this->getRuleConvertedStr( $variant, true );
13621281 } else {
13631282 $this->mRuleDisplay = $this->mManualCodeError;
13641283 }
1365 - // proces T flag
 1284+ // process T flag
13661285 if ( in_array( 'T', $flags ) ) {
1367 - $this->mRuleTitle = $this->getRuleConvertedStr( $variant,
1368 - $this->mConverter->mDoTitleConvert );
 1286+ // true hard-coded now since we shouldn't be called if we're not converting
 1287+ $this->mRuleTitle = $this->getRuleConvertedStr( $variant, true );
13691288 }
13701289
13711290 if ( in_array( '-', $flags ) ) {
Index: trunk/phase3/languages/Language.php
@@ -37,7 +37,6 @@
3838 function FakeConverter($langobj) {$this->mLang = $langobj;}
3939 function autoConvertToAllVariants($text) {return $text;}
4040 function convert($t, $i) {return $t;}
41 - function parserConvert($t, $p) {return $t;}
4241 function getVariants() { return array( $this->mLang->getCode() ); }
4342 function getPreferredVariant() {return $this->mLang->getCode(); }
4443 function findVariantLink(&$l, &$n, $ignoreOtherCond = false) {}
@@ -2358,11 +2357,6 @@
23592358 return $this->mConverter->convert($text, $isTitle);
23602359 }
23612360
2362 - # Convert text from within Parser
2363 - function parserConvert( $text, &$parser ) {
2364 - return $this->mConverter->parserConvert( $text, $parser );
2365 - }
2366 -
23672361 # Check if this is a language with variants
23682362 function hasVariants(){
23692363 return sizeof($this->getVariants())>1;
Index: trunk/phase3/languages/classes/LanguageKk.php
@@ -209,16 +209,6 @@
210210 return $carray;
211211 }
212212
213 - // Do not convert content on talk pages
214 - function parserConvert( $text, &$parser ){
215 - if(is_object($parser->getTitle() ) && $parser->getTitle()->isTalkPage())
216 - $this->mDoContentConvert=false;
217 - else
218 - $this->mDoContentConvert=true;
219 -
220 - return parent::parserConvert($text, $parser );
221 - }
222 -
223213 /*
224214 * A function wrapper:
225215 * - if there is no selected variant, leave the link
Index: trunk/phase3/languages/classes/LanguageKu.php
@@ -132,16 +132,6 @@
133133 );
134134 }
135135
136 - // Do not convert content on talk pages
137 - function parserConvert( $text, &$parser ){
138 - if(is_object($parser->getTitle() ) && $parser->getTitle()->isTalkPage())
139 - $this->mDoContentConvert=false;
140 - else
141 - $this->mDoContentConvert=true;
142 -
143 - return parent::parserConvert($text, $parser );
144 - }
145 -
146136 /*
147137 * A function wrapper:
148138 * - if there is no selected variant, leave the link
Index: trunk/phase3/languages/classes/LanguageSr.php
@@ -76,16 +76,6 @@
7777 return $carray;
7878 }
7979
80 - // Do not convert content on talk pages
81 - function parserConvert( $text, &$parser ){
82 - if(is_object($parser->getTitle() ) && $parser->getTitle()->isTalkPage())
83 - $this->mDoContentConvert=false;
84 - else
85 - $this->mDoContentConvert=true;
86 -
87 - return parent::parserConvert($text, $parser );
88 - }
89 -
9080 /*
9181 * A function wrapper:
9282 * - if there is no selected variant, leave the link

Follow-up revisions

RevisionCommit summaryAuthorDate
r60765follow-up r60763 and r58275. Parser tests now pass.mah04:53, 7 January 2010
r60767follow-up r60763 and r58275. Parser tests now pass.mah05:00, 7 January 2010
r60797Fix the undefined variable and undefined property notices caused by r60763.philip18:02, 7 January 2010
r60832follow up r60763...mah08:22, 8 January 2010
r61101follow up r60832 and follow up r60763...mah19:14, 15 January 2010

Comments

#Comment by MarkAHershberger (talk | contribs)   04:25, 7 January 2010

parser test failures, followup coming.

#Comment by PhiLiP (talk | contribs)   17:54, 7 January 2010

Notice: Undefined variable: wgDisableLangConversion in E:\mwnew\languages\LanguageConverter.php on line 547

Notice: Undefined variable: isTitle in E:\mwnew\languages\LanguageConverter.php on line 559

Notice: Undefined variable: wgDisableLangConversion in E:\mwnew\languages\LanguageConverter.php on line 547

Notice: Undefined variable: isTitle in E:\mwnew\languages\LanguageConverter.php on line 559

Notice: Undefined variable: wgDisableLangConversion in E:\mwnew\languages\LanguageConverter.php on line 547

Notice: Undefined variable: isTitle in E:\mwnew\languages\LanguageConverter.php on line 559

Notice: Undefined variable: wgDisableLangConversion in E:\mwnew\languages\LanguageConverter.php on line 547

Notice: Undefined variable: isTitle in E:\mwnew\languages\LanguageConverter.php on line 559

#Comment by PhiLiP (talk | contribs)   17:55, 7 January 2010

More undefined property here:

Notice: Undefined property: ZhConverter::$mHeaderVariant in E:\mwnew\languages\LanguageConverter.php on line 206

#Comment by PhiLiP (talk | contribs)   17:59, 7 January 2010

The T convert rules failed.

I put a -{T|zh-cn:a;zh-tw:b;}- on an article, but the original title still remains.

#Comment by PhiLiP (talk | contribs)   18:03, 7 January 2010

I have fixed the undefined variable and undefined property notices caused by this. But I need to do more test to find out what happens to T convert.

#Comment by Tim Starling (talk | contribs)   23:58, 7 January 2010
-		$parser->mOutput->setTitleText( $this->mTitleDisplay );
-		if ( $title ) {
-			$this->mTitleFromFlag = true;
-			$this->mTitleDisplay =	$title;
-		}

That's what happened to -{T|...}-, it was just removed.

#Comment by Tim Starling (talk | contribs)   05:35, 15 January 2010
+		if ( $this->mDoTitleConvert && !$this->mTitle->isConversionTable()) {
+			$this->setTitle( Title::newFromText( $wgContLang->convert( $title ) ) );
+		}

This is incorrect, you can't set the main context title to some random garbage and expect section edit links and self-link checks and the like to still work. Maybe you're getting confused with ParserOutput::$mTitleText and ParserOutput::$displayTitle, which can be set to things generated by the parser, for later display by OutputPage. The two variables do basically the same thing, by the way, because $displayTitle was introduced by a developer who was apparently unaware of the redundant functionality already existing in LanguageConverter. You should probably merge them.

+		$this->mDoTitleConvert = true;
+		$this->mDoContentConvert = true;
+		if ( !$wgDisableLangConversion ) {
+			if( isset( $this->mDoubleUnderscores['notitleconvert'] ) ){
+				$this->mDoTitleConvert = false;
+			}
+
+			// Don't convert talk pages
+			if( isset( $this->mDoubleUnderscores['nocontentconvert'] )
+				&& !$this->mTitle->isTalkPage() ){
+				$this->mDoContentConvert = false;
+			}
+		}

What's wrong with using $this->mDoubleUnderscores directly, why does it have to go via another member variable? The function of the convert code in Parser::parse() would be easier to understand that way, if less abstract.

 		global $wgContLang;
-		$name = $wgContLang->convert( $name, true );

The "global $wgContLang" should be removed too.

I won't review the convertFragment() change since it was rewritten by philip in r60986.

Status & tagging log