r105925 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105924‎ | r105925 | r105926 >
Date:20:09, 12 December 2011
Author:dantman
Status:resolved (Comments)
Tags:
Comment:
Followup r105812:
- Fix case of the wfBCP47 call
- Don't call wfBCP47 for every time getHtmlCode is called
- Add @since
Modified paths:
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/Language.php
@@ -61,6 +61,7 @@
6262
6363 var $mVariants, $mCode, $mLoaded = false;
6464 var $mMagicExtensions = array(), $mMagicHookDone = false;
 65+ private $mHtmlCode = null;
6566
6667 var $mNamespaceIds, $namespaceNames, $namespaceAliases;
6768 var $dateFormatStrings = array();
@@ -3467,9 +3468,13 @@
34683469 /**
34693470 * Get the code in Bcp47 format which we can use
34703471 * inside of html lang="" tags.
 3472+ * @since 1.19
34713473 */
34723474 function getHtmlCode() {
3473 - return wfBcp47( $this->getCode() );
 3475+ if ( is_null( $this->mHtmlCode ) ) {
 3476+ $this->mHtmlCode = wfBCP47( $this->getCode() );
 3477+ }
 3478+ return $this->mHtmlCode;
34743479 }
34753480
34763481 /**
@@ -3477,6 +3482,8 @@
34783483 */
34793484 function setCode( $code ) {
34803485 $this->mCode = $code;
 3486+ // Ensure we don't leave an incorrect html code lying around
 3487+ unset( $this->mHtmlCode );
34813488 }
34823489
34833490 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r106072bug 33035: Followup r105925: set to null rather than unset so we don't get an...brion19:58, 13 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r105812Introduce a Language::getHtmlLang method which returns the Bcp47 formatted la...dantman18:46, 11 December 2011

Comments

#Comment by Raymond (talk | contribs)   10:20, 13 December 2011

PHP Notice: Undefined property: Language::$mHtmlCode in /www/w/languages/Language.php on line 3474

#Comment by Brion VIBBER (talk | contribs)   19:50, 13 December 2011

I don't seem to encounter this error; and the property does seem to be defined...

#Comment by Brion VIBBER (talk | contribs)   20:00, 13 December 2011

Per IRC chat w/ Timo this looks like it happens because of the unset() line in Language::setCode(); so if that gets triggered, you end up with the error if getHtmlCode() is called again later.

r106072 should fix this up; replaced the unset() with just setting to null.

Status & tagging log