Merge "Don't cast SpecialPageFactory::$list to an object"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 10 Sep 2014 20:22:42 +0000 (20:22 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 10 Sep 2014 20:22:42 +0000 (20:22 +0000)
includes/WebStart.php
includes/api/ApiQueryAllUsers.php
includes/parser/ParserOutput.php
includes/profiler/Profiler.php
tests/phpunit/includes/TitleTest.php

index e137628..2ae72dc 100644 (file)
@@ -40,8 +40,6 @@ if ( ini_get( 'register_globals' ) ) {
 header( 'X-Content-Type-Options: nosniff' );
 
 $wgRequestTime = microtime( true );
-# getrusage() does not exist on the Microsoft Windows platforms, catching this
-$wgRUstart = function_exists( 'getrusage' ) ? getrusage() : array();
 unset( $IP );
 
 # Valid web server entry point, enable includes.
@@ -60,11 +58,12 @@ if ( $IP === false ) {
        $IP = realpath( '.' ) ?: dirname( __DIR__ );
 }
 
-# Start the autoloader, so that extensions can derive classes from core files
-require_once "$IP/includes/AutoLoader.php";
-
 # Load the profiler
 require_once "$IP/includes/profiler/Profiler.php";
+$wgRUstart = wfGetRusage() ?: array();
+
+# Start the autoloader, so that extensions can derive classes from core files
+require_once "$IP/includes/AutoLoader.php";
 
 # Load up some global defines.
 require_once "$IP/includes/Defines.php";
index dfef286..63990aa 100644 (file)
@@ -156,7 +156,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
 
                        $this->addTables( 'user_groups', 'ug2' );
                        $this->addJoinConds( array( 'ug2' => array( 'LEFT JOIN', 'ug2.ug_user=user_id' ) ) );
-                       $this->addFields( 'ug2.ug_group ug_group2' );
+                       $this->addFields( array( 'ug_group2' => 'ug2.ug_group' ) );
                } else {
                        $sqlLimit = $limit + 1;
                }
index ea9f264..5037ce1 100644 (file)
@@ -733,10 +733,12 @@ class ParserOutput extends CacheTime {
                if ( !$clock || $clock === 'wall' ) {
                        $ret['wall'] = microtime( true );
                }
-               if ( ( !$clock || $clock === 'cpu' ) && function_exists( 'getrusage' ) ) {
-                       $ru = getrusage();
-                       $ret['cpu'] = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
-                       $ret['cpu'] += $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1e6;
+               if ( !$clock || $clock === 'cpu' ) {
+                       $ru = wfGetRusage();
+                       if ( $ru ) {
+                               $ret['cpu'] = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
+                               $ret['cpu'] += $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1e6;
+                       }
                }
                return $ret;
        }
index 7b8f340..418b5d4 100644 (file)
  * @file
  * @ingroup Profiler
  * @defgroup Profiler Profiler
- * This file is only included if profiling is enabled
  */
 
+/**
+ * Get system resource usage of current request context.
+ * Invokes the getrusage(2) system call, requesting RUSAGE_SELF if on PHP5
+ * or RUSAGE_THREAD if on HHVM. Returns false if getrusage is not available.
+ *
+ * @since 1.24
+ * @return array|bool Resource usage data or false if no data available.
+ */
+function wfGetRusage() {
+       if ( !function_exists( 'getrusage' ) ) {
+               return false;
+       } elseif ( defined ( 'HHVM_VERSION' ) ) {
+               return getrusage( 2 /* RUSAGE_THREAD */ );
+       } else {
+               return getrusage( 0 /* RUSAGE_SELF */ );
+       }
+}
+
 /**
  * Begin profiling of a function
  * @param string $functionname Name of the function we will profile
@@ -272,10 +289,10 @@ abstract class Profiler {
         */
        protected function getTime( $metric = 'wall' ) {
                if ( $metric === 'cpu' || $metric === 'user' ) {
-                       if ( !function_exists( 'getrusage' ) ) {
+                       $ru = wfGetRusage();
+                       if ( !$ru ) {
                                return 0;
                        }
-                       $ru = getrusage();
                        $time = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
                        if ( $metric === 'cpu' ) {
                                # This is the time of system calls, added to the user time
index b2b0d34..97f6146 100644 (file)
@@ -39,84 +39,61 @@ class TitleTest extends MediaWikiTestCase {
                }
        }
 
-       /**
-        * See also mediawiki.Title.test.js
-        * @covers Title::secureAndSplit
-        * @todo This method should be split into 2 separate tests each with a provider
-        * @note This mainly tests MediaWikiTitleCodec::parseTitle().
-        */
-       public function testSecureAndSplit() {
-               $this->setMwGlobals( array(
-                       'wgLocalInterwikis' => array( 'localtestiw' ),
-                       'wgHooks' => array(
-                               'InterwikiLoadPrefix' => array(
-                                       function ( $prefix, &$data ) {
-                                               if ( $prefix === 'localtestiw' ) {
-                                                       $data = array( 'iw_url' => 'localtestiw' );
-                                               } elseif ( $prefix === 'remotetestiw' ) {
-                                                       $data = array( 'iw_url' => 'remotetestiw' );
-                                               }
-                                               return false;
-                                       }
-                               )
-                       )
-               ));
-               // Valid
-               foreach ( array(
-                       'Sandbox',
-                       'A "B"',
-                       'A \'B\'',
-                       '.com',
-                       '~',
-                       '#',
-                       '"',
-                       '\'',
-                       'Talk:Sandbox',
-                       'Talk:Foo:Sandbox',
-                       'File:Example.svg',
-                       'File_talk:Example.svg',
-                       'Foo/.../Sandbox',
-                       'Sandbox/...',
-                       'A~~',
-                       ':A',
+       public function provideValidSecureAndSplit() {
+               return array(
+                       array( 'Sandbox' ),
+                       array( 'A "B"' ),
+                       array( 'A \'B\'' ),
+                       array( '.com' ),
+                       array( '~' ),
+                       array( '#' ),
+                       array( '"' ),
+                       array( '\'' ),
+                       array( 'Talk:Sandbox' ),
+                       array( 'Talk:Foo:Sandbox' ),
+                       array( 'File:Example.svg' ),
+                       array( 'File_talk:Example.svg' ),
+                       array( 'Foo/.../Sandbox' ),
+                       array( 'Sandbox/...' ),
+                       array( 'A~~' ),
+                       array( ':A' ),
                        // Length is 256 total, but only title part matters
-                       'Category:' . str_repeat( 'x', 248 ),
-                       str_repeat( 'x', 252 ),
+                       array( 'Category:' . str_repeat( 'x', 248 ) ),
+                       array( str_repeat( 'x', 252 ) ),
                        // interwiki prefix
-                       'localtestiw: #anchor',
-                       'localtestiw:',
-                       'localtestiw:foo',
-                       'localtestiw: foo # anchor',
-                       'localtestiw: Talk: Sandbox # anchor',
-                       'remotetestiw:',
-                       'remotetestiw: Talk: # anchor',
-                       'remotetestiw: #bar',
-                       'remotetestiw: Talk:',
-                       'remotetestiw: Talk: Foo',
-                       'localtestiw:remotetestiw:',
-                       'localtestiw:remotetestiw:foo'
-               ) as $text ) {
-                       $this->assertInstanceOf( 'Title', Title::newFromText( $text ), "Valid: $text" );
-               }
+                       array( 'localtestiw: #anchor' ),
+                       array( 'localtestiw:' ),
+                       array( 'localtestiw:foo' ),
+                       array( 'localtestiw: foo # anchor' ),
+                       array( 'localtestiw: Talk: Sandbox # anchor' ),
+                       array( 'remotetestiw:' ),
+                       array( 'remotetestiw: Talk: # anchor' ),
+                       array( 'remotetestiw: #bar' ),
+                       array( 'remotetestiw: Talk:' ),
+                       array( 'remotetestiw: Talk: Foo' ),
+                       array( 'localtestiw:remotetestiw:' ),
+                       array( 'localtestiw:remotetestiw:foo' )
+               );
+       }
 
-               // Invalid
-               foreach ( array(
-                       '',
-                       ':',
-                       '__  __',
-                       '  __  ',
+       public function provideInvalidSecureAndSplit() {
+               return array(
+                       array( '' ),
+                       array( ':' ),
+                       array( '__  __' ),
+                       array( '  __  ' ),
                        // Bad characters forbidden regardless of wgLegalTitleChars
-                       'A [ B',
-                       'A ] B',
-                       'A { B',
-                       'A } B',
-                       'A < B',
-                       'A > B',
-                       'A | B',
+                       array( 'A [ B' ),
+                       array( 'A ] B' ),
+                       array( 'A { B' ),
+                       array( 'A } B' ),
+                       array( 'A < B' ),
+                       array( 'A > B' ),
+                       array( 'A | B' ),
                        // URL encoding
-                       'A%20B',
-                       'A%23B',
-                       'A%2523B',
+                       array( 'A%20B' ),
+                       array( 'A%23B' ),
+                       array( 'A%2523B' ),
                        // XML/HTML character entity references
                        // Note: Commented out because they are not marked invalid by the PHP test as
                        // Title::newFromText runs Sanitizer::decodeCharReferencesAndNormalize first.
@@ -124,32 +101,70 @@ class TitleTest extends MediaWikiTestCase {
                        //'A &#233; B',
                        //'A &#x00E9; B',
                        // Subject of NS_TALK does not roundtrip to NS_MAIN
-                       'Talk:File:Example.svg',
+                       array( 'Talk:File:Example.svg' ),
                        // Directory navigation
-                       '.',
-                       '..',
-                       './Sandbox',
-                       '../Sandbox',
-                       'Foo/./Sandbox',
-                       'Foo/../Sandbox',
-                       'Sandbox/.',
-                       'Sandbox/..',
+                       array( '.' ),
+                       array( '..' ),
+                       array( './Sandbox' ),
+                       array( '../Sandbox' ),
+                       array( 'Foo/./Sandbox' ),
+                       array( 'Foo/../Sandbox' ),
+                       array( 'Sandbox/.' ),
+                       array( 'Sandbox/..' ),
                        // Tilde
-                       'A ~~~ Name',
-                       'A ~~~~ Signature',
-                       'A ~~~~~ Timestamp',
-                       str_repeat( 'x', 256 ),
+                       array( 'A ~~~ Name' ),
+                       array( 'A ~~~~ Signature' ),
+                       array( 'A ~~~~~ Timestamp' ),
+                       array( str_repeat( 'x', 256 ) ),
                        // Namespace prefix without actual title
-                       'Talk:',
-                       'Talk:#',
-                       'Category: ',
-                       'Category: #bar',
+                       array( 'Talk:' ),
+                       array( 'Talk:#' ),
+                       array( 'Category: ' ),
+                       array( 'Category: #bar' ),
                        // interwiki prefix
-                       'localtestiw: Talk: # anchor',
-                       'localtestiw: Talk:'
-               ) as $text ) {
-                       $this->assertNull( Title::newFromText( $text ), "Invalid: $text" );
-               }
+                       array( 'localtestiw: Talk: # anchor' ),
+                       array( 'localtestiw: Talk:' )
+               );
+       }
+
+       private function secureAndSplitGlobals() {
+               $this->setMwGlobals( array(
+                       'wgLocalInterwikis' => array( 'localtestiw' ),
+                       'wgHooks' => array(
+                               'InterwikiLoadPrefix' => array(
+                                       function ( $prefix, &$data ) {
+                                               if ( $prefix === 'localtestiw' ) {
+                                                       $data = array( 'iw_url' => 'localtestiw' );
+                                               } elseif ( $prefix === 'remotetestiw' ) {
+                                                       $data = array( 'iw_url' => 'remotetestiw' );
+                                               }
+                                               return false;
+                                       }
+                               )
+                       )
+               ));
+       }
+
+       /**
+        * See also mediawiki.Title.test.js
+        * @covers Title::secureAndSplit
+        * @dataProvider provideValidSecureAndSplit
+        * @note This mainly tests MediaWikiTitleCodec::parseTitle().
+        */
+       public function testSecureAndSplitValid( $text ) {
+               $this->secureAndSplitGlobals();
+               $this->assertInstanceOf( 'Title', Title::newFromText( $text ), "Valid: $text" );
+       }
+
+       /**
+        * See also mediawiki.Title.test.js
+        * @covers Title::secureAndSplit
+        * @dataProvider provideInvalidSecureAndSplit
+        * @note This mainly tests MediaWikiTitleCodec::parseTitle().
+        */
+       public function testSecureAndSplitInvalid( $text ) {
+               $this->secureAndSplitGlobals();
+               $this->assertNull( Title::newFromText( $text ), "Invalid: $text" );
        }
 
        public static function provideConvertByteClassToUnicodeClass() {