Prevent some unnecessary lstat system calls, generated by include or require directives.
authorNick Jenkins <nickj@users.mediawiki.org>
Fri, 9 Feb 2007 05:36:56 +0000 (05:36 +0000)
committerNick Jenkins <nickj@users.mediawiki.org>
Fri, 9 Feb 2007 05:36:56 +0000 (05:36 +0000)
This can be done either by:
* Using explicit full paths, using the $IP global for the installation directory full path, and then working down the tree from there.
* Using explicit full paths, using the "dirname(__FILE__)" directive to get a full directory path for the includer file.
* Occasionally removing the line altogether, and then for some files the inclusion is handled by the autoloader.

For example, if the "extensions/wikihiero/wh_main.php" file does an include or require on "wh_list.php", then PHP does the following:
* tries to open "wiki/wh_list.php", and fails.
* tries to open "wiki/includes/wh_list.php", and fails.
* tries to open "wiki/languages/wh_list.php", and fails.
* tries to open "wiki/extensions/wikihiero/wh_list.php", and succeeds.

So in this example, the first 3 calls can be prevented if PHP is told where the file is.

Testing Method: On a Linux box, run these commands to attach strace to all the apache2 processes, and log their system calls to a temporary file, then generate some activity, and then stop the strace:
-----------------------------------
rm /tmp/strace-log.txt
strace -tt -o /tmp/strace-log.txt -p `pidof apache2 | sed 's/ / -p /g'` &
php maintenance/fuzz-tester.php --keep-passed-tests --include-binary --max-runtime=3 > /tmp/strace-tests.txt
killall -9 strace
grep "No such file or directory"  /tmp/strace-log.txt | sort -u
-----------------------------------

Any failed file stats will be marked with: "-1 ENOENT (No such file or directory)".

