From d9b242a14957708b3991d774fb285e2b61245e80 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 22 Aug 2004 23:19:12 +0000 Subject: [PATCH] Set up the Title fields directly in Title::makeTitle(), skipping the secureAndSplit() step. This saves a lot of time and memory when working with titles that are known-good (coming out of the database or other Title objects, for instance). Warning: if you feed invalid input to makeTitle() it will *not* be checked for validity anymore and may do bad things. Don't do that. --- includes/SpecialAllmessages.php | 31 +++++++++++++++++++++++++------ includes/Title.php | 22 +++++++++++++--------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/includes/SpecialAllmessages.php b/includes/SpecialAllmessages.php index 5f52b06fae..dd059028eb 100644 --- a/includes/SpecialAllmessages.php +++ b/includes/SpecialAllmessages.php @@ -3,9 +3,14 @@ function wfSpecialAllmessages() { global $wgOut, $wgAllMessagesEn, $wgRequest, $wgMessageCache, $wgTitle; - $ot = $wgRequest->getText('ot'); + + $fname = "wfSpecialAllMessages"; + wfProfileIn( $fname ); + + wfProfileIn( "$fname-setup"); + $ot = $wgRequest->getText( 'ot' ); $mwMsg =& MagicWord::get( MAG_MSG ); - set_time_limit(0); + $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) ); $first = true; $sortedArray = $wgAllMessagesEn; @@ -17,6 +22,9 @@ $messages[$key]['statmsg'] = wfMsgNoDb( $key ); $messages[$key]['msg'] = wfMsg ( $key ); } + wfProfileOut( "$fname-setup" ); + + wfProfileIn( "$fname-output" ); if ($ot == 'html') { $wgOut->addHTML( 'PHP | HTML' ); $wgOut->addWikiText( $navText ); @@ -25,8 +33,11 @@ $navText .= makePhp($messages); $wgOut->addHTML('PHP | HTML
'.htmlspecialchars($navText).'
'); } - return; + wfProfileOut( "$fname-output" ); + + wfProfileOut( $fname ); } + function makePhp($messages) { global $wgLanguageCode; $txt = "\n\n".'$wgAllMessages'.ucfirst($wgLanguageCode).' = array('."\n"; @@ -53,6 +64,9 @@ function makeHTMLText( $messages ) { global $wgLang, $wgUser; + $fname = "makeHTMLText"; + wfProfileIn( $fname ); + $sk =& $wgUser->getSkin(); $talk = $wgLang->getNsText( NS_TALK ); $mwnspace = $wgLang->getNsText( NS_MEDIAWIKI ); @@ -66,6 +80,7 @@ Current text "; + wfProfileIn( "$fname-check" ); # This is a nasty hack to avoid doing independent existence checks # without sending the links and table through the slow wiki parser. $pageExists = array( @@ -79,11 +94,13 @@ $pageExists[$s->cur_namespace][$s->cur_title] = true; } $dbr->freeResult( $res ); + wfProfileOut( "$fname-check" ); + wfProfileIn( "$fname-output" ); foreach( $messages as $key => $m ) { - $titleObj = Title::makeTitle( NS_MEDIAWIKI, $key ); - $talkPage = Title::makeTitle( NS_MEDIAWIKI_TALK, $key ); - $title = $titleObj->getDBkey(); + $title = $wgLang->ucfirst( $key ); + $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title ); + $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title ); $colorIt = ($m['statmsg'] == $m['msg']) ? " bgcolor=\"#f0f0ff\"" : " bgcolor=\"#ffe2e2\""; $message = htmlspecialchars( $m['statmsg'] ); @@ -113,7 +130,9 @@ "; } $txt .= ""; + wfProfileOut( "$fname-output" ); + wfProfileOut( $fname ); return $txt; } diff --git a/includes/Title.php b/includes/Title.php index 4028ed6cfb..37873a48ac 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -137,15 +137,19 @@ class Title { return $title; } - # From a namespace index and a DB key - /* static */ function makeTitle( $ns, $title ) { - $t = new Title(); - $t->mDbkeyform = Title::makeName( $ns, $title ); - if( $t->secureAndSplit() ) { - return $t; - } else { - return NULL; - } + # From a namespace index and a DB key. + # It's assumed that $ns and $title are *valid*, for instance + # when they came directly from the database. + /* static */ function &makeTitle( $ns, $title ) { + $t =& new Title(); + $t->mInterwiki = ''; + $t->mFragment = ''; + $t->mNamespace = $ns; + $t->mDbkeyform = $title; + $t->mArticleID = ( $ns >= 0 ) ? 0 : -1; + $t->mUrlform = wfUrlencode( $title ); + $t->mTextform = str_replace( '_', ' ', $title ); + return $t; } /* static */ function newMainPage() { -- 2.20.1