From 5e01b49194c47a5f73b43612d08b26e09bd7f7da Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 28 Dec 2008 21:28:40 +0000 Subject: [PATCH] (bug 16497) Cut down on heavy memory usage here --- includes/specials/SpecialAllmessages.php | 85 ++++++++++++++---------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/includes/specials/SpecialAllmessages.php b/includes/specials/SpecialAllmessages.php index c2a8de4ef0..0ff94b493e 100644 --- a/includes/specials/SpecialAllmessages.php +++ b/includes/specials/SpecialAllmessages.php @@ -29,15 +29,19 @@ function wfSpecialAllmessages() { $wgMessageCache->loadAllMessages(); - $sortedArray = array_merge( Language::getMessagesFor( 'en' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) ); + $sortedArray = array_merge( Language::getMessagesFor( 'en' ), + $wgMessageCache->getExtensionMessagesFor( 'en' ) ); ksort( $sortedArray ); - $messages = array(); - foreach ( $sortedArray as $key => $value ) { + $messages = array(); + foreach( $sortedArray as $key => $value ) { $messages[$key]['enmsg'] = $value; - $messages[$key]['statmsg'] = wfMsgReal( $key, array(), false, false, false ); // wfMsgNoDbNoTrans doesn't exist + $messages[$key]['statmsg'] = wfMsgReal( $key, array(), false, false, false ); $messages[$key]['msg'] = wfMsgNoTrans( $key ); + $sortedArray[$key] = NULL; // trade bytes from $sortedArray to this + } + unset($sortedArray); // trade bytes from $sortedArray to this wfProfileOut( __METHOD__ . '-setup' ); @@ -63,13 +67,14 @@ function wfSpecialAllmessages() { wfProfileOut( __METHOD__ ); } -function wfAllMessagesMakeXml( $messages ) { +function wfAllMessagesMakeXml( &$messages ) { global $wgLang; $lang = $wgLang->getCode(); $txt = "\n"; $txt .= "\n"; foreach( $messages as $key => $m ) { $txt .= "\t" . Xml::element( 'message', array( 'name' => $key ), $m['msg'] ) . "\n"; + $messages[$key] = NULL; // trade bytes } $txt .= ""; return $txt; @@ -81,7 +86,7 @@ function wfAllMessagesMakeXml( $messages ) { * @return The PHP messages array. * @todo Make suitable for language files. */ -function wfAllMessagesMakePhp( $messages ) { +function wfAllMessagesMakePhp( &$messages ) { global $wgLang; $txt = "\n\n\$messages = array(\n"; foreach( $messages as $key => $m ) { @@ -94,6 +99,7 @@ function wfAllMessagesMakePhp( $messages ) { $comment = ''; } $txt .= "'$key' => '" . preg_replace( '/(? 'allmessagesmodified()' ), '' ); - $txt = ''; + $txt = ''; $txt .= ' @@ -144,11 +151,14 @@ function wfAllMessagesMakeHTMLText( $messages ) { NS_MEDIAWIKI_TALK => array() ); $dbr = wfGetDB( DB_SLAVE ); - $page = $dbr->tableName( 'page' ); - $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")"; - $res = $dbr->query( $sql ); + $res = $dbr->select( 'page', + array( 'page_namespace', 'page_title' ), + array( 'page_namespace' => array(NS_MEDIAWIKI,NS_MEDIAWIKI_TALK) ), + __METHOD__, + array( 'USE INDEX' => 'name_title' ) + ); while( $s = $dbr->fetchObject( $res ) ) { - $pageExists[$s->page_namespace][$s->page_title] = true; + $pageExists[$s->page_namespace][$s->page_title] = 1; } $dbr->freeResult( $res ); wfProfileOut( __METHOD__ . "-check" ); @@ -163,19 +173,21 @@ function wfAllMessagesMakeHTMLText( $messages ) { $title .= '/' . $wgLang->getCode(); } - $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title ); - $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title ); + $titleObj = Title::makeTitle( NS_MEDIAWIKI, $title ); + $talkPage = Title::makeTitle( NS_MEDIAWIKI_TALK, $title ); $changed = ( $m['statmsg'] != $m['msg'] ); $message = htmlspecialchars( $m['statmsg'] ); $mw = htmlspecialchars( $m['msg'] ); - if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) { - $pageLink = $sk->makeKnownLinkObj( $titleObj, "" . htmlspecialchars( $key ) . '' ); + if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI] ) ) { + $pageLink = $sk->makeKnownLinkObj( $titleObj, "" . + htmlspecialchars( $key ) . '' ); } else { - $pageLink = $sk->makeBrokenLinkObj( $titleObj, "" . htmlspecialchars( $key ) . '' ); + $pageLink = $sk->makeBrokenLinkObj( $titleObj, "" . + htmlspecialchars( $key ) . '' ); } - if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) { + if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI_TALK] ) ) { $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) ); } else { $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) ); @@ -186,27 +198,28 @@ function wfAllMessagesMakeHTMLText( $messages ) { if( $changed ) { $txt .= " - - - - - "; + + + + + "; } else { $txt .= " - - - "; + + + "; } + $messages[$key] = NULL; // trade bytes $i++; } $txt .= '
- $anchor$pageLink
$talkLink -
-$message -
-$mw -
+ $anchor$pageLink
$talkLink +
+ $message +
+ $mw +
- $anchor$pageLink
$talkLink -
-$mw -
+ $anchor$pageLink
$talkLink +
+ $mw +
'; -- 2.20.1