r19835 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19834‎ | r19835 | r19836 >
Date:05:36, 9 February 2007
Author:nickj
Status:old
Tags:
Comment:
Prevent some unnecessary lstat system calls, generated by include or require directives.

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).
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/HistoryBlob.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPrefixindex.php (modified) (history)
  • /trunk/phase3/includes/SpecialRecentchanges.php (modified) (history)
  • /trunk/phase3/includes/SpecialUserrights.php (modified) (history)
  • /trunk/phase3/includes/SpecialWatchlist.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/normal/UtfNormal.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/skins/Chick.deps.php (modified) (history)
  • /trunk/phase3/skins/Chick.php (modified) (history)
  • /trunk/phase3/skins/MySkin.deps.php (modified) (history)
  • /trunk/phase3/skins/MySkin.php (modified) (history)
  • /trunk/phase3/skins/Simple.deps.php (modified) (history)
  • /trunk/phase3/skins/Simple.php (modified) (history)
  • /trunk/phase3/thumb.php (modified) (history)
  • /trunk/phase3/trackback.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/Simple.php
@@ -10,7 +10,7 @@
1111 die( -1 );
1212
1313 /** */
14 -require_once('MonoBook.php');
 14+require_once( dirname(__FILE__) . '/MonoBook.php' );
1515
1616 /**
1717 * @todo document
Index: trunk/phase3/skins/MySkin.deps.php
@@ -9,5 +9,5 @@
1010 die( 1 );
1111
1212 require_once('includes/SkinTemplate.php');
13 -require_once('MonoBook.php');
 13+require_once( dirname(__FILE__) . '/MonoBook.php' );
1414 ?>
Index: trunk/phase3/skins/MySkin.php
@@ -10,7 +10,7 @@
1111 die( -1 );
1212
1313 /** */
14 -require_once('MonoBook.php');
 14+require_once( dirname(__FILE__) . '/MonoBook.php' );
1515
1616 /**
1717 * @todo document
Index: trunk/phase3/skins/Chick.deps.php
@@ -9,5 +9,5 @@
1010 die( 1 );
1111
1212 require_once('includes/SkinTemplate.php');
13 -require_once('MonoBook.php');
 13+require_once( dirname(__FILE__) . '/MonoBook.php' );
1414 ?>
Index: trunk/phase3/skins/Chick.php
@@ -10,7 +10,7 @@
1111 die( -1 );
1212
1313 /** */
14 -require_once('MonoBook.php');
 14+require_once( dirname(__FILE__) . '/MonoBook.php' );
1515
1616 /**
1717 * @todo document
Index: trunk/phase3/skins/Simple.deps.php
@@ -9,5 +9,5 @@
1010 die( 1 );
1111
1212 require_once('includes/SkinTemplate.php');
13 -require_once('MonoBook.php');
 13+require_once( dirname(__FILE__) . '/MonoBook.php' );
1414 ?>
Index: trunk/phase3/includes/SpecialUserrights.php
@@ -8,7 +8,7 @@
99 */
1010
1111 /** */
12 -require_once('HTMLForm.php');
 12+require_once( dirname(__FILE__) . '/HTMLForm.php');