Also:
* Strict Standards: Undefined offset:  230 in includes/normal/UtfNormal.php on line 637
* Strict Standards: iconv() [<a href='function.iconv'>function.iconv</a>]: Detected an illegal character in input string in languages/Language.php on line 776
  [Note: Partial only - despite adding "//IGNORE", it still seems to be possible with some
         messed- up binary input to cause PHP 5.1.2's iconv() function to squeal like a stuck pig].
* Update one $fname variable (method belongs to HistoryBlobStub class).

19 files changed:
includes/AutoLoader.php
includes/GlobalFunctions.php
includes/HistoryBlob.php
includes/SpecialPage.php
includes/SpecialPrefixindex.php
includes/SpecialRecentchanges.php
includes/SpecialUserrights.php
includes/SpecialWatchlist.php
includes/Title.php
includes/normal/UtfNormal.php
languages/Language.php
skins/Chick.deps.php
skins/Chick.php
skins/MySkin.deps.php
skins/MySkin.php
skins/Simple.deps.php
skins/Simple.php
thumb.php
trackback.php

index fb7819c..1365be9 100644 (file)
@@ -313,7 +313,7 @@ function wfLoadAllExtensions() {
        # guaranteed by entering special pages via SpecialPage members such as 
        # executePath(), but here we have to take a more explicit measure.
        
-       require_once( 'SpecialPage.php' );
+       require_once( dirname(__FILE__) . '/SpecialPage.php' );
        
        foreach( $wgAutoloadClasses as $class => $file ) {
                if( !( class_exists( $class ) || interface_exists( $class ) ) ) {
index 9c19758..22237ee 100644 (file)
@@ -18,9 +18,10 @@ $wgTotalViews = -1;
 $wgTotalEdits = -1;
 
 
-require_once( 'LogPage.php' );
-require_once( 'normal/UtfNormalUtil.php' );
-require_once( 'XmlFunctions.php' );
+global $IP;
+require_once "$IP/includes/LogPage.php";
+require_once "$IP/includes/normal/UtfNormalUtil.php";
+require_once "$IP/includes/XmlFunctions.php";
 
 /**
  * Compatibility functions
index 8d54e36..3ce4ffd 100644 (file)
@@ -209,7 +209,7 @@ class HistoryBlobStub {
 
        /** @todo document */
        function getText() {
-               $fname = 'HistoryBlob::getText';
+               $fname = 'HistoryBlobStub::getText';
                global $wgBlobCache;
                if( isset( $wgBlobCache[$this->mOldId] ) ) {
                        $obj = $wgBlobCache[$this->mOldId];
index 5d0955f..c184c06 100644 (file)
@@ -534,7 +534,7 @@ class SpecialPage
                        $this->mFunction = $function;
                }
                if ( $file === 'default' ) {
-                       $this->mFile = "Special{$name}.php";
+                       $this->mFile = dirname(__FILE__) . "/Special{$name}.php";
                } else {
                        $this->mFile = $file;
                }
index 73a67ee..fc14d7a 100644 (file)
@@ -3,8 +3,6 @@
  * @addtogroup SpecialPage
  */
 
-require_once 'SpecialAllpages.php';
-
 /**
  * Entry point : initialise variables and call subfunctions.
  * @param $par String: becomes "FOO" when called like Special:Prefixindex/FOO (default NULL)
index 9ded0af..9844575 100644 (file)
@@ -7,7 +7,7 @@
 /**
  *
  */
-require_once( 'ChangesList.php' );
+require_once( dirname(__FILE__) . '/ChangesList.php' );
 
 /**
  * Constructor
index 6668d0e..30c7945 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 /** */
-require_once('HTMLForm.php');
+require_once( dirname(__FILE__) . '/HTMLForm.php');
 
 /** Entry point */
 function wfSpecialUserrights() {
index 92ee4d6..a9d61c0 100644 (file)
@@ -7,7 +7,7 @@
 /**
  *
  */
-require_once( 'SpecialRecentchanges.php' );
+require_once( dirname(__FILE__) . '/SpecialRecentchanges.php' );
 
 /**
  * Constructor
index cbba219..c40b6e6 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 /** */
-require_once( 'normal/UtfNormal.php' );
+require_once( dirname(__FILE__) . '/normal/UtfNormal.php' );
 
 define ( 'GAID_FOR_UPDATE', 1 );
 
index 7399f18..278c3cc 100644 (file)
@@ -225,7 +225,7 @@ class UtfNormal {
        static function loadData() {
                global $utfCombiningClass;
                if( !isset( $utfCombiningClass ) ) {
-                       require_once( 'UtfNormalData.inc' );
+                       require_once( dirname(__FILE__) . '/UtfNormalData.inc' );
                }
        }
 
@@ -634,7 +634,11 @@ class UtfNormal {
                                }
                                if( isset( $utfCombiningClass[$c] ) ) {
                                        $lastClass = $utfCombiningClass[$c];
-                                       @$combiners[$lastClass] .= $c;
+                                       if( isset( $combiners[$lastClass] ) ) {
+                                               $combiners[$lastClass] .= $c;
+                                       } else {
+                                               $combiners[$lastClass] = $c;
+                                       }
                                        continue;
                                }
                        }
@@ -804,4 +808,4 @@ class UtfNormal {
        }
 }
 
-?>
\ No newline at end of file
+?>
index 7860676..47f169b 100644 (file)
@@ -22,7 +22,7 @@ if( !defined( 'MEDIAWIKI' ) ) {
 
 # Read language names
 global $wgLanguageNames;
-require_once( 'Names.php' );
+require_once( dirname(__FILE__) . '/Names.php' ) ;
 
 global $wgInputEncoding, $wgOutputEncoding;
 
@@ -772,7 +772,7 @@ class Language {
 
        function iconv( $in, $out, $string ) {
                # For most languages, this is a wrapper for iconv
-               return iconv( $in, $out, $string );
+               return iconv( $in, $out . '//IGNORE', $string );
        }
 
        // callback functions for uc(), lc(), ucwords(), ucwordbreaks()
index a178a79..54614c4 100644 (file)
@@ -9,5 +9,5 @@ if ( ! defined( 'MEDIAWIKI' ) )
        die( 1 );
 
 require_once('includes/SkinTemplate.php');
-require_once('MonoBook.php');
+require_once( dirname(__FILE__) . '/MonoBook.php' );
 ?>
index b346007..9721900 100644 (file)
@@ -10,7 +10,7 @@ if( !defined( 'MEDIAWIKI' ) )
        die( -1 );
 
 /** */
-require_once('MonoBook.php');
+require_once( dirname(__FILE__) . '/MonoBook.php' );
 
 /**
  * @todo document
index ba00558..633ab55 100644 (file)
@@ -9,5 +9,5 @@ if ( ! defined( 'MEDIAWIKI' ) )
        die( 1 );
 
 require_once('includes/SkinTemplate.php');
-require_once('MonoBook.php');
+require_once( dirname(__FILE__) . '/MonoBook.php' );
 ?>
index 8abc75b..5331e21 100644 (file)
@@ -10,7 +10,7 @@ if( !defined( 'MEDIAWIKI' ) )
        die( -1 );
 
 /** */
-require_once('MonoBook.php');
+require_once( dirname(__FILE__) . '/MonoBook.php' );
 
 /**
  * @todo document
index 369f6b0..b7f1f5e 100644 (file)
@@ -9,5 +9,5 @@ if ( ! defined( 'MEDIAWIKI' ) )
        die( 1 );
 
 require_once('includes/SkinTemplate.php');
-require_once('MonoBook.php');
+require_once( dirname(__FILE__) . '/MonoBook.php' );
 ?>
index b180e80..a9c0cc5 100644 (file)
@@ -10,7 +10,7 @@ if( !defined( 'MEDIAWIKI' ) )
        die( -1 );
 
 /** */
-require_once('MonoBook.php');
+require_once( dirname(__FILE__) . '/MonoBook.php' );
 
 /**
  * @todo document
index c325d07..cad4a1b 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -8,13 +8,13 @@ define( 'MW_NO_SETUP', 1 );
 require_once( './includes/WebStart.php' );
 wfProfileIn( 'thumb.php' );
 wfProfileIn( 'thumb.php-start' );
-require_once( 'GlobalFunctions.php' );
-require_once( 'ImageFunctions.php' );
+require_once( './includes/GlobalFunctions.php' );
+require_once( './includes/ImageFunctions.php' );
 
 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
 
-require_once( 'Image.php' );
-require_once( 'StreamFile.php' );
+require_once( './includes/Image.php' );
+require_once( './includes/StreamFile.php' );
 
 // Get input parameters
 $fileName = isset( $_REQUEST['f'] ) ? $_REQUEST['f'] : '';
@@ -50,7 +50,7 @@ if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath )
 
 // OK, no valid thumbnail, time to get out the heavy machinery
 wfProfileOut( 'thumb.php-start' );
-require_once( 'Setup.php' );
+require_once( './includes/Setup.php' );
 wfProfileIn( 'thumb.php-render' );
 
 $img = Image::newFromName( $fileName );
index 50a3341..ea3f90f 100644 (file)
@@ -4,8 +4,7 @@
  * @addtogroup SpecialPage
  */
 require_once( './includes/WebStart.php' );
-
-require_once('DatabaseFunctions.php');
+require_once( './includes/DatabaseFunctions.php' );
 
 /**
  *