r64876 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64875‎ | r64876 | r64877 >
Date:13:38, 10 April 2010
Author:tstarling
Status:resolved (Comments)
Tags:
Comment:
Proposed cleanup of recent LanguageConverter-related commits:

* Moved the responsibility for calling $wgOut->setPageTitle() from OutputPage::addParserOutputNoText() to the OutputPage/Parser caller. Previously, every call to $wgOut->addWikiText() (or any other message parsing function) was resulting in the title being reset to a converted version of $wgTitle, producing bug 23124. Moving responsibility to the caller seems to work fairly well, since there are apparently only two callers that really want {{DISPLAYTITLE}} etc. to work (EditPage and Article::view).
* Reverted data flow obfuscation in OutputPage::setHTMLTitle() from r64851, replaced by the above. The caller decides what overrides what.
* Reverted inappropriate, cache-polluting references to $wgUser and $wgRequest in Parser::parse(), introduced in r64819.
* Reverted incomprehensible boolean parameter to Language::convert() from r64851, reintroduced Language::convertTitle() instead. Gave it a simpler implementation than before.
* Fixed broken {{DISPLAYTITLE}} feature, was being unconditionally overwritten by the ParserOutput::setTitleText() call in Parser::parse(). Give {{DISPLAYTITLE}} precedence over autoconverted title, like we do for -{T|...}-.
* Tested extensively (perhaps not exhaustively)
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.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)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -303,7 +303,7 @@
304304 * to internalParse() which does all the real work.
305305 */
306306
307 - global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion, $wgUser, $wgRequest;
 307+ global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion;
308308 $fname = __METHOD__.'-' . wfGetCaller();
309309 wfProfileIn( __METHOD__ );
310310 wfProfileIn( $fname );
@@ -377,16 +377,16 @@
378378 */
379379 if ( !( $wgDisableLangConversion
380380 || $wgDisableTitleConversion
381 - || $wgRequest->getText( 'redirect', 'yes' ) == 'no'
382 - || $wgRequest->getText( 'linkconvert', 'yes' ) == 'no'
383381 || isset( $this->mDoubleUnderscores['nocontentconvert'] )
384382 || isset( $this->mDoubleUnderscores['notitleconvert'] )
385 - || $wgUser->getOption( 'noconvertlink' ) == 1 ) ) {
 383+ || $this->mOutput->getDisplayTitle() !== false ) )
 384+ {
386385 $convruletitle = $wgContLang->getConvRuleTitle();
387386 if ( $convruletitle ) {
388387 $this->mOutput->setTitleText( $convruletitle );
389388 } else {
390 - $this->mOutput->setTitleText( $wgContLang->convert( $title->getPrefixedText(), true ) );
 389+ $titleText = $wgContLang->convertTitle( $title );
 390+ $this->mOutput->setTitleText( $titleText );
391391 }
392392 }
393393
Index: trunk/phase3/includes/OutputPage.php
@@ -9,7 +9,7 @@
1010 var $mMetatags = array(), $mKeywords = array(), $mLinktags = array();
1111 var $mExtStyles = array();
1212 var $mPagetitle = '', $mBodytext = '', $mDebugtext = '';
13 - var $mHTMLtitle = '', $mHTMLtitleFromPagetitle = true, $mIsarticle = true, $mPrintable = false;
 13+ var $mHTMLtitle = '', $mIsarticle = true, $mPrintable = false;