1313
1414 /** Entry point */
1515 function wfSpecialUserrights() {
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -18,9 +18,10 @@
1919 $wgTotalEdits = -1;
2020
2121
22 -require_once( 'LogPage.php' );
23 -require_once( 'normal/UtfNormalUtil.php' );
24 -require_once( 'XmlFunctions.php' );
 22+global $IP;
 23+require_once "$IP/includes/LogPage.php";
 24+require_once "$IP/includes/normal/UtfNormalUtil.php";
 25+require_once "$IP/includes/XmlFunctions.php";
2526
2627 /**
2728 * Compatibility functions
Index: trunk/phase3/includes/SpecialRecentchanges.php
@@ -7,7 +7,7 @@
88 /**
99 *
1010 */
11 -require_once( 'ChangesList.php' );
 11+require_once( dirname(__FILE__) . '/ChangesList.php' );
1212
1313 /**
1414 * Constructor
Index: trunk/phase3/includes/SpecialWatchlist.php
@@ -7,7 +7,7 @@
88 /**
99 *
1010 */
11 -require_once( 'SpecialRecentchanges.php' );
 11+require_once( dirname(__FILE__) . '/SpecialRecentchanges.php' );
1212
1313 /**
1414 * Constructor
Index: trunk/phase3/includes/AutoLoader.php
@@ -313,7 +313,7 @@
314314 # guaranteed by entering special pages via SpecialPage members such as
315315 # executePath(), but here we have to take a more explicit measure.
316316
317 - require_once( 'SpecialPage.php' );
 317+ require_once( dirname(__FILE__) . '/SpecialPage.php' );
318318
319319 foreach( $wgAutoloadClasses as $class => $file ) {
320320 if( !( class_exists( $class ) || interface_exists( $class ) ) ) {
Index: trunk/phase3/includes/Title.php
@@ -5,7 +5,7 @@
66 */
77
88 /** */
9 -require_once( 'normal/UtfNormal.php' );
 9+require_once( dirname(__FILE__) . '/normal/UtfNormal.php' );
1010
1111 define ( 'GAID_FOR_UPDATE', 1 );
1212
Index: trunk/phase3/includes/SpecialPrefixindex.php
@@ -3,8 +3,6 @@
44 * @addtogroup SpecialPage
55 */
66
7 -require_once 'SpecialAllpages.php';
8 -
97 /**
108 * Entry point : initialise variables and call subfunctions.
119 * @param $par String: becomes "FOO" when called like Special:Prefixindex/FOO (default NULL)
Index: trunk/phase3/includes/SpecialPage.php
@@ -534,7 +534,7 @@
535535 $this->mFunction = $function;
536536 }
537537 if ( $file === 'default' ) {
538 - $this->mFile = "Special{$name}.php";
 538+ $this->mFile = dirname(__FILE__) . "/Special{$name}.php";
539539 } else {
540540 $this->mFile = $file;
541541 }
Index: trunk/phase3/includes/HistoryBlob.php
@@ -209,7 +209,7 @@
210210
211211 /** @todo document */
212212 function getText() {
213 - $fname = 'HistoryBlob::getText';
 213+ $fname = 'HistoryBlobStub::getText';
214214 global $wgBlobCache;
215215 if( isset( $wgBlobCache[$this->mOldId] ) ) {
216216 $obj = $wgBlobCache[$this->mOldId];
Index: trunk/phase3/includes/normal/UtfNormal.php
@@ -225,7 +225,7 @@
226226 static function loadData() {
227227 global $utfCombiningClass;
228228 if( !isset( $utfCombiningClass ) ) {
229 - require_once( 'UtfNormalData.inc' );
 229+ require_once( dirname(__FILE__) . '/UtfNormalData.inc' );
230230 }
231231 }
232232
@@ -634,7 +634,11 @@
635635 }
636636 if( isset( $utfCombiningClass[$c] ) ) {
637637 $lastClass = $utfCombiningClass[$c];
638 - @$combiners[$lastClass] .= $c;
 638+ if( isset( $combiners[$lastClass] ) ) {
 639+ $combiners[$lastClass] .= $c;
 640+ } else {
 641+ $combiners[$lastClass] = $c;
 642+ }
639643 continue;
640644 }
641645 }
@@ -804,4 +808,4 @@
805809 }
806810 }
807811
808 -?>
\ No newline at end of file
 812+?>
Index: trunk/phase3/trackback.php
@@ -4,9 +4,8 @@
55 * @addtogroup SpecialPage
66 */
77 require_once( './includes/WebStart.php' );
 8+require_once( './includes/DatabaseFunctions.php' );
89
9 -require_once('DatabaseFunctions.php');
10 -
1110 /**
1211 *
1312 */
Index: trunk/phase3/thumb.php
@@ -8,13 +8,13 @@
99 require_once( './includes/WebStart.php' );
1010 wfProfileIn( 'thumb.php' );
1111 wfProfileIn( 'thumb.php-start' );
12 -require_once( 'GlobalFunctions.php' );
13 -require_once( 'ImageFunctions.php' );
 12+require_once( './includes/GlobalFunctions.php' );
 13+require_once( './includes/ImageFunctions.php' );
1414
1515 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
1616
17 -require_once( 'Image.php' );
18 -require_once( 'StreamFile.php' );
 17+require_once( './includes/Image.php' );
 18+require_once( './includes/StreamFile.php' );
1919
2020 // Get input parameters
2121 $fileName = isset( $_REQUEST['f'] ) ? $_REQUEST['f'] : '';
@@ -50,7 +50,7 @@
5151
5252 // OK, no valid thumbnail, time to get out the heavy machinery
5353 wfProfileOut( 'thumb.php-start' );
54 -require_once( 'Setup.php' );
 54+require_once( './includes/Setup.php' );
5555 wfProfileIn( 'thumb.php-render' );
5656
5757 $img = Image::newFromName( $fileName );
Index: trunk/phase3/languages/Language.php
@@ -22,7 +22,7 @@
2323
2424 # Read language names
2525 global $wgLanguageNames;
26 -require_once( 'Names.php' );
 26+require_once( dirname(__FILE__) . '/Names.php' ) ;
2727
2828 global $wgInputEncoding, $wgOutputEncoding;
2929
@@ -772,7 +772,7 @@
773773
774774 function iconv( $in, $out, $string ) {
775775 # For most languages, this is a wrapper for iconv
776 - return iconv( $in, $out, $string );
 776+ return iconv( $in, $out . '//IGNORE', $string );
777777 }
778778
779779 // callback functions for uc(), lc(), ucwords(), ucwordbreaks()

Follow-up revisions

RevisionCommit summaryAuthorDate
r19838As per r19835, but for a few extensions (prevent some unnecessary lstat...nickj05:55, 9 February 2007
r20523Removed //IGNORE suffix in call to Language::iconv, redundant (generates warn...tstarling13:04, 16 March 2007