Merge "Made master connection expectations actually work"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 4 Mar 2015 05:26:49 +0000 (05:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 4 Mar 2015 05:26:49 +0000 (05:26 +0000)
29 files changed:
StartProfiler.sample
autoload.php
includes/DefaultSettings.php
includes/Html.php
includes/HttpFunctions.php
includes/Linker.php
includes/MovePage.php
includes/User.php
includes/UserRightsProxy.php
includes/api/ApiBase.php
includes/jobqueue/jobs/HTMLCacheUpdateJob.php
includes/profiler/Profiler.php
includes/profiler/ProfilerXhprof.php
includes/profiler/output/ProfilerOutputDump.php [new file with mode: 0644]
includes/resourceloader/ResourceLoaderFilePageModule.php [deleted file]
includes/resourceloader/ResourceLoaderNoscriptModule.php [deleted file]
includes/resourceloader/ResourceLoaderSiteModule.php
includes/resourceloader/ResourceLoaderUserGroupsModule.php
includes/resourceloader/ResourceLoaderUserModule.php
includes/resourceloader/ResourceLoaderWikiModule.php
maintenance/backupTextPass.inc
maintenance/dumpTextPass.php
resources/Resources.php
resources/src/mediawiki/mediawiki.user.js
tests/TestsAutoLoader.php
tests/phpunit/ResourceLoaderTestCase.php
tests/phpunit/includes/HttpTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
tests/phpunit/maintenance/backupTextPassTest.php

index 4721a9d..6681b87 100644 (file)
@@ -6,7 +6,7 @@
  *
  * For output, add:
  *  $wgProfiler['output'] = array( 'text' );
- *    'text' can be one (or more) of 'text' 'udp' or 'db'
+ *    'text' can be one (or more) of 'text' 'udp' 'db' or 'dump'
  *    'db' requires creating the profiling table, see patch-profiling.sql
  *
  * The 'text' output will be added to the output page in a comment approriate
@@ -18,6 +18,9 @@
  * The 'db' output expects a database table that can be created by applying
  * maintenance/archives/patch-profiling.sql to your database.
  *
+ * The 'dump' output expects a $wgProfiler['outputDir'] telling it where to
+ * write dump files. The files produced are compatible with the XHProf gui.
+ *
  * For a rudimentary sampling profiler:
  *   $wgProfiler['class'] = 'ProfilerXhprof';
  *   $wgProfiler['output'] = array( 'db' );
index 445d752..998deb9 100644 (file)
@@ -907,6 +907,7 @@ $wgAutoloadLocalClasses = array(
        'Profiler' => __DIR__ . '/includes/profiler/Profiler.php',
        'ProfilerOutput' => __DIR__ . '/includes/profiler/output/ProfilerOutput.php',
        'ProfilerOutputDb' => __DIR__ . '/includes/profiler/output/ProfilerOutputDb.php',
+       'ProfilerOutputDump' => __DIR__ . '/includes/profiler/output/ProfilerOutputDump.php',
        'ProfilerOutputText' => __DIR__ . '/includes/profiler/output/ProfilerOutputText.php',
        'ProfilerOutputUdp' => __DIR__ . '/includes/profiler/output/ProfilerOutputUdp.php',
        'ProfilerSectionOnly' => __DIR__ . '/includes/profiler/ProfilerSectionOnly.php',
@@ -977,14 +978,12 @@ $wgAutoloadLocalClasses = array(
        'ResourceLoaderContext' => __DIR__ . '/includes/resourceloader/ResourceLoaderContext.php',
        'ResourceLoaderEditToolbarModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderEditToolbarModule.php',
        'ResourceLoaderFileModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderFileModule.php',
-       'ResourceLoaderFilePageModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderFilePageModule.php',
        'ResourceLoaderFilePath' => __DIR__ . '/includes/resourceloader/ResourceLoaderFilePath.php',
        'ResourceLoaderImage' => __DIR__ . '/includes/resourceloader/ResourceLoaderImage.php',
        'ResourceLoaderImageModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderImageModule.php',
        'ResourceLoaderLanguageDataModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageDataModule.php',
        'ResourceLoaderLanguageNamesModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageNamesModule.php',
        'ResourceLoaderModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderModule.php',
-       'ResourceLoaderNoscriptModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderNoscriptModule.php',
        'ResourceLoaderSiteModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderSiteModule.php',
        'ResourceLoaderSkinModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderSkinModule.php',
        'ResourceLoaderStartUpModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderStartUpModule.php',
index fdb05fe..89cc1fd 100644 (file)
@@ -951,7 +951,8 @@ $wgExiv2Command = '/usr/bin/exiv2';
  * are passed as parameters after $srcPath, $dstPath, $width, $height
  */
 $wgSVGConverters = array(
-       'ImageMagick' => '$path/convert -background "#ffffff00" -thumbnail $widthx$height\! $input PNG:$output',
+       'ImageMagick' =>
+               '$path/convert -background "#ffffff00" -thumbnail $widthx$height\! $input PNG:$output',
        'sodipodi' => '$path/sodipodi -z -w $width -f $input -e $output',
        'inkscape' => '$path/inkscape -z -w $width -f $input -e $output',
        'batik' => 'java -Djava.awt.headless=true -jar $path/batik-rasterizer.jar -w $width -d '
@@ -3173,9 +3174,10 @@ $wgFooterIcons = array(
        ),
        "poweredby" => array(
                "mediawiki" => array(
-                       "src" => null, // Defaults to point at
-                                      // "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png"
-                                      // plus srcset for 1.5x, 2x resolution variants.
+                       // Defaults to point at
+                       // "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png"
+                       // plus srcset for 1.5x, 2x resolution variants.
+                       "src" => null,
                        "url" => "//www.mediawiki.org/",
                        "alt" => "Powered by MediaWiki",
                )
index fe8f57e..bc5cde8 100644 (file)
@@ -159,7 +159,8 @@ class Html {
        }
 
        /**
-        * Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enabled).
+        * Returns an HTML link element in a string styled as a button
+        * (when $wgUseMediaWikiUIEverywhere is enabled).
         *
         * @param string $contents The raw HTML contents of the element: *not*
         *   escaped!
@@ -178,7 +179,8 @@ class Html {
        }
 
        /**
-        * Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enabled).
+        * Returns an HTML link element in a string styled as a button
+        * (when $wgUseMediaWikiUIEverywhere is enabled).
         *
         * @param string $contents The raw HTML contents of the element: *not*
         *   escaped!
index 3728cdf..36e06b5 100644 (file)
@@ -55,9 +55,10 @@ class Http {
         *                                  to avoid attacks on intranet services accessible by HTTP.
         *    - userAgent           A user agent, if you want to override the default
         *                          MediaWiki/$wgVersion
+        * @param string $caller The method making this request, for profiling
         * @return string|bool (bool)false on failure or a string on success
         */
-       public static function request( $method, $url, $options = array() ) {
+       public static function request( $method, $url, $options = array(), $caller = __METHOD__ ) {
                wfDebug( "HTTP: $method: $url\n" );
 
                $options['method'] = strtoupper( $method );
@@ -69,7 +70,7 @@ class Http {
                        $options['connectTimeout'] = 'default';
                }
 
-               $req = MWHttpRequest::factory( $url, $options );
+               $req = MWHttpRequest::factory( $url, $options, $caller );
                $status = $req->execute();
 
                $content = false;
@@ -87,18 +88,21 @@ class Http {
         *
         * @param string $url
         * @param array $options
+        * @param string $caller The method making this request, for profiling
         * @return string
         */
-       public static function get( $url, $options = array() ) {
+       public static function get( $url, $options = array(), $caller = __METHOD__ ) {
                $args = func_get_args();
                if ( isset( $args[1] ) && ( is_string( $args[1] ) || is_numeric( $args[1] ) ) ) {
                        // Second was used to be the timeout
                        // And third parameter used to be $options
                        wfWarn( "Second parameter should not be a timeout." );
-                       $options = isset( $args[2] ) ? $args[2] : array();
+                       $options = isset( $args[2] ) && is_array( $args[2] ) ?
+                               $args[2] : array();
                        $options['timeout'] = $args[1];
+                       $caller = __METHOD__;
                }
-               return Http::request( 'GET', $url, $options );
+               return Http::request( 'GET', $url, $options, $caller );
        }
 
        /**
@@ -107,10 +111,11 @@ class Http {
         *
         * @param string $url
         * @param array $options
+        * @param string $caller The method making this request, for profiling
         * @return string
         */
-       public static function post( $url, $options = array() ) {
-               return Http::request( 'POST', $url, $options );
+       public static function post( $url, $options = array(), $caller = __METHOD__ ) {
+               return Http::request( 'POST', $url, $options, $caller );
        }
 
        /**
@@ -224,11 +229,23 @@ class MWHttpRequest {
 
        public $status;
 
+       /**
+        * @var Profiler
+        */
+       protected $profiler;
+
+       /**
+        * @var string
+        */
+       protected $profileName;
+
        /**
         * @param string $url Url to use. If protocol-relative, will be expanded to an http:// URL
         * @param array $options (optional) extra params to pass (see Http::request())
+        * @param string $caller The method making this request, for profiling
+        * @param Profiler $profiler An instance of the profiler for profiling, or null
         */
-       protected function __construct( $url, $options = array() ) {
+       protected function __construct( $url, $options = array(), $caller = __METHOD__, $profiler = null ) {
                global $wgHTTPTimeout, $wgHTTPConnectTimeout;
 
                $this->url = wfExpandUrl( $url, PROTO_HTTP );
@@ -271,6 +288,10 @@ class MWHttpRequest {
                if ( $this->noProxy ) {
                        $this->proxy = ''; // noProxy takes precedence
                }
+
+               // Profile based on what's calling us
+               $this->profiler = $profiler;
+               $this->profileName = $caller;
        }
 
        /**
@@ -286,11 +307,12 @@ class MWHttpRequest {
         * Generate a new request object
         * @param string $url Url to use
         * @param array $options (optional) extra params to pass (see Http::request())
+        * @param string $caller The method making this request, for profiling
         * @throws MWException
         * @return CurlHttpRequest|PhpHttpRequest
         * @see MWHttpRequest::__construct
         */
-       public static function factory( $url, $options = null ) {
+       public static function factory( $url, $options = null, $caller = __METHOD__ ) {
                if ( !Http::$httpEngine ) {
                        Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
                } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
@@ -300,7 +322,7 @@ class MWHttpRequest {
 
                switch ( Http::$httpEngine ) {
                        case 'curl':
-                               return new CurlHttpRequest( $url, $options );
+                               return new CurlHttpRequest( $url, $options, $caller, Profiler::instance() );
                        case 'php':
                                if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
                                        throw new MWException( __METHOD__ . ': allow_url_fopen ' .
@@ -309,7 +331,7 @@ class MWHttpRequest {
                                                'http://php.net/curl.'
                                        );
                                }
-                               return new PhpHttpRequest( $url, $options );
+                               return new PhpHttpRequest( $url, $options, $caller, Profiler::instance() );
                        default:
                                throw new MWException( __METHOD__ . ': The setting of Http::$httpEngine is not valid.' );
                }
@@ -780,6 +802,12 @@ class CurlHttpRequest extends MWHttpRequest {
                        wfRestoreWarnings();
                }
 
+               if ( $this->profiler ) {
+                       $profileSection = $this->profiler->scopedProfileIn(
+                               __METHOD__ . '-' . $this->profileName
+                       );
+               }
+
                $curlRes = curl_exec( $curlHandle );
                if ( curl_errno( $curlHandle ) == CURLE_OPERATION_TIMEOUTED ) {
                        $this->status->fatal( 'http-timed-out', $this->url );
@@ -791,6 +819,10 @@ class CurlHttpRequest extends MWHttpRequest {
 
                curl_close( $curlHandle );
 
+               if ( $this->profiler ) {
+                       $this->profiler->scopedProfileOut( $profileSection );
+               }
+
                $this->parseHeader();
                $this->setStatus();
 
@@ -899,6 +931,11 @@ class PhpHttpRequest extends MWHttpRequest {
 
                $result = array();
 
+               if ( $this->profiler ) {
+                       $profileSection = $this->profiler->scopedProfileIn(
+                               __METHOD__ . '-' . $this->profileName
+                       );
+               }
                do {
                        $reqCount++;
                        wfSuppressWarnings();
@@ -929,6 +966,9 @@ class PhpHttpRequest extends MWHttpRequest {
                                break;
                        }
                } while ( true );
+               if ( $this->profiler ) {
+                       $this->profiler->scopedProfileOut( $profileSection );
+               }
 
                $this->setStatus();
 
index 5a05bd4..a9c26c6 100644 (file)
@@ -1388,7 +1388,9 @@ class Linker {
         *
         * @return string
         */
-       public static function formatLinksInComment( $comment, $title = null, $local = false, $wikiId = null ) {
+       public static function formatLinksInComment(
+               $comment, $title = null, $local = false, $wikiId = null
+       ) {
                return preg_replace_callback(
                        '/
                                \[\[
index 065e189..01c25d3 100644 (file)
@@ -370,7 +370,10 @@ class MovePage {
 
                $dbw->commit( __METHOD__ );
 
-               Hooks::run( 'TitleMoveComplete', array( &$this->oldTitle, &$this->newTitle, &$user, $pageid, $redirid, $reason ) );
+               Hooks::run(
+                       'TitleMoveComplete',
+                       array( &$this->oldTitle, &$this->newTitle, &$user, $pageid, $redirid, $reason )
+               );
                return Status::newGood();
        }
 
index 03ac4fd..a4f6b77 100644 (file)
@@ -3375,7 +3375,9 @@ class User implements IDBAccessObject {
         * @param WebRequest|null $request WebRequest object to use; $wgRequest will be used if null
         *        is passed.
         */
-       protected function setCookie( $name, $value, $exp = 0, $secure = null, $params = array(), $request = null ) {
+       protected function setCookie(
+               $name, $value, $exp = 0, $secure = null, $params = array(), $request = null
+       ) {
                if ( $request === null ) {
                        $request = $this->getRequest();
                }
index 3be5847..1b9e4b6 100644 (file)
@@ -114,7 +114,8 @@ class UserRightsProxy {
         */
        private static function newFromLookup( $database, $field, $value, $ignoreInvalidDB = false ) {
                global $wgSharedDB, $wgSharedTables;
-               // If the user table is shared, perform the user query on it, but don't pass it to the UserRightsProxy,
+               // If the user table is shared, perform the user query on it,
+               // but don't pass it to the UserRightsProxy,
                // as user rights are normally not shared.
                if ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
                        $userdb = self::getDB( $wgSharedDB, $ignoreInvalidDB );
index be5a9c3..b03782f 100644 (file)
@@ -160,6 +160,9 @@ abstract class ApiBase extends ContextSource {
         * If the module may only be used with a certain format module,
         * it should override this method to return an instance of that formatter.
         * A value of null means the default format will be used.
+        * @note Do not use this just because you don't want to support non-json
+        * formats. This should be used only when there is a fundamental
+        * requirement for a specific format.
         * @return mixed Instance of a derived class of ApiFormatBase, or null
         */
        public function getCustomPrinter() {
index b4ddd11..9d91565 100644 (file)
@@ -42,17 +42,8 @@ class HTMLCacheUpdateJob extends Job {
        function run() {
                global $wgUpdateRowsPerJob, $wgUpdateRowsPerQuery;
 
-               static $expected = array( 'recursive', 'pages' ); // new jobs have one of these
-
-               $oldRangeJob = false;
-               if ( !array_intersect( array_keys( $this->params ), $expected ) ) {
-                       // B/C for older job params formats that lack these fields:
-                       // a) base jobs with just ("table") and b) range jobs with ("table","start","end")
-                       if ( isset( $this->params['start'] ) && isset( $this->params['end'] ) ) {
-                               $oldRangeJob = true;
-                       } else {
-                               $this->params['recursive'] = true; // base job
-                       }
+               if ( isset( $this->params['table'] ) && !isset( $this->params['pages'] ) ) {
+                       $this->params['recursive'] = true; // b/c; base job
                }
 
                // Job to purge all (or a range of) backlink pages for a page
@@ -70,26 +61,12 @@ class HTMLCacheUpdateJob extends Job {
                // Job to purge pages for a set of titles
                } elseif ( isset( $this->params['pages'] ) ) {
                        $this->invalidateTitles( $this->params['pages'] );
-               // B/C for job to purge a range of backlink pages for a given page
-               } elseif ( $oldRangeJob ) {
-                       $titleArray = $this->title->getBacklinkCache()->getLinks(
-                               $this->params['table'], $this->params['start'], $this->params['end'] );
-
-                       $pages = array(); // same format BacklinkJobUtils uses
-                       foreach ( $titleArray as $tl ) {
-                               $pages[$tl->getArticleId()] = array( $tl->getNamespace(), $tl->getDbKey() );
-                       }
-
-                       $jobs = array();
-                       foreach ( array_chunk( $pages, $wgUpdateRowsPerJob ) as $pageChunk ) {
-                               $jobs[] = new HTMLCacheUpdateJob( $this->title,
-                                       array(
-                                               'table' => $this->params['table'],
-                                               'pages' => $pageChunk
-                                       ) + $this->getRootJobParams() // carry over information for de-duplication
-                               );
-                       }
-                       JobQueueGroup::singleton()->push( $jobs );
+               // Job to update a single title
+               } else {
+                       $t = $this->title;
+                       $this->invalidateTitles( array(
+                               $t->getArticleID() => array( $t->getNamespace(), $t->getDBkey() )
+                       ) );
                }
 
                return true;
index 4b74206..69470fd 100644 (file)
@@ -46,6 +46,7 @@ abstract class Profiler {
                'db' => 'ProfilerOutputDb',
                'text' => 'ProfilerOutputText',
                'udp' => 'ProfilerOutputUdp',
+               'dump' => 'ProfilerOutputDump',
        );
 
        /** @var Profiler */
@@ -167,7 +168,7 @@ abstract class Profiler {
                if ( !is_array( $output ) ) {
                        $output = array( $output );
                }
-
+               $stats = null;
                foreach ( $output as $outType ) {
                        if ( !isset( self::$outputTypes[$outType] ) ) {
                                throw new MWException( "'$outType' is an invalid output type" );
@@ -177,7 +178,10 @@ abstract class Profiler {
                        /** @var ProfilerOutput $profileOut */
                        $profileOut = new $class( $this, $this->params );
                        if ( $profileOut->canUse() ) {
-                               $profileOut->log( $this->getFunctionStats() );
+                               if ( is_null( $stats ) ) {
+                                       $stats = $this->getFunctionStats();
+                               }
+                               $profileOut->log( $stats );
                        }
                }
        }
index 7a50497..f36cdc1 100644 (file)
@@ -183,4 +183,12 @@ class ProfilerXhprof extends Profiler {
                }
                return implode( "\n", $out );
        }
+
+       /**
+        * Retrieve raw data from xhprof
+        * @return array
+        */
+       public function getRawData() {
+               return $this->xhprof->getRawData();
+       }
 }
diff --git a/includes/profiler/output/ProfilerOutputDump.php b/includes/profiler/output/ProfilerOutputDump.php
new file mode 100644 (file)
index 0000000..bf4b85c
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Profiler dumping output in xhprof dump file
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Profiler
+ */
+
+/**
+ * Profiler dumping output in xhprof dump file
+ * @ingroup Profiler
+ *
+ * @since 1.25
+ */
+class ProfilerOutputDump extends ProfilerOutput {
+
+       protected $suffix = ".xhprof";
+
+       /**
+        * Can this output type be used?
+        *
+        * @return bool
+        */
+       public function canUse() {
+               if ( empty( $this->params['outputDir'] ) ) {
+                       return false;
+               }
+               return true;
+       }
+
+       public function log( array $stats ) {
+               $data = $this->collector->getRawData();
+               $filename = sprintf( "%s/%s.%s%s", $this->params['outputDir'], uniqid(), $this->collector->getProfileID(), $this->suffix );
+               file_put_contents( $filename, serialize( $data ) );
+       }
+}
diff --git a/includes/resourceloader/ResourceLoaderFilePageModule.php b/includes/resourceloader/ResourceLoaderFilePageModule.php
deleted file mode 100644 (file)
index 8c7fbe7..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-/**
- * Resource loader module for MediaWiki:Filepage.css
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- */
-
-/**
- * ResourceLoader definition for MediaWiki:Filepage.css
- */
-class ResourceLoaderFilePageModule extends ResourceLoaderWikiModule {
-
-       /**
-        * @param ResourceLoaderContext $context
-        * @return array
-        */
-       protected function getPages( ResourceLoaderContext $context ) {
-               return array(
-                       'MediaWiki:Filepage.css' => array( 'type' => 'style' ),
-               );
-       }
-}
diff --git a/includes/resourceloader/ResourceLoaderNoscriptModule.php b/includes/resourceloader/ResourceLoaderNoscriptModule.php
deleted file mode 100644 (file)
index 61927d7..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/**
- * Resource loader for site customizations for users without JavaScript enabled.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @author Trevor Parscal
- * @author Roan Kattouw
- */
-
-/**
- * Module for site customizations
- */
-class ResourceLoaderNoscriptModule extends ResourceLoaderWikiModule {
-
-       /* Protected Methods */
-
-       /**
-        * Gets list of pages used by this module.  Obviously, it makes absolutely no
-        * sense to include JavaScript files here... :D
-        *
-        * @param ResourceLoaderContext $context
-        *
-        * @return array List of pages
-        */
-       protected function getPages( ResourceLoaderContext $context ) {
-               return array( 'MediaWiki:Noscript.css' => array( 'type' => 'style' ) );
-       }
-
-       /* Methods */
-
-       /**
-        * Gets group name
-        *
-        * @return string Name of group
-        */
-       public function getGroup() {
-               return 'noscript';
-       }
-}
index 35d5c05..19e0bae 100644 (file)
  */
 class ResourceLoaderSiteModule extends ResourceLoaderWikiModule {
 
-       /* Protected Methods */
-
        /**
-        * Gets list of pages used by this module
+        * Get list of pages used by this module
         *
         * @param ResourceLoaderContext $context
-        *
         * @return array List of pages
         */
        protected function getPages( ResourceLoaderContext $context ) {
@@ -51,12 +48,10 @@ class ResourceLoaderSiteModule extends ResourceLoaderWikiModule {
                return $pages;
        }
 
-       /* Methods */
-
        /**
-        * Gets group name
+        * Get group name
         *
-        * @return string Name of group
+        * @return string
         */
        public function getGroup() {
                return 'site';
index ee350cf..417cfce 100644 (file)
  */
 class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
 
-       /* Protected Members */
-
        protected $origin = self::ORIGIN_USER_SITEWIDE;
        protected $targets = array( 'desktop', 'mobile' );
 
-       /* Protected Methods */
-
        /**
         * @param ResourceLoaderContext $context
         * @return array
@@ -63,9 +59,9 @@ class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
                return $pages;
        }
 
-       /* Methods */
-
        /**
+        * Get group name
+        *
         * @return string
         */
        public function getGroup() {
index e2d39d0..a097844 100644 (file)
  */
 class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
 
-       /* Protected Members */
-
        protected $origin = self::ORIGIN_USER_INDIVIDUAL;
 
-       /* Protected Methods */
-
        /**
+        * Get list of pages used by this module
+        *
         * @param ResourceLoaderContext $context
-        * @return array
+        * @return array List of pages
         */
        protected function getPages( ResourceLoaderContext $context ) {
                $allowUserJs = $this->getConfig()->get( 'AllowUserJs' );
@@ -74,9 +72,9 @@ class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
                return $pages;
        }
 
-       /* Methods */
-
        /**
+        * Get group name
+        *
         * @return string
         */
        public function getGroup() {
index 1a1a6d0..7b44cc6 100644 (file)
  * because of its dependence on the functionality of
  * Title::isCssJsSubpage.
  */
-abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
+class ResourceLoaderWikiModule extends ResourceLoaderModule {
 
-       /* Protected Members */
-
-       # Origin is user-supplied code
+       // Origin defaults to users with sitewide authority
        protected $origin = self::ORIGIN_USER_SITEWIDE;
 
        // In-object cache for title info
        protected $titleInfo = array();
 
-       /* Abstract Protected Methods */
+       // List of page names that contain CSS
+       protected $styles = array();
+
+       // List of page names that contain JavaScript
+       protected $scripts = array();
+
+       // Group of module
+       protected $group;
+
+       /**
+        * @param array $options For back-compat, this can be omitted in favour of overwriting getPages.
+        */
+       public function __construct( array $options = null ) {
+               if ( isset( $options['styles'] ) ) {
+                       $this->styles = $options['styles'];
+               }
+               if ( isset( $options['scripts'] ) ) {
+                       $this->scripts = $options['scripts'];
+               }
+               if ( isset( $options['group'] ) ) {
+                       $this->group = $options['group'];
+               }
+       }
 
        /**
         * Subclasses should return an associative array of resources in the module.
@@ -57,9 +77,34 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
         * @param ResourceLoaderContext $context
         * @return array
         */
-       abstract protected function getPages( ResourceLoaderContext $context );
+       protected function getPages( ResourceLoaderContext $context ) {
+               $config = $this->getConfig();
+               $pages = array();
+
+               // Filter out pages from origins not allowed by the current wiki configuration.
+               if ( $config->get( 'UseSiteJs' ) ) {
+                       foreach ( $this->scripts as $script ) {
+                               $pages[$script] = array( 'type' => 'script' );
+                       }
+               }
+
+               if ( $config->get( 'UseSiteCss' ) ) {
+                       foreach ( $this->styles as $style ) {
+                               $pages[$style] = array( 'type' => 'style' );
+                       }
+               }
+
+               return $pages;
+       }
 
-       /* Protected Methods */
+       /**
+        * Get group name
+        *
+        * @return string
+        */
+       public function getGroup() {
+               return $this->group;
+       }
 
        /**
         * Get the Database object used in getTitleMTimes(). Defaults to the local slave DB
@@ -105,8 +150,6 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
                return $content->serialize( $format );
        }
 
-       /* Methods */
-
        /**
         * @param ResourceLoaderContext $context
         * @return string
index 85ebd51..d83f1fc 100644 (file)
@@ -48,6 +48,8 @@ class TextPassDumper extends BackupDumper {
        protected $maxConsecutiveFailedTextRetrievals = 200;
        protected $failureTimeout = 5; // Seconds to sleep after db failure
 
+       protected $bufferSize = 524288; // In bytes. Maximum size to read from the stub in on go.
+
        protected $php = "php";
        protected $spawn = false;
 
@@ -186,6 +188,10 @@ class TextPassDumper extends BackupDumper {
                $url = $this->processFileOpt( $val, $param );
 
                switch ( $opt ) {
+                       case 'buffersize':
+                               // Lower bound for xml reading buffer size is 4 KB
+                               $this->bufferSize = max( intval( $val ), 4 * 1024 );
+                               break;
                        case 'prefetch':
                                require_once "$IP/maintenance/backupPrefetch.inc";
                                $this->prefetch = new BaseDump( $url );
@@ -368,12 +374,11 @@ class TextPassDumper extends BackupDumper {
                xml_set_character_data_handler( $parser, array( &$this, 'characterData' ) );
 
                $offset = 0; // for context extraction on error reporting
-               $bufferSize = 512 * 1024;
                do {
                        if ( $this->checkIfTimeExceeded() ) {
                                $this->setTimeExceeded();
                        }
-                       $chunk = fread( $input, $bufferSize );
+                       $chunk = fread( $input, $this->bufferSize );
                        if ( !xml_parse( $parser, $chunk, feof( $input ) ) ) {
                                wfDebug( "TextDumpPass::readDump encountered XML parsing error\n" );
 
index 7c17607..bde5a07 100644 (file)
@@ -59,6 +59,8 @@ Options:
   --server=h  Force reading from MySQL server h
   --current      Base ETA on number of pages in database instead of all revisions
   --spawn        Spawn a subprocess for loading text records
+  --buffersize=<size> Buffer size in bytes to use for reading the stub.
+              (Default: 512KB, Minimum: 4KB)
   --help      Display this help message
 ENDS
        );
index 58a93a7..4d000b6 100644 (file)
@@ -29,12 +29,19 @@ return array(
        /**
         * Special modules who have their own classes
         */
+       'startup' => array( 'class' => 'ResourceLoaderStartUpModule' ),
 
        // Scripts managed by the local wiki (stored in the MediaWiki namespace)
        'site' => array( 'class' => 'ResourceLoaderSiteModule' ),
-       'noscript' => array( 'class' => 'ResourceLoaderNoscriptModule' ),
-       'startup' => array( 'class' => 'ResourceLoaderStartUpModule' ),
-       'filepage' => array( 'class' => 'ResourceLoaderFilePageModule' ),
+       'noscript' => array(
+               'class' => 'ResourceLoaderWikiModule',
+               'styles' => array( 'MediaWiki:Noscript.css' ),
+               'group' => 'noscript',
+       ),
+       'filepage' => array(
+               'class' => 'ResourceLoaderWikiModule',
+               'styles' => array( 'MediaWiki:Filepage.css' ),
+       ),
        'user.groups' => array( 'class' => 'ResourceLoaderUserGroupsModule' ),
 
        // Scripts managed by the current user (stored in their user space)
index b777cd3..817c856 100644 (file)
@@ -78,7 +78,7 @@
                                crypto = window.crypto || window.msCrypto;
 
                        // Based on https://github.com/broofa/node-uuid/blob/bfd9f96127/uuid.js
-                       if ( crypto ) {
+                       if ( crypto && crypto.getRandomValues ) {
                                // Fill an array with 8 random values, each of which is 8 bits.
                                // Note that Uint8Array is array-like but does not implement Array.
                                rnds = new Uint8Array( 8 );
index 4ed28a8..b410898 100644 (file)
@@ -44,7 +44,6 @@ $wgAutoloadClasses += array(
        'ResourceLoaderTestCase' => "$testDir/phpunit/ResourceLoaderTestCase.php",
        'ResourceLoaderTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
        'ResourceLoaderFileModuleTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
-       'ResourceLoaderWikiModuleTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php",
        'TestUser' => "$testDir/phpunit/includes/TestUser.php",
        'LessFileCompilationTest' => "$testDir/phpunit/LessFileCompilationTest.php",
 
index 055beb0..deecb31 100644 (file)
@@ -98,10 +98,3 @@ class ResourceLoaderTestModule extends ResourceLoaderModule {
 
 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
 }
-
-class ResourceLoaderWikiModuleTestModule extends ResourceLoaderWikiModule {
-       // Override expected via PHPUnit mocks and stubs
-       protected function getPages( ResourceLoaderContext $context ) {
-               return array();
-       }
-}
index fbd2c31..e3ee705 100644 (file)
@@ -486,7 +486,7 @@ class HttpTest extends MediaWikiTestCase {
 class MWHttpRequestTester extends MWHttpRequest {
        // function derived from the MWHttpRequest factory function but
        // returns appropriate tester class here
-       public static function factory( $url, $options = null ) {
+       public static function factory( $url, $options = null, $caller = __METHOD__ ) {
                if ( !Http::$httpEngine ) {
                        Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
                } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
@@ -496,7 +496,7 @@ class MWHttpRequestTester extends MWHttpRequest {
 
                switch ( Http::$httpEngine ) {
                        case 'curl':
-                               return new CurlHttpRequestTester( $url, $options );
+                               return new CurlHttpRequestTester( $url, $options, $caller );
                        case 'php':
                                if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
                                        throw new MWException( __METHOD__ .
@@ -504,7 +504,7 @@ class MWHttpRequestTester extends MWHttpRequest {
                                                        . 'If possible, curl should be used instead. See http://php.net/curl.' );
                                }
 
-                               return new PhpHttpRequestTester( $url, $options );
+                               return new PhpHttpRequestTester( $url, $options, $caller );
                        default:
                }
        }
index 9dc1805..93a3ebb 100644 (file)
@@ -2,12 +2,94 @@
 
 class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase {
 
+       /**
+        * @covers ResourceLoaderWikiModule::__construct
+        * @dataProvider provideConstructor
+        */
+       public function testConstructor( $params ) {
+               $module = new ResourceLoaderWikiModule( $params );
+               $this->assertInstanceOf( 'ResourceLoaderWikiModule', $module );
+       }
+
+       public static function provideConstructor() {
+               return array(
+                       // Nothing
+                       array( null ),
+                       array( array() ),
+                       // Unrecognized settings
+                       array( array( 'foo' => 'baz' ) ),
+                       // Real settings
+                       array( array( 'scripts' => array( 'MediaWiki:Common.js' ) ) ),
+               );
+       }
+
+       /**
+        * @dataProvider provideGetPages
+        * @covers ResourceLoaderWikiModule::getPages
+        */
+       public function testGetPages( $params, Config $config, $expected ) {
+               $module = new ResourceLoaderWikiModule( $params );
+               $module->setConfig( $config );
+
+               // Use getDefinitionSummary because getPages is protected
+               $summary = $module->getDefinitionSummary( ResourceLoaderContext::newDummyContext() );
+               $this->assertEquals(
+                       $expected,
+                       $summary['pages']
+               );
+       }
+
+       public static function provideGetPages() {
+               $settings = array(
+                       'UseSiteJs' => true,
+                       'UseSiteCss' => true,
+               );
+
+               $params = array(
+                       'styles' => array( 'MediaWiki:Common.css' ),
+                       'scripts' => array( 'MediaWiki:Common.js' ),
+               );
+
+               return array(
+                       array( array(), new HashConfig( $settings ), array() ),
+                       array( $params, new HashConfig( $settings ), array(
+                               'MediaWiki:Common.js' => array( 'type' => 'script' ),
+                               'MediaWiki:Common.css' => array( 'type' => 'style' )
+                       ) ),
+                       array( $params, new HashConfig( array( 'UseSiteCss' => false ) + $settings ), array(
+                               'MediaWiki:Common.js' => array( 'type' => 'script' ),
+                       ) ),
+                       array( $params, new HashConfig( array( 'UseSiteJs' => false ) + $settings ), array(
+                               'MediaWiki:Common.css' => array( 'type' => 'style' ),
+                       ) ),
+                       array( $params, new HashConfig( array( 'UseSiteJs' => false, 'UseSiteCss' => false ) ), array() ),
+               );
+       }
+
+       /**
+        * @covers ResourceLoaderWikiModule::getGroup
+        * @dataProvider provideGetGroup
+        */
+       public function testGetGroup( $params, $expected ) {
+               $module = new ResourceLoaderWikiModule( $params );
+               $this->assertEquals( $expected, $module->getGroup() );
+       }
+
+       public static function provideGetGroup() {
+               return array(
+                       // No group specified
+                       array( array(), null ),
+                       // A random group
+                       array( array( 'group' => 'foobar' ), 'foobar' ),
+               );
+       }
+
        /**
         * @covers ResourceLoaderWikiModule::isKnownEmpty
         * @dataProvider provideIsKnownEmpty
         */
        public function testIsKnownEmpty( $titleInfo, $group, $expected ) {
-               $module = $this->getMockBuilder( 'ResourceLoaderWikiModuleTestModule' )
+               $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' )
                        ->setMethods( array( 'getTitleInfo', 'getGroup' ) )
                        ->getMock();
                $module->expects( $this->any() )
index 0a977dc..a5ef762 100644 (file)
@@ -3,13 +3,13 @@
 require_once __DIR__ . "/../../../maintenance/backupTextPass.inc";
 
 /**
- * Tests for page dumps of BackupDumper
+ * Tests for TextPassDumper that rely on the database
  *
  * @group Database
  * @group Dump
  * @covers TextPassDumper
  */
-class TextPassDumperTest extends DumpTestCase {
+class TextPassDumperDatabaseTest extends DumpTestCase {
 
        // We'll add several pages, revision and texts. The following variables hold the
        // corresponding ids.
@@ -244,7 +244,9 @@ class TextPassDumperTest extends DumpTestCase {
                        $this->fail( "Could not open stream for stderr" );
                }
 
-               $iterations = 32; // We'll start with that many iterations of revisions in stub
+               $iterations = 32; // We'll start with that many iterations of revisions
+               // in stub. Make sure that the generated volume is above the buffer size
+               // set below. Otherwise, the checkpointing does not trigger.
                $lastDuration = 0;
                $minDuration = 2; // We want the dump to take at least this many seconds
                $checkpointAfter = 0.5; // Generate checkpoint after this many seconds
@@ -262,6 +264,7 @@ class TextPassDumperTest extends DumpTestCase {
                        $dumper = new TextPassDumper( array( "--stub=file:" . $nameStub,
                                "--output=" . $checkpointFormat . ":" . $nameOutputDir . "/full",
                                "--maxtime=1" /*This is in minutes. Fixup is below*/,
+                               "--buffersize=32768", // The default of 32 iterations fill up 32KB about twice
                                "--checkpointfile=checkpoint-%s-%s.xml.gz" ) );
                        $dumper->setDb( $this->db );
                        $dumper->maxTimeAllowed = $checkpointAfter; // Patching maxTime from 1 minute
@@ -415,10 +418,7 @@ class TextPassDumperTest extends DumpTestCase {
        }
 
        /**
-        * Broken per T70653.
-        *
         * @group large
-        * @group Broken
         */
        function testCheckpointPlain() {
                $this->checkpointHelper();
@@ -434,10 +434,7 @@ class TextPassDumperTest extends DumpTestCase {
         * PHP extensions, we go for gzip instead, which triggers the same relevant code
         * paths while still being testable on more systems.
         *
-        * Broken per T70653.
-        *
         * @group large
-        * @group Broken
         */
        function testCheckpointGzip() {
                $this->checkHasGzip();
@@ -615,3 +612,61 @@ class BackupTextPassTestModelHandler extends TextContentHandler {
        }
 
 }
+
+/**
+ * Tests for TextPassDumper that do not rely on the database
+ *
+ * (As the Database group is only detected at class level (not method level), we
+ * cannot bring this test case's tests into the above main test case.)
+ *
+ * @group Dump
+ * @covers TextPassDumper
+ */
+class TextPassDumperDatabaselessTest extends MediaWikiLangTestCase {
+       /**
+        * Ensures that setting the buffer size is effective.
+        *
+        * @dataProvider bufferSizeProvider
+        */
+       function testBufferSizeSetting( $expected, $size, $msg ) {
+               $dumper = new TextPassDumperAccessor( array( "--buffersize=" . $size ) );
+               $this->assertEquals( $expected, $dumper->getBufferSize(), $msg);
+       }
+
+       /**
+        * Ensures that setting the buffer size is effective.
+        *
+        * @dataProvider bufferSizeProvider
+        */
+       function bufferSizeProvider() {
+               // expected, bufferSize to initialize with, message
+               return array(
+                       array( 512 * 1024, 512 * 1024, "Setting 512KB is not effective" ),
+                       array( 8192, 8192, "Setting 8KB is not effective" ),
+                       array( 4096, 2048, "Could set buffer size below lower bound" )
+               );
+       }
+}
+
+/**
+ * Accessor for internal state of TextPassDumper
+ *
+ * Do not warrentless add getters here.
+ */
+class TextPassDumperAccessor extends TextPassDumper {
+       /**
+        * Gets the bufferSize.
+        *
+        * If bufferSize setting does not work correctly, testCheckpoint... tests
+        * fail and point in the wrong direction. To aid in troubleshooting when
+        * testCheckpoint... tests break at some point in the future, we test the
+        * bufferSize setting, hence need this accessor.
+        *
+        * (Yes, bufferSize is internal state of the TextPassDumper, but aiding
+        * debugging of testCheckpoint... in the future seems to be worth testing
+        * against it nonetheless.)
+        */
+       public function getBufferSize() {
+               return $this->bufferSize;
+       }
+}