r45141 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45140‎ | r45141 | r45142 >
Date:21:28, 28 December 2008
Author:aaron
Status:ok (Comments)
Tags:
Comment:
(bug 16497) Cut down on heavy memory usage here
Modified paths:
  • /trunk/phase3/includes/specials/SpecialAllmessages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialAllmessages.php
@@ -29,15 +29,19 @@
3030
3131 $wgMessageCache->loadAllMessages();
3232
33 - $sortedArray = array_merge( Language::getMessagesFor( 'en' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) );
 33+ $sortedArray = array_merge( Language::getMessagesFor( 'en' ),
 34+ $wgMessageCache->getExtensionMessagesFor( 'en' ) );
3435 ksort( $sortedArray );
 36+
3537 $messages = array();
36 -
37 - foreach ( $sortedArray as $key => $value ) {
 38+ foreach( $sortedArray as $key => $value ) {
3839 $messages[$key]['enmsg'] = $value;
39 - $messages[$key]['statmsg'] = wfMsgReal( $key, array(), false, false, false ); // wfMsgNoDbNoTrans doesn't exist
 40+ $messages[$key]['statmsg'] = wfMsgReal( $key, array(), false, false, false );
4041 $messages[$key]['msg'] = wfMsgNoTrans( $key );
 42+ $sortedArray[$key] = NULL; // trade bytes from $sortedArray to this
 43+
4144 }
 45+ unset($sortedArray); // trade bytes from $sortedArray to this
4246
4347 wfProfileOut( __METHOD__ . '-setup' );
4448
@@ -63,13 +67,14 @@
6468 wfProfileOut( __METHOD__ );
6569 }
6670
67 -function wfAllMessagesMakeXml( $messages ) {
 71+function wfAllMessagesMakeXml( &$messages ) {
6872 global $wgLang;
6973 $lang = $wgLang->getCode();
7074 $txt = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
7175 $txt .= "<messages lang=\"$lang\">\n";
7276 foreach( $messages as $key => $m ) {
7377 $txt .= "\t" . Xml::element( 'message', array( 'name' => $key ), $m['msg'] ) . "\n";
 78+ $messages[$key] = NULL; // trade bytes
7479 }
7580 $txt .= "</messages>";
7681 return $txt;
@@ -81,7 +86,7 @@
8287 * @return The PHP messages array.
8388 * @todo Make suitable for language files.
8489 */
85 -function wfAllMessagesMakePhp( $messages ) {
 90+function wfAllMessagesMakePhp( &$messages ) {
8691 global $wgLang;
8792 $txt = "\n\n\$messages = array(\n";
8893 foreach( $messages as $key => $m ) {
@@ -94,6 +99,7 @@
95100 $comment = '';
96101 }
97102 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
 103+ $messages[$key] = NULL; // trade bytes
98104 }
99105 $txt .= ');';
100106 return $txt;
@@ -104,7 +110,7 @@
105111 * @param $messages Messages array.
106112 * @return The HTML list of messages.
107113 */
108 -function wfAllMessagesMakeHTMLText( $messages ) {
 114+function wfAllMessagesMakeHTMLText( &$messages ) {
109115 global $wgLang, $wgContLang, $wgUser;
110116 wfProfileIn( __METHOD__ );
111117
@@ -123,7 +129,8 @@
124130 'onclick' => 'allmessagesmodified()'
125131 ), '' );
126132
127 - $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) . " {$input}{$checkbox} " . '</span>';
 133+ $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) .
 134+ " {$input}{$checkbox} " . '</span>';
128135
129136 $txt .= '
130137 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
@@ -144,11 +151,14 @@
145152 NS_MEDIAWIKI_TALK => array()
146153 );
147154 $dbr = wfGetDB( DB_SLAVE );
148 - $page = $dbr->tableName( 'page' );
149 - $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
150 - $res = $dbr->query( $sql );
 155+ $res = $dbr->select( 'page',
 156+ array( 'page_namespace', 'page_title' ),
 157+ array( 'page_namespace' => array(NS_MEDIAWIKI,NS_MEDIAWIKI_TALK) ),
 158+ __METHOD__,
 159+ array( 'USE INDEX' => 'name_title' )
 160+ );
151161 while( $s = $dbr->fetchObject( $res ) ) {
152 - $pageExists[$s->page_namespace][$s->page_title] = true;
 162+ $pageExists[$s->page_namespace][$s->page_title] = 1;
153163 }
154164 $dbr->freeResult( $res );
155165 wfProfileOut( __METHOD__ . "-check" );
@@ -163,19 +173,21 @@
164174 $title .= '/' . $wgLang->getCode();
165175 }
166176
167 - $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
168 - $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
 177+ $titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
 178+ $talkPage = Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
169179
170180 $changed = ( $m['statmsg'] != $m['msg'] );
171181 $message = htmlspecialchars( $m['statmsg'] );
172182 $mw = htmlspecialchars( $m['msg'] );
173183
174 - if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
175 - $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
 184+ if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI] ) ) {
 185+ $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .
 186+ htmlspecialchars( $key ) . '</span>' );
176187 } else {
177 - $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
 188+ $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .
 189+ htmlspecialchars( $key ) . '</span>' );
178190 }
179 - if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
 191+ if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI_TALK] ) ) {
180192 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
181193 } else {
182194 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
@@ -186,27 +198,28 @@
187199
188200 if( $changed ) {
189201 $txt .= "
190 - <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
191 - <td rowspan=\"2\">
192 - $anchor$pageLink<br />$talkLink
193 - </td><td>
194 -$message
195 - </td>
196 - </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
197 - <td>
198 -$mw
199 - </td>
200 - </tr>";
 202+ <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
 203+ <td rowspan=\"2\">
 204+ $anchor$pageLink<br />$talkLink
 205+ </td><td>
 206+ $message
 207+ </td>
 208+ </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
 209+ <td>
 210+ $mw
 211+ </td>
 212+ </tr>";
201213 } else {
202214 $txt .= "
203 - <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
204 - <td>
205 - $anchor$pageLink<br />$talkLink
206 - </td><td>
207 -$mw
208 - </td>
209 - </tr>";
 215+ <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
 216+ <td>
 217+ $anchor$pageLink<br />$talkLink
 218+ </td><td>
 219+ $mw
 220+ </td>
 221+ </tr>";
210222 }
 223+ $messages[$key] = NULL; // trade bytes
211224 $i++;
212225 }
213226 $txt .= '</table>';

Follow-up revisions

RevisionCommit summaryAuthorDate
r53286(bug 16497) Paginate Special:AllMessagesdemon02:03, 15 July 2009

Comments

#Comment by Brion VIBBER (talk | contribs)   20:12, 31 December 2008

This has very little effect on my installation; with this change the minimum memory_limit needed to render Special:Allmessages only goes down from 44M to 42M.

#Comment by Brion VIBBER (talk | contribs)   20:26, 31 December 2008

I've added some further notes on bug 16497.

Status & tagging log