Merge "Clean up array() syntax from docs, part VI"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 12 Sep 2016 10:15:58 +0000 (10:15 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 12 Sep 2016 10:15:58 +0000 (10:15 +0000)
includes/libs/WaitConditionLoop.php
includes/specials/SpecialUserrights.php

index 3339eb3..969e86e 100644 (file)
@@ -34,6 +34,8 @@ class WaitConditionLoop {
        private $timeout;
        /** @var float Seconds */
        private $lastWaitTime;
+       /** @var integer|null */
+       private $rusageMode;
 
        const CONDITION_REACHED = 1;
        const CONDITION_CONTINUE = 0; // evaluates as falsey
@@ -50,6 +52,12 @@ class WaitConditionLoop {
                $this->condition = $condition;
                $this->timeout = $timeout;
                $this->busyCallbacks =& $busyCallbacks;
+
+               if ( defined( 'HHVM_VERSION' ) && PHP_OS === 'Linux' ) {
+                       $this->rusageMode = 2; // RUSAGE_THREAD
+               } elseif ( function_exists( 'getrusage' ) ) {
+                       $this->rusageMode = 0; // RUSAGE_SELF
+               }
        }
 
        /**
@@ -139,18 +147,14 @@ class WaitConditionLoop {
         * @return float Returns 0.0 if not supported (Windows on PHP < 7)
         */
        protected function getCpuTime() {
-               $time = 0.0;
-
-               if ( defined( 'HHVM_VERSION' ) && PHP_OS === 'Linux' ) {
-                       $ru = getrusage( 2 /* RUSAGE_THREAD */ );
-               } else {
-                       $ru = getrusage( 0 /* RUSAGE_SELF */ );
-               }
-               if ( $ru ) {
-                       $time += $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
-                       $time += $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1e6;
+               if ( $this->rusageMode === null ) {
+                       return microtime( true ); // assume worst case (all time is CPU)
                }
 
+               $ru = getrusage( $this->rusageMode );
+               $time = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
+               $time += $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1e6;
+
                return $time;
        }
 
index c7c1239..8a06abf 100644 (file)
  * @ingroup SpecialPage
  */
 class UserrightsPage extends SpecialPage {
-       # The target of the local right-adjuster's interest.  Can be gotten from
-       # either a GET parameter or a subpage-style parameter, so have a member
-       # variable for it.
+       /**
+        * The target of the local right-adjuster's interest.  Can be gotten from
+        * either a GET parameter or a subpage-style parameter, so have a member
+        * variable for it.
+        * @var null|string $mTarget
+        */
        protected $mTarget;
        /*
         * @var null|User $mFetchedUser The user object of the target username or null.
@@ -101,6 +104,10 @@ class UserrightsPage extends SpecialPage {
                        $this->mTarget = $request->getVal( 'user' );
                }
 
+               if ( is_string( $this->mTarget ) ) {
+                       $this->mTarget = trim( $this->mTarget );
+               }
+
                $available = $this->changeableGroups();
 
                if ( $this->mTarget === null ) {