1414 var $mSubtitle = '', $mRedirect = '', $mStatusCode;
1515 var $mLastModified = '', $mETag = false;
1616 var $mCategoryLinks = array(), $mCategories = array(), $mLanguageLinks = array();
@@ -447,17 +447,9 @@
448448 /**
449449 * "HTML title" means the contents of <title>.
450450 * It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
451 - * If $name is from page title, it can only override names which are also from page title,
452 - * but if it is not from page title, it can override all other names.
453451 */
454 - public function setHTMLTitle( $name, $frompagetitle = false ) {
455 - if ( $frompagetitle && $this->mHTMLtitleFromPagetitle ) {
456 - $this->mHTMLtitle = $name;
457 - }
458 - elseif ( $this->mHTMLtitleFromPagetitle ) {
459 - $this->mHTMLtitle = $name;
460 - $this->mHTMLtitleFromPagetitle = false;
461 - }
 452+ public function setHTMLTitle( $name ) {
 453+ $this->mHTMLtitle = $name;
462454 }
463455
464456 /**
@@ -1104,11 +1096,6 @@
11051097 $this->mTemplateIds[$ns] = $dbks;
11061098 }
11071099 }
1108 - // Page title
1109 - $title = $parserOutput->getTitleText();
1110 - if ( $title != '' ) {
1111 - $this->setPageTitle( $title );
1112 - }
11131100
11141101 // Hooks registered in the object
11151102 global $wgParserOutputHooks;
Index: trunk/phase3/includes/Article.php
@@ -956,6 +956,12 @@
957957 }
958958 }
959959
 960+ # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
 961+ $titleText = $this->mParserOutput->getTitleText();
 962+ if ( strval( $titleText ) !== '' ) {
 963+ $wgOut->setPageTitle( $titleText );
 964+ }
 965+
960966 # Now that we've filled $this->mParserOutput, we know whether
961967 # there are any __NOINDEX__ tags on the page
962968 $policy = $this->getRobotPolicy( 'view' );
Index: trunk/phase3/languages/LanguageConverter.php
@@ -516,24 +516,6 @@
517517 }
518518
519519 /**
520 - * Convert namespace.
521 - * @param $title String: the title included namespace
522 - * @return Array of string
523 - * @private
524 - */
525 - function convertNamespace( $title, $variant ) {
526 - $splittitle = explode( ':', $title, 2 );
527 - if ( count( $splittitle ) < 2 ) {
528 - return $title;
529 - }
530 - if ( isset( $this->mNamespaceTables[$variant][$splittitle[0]] ) ) {
531 - $splittitle[0] = $this->mNamespaceTables[$variant][$splittitle[0]];
532 - }
533 - $ret = implode( ':', $splittitle );
534 - return $ret;
535 - }
536 -
537 - /**
538520 * Convert text to different variants of a language. The automatic
539521 * conversion is done in autoConvert(). Here we parse the text
540522 * marked with -{}-, which specifies special conversions of the
@@ -547,19 +529,34 @@
548530 * @param $text String: text to be converted
549531 * @return String: converted text
550532 */
551 - public function convert( $text, $istitle = false ) {
 533+ public function convert( $text ) {
552534 global $wgDisableLangConversion;
553535 if ( $wgDisableLangConversion ) return $text;
554536
555537 $variant = $this->getPreferredVariant();
556538
557 - if( $istitle ) {
558 - $text = $this->convertNamespace( $text, $variant );
559 - }
560 -
561539 return $this->recursiveConvertTopLevel( $text, $variant );
562540 }
563541
 542+ /**
 543+ * Convert a Title object to a readable string in the preferred variant
 544+ */
 545+ public function convertTitle( $title ) {
 546+ $variant = $this->getPreferredVariant();
 547+ if ( $title->getNamespace() === NS_MAIN ) {
 548+ $text = '';
 549+ } else {
 550+ $text = $title->getNsText();
 551+ if ( isset( $this->mNamespaceTables[$variant][$text] ) ) {
 552+ $text = $this->mNamespaceTables[$variant][$text];
 553+ }
 554+ $text .= ':';
 555+ }
 556+ $text .= $title->getText();
 557+ $text = $this->autoConvert( $text, $variant );
 558+ return $text;
 559+ }
 560+
564561 protected function recursiveConvertTopLevel( $text, $variant, $depth = 0 ) {
565562 $startPos = 0;
566563 $out = '';
Index: trunk/phase3/languages/Language.php
@@ -36,7 +36,8 @@
3737 var $mLang;
3838 function FakeConverter( $langobj ) { $this->mLang = $langobj; }
3939 function autoConvertToAllVariants( $text ) { return $text; }
40 - function convert( $t, $i ) { return $t; }
 40+ function convert( $t ) { return $t; }
 41+ function convertTitle( $t ) { return $t->getPrefixedText(); }
4142 function getVariants() { return array( $this->mLang->getCode() ); }
4243 function getPreferredVariant() { return $this->mLang->getCode(); }
4344 function getConvRuleTitle() { return false; }
@@ -2606,10 +2607,15 @@
26072608 }
26082609
26092610 # convert text to different variants of a language.
2610 - function convert( $text, $isTitle = false ) {
2611 - return $this->mConverter->convert( $text, $isTitle );
 2611+ function convert( $text ) {
 2612+ return $this->mConverter->convert( $text );
26122613 }
26132614
 2615+ # Convert a Title object to a string in the preferred variant
 2616+ function convertTitle( $title ) {
 2617+ return $this->mConverter->convertTitle( $title );
 2618+ }
 2619+
26142620 # Check if this is a language with variants
26152621 function hasVariants() {
26162622 return sizeof( $this->getVariants() ) > 1;

Follow-up revisions

RevisionCommit summaryAuthorDate
r64892Follow up r64876 setHTMLTitle with boolean parameter left.platonides18:29, 10 April 2010
r64918Fix for issue noted on CR r64876: fatal error on CSS/JS subpage displaytstarling23:52, 10 April 2010
r649291.16wmf4: Merge langconverter fixes from trunk: r64851, r64856, r64876, r6489...catrope12:01, 11 April 2010
r64934Follow up r64876. Try to fix pagetitle-view-mainpage.philip13:04, 11 April 2010
r65393MFT r64876 and followups r64892, r64918, 64934: fix various language converte...tstarling14:51, 21 April 2010
r71485Use the common code at switch end if viewing the current version of a page us...platonides14:13, 23 August 2010
r79785Update comment for r64876tstarling01:38, 7 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r64819Bug 23115: Follow up on r64811. Fix another bug which cause talk page can't c...philip19:02, 9 April 2010
r64851Fix bug 23115 again. Follow up r64821, r64823 and r64827. Rewrite the convert...philip05:46, 10 April 2010

Comments

#Comment by Raymond (talk | contribs)   15:24, 10 April 2010

Seen at translatewiki:

PHP Fatal error: Call to a member function getTitleText() on a non-object in /www/w/includes/Article.php on line 960
#Comment by Liangent (talk | contribs)   12:05, 18 June 2010

This commit introduced a bug (which has appeared on Wikipedia a while):

convertTitle in LanguageConverter.php invokes $title->getNsText() to get namespace 'text', where underscores are used instead of spaces. This causes "isset( $this->mNamespaceTables[$variant][$text]" to fail, and namespace names with underscores are directly output to users.

#Comment by Liangent (talk | contribs)   10:29, 6 July 2010

That part has been rewritten in r69081.

#Comment by MarkAHershberger (talk | contribs)   21:23, 10 December 2010

Above this removed bit:

-				|| $wgRequest->getText( 'redirect', 'yes' ) == 'no'
-				|| $wgRequest->getText( 'linkconvert', 'yes' ) == 'no'

the comments read

/** * A page get its title converted except: ... * c) The page is a redirect page * d) User request with a "linkconvert" set to "no"

Do these two conditions where the title isn't converted still apply?

What relation does this have to LanguageConverter::findVariantLink which is the only other place that I found where these two conditions are checked?

#Comment by MarkAHershberger (talk | contribs)   21:26, 10 December 2010

Meant to use preview on this comment. Sorry if it is difficult to read the part where I quote the comments.

#Comment by MarkAHershberger (talk | contribs)   15:43, 14 December 2010

Marking fixme b/c of the discrepency between the (unchanged) comments and the (changed) code.

#Comment by Tim Starling (talk | contribs)   01:38, 7 January 2011

Should be OK now.

Status & tagging log