Set up the Title fields directly in Title::makeTitle(), skipping the
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 22 Aug 2004 23:19:12 +0000 (23:19 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 22 Aug 2004 23:19:12 +0000 (23:19 +0000)
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
includes/Title.php

index 5f52b06..dd05902 100644 (file)
@@ -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( '<a href="'.$wgTitle->escapeLocalUrl('ot=php').'">PHP</a> | HTML' );
                        $wgOut->addWikiText( $navText );
                        $navText .= makePhp($messages);
                        $wgOut->addHTML('PHP | <a href="'.$wgTitle->escapeLocalUrl('ot=html').'">HTML</a><pre>'.htmlspecialchars($navText).'</pre>');
                }
-               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 @@
                        <th>Current text</th>
                </tr>";
                
+               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(
                        $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'] );
                        </td></tr>";
                }
                $txt .= "</table>";
+               wfProfileOut( "$fname-output" );
 
+               wfProfileOut( $fname );
                return $txt;
        }
 
index 4028ed6..37873a4 100644 (file)
@@ -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() {