*
* 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
* 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' );
'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',
'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',
* 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 '
),
"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",
)
}
/**
- * 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!
}
/**
- * 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!
* 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 );
$options['connectTimeout'] = 'default';
}
- $req = MWHttpRequest::factory( $url, $options );
+ $req = MWHttpRequest::factory( $url, $options, $caller );
$status = $req->execute();
$content = false;
*
* @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 );
}
/**
*
* @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 );
}
/**
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 );
if ( $this->noProxy ) {
$this->proxy = ''; // noProxy takes precedence
}
+
+ // Profile based on what's calling us
+ $this->profiler = $profiler;
+ $this->profileName = $caller;
}
/**
* 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' ) ) {
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 ' .
'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.' );
}
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 );
curl_close( $curlHandle );
+ if ( $this->profiler ) {
+ $this->profiler->scopedProfileOut( $profileSection );
+ }
+
$this->parseHeader();
$this->setStatus();
$result = array();
+ if ( $this->profiler ) {
+ $profileSection = $this->profiler->scopedProfileIn(
+ __METHOD__ . '-' . $this->profileName
+ );
+ }
do {
$reqCount++;
wfSuppressWarnings();
break;
}
} while ( true );
+ if ( $this->profiler ) {
+ $this->profiler->scopedProfileOut( $profileSection );
+ }
$this->setStatus();
*
* @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(
'/
\[\[
$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();
}
* @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();
}
*/
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 );
* 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() {
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
// 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;
'db' => 'ProfilerOutputDb',
'text' => 'ProfilerOutputText',
'udp' => 'ProfilerOutputUdp',
+ 'dump' => 'ProfilerOutputDump',
);
/** @var 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" );
/** @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 );
}
}
}
}
return implode( "\n", $out );
}
+
+ /**
+ * Retrieve raw data from xhprof
+ * @return array
+ */
+ public function getRawData() {
+ return $this->xhprof->getRawData();
+ }
}
--- /dev/null
+<?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 ) );
+ }
+}
+++ /dev/null
-<?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' ),
- );
- }
-}
+++ /dev/null
-<?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';
- }
-}
*/
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 ) {
return $pages;
}
- /* Methods */
-
/**
- * Gets group name
+ * Get group name
*
- * @return string Name of group
+ * @return string
*/
public function getGroup() {
return 'site';
*/
class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
- /* Protected Members */
-
protected $origin = self::ORIGIN_USER_SITEWIDE;
protected $targets = array( 'desktop', 'mobile' );
- /* Protected Methods */
-
/**
* @param ResourceLoaderContext $context
* @return array
return $pages;
}
- /* Methods */
-
/**
+ * Get group name
+ *
* @return string
*/
public function getGroup() {
*/
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' );
return $pages;
}
- /* Methods */
-
/**
+ * Get group name
+ *
* @return string
*/
public function getGroup() {
* 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.
* @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
return $content->serialize( $format );
}
- /* Methods */
-
/**
* @param ResourceLoaderContext $context
* @return string
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;
$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 );
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" );
--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
);
/**
* 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)
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 );
'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",
class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
}
-
-class ResourceLoaderWikiModuleTestModule extends ResourceLoaderWikiModule {
- // Override expected via PHPUnit mocks and stubs
- protected function getPages( ResourceLoaderContext $context ) {
- return array();
- }
-}
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' ) ) {
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__ .
. 'If possible, curl should be used instead. See http://php.net/curl.' );
}
- return new PhpHttpRequestTester( $url, $options );
+ return new PhpHttpRequestTester( $url, $options, $caller );
default:
}
}
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() )
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.
$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
$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
}
/**
- * Broken per T70653.
- *
* @group large
- * @group Broken
*/
function testCheckpointPlain() {
$this->checkpointHelper();
* 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();
}
}
+
+/**
+ * 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;
+ }
+}