r107542 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107541‎ | r107542 | r107543 >
Date:23:12, 28 December 2011
Author:krinkle
Status:reverted
Tags:
Comment:
[Toolserver Intuition] Address memory usage problem for preferences page
* On the preferences page, all text domains are loaded
* We only do that because we need to know all used language codes
* Adding a way to only load langCodes instead of looping through and calling setMsgs() which then does something for each message in each language etc. etc.
* wolfsbane php-cgi[24695]: [ID 702911 user.notice] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 89 bytes) in /home/project/i/n/t/intuition/ToolserverI18N/TsIntuition.php on line 787"
Modified paths:
  • /trunk/tools/ToolserverI18N/TsIntuition.php (modified) (history)

Diff [purge]

Index: trunk/tools/ToolserverI18N/TsIntuition.php
@@ -645,9 +645,11 @@
646646 * Load a textdomain (if not loaded already).
647647 *
648648 * @param $domain string Name of the textdomain (case-insensitive)
 649+ * @param $msgAction string What to do with the messages from the text domain
 650+ * one of 'register', 'ignore'.
649651 * @return False on error, (normalized) domainname if success.
650652 */
651 - public function loadTextdomain( $domain ) {
 653+ public function loadTextdomain( $domain, $msgAction = 'register' ) {
652654
653655 // Generally validate input and protect against path traversal
654656 if ( !TsIntuitionUtil::nonEmptyStr( $domain ) || strcspn( $domain, ":/\\\000" ) !== strlen( $domain ) ) {
@@ -676,7 +678,7 @@
677679 }
678680
679681 // Load it
680 - $load = $this->loadTextdomainFromFile( $path, $domain );
 682+ $load = $this->loadTextdomainFromFile( $path, $domain, $msgAction );
681683
682684 // Return (normalized) domainname or false
683685 return !!$load ? $domain : false;
@@ -686,7 +688,7 @@
687689 /**
688690 * @DOCME:
689691 */
690 - public function loadTextdomainFromFile( $filePath = '', $domain = '' ) {
 692+ public function loadTextdomainFromFile( $filePath = '', $domain = '', $msgAction = 'register' ) {
691693 if ( !TsIntuitionUtil::nonEmptyStrs( $filePath, $domain ) ) {
692694 $this->errTrigger( 'One or more arguments are missing', __METHOD__, E_NOTICE, __FILE__, __LINE__ );
693695 return false;
@@ -702,14 +704,14 @@
703705
704706 // Parse it
705707 $compact = compact( $this->includeVariables );
706 - $this->parseTextdomain( $compact, $domain, $filePath );
 708+ $this->parseTextdomain( $compact, $domain, $filePath, $msgAction );
707709 return true;
708710 }
709711
710712 /**
711713 * @DOCME:
712714 */
713 - private function parseTextdomain( $data, $domain, $filePath ) {
 715+ private function parseTextdomain( $data, $domain, $filePath, $msgAction ) {
714716 if ( !is_array( $data ) ) {
715717 $this->errTrigger( 'Invalid $data passed to ' . __FUNCTION__,
716718 __METHOD__, E_ERROR, __FILE__, __LINE__ );
@@ -721,13 +723,19 @@
722724 }
723725 unset( $data['messages']['qqq'] ); // Workaround
724726
725 - // Load the message into the blob
726 - // overwrites the existing array of messages if it already existed
727 - // If you need to add or overwrite some messages temporarily,
728 - // use Itui::setMsg() or Itui::setMsgs() instead
729 - foreach ( $data['messages'] as $langcode => $messages ) {
730 - $this->availableLanguages[$langcode] = true;
731 - $this->setMsgs( (array)$messages, $domain, $langcode );
 727+ if ( $msgAction === 'register' ) {
 728+ // Load the message into the blob
 729+ // overwrites the existing array of messages if it already existed
 730+ // If you need to add or overwrite some messages temporarily,
 731+ // use Itui::setMsg() or Itui::setMsgs() instead
 732+ foreach ( $data['messages'] as $langCode => $messages ) {
 733+ $this->availableLanguages[$langCode] = true;
 734+ $this->setMsgs( (array)$messages, $domain, $langCode );
 735+ }
 736+ } else {
 737+ foreach ( array_keys( $data['messages'] ) as $langCode ) {
 738+ $this->availableLanguages[$langCode] = true;
 739+ }
732740 }
733741
734742 // Was there a url defined in the textdomain file ?

Sign-offs

UserFlagDate
Platonidesinspected23:22, 28 December 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r107543[Toolserver Intuition] Address memory usage problem for preferences page...krinkle23:14, 28 December 2011
r107548[Toolserver Intuition] Revert r107542, 107543...krinkle23:52, 28 December 2011

Status & tagging log