More unitialized variable cleanup && 'pure' register_globals cleanup...
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 8 Mar 2004 02:50:04 +0000 (02:50 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 8 Mar 2004 02:50:04 +0000 (02:50 +0000)
Added wfDebugDieBacktrace() function to help in pinpointing problems by
showing a function call backtrace along with a friendly die message.

includes/GlobalFunctions.php
includes/Parser.php
includes/Skin.php
includes/Title.php
index.php

index 8322905..3fdba5e 100644 (file)
@@ -353,8 +353,13 @@ function wfSpecialPage()
        $wgOut->setArticleRelated( false );
        $wgOut->setRobotpolicy( "noindex,follow" );
 
-       $par = NULL;
-       list($t, $par) = split( "/", $wgTitle->getDBkey(), 2 );
+       $bits = split( "/", $wgTitle->getDBkey(), 2 );
+       $t = $bits[0];
+       if( empty( $bits[1] ) ) {
+               $par = NULL;
+       } else {
+               $par = $bits[1];
+       }
 
        if ( array_key_exists( $t, $validSP ) ||
          ( $wgUser->isSysop() && array_key_exists( $t, $sysopSP ) ) ||
@@ -410,6 +415,19 @@ function wfAbruptExit(){
        exit();
 }
 
+function wfDebugDieBacktrace( $msg = "" ) {
+       $msg .= "\n<p>Backtrace:</p>\n<ul>\n";
+       $backtrace = debug_backtrace();
+       foreach( $backtrace as $call ) {
+               $f = split( DIRECTORY_SEPARATOR, $call['file'] );
+               $file = $f[count($f)-1];
+               $msg .= "<li>" . $file . " line " . $call['line'] . ", in ";
+               if( !empty( $call['class'] ) ) $msg .= $call['class'] . "::";
+               $msg .= $call['function'] . "()</li>\n";
+       }
+       die( $msg );
+}
+
 function wfNumberOfArticles()
 {
        global $wgNumberOfArticles;
@@ -672,7 +690,11 @@ function wfClientAcceptsGzip() {
 function wfCheckLimits( $deflimit = 50, $optionname = "rclimit" ) {
        global $wgUser;
        
-       $limit = (int)$_REQUEST['limit'];
+       if( isset( $_REQUEST['limit'] ) ) {
+               $limit = IntVal( $_REQUEST['limit'] );
+       } else {
+               $limit = 0;
+       }
        if( $limit < 0 ) $limit = 0;
        if( ( $limit == 0 ) && ( $optionname != "" ) ) {
                $limit = (int)$wgUser->getOption( $optionname );
@@ -680,8 +702,11 @@ function wfCheckLimits( $deflimit = 50, $optionname = "rclimit" ) {
        if( $limit <= 0 ) $limit = $deflimit;
        if( $limit > 5000 ) $limit = 5000; # We have *some* limits...
        
-       $offset = (int)$_REQUEST['offset'];
-       $offset = (int)$offset;
+       if( isset( $_REQUEST['offset'] ) ) {
+               $offset = IntVal( $_REQUEST['offset'] );
+       } else {
+               $offset = 0;
+       }
        if( $offset < 0 ) $offset = 0;
        if( $offset > 65000 ) $offset = 65000; # do we need a max? what?
        
index 8d4db95..df1a928 100644 (file)
@@ -21,6 +21,7 @@ class Parser
 {
        # Cleared with clearState():
        var $mOutput, $mAutonumber, $mLastSection, $mDTopen, $mStripState;
+       var $mContainsOldMagic = 0;
 
        # Temporary:
        var $mOptions, $mTitle;
@@ -621,11 +622,17 @@ class Parser
                                                $lastToken = array_pop( $tokenStack );
                                                while ( $lastToken["type"] != "[[" )
                                                {
-                                                       $linkText = $lastToken["text"] . $linkText;
+                                                       if( !empty( $lastToken["text"] ) ) {
+                                                               $linkText = $lastToken["text"] . $linkText;
+                                                       }
                                                        $lastToken = array_pop( $tokenStack );
                                                }
                                                $txt = $linkText ."]]";
-                                               $prefix = $lastToken["text"];
+                                               if( isset( $lastToken["text"] ) ) {
+                                                       $prefix = $lastToken["text"];
+                                               } else {
+                                                       $prefix = "";
+                                               }
                                                $nextToken = $tokenizer->previewToken();
                                                if ( $nextToken["type"] == "text" ) 
                                                {
@@ -741,7 +748,8 @@ class Parser
                $nottalk = !Namespace::isTalk( $this->mTitle->getNamespace() );
 
                wfProfileOut( "$fname-setup" );
-
+               $s = "";
+               
                if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
                        $text = $m[2];
                        $trail = $m[3];                         
@@ -1206,6 +1214,10 @@ class Parser
 
                # Ugh .. the TOC should have neat indentation levels which can be
                # passed to the skin functions. These are determined here
+               $toclevel = 0;
+               $toc = "";
+               $full = "";
+               $head = array();
                foreach($matches[3] as $headline) {
                        if($level) { $prevlevel=$level;}
                        $level=$matches[1][$c];
@@ -1257,7 +1269,6 @@ class Parser
                        }
                        
                        // Create the anchor for linking from the TOC to the section
-                       
                        $anchor=$canonized_headline;
                        if($refcount[$c]>1) {$anchor.="_".$refcount[$c];}
                        if($st) {
@@ -1309,7 +1320,9 @@ class Parser
                                $full="<a name=\"top\"></a>".$full.$toc;
                        }
 
-                       $full.=$head[$i];
+                       if( !empty( $head[$i] ) ) {
+                               $full .= $head[$i];
+                       }
                        $i++;
                }
                
@@ -1348,10 +1361,10 @@ class Parser
                        $num = str_replace( " ", "", $num );
                
                        if ( "" == $num ) {
-                               $text .= "ISBN $blank$x";
+                               $text = "ISBN $blank$x";
                        } else {
                                $titleObj = Title::makeTitle( NS_SPECIAL, "Booksources" );
-                               $text .= "<a href=\"" .
+                               $text = "<a href=\"" .
                                $titleObj->escapeLocalUrl( "isbn={$num}" ) .
                                        "\" class=\"internal\">ISBN $isbn</a>";
                                $text .= $x;
index fc80640..36752f5 100644 (file)
@@ -1896,7 +1896,7 @@ class Skin {
                        if ( $rc_type == RC_LOG ) {
                                $link = $rcObj->timestamp ;
                        } else {
-                               $link = $this->makeKnownLink( $rcObj->getTitle(), $rcObj->timestamp , "{$curIdEq}&$o" ) ;
+                               $link = $this->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp , "{$curIdEq}&$o" ) ;
                        }
                        $link = "<tt>{$link}</tt>" ;
 
@@ -1924,16 +1924,16 @@ class Skin {
        {
                global $wgUploadPath ;
                if ( count ( $this->rc_cache ) == 0 ) return "" ;
-               #$k = array_keys ( $this->rc_cache ) ;
+               $blockOut = "";
                foreach ( $this->rc_cache AS $secureName => $block ) {
                        if ( count ( $block ) < 2 ) {
-                               $r .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ;
+                               $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ;
                        } else {
-                               $r .= $this->recentChangesBlockGroup ( $block ) ;
+                               $blockOut .= $this->recentChangesBlockGroup ( $block ) ;
                        }
                }
 
-               return "<div align=left>{$r}</div>" ;
+               return "<div align=left>{$blockOut}</div>" ;
        }
 
        # Called in a loop over all displayed RC entries
@@ -2145,7 +2145,7 @@ class Skin {
                $secureName = $title->getPrefixedDBkey();
                if ( $rc_type == RC_MOVE ) {
                        # Use an @ character to prevent collision with page names
-                       $this->rc_cache["@@" . ($rcMoveIndex++)] = array($rc);
+                       $this->rc_cache["@@" . ($this->rcMoveIndex++)] = array($rc);
                } else {
                        if ( !isset ( $this->rc_cache[$secureName] ) ) $this->rc_cache[$secureName] = array() ;
                        array_push ( $this->rc_cache[$secureName] , $rc ) ;
index 62bc12d..2ab5a89 100644 (file)
@@ -66,6 +66,9 @@ class Title {
                        }
                }
 
+               if( is_object( $text ) ) {
+                       wfDebugDieBacktrace( "Called with object instead of string." );
+               }
                $text = strtr( $text, $trans );
                
                $text = wfMungeToUtf8( $text );
index 6fb8197..45c8bc6 100644 (file)
--- a/index.php
+++ b/index.php
@@ -42,7 +42,7 @@ if( defined('DEBUG_GLOBALS') ) {
 unset( $IP );
 ini_set( "allow_url_fopen", 0 ); # For security...
 if(!file_exists("LocalSettings.php")) {
-       die( "You'll have to <a href='$wgScriptPath/config/index.php'>set the wiki up</a> first!" );
+       die( "You'll have to <a href='config/index.php'>set the wiki up</a> first!" );
 }
 include_once( "./LocalSettings.php" );
 
@@ -60,15 +60,18 @@ wfProfileIn( "main-misc-setup" );
 OutputPage::setEncodings(); # Not really used yet
 
 # Query string fields
-#
-#global $action, $title, $search, $go, $target, $printable;
-#global $returnto, $diff, $oldid, $curid;
+if( empty( $_REQUEST['action'] ) ) {
+       $action = "view";
+} else {
+       $action = $_REQUEST['action'];
+}
 
-$action = $_REQUEST['action'];
 if( isset( $_SERVER['PATH_INFO'] ) ) {
        $title = substr( $_SERVER['PATH_INFO'], 1 );
-} else {
+} elseif( !empty( $_REQUEST['title'] ) ) {
        $title = $_REQUEST['title'];
+} else {
+       $title = "";
 }
 
 # Placeholders in case of DB error