parent::__construct();
// Register the given Config object as the bootstrap config service.
- $this->defineService( 'BootstrapConfig', function() use ( $config ) {
+ $this->defineService( 'BootstrapConfig', function () use ( $config ) {
return $config;
} );
}
}
$previousValue = self::$instance;
self::$instance = $store;
- return new ScopedCallback( function() use ( $previousValue ) {
+ return new ScopedCallback( function () use ( $previousValue ) {
self::$instance = $previousValue;
} );
}
use MediaWiki\MediaWikiServices;
return [
- 'DBLoadBalancerFactory' => function( MediaWikiServices $services ) {
+ 'DBLoadBalancerFactory' => function ( MediaWikiServices $services ) {
$mainConfig = $services->getMainConfig();
$lbConf = MWLBFactory::applyDefaultConfig(
return new $class( $lbConf );
},
- 'DBLoadBalancer' => function( MediaWikiServices $services ) {
+ 'DBLoadBalancer' => function ( MediaWikiServices $services ) {
// just return the default LB from the DBLoadBalancerFactory service
return $services->getDBLoadBalancerFactory()->getMainLB();
},
- 'SiteStore' => function( MediaWikiServices $services ) {
+ 'SiteStore' => function ( MediaWikiServices $services ) {
$rawSiteStore = new DBSiteStore( $services->getDBLoadBalancer() );
// TODO: replace wfGetCache with a CacheFactory service.
return new CachingSiteStore( $rawSiteStore, $cache );
},
- 'SiteLookup' => function( MediaWikiServices $services ) {
+ 'SiteLookup' => function ( MediaWikiServices $services ) {
$cacheFile = $services->getMainConfig()->get( 'SitesCacheFile' );
if ( $cacheFile !== false ) {
}
},
- 'ConfigFactory' => function( MediaWikiServices $services ) {
+ 'ConfigFactory' => function ( MediaWikiServices $services ) {
// Use the bootstrap config to initialize the ConfigFactory.
$registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
$factory = new ConfigFactory();
return $factory;
},
- 'MainConfig' => function( MediaWikiServices $services ) {
+ 'MainConfig' => function ( MediaWikiServices $services ) {
// Use the 'main' config from the ConfigFactory service.
return $services->getConfigFactory()->makeConfig( 'main' );
},
- 'InterwikiLookup' => function( MediaWikiServices $services ) {
+ 'InterwikiLookup' => function ( MediaWikiServices $services ) {
global $wgContLang; // TODO: manage $wgContLang as a service
$config = $services->getMainConfig();
return new ClassicInterwikiLookup(
);
},
- 'StatsdDataFactory' => function( MediaWikiServices $services ) {
+ 'StatsdDataFactory' => function ( MediaWikiServices $services ) {
return new BufferingStatsdDataFactory(
rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
);
},
- 'EventRelayerGroup' => function( MediaWikiServices $services ) {
+ 'EventRelayerGroup' => function ( MediaWikiServices $services ) {
return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
},
- 'SearchEngineFactory' => function( MediaWikiServices $services ) {
+ 'SearchEngineFactory' => function ( MediaWikiServices $services ) {
return new SearchEngineFactory( $services->getSearchEngineConfig() );
},
- 'SearchEngineConfig' => function( MediaWikiServices $services ) {
+ 'SearchEngineConfig' => function ( MediaWikiServices $services ) {
global $wgContLang;
return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
},
- 'SkinFactory' => function( MediaWikiServices $services ) {
+ 'SkinFactory' => function ( MediaWikiServices $services ) {
$factory = new SkinFactory();
$names = $services->getMainConfig()->get( 'ValidSkinNames' );
return $factory;
},
- 'WatchedItemStore' => function( MediaWikiServices $services ) {
+ 'WatchedItemStore' => function ( MediaWikiServices $services ) {
$store = new WatchedItemStore(
$services->getDBLoadBalancer(),
new HashBagOStuff( [ 'maxKeys' => 100 ] ),
return $store;
},
- 'WatchedItemQueryService' => function( MediaWikiServices $services ) {
+ 'WatchedItemQueryService' => function ( MediaWikiServices $services ) {
return new WatchedItemQueryService( $services->getDBLoadBalancer() );
},
- 'CryptRand' => function( MediaWikiServices $services ) {
+ 'CryptRand' => function ( MediaWikiServices $services ) {
$secretKey = $services->getMainConfig()->get( 'SecretKey' );
return new CryptRand(
[
// for a little more variance
'wfWikiID',
// If we have a secret key set then throw it into the state as well
- function() use ( $secretKey ) {
+ function () use ( $secretKey ) {
return $secretKey ?: '';
}
],
);
},
- 'CryptHKDF' => function( MediaWikiServices $services ) {
+ 'CryptHKDF' => function ( MediaWikiServices $services ) {
$config = $services->getMainConfig();
$secret = $config->get( 'HKDFSecret' ) ?: $config->get( 'SecretKey' );
);
},
- 'MediaHandlerFactory' => function( MediaWikiServices $services ) {
+ 'MediaHandlerFactory' => function ( MediaWikiServices $services ) {
return new MediaHandlerFactory(
$services->getMainConfig()->get( 'MediaHandlers' )
);
},
- 'MimeAnalyzer' => function( MediaWikiServices $services ) {
+ 'MimeAnalyzer' => function ( MediaWikiServices $services ) {
$logger = LoggerFactory::getInstance( 'Mime' );
$mainConfig = $services->getMainConfig();
$params = [
return new MimeMagic( $params );
},
- 'ProxyLookup' => function( MediaWikiServices $services ) {
+ 'ProxyLookup' => function ( MediaWikiServices $services ) {
$mainConfig = $services->getMainConfig();
return new ProxyLookup(
$mainConfig->get( 'SquidServers' ),
);
},
- 'Parser' => function( MediaWikiServices $services ) {
+ 'Parser' => function ( MediaWikiServices $services ) {
$conf = $services->getMainConfig()->get( 'ParserConf' );
return ObjectFactory::constructClassInstance( $conf['class'], [ $conf ] );
},
- 'LinkCache' => function( MediaWikiServices $services ) {
+ 'LinkCache' => function ( MediaWikiServices $services ) {
return new LinkCache(
$services->getTitleFormatter(),
$services->getMainWANObjectCache()
);
},
- 'LinkRendererFactory' => function( MediaWikiServices $services ) {
+ 'LinkRendererFactory' => function ( MediaWikiServices $services ) {
return new LinkRendererFactory(
$services->getTitleFormatter(),
$services->getLinkCache()
);
},
- 'LinkRenderer' => function( MediaWikiServices $services ) {
+ 'LinkRenderer' => function ( MediaWikiServices $services ) {
global $wgUser;
if ( defined( 'MW_NO_SESSION' ) ) {
}
},
- 'GenderCache' => function( MediaWikiServices $services ) {
+ 'GenderCache' => function ( MediaWikiServices $services ) {
return new GenderCache();
},
- '_MediaWikiTitleCodec' => function( MediaWikiServices $services ) {
+ '_MediaWikiTitleCodec' => function ( MediaWikiServices $services ) {
global $wgContLang;
return new MediaWikiTitleCodec(
);
},
- 'TitleFormatter' => function( MediaWikiServices $services ) {
+ 'TitleFormatter' => function ( MediaWikiServices $services ) {
return $services->getService( '_MediaWikiTitleCodec' );
},
- 'TitleParser' => function( MediaWikiServices $services ) {
+ 'TitleParser' => function ( MediaWikiServices $services ) {
return $services->getService( '_MediaWikiTitleCodec' );
},
- 'MainObjectStash' => function( MediaWikiServices $services ) {
+ 'MainObjectStash' => function ( MediaWikiServices $services ) {
$mainConfig = $services->getMainConfig();
$id = $mainConfig->get( 'MainStash' );
return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] );
},
- 'MainWANObjectCache' => function( MediaWikiServices $services ) {
+ 'MainWANObjectCache' => function ( MediaWikiServices $services ) {
$mainConfig = $services->getMainConfig();
$id = $mainConfig->get( 'MainWANCache' );
return \ObjectCache::newWANCacheFromParams( $params );
},
- 'LocalServerObjectCache' => function( MediaWikiServices $services ) {
+ 'LocalServerObjectCache' => function ( MediaWikiServices $services ) {
$mainConfig = $services->getMainConfig();
if ( function_exists( 'apc_fetch' ) ) {
return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] );
},
- 'VirtualRESTServiceClient' => function( MediaWikiServices $services ) {
+ 'VirtualRESTServiceClient' => function ( MediaWikiServices $services ) {
$config = $services->getMainConfig()->get( 'VirtualRestConfig' );
$vrsClient = new VirtualRESTServiceClient( new MultiHttpClient( [] ) );
return $vrsClient;
},
- 'ConfiguredReadOnlyMode' => function( MediaWikiServices $services ) {
+ 'ConfiguredReadOnlyMode' => function ( MediaWikiServices $services ) {
return new ConfiguredReadOnlyMode( $services->getMainConfig() );
},
- 'ReadOnlyMode' => function( MediaWikiServices $services ) {
+ 'ReadOnlyMode' => function ( MediaWikiServices $services ) {
return new ReadOnlyMode(
$services->getConfiguredReadOnlyMode(),
$services->getDBLoadBalancer()
$allFields = get_object_vars( $row );
$rcKeys = array_filter(
array_keys( $allFields ),
- function( $key ) {
+ function ( $key ) {
return substr( $key, 0, 3 ) === 'rc_';
}
);
}
$previousValue = $this->deferredUpdatesAddCallableUpdateCallback;
$this->deferredUpdatesAddCallableUpdateCallback = $callback;
- return new ScopedCallback( function() use ( $previousValue ) {
+ return new ScopedCallback( function () use ( $previousValue ) {
$this->deferredUpdatesAddCallableUpdateCallback = $previousValue;
} );
}
}
$previousValue = $this->revisionGetTimestampFromIdCallback;
$this->revisionGetTimestampFromIdCallback = $callback;
- return new ScopedCallback( function() use ( $previousValue ) {
+ return new ScopedCallback( function () use ( $previousValue ) {
$this->revisionGetTimestampFromIdCallback = $previousValue;
} );
}
// Calls DeferredUpdates::addCallableUpdate in normal operation
call_user_func(
$this->deferredUpdatesAddCallableUpdateCallback,
- function() use ( $job ) {
+ function () use ( $job ) {
$job->run();
}
);
<?php
/**
- * Copyright © 2016 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2016 Wikimedia Foundation and contributors
*
* 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
<?php
/**
- * Copyright © 2016 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2016 Wikimedia Foundation and contributors
*
* 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
<?php
/**
- * Copyright © 2016 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2016 Wikimedia Foundation and contributors
*
* 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
/**
* Created on Jan 29, 2015
*
- * Copyright © 2015 Brad Jorsch bjorsch@wikimedia.org
+ * Copyright © 2015 Wikimedia Foundation and contributors
*
* 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
<?php
/**
- * Copyright © 2016 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2016 Wikimedia Foundation and contributors
*
* 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
*
* Created on Aug 29, 2014
*
- * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2014 Wikimedia Foundation and contributors
*
* 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
*
* Created on Dec 22, 2014
*
- * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2014 Wikimedia Foundation and contributors
*
* 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
<?php
/**
- * Copyright © 2016 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2016 Wikimedia Foundation and contributors
*
* 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
*
* Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
* Copyright © 2008 Brion Vibber <brion@wikimedia.org>
- * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2014 Wikimedia Foundation and contributors
*
* 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
/**
* Created on Oct 3, 2014
*
- * Copyright © 2014 Brad Jorsch "bjorsch@wikimedia.org"
+ * Copyright © 2014 Wikimedia Foundation and contributors
*
* Heavily based on ApiQueryDeletedrevs,
* Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
/**
* Created on Sep 27, 2015
*
- * Copyright © 2015 Brad Jorsch "bjorsch@wikimedia.org"
+ * Copyright © 2015 Wikimedia Foundation and contributors
*
* 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
<?php
/**
- * Copyright © 2016 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2016 Wikimedia Foundation and contributors
*
* 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
*
* Created on Aug 19, 2014
*
- * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2014 Wikimedia Foundation and contributors
*
* 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
*
* Created on Nov 14, 2013
*
- * Copyright © 2013 Brad Jorsch
+ * Copyright © 2013 Wikimedia Foundation and contributors
*
* 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
/**
* Created on Oct 3, 2014
*
- * Copyright © 2014 Brad Jorsch "bjorsch@wikimedia.org"
+ * Copyright © 2014 Wikimedia Foundation and contributors
*
* Heavily based on ApiQueryDeletedrevs,
* Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
if ( $this->fld_watched ) {
foreach ( $timestamps as $namespaceId => $dbKeys ) {
$this->watched[$namespaceId] = array_map(
- function( $x ) {
+ function ( $x ) {
return $x !== false;
},
$dbKeys
$timestamps[$row->page_namespace][$row->page_title] = $revTimestamp - $age;
}
$titlesWithThresholds = array_map(
- function( LinkTarget $target ) use ( $timestamps ) {
+ function ( LinkTarget $target ) use ( $timestamps ) {
return [
$target, $timestamps[$target->getNamespace()][$target->getDBkey()]
];
$titlesWithThresholds = array_merge(
$titlesWithThresholds,
array_map(
- function( LinkTarget $target ) {
+ function ( LinkTarget $target ) {
return [ $target, null ];
},
$this->missing
/**
* Created on January 21, 2013
*
- * Copyright © 2013 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2013 Wikimedia Foundation and contributors
*
* 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
*
* @file
* @since 1.21
- * @author Brad Jorsch
*/
/**
/**
* Created on December 31, 2012
*
- * Copyright © 2012 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2012 Wikimedia Foundation and contributors
*
* 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
*
* @file
* @since 1.21
- * @author Brad Jorsch
*/
/**
$titles = $searchEngine->extractTitles( $searchEngine->completionSearchWithVariants( $search ) );
if ( $resultPageSet ) {
- $resultPageSet->setRedirectMergePolicy( function( array $current, array $new ) {
+ $resultPageSet->setRedirectMergePolicy( function ( array $current, array $new ) {
if ( !isset( $current['index'] ) || $new['index'] < $current['index'] ) {
$current['index'] = $new['index'];
}
*
* Created on August 8, 2014
*
- * Copyright © 2014 Brad Jorsch bjorsch@wikimedia.org
+ * Copyright © 2014 Wikimedia Foundation and contributors
*
* 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
}
if ( isset( $this->prop['groupmemberships'] ) ) {
- $data[$key]['groupmemberships'] = array_map( function( $ugm ) {
+ $data[$key]['groupmemberships'] = array_map( function ( $ugm ) {
return [
'group' => $ugm->getGroup(),
'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
<?php
/**
- * Copyright © 2016 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2016 Wikimedia Foundation and contributors
*
* 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
<?php
/**
- * Copyright © 2016 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2016 Wikimedia Foundation and contributors
*
* 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
/**
* Created on Jun 25, 2013
*
- * Copyright © 2013 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2013 Wikimedia Foundation and contributors
*
* 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
/**
* Created on Feb 25, 2015
*
- * Copyright © 2015 Brad Jorsch "bjorsch@wikimedia.org"
+ * Copyright © 2015 Wikimedia Foundation and contributors
*
* 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
*
* Created on Jun 18, 2012
*
- * Copyright © 2012 Brad Jorsch
+ * Copyright © 2012 Wikimedia Foundation and contributors
*
* 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
}
$attribs = $data['attribs'];
unset( $data['attribs'] );
- $attribs = wfArrayFilterByKey( $attribs, function( $key ) {
+ $attribs = wfArrayFilterByKey( $attribs, function ( $key ) {
return $key === 'class' || Sanitizer::isReservedDataAttribute( $key );
} );
*
* @see \MediaWiki\Logger\LoggerFactory
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
*/
class LegacyLogger extends AbstractLogger {
*
* @see \MediaWiki\Logger\LoggerFactory
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
*/
class LegacySpi implements Spi {
*
* @see \MediaWiki\Logger\Spi
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
*/
class LoggerFactory {
*
* @see https://github.com/Seldaek/monolog
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
*/
class MonologSpi implements Spi {
*
* @see \MediaWiki\Logger\LoggerFactory
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
*/
class NullSpi implements Spi {
*
* @see \MediaWiki\Logger\LoggerFactory
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
*/
interface Spi {
* delegating the formatting to \MediaWiki\Logger\LegacyLogger.
*
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2013 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2013 Wikimedia Foundation and contributors
* @see \MediaWiki\Logger\LegacyLogger
*/
class LegacyFormatter extends NormalizerFormatter {
* replacement for \Monolog\Handler\StreamHandler.
*
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2013 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2013 Wikimedia Foundation and contributors
*/
class LegacyHandler extends AbstractProcessingHandler {
* will be used to redact the trace information.
*
* @since 1.26
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2015 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2015 Wikimedia Foundation and contributors
*/
class LineFormatter extends MonologLineFormatter {
* default Logstash syslog input handler.
*
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2015 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2015 Wikimedia Foundation and contributors
*/
class SyslogHandler extends SyslogUdpHandler {
* wiki / request ID, and MediaWiki version.
*
* @since 1.25
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2013 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2013 Wikimedia Foundation and contributors
*/
class WikiProcessor {
* @return bool|string
*/
public function generateTextDiffBody( $otext, $ntext ) {
- $diff = function() use ( $otext, $ntext ) {
+ $diff = function () use ( $otext, $ntext ) {
$time = microtime( true );
$result = $this->textDiff( $otext, $ntext );
* @param Status $status
* @throws FatalError
*/
- $error = function( $status ) {
+ $error = function ( $status ) {
throw new FatalError( $status->getWikiText() );
};
* @return Closure
*/
protected function getDBFactory() {
- return function( $index ) {
+ return function ( $index ) {
return wfGetLB( $this->wiki )->getConnectionRef( $index, [], $this->wiki );
};
}
* @return Closure
*/
protected function getDBFactory() {
- return function( $index ) {
+ return function ( $index ) {
return wfGetDB( $index );
};
}
if ( $upgrade ) {
$this->upgrading = true;
// Defer updates unless in auto-commit CLI mode
- DeferredUpdates::addCallableUpdate( function() {
+ DeferredUpdates::addCallableUpdate( function () {
$this->upgrading = false; // avoid duplicate updates
try {
$this->upgradeRow();
// And it's not needed anymore after infusing, so we don't put it in JS config at all.
$this->setAttributes( [ 'data-mw-modules' => implode( ',', $this->modules ) ] );
}
- $this->registerConfigCallback( function( &$config ) {
+ $this->registerConfigCallback( function ( &$config ) {
if ( $this->hideIf !== null ) {
$config['hideIf'] = $this->hideIf;
}
$usersArray = explode( "\n", $request->getText( $this->mName ) );
// Remove empty lines
- $usersArray = array_values( array_filter( $usersArray, function( $username ) {
+ $usersArray = array_values( array_filter( $usersArray, function ( $username ) {
return trim( $username ) !== '';
} ) );
return $usersArray;
$services = \MediaWiki\MediaWikiServices::getInstance();
$connection = $status->value;
- $services->redefineService( 'DBLoadBalancerFactory', function() use ( $connection ) {
+ $services->redefineService( 'DBLoadBalancerFactory', function () use ( $connection ) {
return LBFactorySingle::newFromConnection( $connection );
} );
}
// make sure we use the installer config as the main config
$configRegistry = $baseConfig->get( 'ConfigRegistry' );
- $configRegistry['main'] = function() use ( $installerConfig ) {
+ $configRegistry['main'] = function () use ( $installerConfig ) {
return $installerConfig;
};
// Re-insert comments
$pattern = '/' . CSSMin::PLACEHOLDER . '(\d+)x/';
- $source = preg_replace_callback( $pattern, function( $match ) use ( &$comments ) {
+ $source = preg_replace_callback( $pattern, function ( $match ) use ( &$comments ) {
return $comments[ $match[1] ];
}, $source );
if ( $this->liveRing === null || $this->ejectionNextExpiry <= $now ) {
$this->ejectionExpiries = array_filter(
$this->ejectionExpiries,
- function( $expiry ) use ( $now ) {
+ function ( $expiry ) use ( $now ) {
return ( $expiry > $now );
}
);
/**
* Construct objects from configuration instructions.
*
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
*/
class ObjectFactory {
* <https://github.com/phacility/xhprof>. XHProf can be installed as a PECL
* package for use with PHP5 (Zend PHP) and is built-in to HHVM 3.3.0.
*
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
* @since 1.28
*/
class XhprofData {
if ( $this->asyncWrites && !$this->hasVolatileSources( $ops ) ) {
// Bind $scopeLock to the callback to preserve locks
DeferredUpdates::addCallableUpdate(
- function() use ( $backend, $realOps, $opts, $scopeLock, $relevantPaths ) {
+ function () use ( $backend, $realOps, $opts, $scopeLock, $relevantPaths ) {
wfDebugLog( 'FileOperationReplication',
"'{$backend->getName()}' async replication; paths: " .
FormatJson::encode( $relevantPaths ) );
$realOps = $this->substOpBatchPaths( $ops, $backend );
if ( $this->asyncWrites && !$this->hasVolatileSources( $ops ) ) {
DeferredUpdates::addCallableUpdate(
- function() use ( $backend, $realOps ) {
+ function () use ( $backend, $realOps ) {
$backend->doQuickOperations( $realOps );
}
);
$realParams = $this->substOpPaths( $params, $backend );
if ( $this->asyncWrites ) {
DeferredUpdates::addCallableUpdate(
- function() use ( $backend, $method, $realParams ) {
+ function () use ( $backend, $method, $realParams ) {
$backend->$method( $realParams );
}
);
$lSince = microtime( true ); // lock timestamp
- return new ScopedCallback( function() use ( $key, $lSince, $expiry ) {
+ return new ScopedCallback( function () use ( $key, $lSince, $expiry ) {
$latency = .050; // latency skew (err towards keeping lock present)
$age = ( microtime( true ) - $lSince + $latency );
if ( ( $age + $latency ) >= $expiry ) {
}
/**
- * @param string $name Table name
- * @return array (DB name, schema name, table prefix, table name)
+ * Get the table components needed for a query given the currently selected database
+ *
+ * @param string $name Table name in the form of db.schema.table, db.table, or table
+ * @return array (DB name or "" for default, schema name, table prefix, table name)
*/
protected function qualifiedTableComponents( $name ) {
# We reverse the explode so that database.table and table both output the correct table.
}
public function tableExists( $table, $fname = __METHOD__ ) {
- $table = $this->tableName( $table, 'raw' );
- if ( isset( $this->mSessionTempTables[$table] ) ) {
- return true; // already known to exist and won't show in SHOW TABLES anyway
- }
-
// Split database and table into proper variables as Database::tableName() returns
// shared tables prefixed with their database, which do not work in SHOW TABLES statements
- list( $database, $schema, $prefix, $table ) = $this->qualifiedTableComponents( $table );
+ list( $database, , $prefix, $table ) = $this->qualifiedTableComponents( $table );
+ $tableName = "{$prefix}{$table}";
- $table = $prefix . $table;
+ if ( isset( $this->mSessionTempTables[$tableName] ) ) {
+ return true; // already known to exist and won't show in SHOW TABLES anyway
+ }
// We can't use buildLike() here, because it specifies an escape character
// other than the backslash, which is the only one supported by SHOW TABLES
- $encLike = $this->escapeLikeInternal( $table, '\\' );
+ $encLike = $this->escapeLikeInternal( $tableName, '\\' );
- // If the database has been specified (such as for shared tables), add a FROM $database clause
+ // If the database has been specified (such as for shared tables), use "FROM"
if ( $database !== '' ) {
- $database = $this->addIdentifierQuotes( $database );
- $query = "SHOW TABLES FROM $database LIKE '$encLike'";
+ $encDatabase = $this->addIdentifierQuotes( $database );
+ $query = "SHOW TABLES FROM $encDatabase LIKE '$encLike'";
} else {
$query = "SHOW TABLES LIKE '$encLike'";
}
}
class_alias( DatabaseSqlite::class, 'DatabaseSqlite' );
-
}
class_alias( FakeResultWrapper::class, 'FakeResultWrapper' );
-
}
class_alias( DBTransactionError::class, 'DBTransactionError' );
-
$prefix
);
- $this->forEachLB( function( ILoadBalancer $lb ) use ( $prefix ) {
+ $this->forEachLB( function ( ILoadBalancer $lb ) use ( $prefix ) {
$lb->setDomainPrefix( $prefix );
} );
}
$samplingRates = [ '*' => $sampleRate ];
}
if ( $samplingRates ) {
- array_walk( $data, function( $item ) use ( $samplingRates ) {
+ array_walk( $data, function ( $item ) use ( $samplingRates ) {
/** @var $item StatsdData */
foreach ( $samplingRates as $pattern => $rate ) {
if ( fnmatch( $pattern, $item->getKey(), FNM_NOESCAPE ) ) {
* @return array (prefix,VirtualRESTService) or (null,null) if none found
*/
public function getMountAndService( $path ) {
- $cmpFunc = function( $a, $b ) {
+ $cmpFunc = function ( $a, $b ) {
$al = substr_count( $a, '/' );
$bl = substr_count( $b, '/' );
if ( $al === $bl ) {
}
// Function to get IDs that won't collide with keys in $armoredIndexMap
- $idFunc = function() use ( &$curUniqueId ) {
+ $idFunc = function () use ( &$curUniqueId ) {
return $curUniqueId++;
};
$parts = explode( '/', $subPage, 2 );
if ( $parts !== 2 ) {
$slot = $parts[0];
- if ( $slot === 'main' or $slot === '' ) {
+ if ( $slot === 'main' || $slot === '' ) {
return true;
}
}
$oldmetadata =& $params['oldmetadata'];
// unset old metadata entry to ensure metadata goes at the end of the params array
unset( $params['oldmetadata'] );
- $params['oldmetadata'] = array_map( function( $index ) use ( $params, $oldmetadata ) {
+ $params['oldmetadata'] = array_map( function ( $index ) use ( $params, $oldmetadata ) {
$result = [ 'group' => $params['4:array:oldgroups'][$index] ];
if ( isset( $oldmetadata[$index] ) ) {
$result += $oldmetadata[$index];
$newmetadata =& $params['newmetadata'];
// unset old metadata entry to ensure metadata goes at the end of the params array
unset( $params['newmetadata'] );
- $params['newmetadata'] = array_map( function( $index ) use ( $params, $newmetadata ) {
+ $params['newmetadata'] = array_map( function ( $index ) use ( $params, $newmetadata ) {
$result = [ 'group' => $params['5:array:newgroups'][$index] ];
if ( isset( $newmetadata[$index] ) ) {
$result += $newmetadata[$index];
HTMLFileCache::clearFileCache( $title );
$revid = $revision ? $revision->getId() : null;
- DeferredUpdates::addCallableUpdate( function() use ( $title, $revid ) {
+ DeferredUpdates::addCallableUpdate( function () use ( $title, $revid ) {
InfoAction::invalidateCache( $title, $revid );
} );
}
$e = new Exception;
$this->mInParse = $e->getTraceAsString();
- $recursiveCheck = new ScopedCallback( function() {
+ $recursiveCheck = new ScopedCallback( function () {
$this->mInParse = false;
} );
*/
protected function getFunctionReport() {
$data = $this->getFunctionStats();
- usort( $data, function( $a, $b ) {
+ usort( $data, function ( $a, $b ) {
if ( $a['real'] === $b['real'] ) {
return 0;
}
* a drop-in replacement for Xhprof. Just change the XHPROF_FLAGS_* constants
* to TIDEWAYS_FLAGS_*.
*
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
* @ingroup Profiler
* @see Xhprof
* @see https://php.net/xhprof
*/
protected function getFunctionReport() {
$data = $this->getFunctionStats();
- usort( $data, function( $a, $b ) {
+ usort( $data, function ( $a, $b ) {
if ( $a['real'] === $b['real'] ) {
return 0;
}
protected function extractExtensionMessagesFiles( $dir, array $info ) {
if ( isset( $info['ExtensionMessagesFiles'] ) ) {
- $this->globals["wgExtensionMessagesFiles"] += array_map( function( $file ) use ( $dir ) {
+ $this->globals["wgExtensionMessagesFiles"] += array_map( function ( $file ) use ( $dir ) {
return "$dir/$file";
}, $info['ExtensionMessagesFiles'] );
}
protected function processAutoLoader( $dir, array $info ) {
if ( isset( $info['AutoloadClasses'] ) ) {
// Make paths absolute, relative to the JSON file
- return array_map( function( $file ) use ( $dir ) {
+ return array_map( function ( $file ) use ( $dir ) {
return "$dir/$file";
}, $info['AutoloadClasses'] );
} else {
* http://www.gnu.org/copyleft/gpl.html
*
* @file
- * @author Brad Jorsch
*/
/**
if ( $namespaces ) {
// Filter namespaces to only keep valid ones
$validNs = $this->searchableNamespaces();
- $namespaces = array_filter( $namespaces, function( $ns ) use( $validNs ) {
+ $namespaces = array_filter( $namespaces, function ( $ns ) use( $validNs ) {
return $ns < 0 || isset( $validNs[$ns] );
} );
} else {
}
}
- $ns = array_map( function( $space ) {
+ $ns = array_map( function ( $space ) {
return $space == NS_MEDIA ? NS_FILE : $space;
}, $ns );
* @return Title[]
*/
public function extractTitles( SearchSuggestionSet $completionResults ) {
- return $completionResults->map( function( SearchSuggestion $sugg ) {
+ return $completionResults->map( function ( SearchSuggestion $sugg ) {
return $sugg->getSuggestedTitle();
} );
}
protected function processCompletionResults( $search, SearchSuggestionSet $suggestions ) {
$search = trim( $search );
// preload the titles with LinkBatch
- $titles = $suggestions->map( function( SearchSuggestion $sugg ) {
+ $titles = $suggestions->map( function ( SearchSuggestion $sugg ) {
return $sugg->getSuggestedTitle();
} );
$lb = new LinkBatch( $titles );
$lb->setCaller( __METHOD__ );
$lb->execute();
- $results = $suggestions->map( function( SearchSuggestion $sugg ) {
+ $results = $suggestions->map( function ( SearchSuggestion $sugg ) {
return $sugg->getSuggestedTitle()->getPrefixedText();
} );
*/
public static function fromTitles( array $titles ) {
$score = count( $titles );
- $suggestions = array_map( function( $title ) use ( &$score ) {
+ $suggestions = array_map( function ( $title ) use ( &$score ) {
return SearchSuggestion::fromTitle( $score--, $title );
}, $titles );
return new SearchSuggestionSet( $suggestions );
*/
public static function fromStrings( array $titles ) {
$score = count( $titles );
- $suggestions = array_map( function( $title ) use ( &$score ) {
+ $suggestions = array_map( function ( $title ) use ( &$score ) {
return SearchSuggestion::fromText( $score--, $title );
}, $titles );
return new SearchSuggestionSet( $suggestions );
* Subclass of UnexpectedValueException that can be annotated with additional
* data for debug logging.
*
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2016 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2016 Wikimedia Foundation and contributors
* @since 1.27
*/
class MetadataMergeException extends UnexpectedValueException {
*
* Created on Sep 08, 2014
*
- * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2014 Wikimedia Foundation and contributors
*
* 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
*
* Created on Sep 08, 2014
*
- * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright © 2014 Wikimedia Foundation and contributors
*
* 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
$searchEngine->setLimitOffset( $limit, $offset );
$searchEngine->setNamespaces( [] );
$result = $searchEngine->defaultPrefixSearch( $search );
- return array_map( function( Title $t ) {
+ return array_map( function ( Title $t ) {
return $t->getPrefixedText();
}, $result );
}
$showGrants
),
'default' => array_map(
- function( $g ) {
+ function ( $g ) {
return "grant-$g";
},
$this->botPassword->getGrants()
'tooltips' => array_combine(
array_map( 'MWGrants::getGrantsLink', $showGrants ),
array_map(
- function( $rights ) use ( $lang ) {
+ function ( $rights ) use ( $lang ) {
return $lang->semicolonList( array_map( 'User::getRightDescription', $rights ) );
},
array_intersect_key( MWGrants::getRightsByGrant(), array_flip( $showGrants ) )
)
),
'force-options-on' => array_map(
- function( $g ) {
+ function ( $g ) {
return "grant-$g";
},
MWGrants::getHiddenGrants()
'reason' => [
'type' => 'text',
'name' => 'reason',
- 'validation-callback' => function( $reason ) {
+ 'validation-callback' => function ( $reason ) {
$match = EditPage::matchSummarySpamRegex( $reason );
if ( $match ) {
return $this->msg( 'spamprotectionmatch', $match )->parse();
$permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $user );
if ( count( $permErrors ) ) {
// Auto-block user's IP if the account was "hard" blocked
- DeferredUpdates::addCallableUpdate( function() use ( $user ) {
+ DeferredUpdates::addCallableUpdate( function () use ( $user ) {
$user->spreadAnyEditBlock();
} );
throw new PermissionsError( 'move', $permErrors );
* @since 1.21
* @file
* @ingroup SpecialPage
- * @author Brad Jorsch
*/
/**
// UNLESS the user can only add this group (not remove it) and the expiry time
// is being brought forward (T156784)
$add = array_filter( $add,
- function( $group ) use ( $groups, $groupExpiries, $removable, $ugms ) {
+ function ( $group ) use ( $groups, $groupExpiries, $removable, $ugms ) {
if ( isset( $groupExpiries[$group] ) &&
!in_array( $group, $removable ) &&
isset( $ugms[$group] ) &&
// make sure $oldUGMs and $newUGMs are in the same order, and serialise
// each UGM object to a simplified array
- $oldUGMs = array_map( function( $group ) use ( $oldUGMs ) {
+ $oldUGMs = array_map( function ( $group ) use ( $oldUGMs ) {
return isset( $oldUGMs[$group] ) ?
self::serialiseUgmForLog( $oldUGMs[$group] ) :
null;
}, $oldGroups );
- $newUGMs = array_map( function( $group ) use ( $newUGMs ) {
+ $newUGMs = array_map( function ( $group ) use ( $newUGMs ) {
return isset( $newUGMs[$group] ) ?
self::serialiseUgmForLog( $newUGMs[$group] ) :
null;
// in their proper section
continue;
}
- $authors = array_map( function( $arr ) {
+ $authors = array_map( function ( $arr ) {
// If a homepage is set, link to it
if ( isset( $arr['homepage'] ) ) {
return "[{$arr['homepage']} {$arr['name']}]";
$bad = array_uintersect_assoc(
$this->allowedHtmlElements,
BalanceSets::$unsupportedSet[BalanceSets::HTML_NAMESPACE],
- function( $a, $b ) {
+ function ( $a, $b ) {
// Ignore the values (just intersect the keys) by saying
// all values are equal to each other.
return 0;
$cache->delete( $key, 1 );
} else {
wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle(
- function() use ( $cache, $key ) {
+ function () use ( $cache, $key ) {
$cache->delete( $key );
},
__METHOD__
}
// Try to update the DB post-send and only if needed...
- DeferredUpdates::addCallableUpdate( function() use ( $title, $oldid ) {
+ DeferredUpdates::addCallableUpdate( function () use ( $title, $oldid ) {
if ( !$this->getNewtalk() ) {
return; // no notifications to clear
}
$this->reader = $reader;
$this->writer = $writer;
$this->generator = $generator;
- $this->output = function() {
+ $this->output = function () {
}; // nop
}
$this->addArg( 'path', 'Path to extension.json/skin.json file.', true );
}
public function execute() {
- $validator = new ExtensionJsonValidator( function( $msg ) {
+ $validator = new ExtensionJsonValidator( function ( $msg ) {
$this->error( $msg, 1 );
} );
$validator->checkDependencies();
</properties>
</rule>
<file>.</file>
- <arg name="encoding" value="utf8"/>
+ <arg name="encoding" value="UTF-8"/>
<arg name="extensions" value="php,php5,inc,sample"/>
<rule ref="Generic.Files.LineLength">
<exclude-pattern>*/languages/messages/Messages*.php</exclude-pattern>
* @cfg {string} [view='default'] Name of the display group this group
* is a part of.
* @cfg {string} [title] Group title
+ * @cfg {boolean} [hidden] This group is hidden from the regular menu views
* @cfg {string} [separator='|'] Value separator for 'string_options' groups
* @cfg {boolean} [active] Group is active
* @cfg {boolean} [fullCoverage] This filters in this group collectively cover all results
this.type = config.type || 'send_unselected_if_any';
this.view = config.view || 'default';
this.title = config.title || name;
+ this.hidden = !!config.hidden;
this.separator = config.separator || '|';
this.labelPrefixKey = config.labelPrefixKey;
return item.getParamName();
} )
).join( this.getSeparator() );
+ } else if ( this.getType() === 'single_option' ) {
+ // For this group, the parameter is the group name,
+ // and a single item can be selected, or none at all
+ // The item also must be recognized or none is set as
+ // default
+ model.defaultParams[ this.getName() ] = this.getItemByParamName( groupDefault ) ? groupDefault : '';
}
};
/**
* Respond to filterItem update event
*
+ * @param {mw.rcfilters.dm.FilterItem} item Updated filter item
* @fires update
*/
- mw.rcfilters.dm.FilterGroup.prototype.onFilterItemUpdate = function () {
+ mw.rcfilters.dm.FilterGroup.prototype.onFilterItemUpdate = function ( item ) {
// Update state
- var active = this.areAnySelected();
+ var active = this.areAnySelected(),
+ itemName = item && item.getName();
+
+ if ( item.isSelected() && this.getType() === 'single_option' ) {
+ // Change the selection to only be the newly selected item
+ this.getItems().forEach( function ( filterItem ) {
+ if ( filterItem.getName() !== itemName ) {
+ filterItem.toggleSelected( false );
+ }
+ } );
+ }
if ( this.active !== active ) {
this.active = active;
return this.active;
};
+ /**
+ * Get group hidden state
+ *
+ * @return {boolean} Hidden state
+ */
+ mw.rcfilters.dm.FilterGroup.prototype.isHidden = function () {
+ return this.hidden;
+ };
+
/**
* Get group name
*
areAnySelected = false,
buildFromCurrentState = !filterRepresentation,
result = {},
- filterParamNames = {};
+ model = this,
+ filterParamNames = {},
+ getSelectedParameter = function ( filters ) {
+ var item,
+ selected = [];
+
+ // Find if any are selected
+ $.each( filters, function ( name, value ) {
+ if ( value ) {
+ selected.push( name );
+ }
+ } );
+
+ item = model.getItemByName( selected[ 0 ] );
+ return ( item && item.getParamName() ) || '';
+ };
filterRepresentation = filterRepresentation || {};
result[ this.getName() ] = ( values.length === Object.keys( filterRepresentation ).length ) ?
'all' : values.join( this.getSeparator() );
+ } else if ( this.getType() === 'single_option' ) {
+ result[ this.getName() ] = getSelectedParameter( filterRepresentation );
}
return result;
// Otherwise, the filter is selected only if it appears in the parameter values
paramValues.indexOf( filterItem.getParamName() ) > -1;
} );
+ } else if ( this.getType() === 'single_option' ) {
+ // There is parameter that fits a single filter, or none at all
+ this.getItems().forEach( function ( filterItem ) {
+ result[ filterItem.getName() ] = filterItem.getParamName() === paramRepresentation;
+ } );
}
// Go over result and make sure all filters are represented.
return result;
};
+ /**
+ * Get item by its filter name
+ *
+ * @param {string} filterName Filter name
+ * @return {mw.rcfilters.dm.FilterItem} Filter item
+ */
+ mw.rcfilters.dm.FilterGroup.prototype.getItemByName = function ( filterName ) {
+ return this.getItems().filter( function ( item ) {
+ return item.getName() === filterName;
+ } )[ 0 ];
+ };
+
/**
* Get item by its parameter name
*
// Collect views
allViews = {
'default': {
- label: mw.msg( 'rcfilters-filterlist-title' ),
+ title: mw.msg( 'rcfilters-filterlist-title' ),
groups: filterGroups
}
};
viewData.groups.forEach( function ( groupData ) {
var group = groupData.name;
- model.groups[ group ] = new mw.rcfilters.dm.FilterGroup(
- group,
- $.extend( true, {}, groupData, { view: viewName } )
- );
+ if ( !model.groups[ group ] ) {
+ model.groups[ group ] = new mw.rcfilters.dm.FilterGroup(
+ group,
+ $.extend( true, {}, groupData, { view: viewName } )
+ );
+ }
model.groups[ group ].initializeFilters( groupData.filters, groupData.default );
items = items.concat( model.groups[ group ].getItems() );
groupModel.getItems().forEach( function ( filterItem ) {
model.parameterMap[ filterItem.getParamName() ] = filterItem;
} );
- } else if ( groupModel.getType() === 'string_options' ) {
+ } else if (
+ groupModel.getType() === 'string_options' ||
+ groupModel.getType() === 'single_option'
+ ) {
// Group
model.parameterMap[ groupModel.getName() ] = groupModel;
}
/**
* Get the label for the current view
*
+ * @param {string} viewName View name
* @return {string} Label for the current view
*/
- mw.rcfilters.dm.FiltersViewModel.prototype.getCurrentViewLabel = function () {
- return this.views[ this.getCurrentView() ].title;
+ mw.rcfilters.dm.FiltersViewModel.prototype.getViewTitle = function ( viewName ) {
+ viewName = viewName || this.getCurrentView();
+
+ return this.views[ viewName ] && this.views[ viewName ].title;
};
/**
mw.rcfilters.ui.FilterMenuHeaderWidget.prototype.onModelUpdate = function () {
var currentView = this.model.getCurrentView();
- this.setLabel( this.model.getCurrentViewLabel() );
+ this.setLabel( this.model.getViewTitle( currentView ) );
this.invertNamespacesButton.toggle( currentView === 'namespaces' );
this.backButton.toggle( currentView !== 'default' );
this.$element.find( '.mw-tagfilter-label' ).closest( 'tr' ).detach();
}
+ if ( !this.$element.find( '.mw-recentchanges-table tr' ).length ) {
+ this.$element.find( 'hr' ).detach();
+ }
+
// Collapse legend
// see resources/src/mediawiki.special/mediawiki.special.changelist.legend.js
this.$element.find( '.mw-changeslist-legend' )
// Count groups per view
$.each( groups, function ( groupName, groupModel ) {
- viewGroupCount[ groupModel.getView() ] = viewGroupCount[ groupModel.getView() ] || 0;
- viewGroupCount[ groupModel.getView() ]++;
+ if ( !groupModel.isHidden() ) {
+ viewGroupCount[ groupModel.getView() ] = viewGroupCount[ groupModel.getView() ] || 0;
+ viewGroupCount[ groupModel.getView() ]++;
+ }
} );
$.each( groups, function ( groupName, groupModel ) {
var currentItems = [],
view = groupModel.getView();
- if ( viewGroupCount[ view ] > 1 ) {
- // Only add a section header if there is more than
- // one group
- currentItems.push(
- // Group section
- new mw.rcfilters.ui.FilterMenuSectionOptionWidget(
- widget.controller,
- groupModel,
- {
- $overlay: widget.$overlay
- }
- )
- );
- }
+ if ( !groupModel.isHidden() ) {
+ if ( viewGroupCount[ view ] > 1 ) {
+ // Only add a section header if there is more than
+ // one group
+ currentItems.push(
+ // Group section
+ new mw.rcfilters.ui.FilterMenuSectionOptionWidget(
+ widget.controller,
+ groupModel,
+ {
+ $overlay: widget.$overlay
+ }
+ )
+ );
+ }
- // Add items
- widget.model.getGroupFilters( groupName ).forEach( function ( filterItem ) {
- currentItems.push(
- new mw.rcfilters.ui.FilterMenuOptionWidget(
- widget.controller,
- filterItem,
- {
- $overlay: widget.$overlay
- }
- )
- );
- } );
-
- // Cache the items per view, so we can switch between them
- // without rebuilding the widgets each time
- widget.views[ view ] = widget.views[ view ] || [];
- widget.views[ view ] = widget.views[ view ].concat( currentItems );
+ // Add items
+ widget.model.getGroupFilters( groupName ).forEach( function ( filterItem ) {
+ currentItems.push(
+ new mw.rcfilters.ui.FilterMenuOptionWidget(
+ widget.controller,
+ filterItem,
+ {
+ $overlay: widget.$overlay
+ }
+ )
+ );
+ } );
+
+ // Cache the items per view, so we can switch between them
+ // without rebuilding the widgets each time
+ widget.views[ view ] = widget.views[ view ] || [];
+ widget.views[ view ] = widget.views[ view ].concat( currentItems );
+ }
} );
this.switchView( this.model.getCurrentView() );
'name' => 'nullLockManager',
'class' => 'NullLockManager',
] ];
- $reset = function() {
+ $reset = function () {
LockManagerGroup::destroySingletons();
};
$setup[] = $reset;
MediaWikiServices::getInstance()->disableService( 'MediaHandlerFactory' );
MediaWikiServices::getInstance()->redefineService(
'MediaHandlerFactory',
- function() {
+ function () {
return new MockMediaHandlerFactory();
}
);
* @return ScopedCallback
*/
protected function createTeardownObject( $teardown, $nextTeardown = null ) {
- return new ScopedCallback( function() use ( $teardown, $nextTeardown ) {
+ return new ScopedCallback( function () use ( $teardown, $nextTeardown ) {
// Schedule teardown snippets in reverse order
$teardown = array_reverse( $teardown );
ConfigFactory $oldFactory,
array $configurations
) {
- return function( MediaWikiServices $services ) use ( $oldFactory, $configurations ) {
+ return function ( MediaWikiServices $services ) use ( $oldFactory, $configurations ) {
$factory = new ConfigFactory();
// clone configurations from $oldFactory that are not overwritten by $configurations
class WfArrayFilterTest extends \PHPUnit_Framework_TestCase {
public function testWfArrayFilter() {
$arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
- $filtered = wfArrayFilter( $arr, function( $val, $key ) {
+ $filtered = wfArrayFilter( $arr, function ( $val, $key ) {
return $key !== 'b';
} );
$this->assertSame( [ 'a' => 1, 'c' => 3 ], $filtered );
$arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
- $filtered = wfArrayFilter( $arr, function( $val, $key ) {
+ $filtered = wfArrayFilter( $arr, function ( $val, $key ) {
return $val !== 2;
} );
$this->assertSame( [ 'a' => 1, 'c' => 3 ], $filtered );
$arr = [ 'a', 'b', 'c' ];
- $filtered = wfArrayFilter( $arr, function( $val, $key ) {
+ $filtered = wfArrayFilter( $arr, function ( $val, $key ) {
return $key !== 0;
} );
$this->assertSame( [ 1 => 'b', 2 => 'c' ], $filtered );
public function testWfArrayFilterByKey() {
$arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
- $filtered = wfArrayFilterByKey( $arr, function( $key ) {
+ $filtered = wfArrayFilterByKey( $arr, function ( $key ) {
return $key !== 'b';
} );
$this->assertSame( [ 'a' => 1, 'c' => 3 ], $filtered );
$arr = [ 'a', 'b', 'c' ];
- $filtered = wfArrayFilterByKey( $arr, function( $key ) {
+ $filtered = wfArrayFilterByKey( $arr, function ( $key ) {
return $key !== 0;
} );
$this->assertSame( [ 1 => 'b', 2 => 'c' ], $filtered );
return [
// Override $html
[
- function( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
+ function ( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
$html = 'foobar';
},
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage">foobar</a>'
],
// Modify $attribs
[
- function( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
+ function ( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
$attribs['bar'] = 'baz';
},
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage" bar="baz">Special:BlankPage</a>'
],
// Fully override return value and abort hook
[
- function( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
+ function ( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
$ret = 'blahblahblah';
return false;
},
$newServices->defineService(
'Test',
- function() use ( $service1 ) {
+ function () use ( $service1 ) {
return $service1;
}
);
$newServices->defineService(
'Test',
- function() use ( &$instantiatorReturnValues ) {
+ function () use ( &$instantiatorReturnValues ) {
return array_shift( $instantiatorReturnValues );
}
);
$newServices->redefineService(
'DBLoadBalancerFactory',
- function() use ( $lbFactory ) {
+ function () use ( $lbFactory ) {
return $lbFactory;
}
);
$newServices->defineService(
'Test',
- function() use ( &$instantiatorReturnValues ) {
+ function () use ( &$instantiatorReturnValues ) {
return array_shift( $instantiatorReturnValues );
}
);
$services->defineService(
'Test',
- function() use ( &$serviceCounter ) {
+ function () use ( &$serviceCounter ) {
$serviceCounter++;
$service = $this->createMock( 'MediaWiki\Services\DestructibleService' );
$service->expects( $this->once() )->method( 'destroy' );
$services->defineService(
'Test',
- function() {
+ function () {
$service = $this->createMock( 'MediaWiki\Services\DestructibleService' );
$service->expects( $this->never() )->method( 'destroy' );
return $service;
$this->assertEmpty( $names );
$name = 'TestService92834576';
- $services->defineService( $name, function() {
+ $services->defineService( $name, function () {
return null;
} );
$name = 'TestService92834576';
$this->assertFalse( $services->hasService( $name ) );
- $services->defineService( $name, function() {
+ $services->defineService( $name, function () {
return null;
} );
$services->defineService(
$name,
- function( $actualLocator, $extra ) use ( $services, $theService, &$count ) {
+ function ( $actualLocator, $extra ) use ( $services, $theService, &$count ) {
$count++;
PHPUnit_Framework_Assert::assertSame( $services, $actualLocator );
PHPUnit_Framework_Assert::assertSame( $extra, 'Foo' );
$services->defineService(
'Foo',
- function() {
+ function () {
return new stdClass();
}
);
$services->defineService(
'Bar',
- function() {
+ function () {
return new stdClass();
}
);
$theService = new stdClass();
$name = 'TestService92834576';
- $services->defineService( $name, function( $actualLocator ) use ( $services, $theService ) {
+ $services->defineService( $name, function ( $actualLocator ) use ( $services, $theService ) {
PHPUnit_Framework_Assert::assertSame( $services, $actualLocator );
return $theService;
} );
$theService = new stdClass();
$name = 'TestService92834576';
- $services->defineService( $name, function() use ( $theService ) {
+ $services->defineService( $name, function () use ( $theService ) {
return $theService;
} );
$this->setExpectedException( 'MediaWiki\Services\ServiceAlreadyDefinedException' );
- $services->defineService( $name, function() use ( $theService ) {
+ $services->defineService( $name, function () use ( $theService ) {
return $theService;
} );
}
$services = $this->newServiceContainer();
$wiring = [
- 'Foo' => function() {
+ 'Foo' => function () {
return 'Foo!';
},
- 'Bar' => function() {
+ 'Bar' => function () {
return 'Bar!';
},
];
$services = $this->newServiceContainer();
$wiring = [
- 'Foo' => function() {
+ 'Foo' => function () {
return 'Foo!';
},
- 'Bar' => function() {
+ 'Bar' => function () {
return 'Bar!';
},
- 'Car' => function() {
+ 'Car' => function () {
return 'FUBAR!';
},
];
// define a service before importing, so we can later check that
// existing service instances survive importWiring()
- $newServices->defineService( 'Car', function() {
+ $newServices->defineService( 'Car', function () {
return 'Car!';
} );
// Define another service, so we can later check that extra wiring
// is not lost.
- $newServices->defineService( 'Xar', function() {
+ $newServices->defineService( 'Xar', function () {
return 'Xar!';
} );
$theService1 = new stdClass();
$name = 'TestService92834576';
- $services->defineService( $name, function() {
+ $services->defineService( $name, function () {
PHPUnit_Framework_Assert::fail(
'The original instantiator function should not get called'
);
// redefine before instantiation
$services->redefineService(
$name,
- function( $actualLocator, $extra ) use ( $services, $theService1 ) {
+ function ( $actualLocator, $extra ) use ( $services, $theService1 ) {
PHPUnit_Framework_Assert::assertSame( $services, $actualLocator );
PHPUnit_Framework_Assert::assertSame( 'Foo', $extra );
return $theService1;
$theService1 = new stdClass();
$name = 'TestService92834576';
- $services->defineService( $name, function() {
+ $services->defineService( $name, function () {
return 'Foo';
} );
// disable the service. we should be able to redefine it anyway.
$services->disableService( $name );
- $services->redefineService( $name, function() use ( $theService1 ) {
+ $services->redefineService( $name, function () use ( $theService1 ) {
return $theService1;
} );
$this->setExpectedException( 'MediaWiki\Services\NoSuchServiceException' );
- $services->redefineService( $name, function() use ( $theService ) {
+ $services->redefineService( $name, function () use ( $theService ) {
return $theService;
} );
}
$theService = new stdClass();
$name = 'TestService92834576';
- $services->defineService( $name, function() {
+ $services->defineService( $name, function () {
return 'Foo';
} );
$this->setExpectedException( 'MediaWiki\Services\CannotReplaceActiveServiceException' );
- $services->redefineService( $name, function() use ( $theService ) {
+ $services->redefineService( $name, function () use ( $theService ) {
return $theService;
} );
}
$destructible->expects( $this->once() )
->method( 'destroy' );
- $services->defineService( 'Foo', function() use ( $destructible ) {
+ $services->defineService( 'Foo', function () use ( $destructible ) {
return $destructible;
} );
- $services->defineService( 'Bar', function() {
+ $services->defineService( 'Bar', function () {
return new stdClass();
} );
- $services->defineService( 'Qux', function() {
+ $services->defineService( 'Qux', function () {
return new stdClass();
} );
$this->setExpectedException( 'MediaWiki\Services\NoSuchServiceException' );
- $services->redefineService( $name, function() use ( $theService ) {
+ $services->redefineService( $name, function () use ( $theService ) {
return $theService;
} );
}
$destructible->expects( $this->once() )
->method( 'destroy' );
- $services->defineService( 'Foo', function() use ( $destructible ) {
+ $services->defineService( 'Foo', function () use ( $destructible ) {
return $destructible;
} );
- $services->defineService( 'Bar', function() {
+ $services->defineService( 'Bar', function () {
return new stdClass();
} );
*/
return [
- 'Foo' => function() {
+ 'Foo' => function () {
return 'Foo!';
},
];
*/
return [
- 'Bar' => function() {
+ 'Bar' => function () {
return 'Bar!';
},
];
/**
* Testing logger
*
- * Copyright (C) 2015 Brad Jorsch <bjorsch@wikimedia.org>
+ * Copyright (C) 2015 Wikimedia Foundation and contributors
*
* 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
* http://www.gnu.org/copyleft/gpl.html
*
* @file
- * @author Brad Jorsch <bjorsch@wikimedia.org>
*/
use Psr\Log\LogLevel;
$this->isType( 'array' ),
$this->isType( 'int' )
)
- ->will( $this->returnCallback( function( $a, $conj ) {
+ ->will( $this->returnCallback( function ( $a, $conj ) {
$sqlConj = $conj === LIST_AND ? ' AND ' : ' OR ';
- return join( $sqlConj, array_map( function( $s ) {
+ return join( $sqlConj, array_map( function ( $s ) {
return '(' . $s . ')';
}, $a
) );
$mock->expects( $this->any() )
->method( 'addQuotes' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return "'$value'";
} ) );
$mock->expects( $this->any() )
->method( 'bitAnd' )
- ->willReturnCallback( function( $a, $b ) {
+ ->willReturnCallback( function ( $a, $b ) {
return "($a & $b)";
} );
$mock->expects( $this->any() )
->method( 'isAllowed' )
- ->will( $this->returnCallback( function( $action ) use ( $notAllowedAction ) {
+ ->will( $this->returnCallback( function ( $action ) use ( $notAllowedAction ) {
return $action !== $notAllowedAction;
} ) );
$mock->expects( $this->any() )
->method( 'isAllowedAny' )
- ->will( $this->returnCallback( function() use ( $notAllowedAction ) {
+ ->will( $this->returnCallback( function () use ( $notAllowedAction ) {
$actions = func_get_args();
return !in_array( $notAllowedAction, $actions );
} ) );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->any() )
->method( 'addQuotes' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return "'$value'";
} ) );
$mockDb->expects( $this->any() )
$this->isType( 'array' ),
$this->isType( 'int' )
)
- ->will( $this->returnCallback( function( $a, $conj ) {
+ ->will( $this->returnCallback( function ( $a, $conj ) {
$sqlConj = $conj === LIST_AND ? ' AND ' : ' OR ';
- return join( $sqlConj, array_map( function( $s ) {
+ return join( $sqlConj, array_map( function ( $s ) {
return '(' . $s . ')';
}, $a
) );
->getMock();
$mock->expects( $this->any() )
->method( 'makeKey' )
- ->will( $this->returnCallback( function() {
+ ->will( $this->returnCallback( function () {
return implode( ':', func_get_args() );
} ) );
return $mock;
->will( $this->returnValue( 7 ) );
$mockDb->expects( $this->exactly( 1 ) )
->method( 'addQuotes' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return "'$value'";
} ) );
$mockDb->expects( $this->exactly( 1 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->exactly( 2 * 3 ) )
->method( 'addQuotes' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return "'$value'";
} ) );
$mockDb->expects( $this->exactly( 3 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
$mockDb->expects( $this->any() )
$this->isType( 'array' ),
$this->isType( 'int' )
)
- ->will( $this->returnCallback( function( $a, $conj ) {
+ ->will( $this->returnCallback( function ( $a, $conj ) {
$sqlConj = $conj === LIST_AND ? ' AND ' : ' OR ';
- return join( $sqlConj, array_map( function( $s ) {
+ return join( $sqlConj, array_map( function ( $s ) {
return '(' . $s . ')';
}, $a
) );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->exactly( 2 * 3 ) )
->method( 'addQuotes' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return "'$value'";
} ) );
$mockDb->expects( $this->exactly( 3 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
$mockDb->expects( $this->any() )
$this->isType( 'array' ),
$this->isType( 'int' )
)
- ->will( $this->returnCallback( function( $a, $conj ) {
+ ->will( $this->returnCallback( function ( $a, $conj ) {
$sqlConj = $conj === LIST_AND ? ' AND ' : ' OR ';
- return join( $sqlConj, array_map( function( $s ) {
+ return join( $sqlConj, array_map( function ( $s ) {
return '(' . $s . ')';
}, $a
) );
// Note: This does not actually assert the job is correct
$callableCallCounter = 0;
- $mockCallback = function( $callable ) use ( &$callableCallCounter ) {
+ $mockCallback = function ( $callable ) use ( &$callableCallCounter ) {
$callableCallCounter++;
$this->assertInternalType( 'callable', $callable );
};
// Note: This does not actually assert the job is correct
$callableCallCounter = 0;
- $mockCallback = function( $callable ) use ( &$callableCallCounter ) {
+ $mockCallback = function ( $callable ) use ( &$callableCallCounter ) {
$callableCallCounter++;
$this->assertInternalType( 'callable', $callable );
};
$callableCallCounter = 0;
$scopedOverride = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
- function( $callable ) use ( &$callableCallCounter, $title, $user ) {
+ function ( $callable ) use ( &$callableCallCounter, $title, $user ) {
$callableCallCounter++;
$this->verifyCallbackJob(
$callable,
$title,
$user->getId(),
- function( $time ) {
+ function ( $time ) {
return $time === null;
}
);
$addUpdateCallCounter = 0;
$scopedOverrideDeferred = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
- function( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
+ function ( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
$addUpdateCallCounter++;
$this->verifyCallbackJob(
$callable,
$title,
$user->getId(),
- function( $time ) {
+ function ( $time ) {
return $time !== null && $time > '20151212010101';
}
);
$getTimestampCallCounter = 0;
$scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
- function( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
+ function ( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
$getTimestampCallCounter++;
$this->assertEquals( $title, $titleParam );
$this->assertEquals( $oldid, $oldidParam );
$callableCallCounter = 0;
$scopedOverride = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
- function( $callable ) use ( &$callableCallCounter, $title, $user ) {
+ function ( $callable ) use ( &$callableCallCounter, $title, $user ) {
$callableCallCounter++;
$this->verifyCallbackJob(
$callable,
$title,
$user->getId(),
- function( $time ) {
+ function ( $time ) {
return $time === null;
}
);
$addUpdateCallCounter = 0;
$scopedOverrideDeferred = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
- function( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
+ function ( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
$addUpdateCallCounter++;
$this->verifyCallbackJob(
$callable,
$title,
$user->getId(),
- function( $time ) {
+ function ( $time ) {
return $time === '30151212010101';
}
);
$getTimestampCallCounter = 0;
$scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
- function( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
+ function ( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
$getTimestampCallCounter++;
$this->assertEquals( $title, $titleParam );
$this->assertEquals( $oldid, $oldidParam );
$addUpdateCallCounter = 0;
$scopedOverrideDeferred = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
- function( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
+ function ( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
$addUpdateCallCounter++;
$this->verifyCallbackJob(
$callable,
$title,
$user->getId(),
- function( $time ) {
+ function ( $time ) {
return $time === false;
}
);
$getTimestampCallCounter = 0;
$scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
- function( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
+ function ( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
$getTimestampCallCounter++;
$this->assertEquals( $title, $titleParam );
$this->assertEquals( $oldid, $oldidParam );
->will( $this->returnValue( true ) );
$mockDb->expects( $this->exactly( 1 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
->will( $this->returnValue( true ) );
$mockDb->expects( $this->exactly( 0 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
->will( $this->returnValue( true ) );
$mockDb->expects( $this->exactly( 1 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
$mockDb->expects( $this->once() )
],
'A simple merge policy adds the redirect data in' => [
- function( $current, $new ) {
+ function ( $current, $new ) {
if ( !isset( $current['index'] ) || $new['index'] < $current['index'] ) {
$current['index'] = $new['index'];
}
// not checking values of all keys of the actual item, so removing unwanted keys from comparison
$actualItemsOnlyComparedValues = array_map(
- function( array $item ) use ( $keysUsedInValueComparison ) {
+ function ( array $item ) use ( $keysUsedInValueComparison ) {
return array_intersect_key( $item, array_flip( $keysUsedInValueComparison ) );
},
$actualItems
__DIR__ . '/words.txt'
] as $dictionaryFile
) {
- if ( is_file( $dictionaryFile ) and is_readable( $dictionaryFile ) ) {
+ if ( is_file( $dictionaryFile ) && is_readable( $dictionaryFile ) ) {
$this->dictionaryFile = $dictionaryFile;
break;
}
// define new config instance
$newFactory = new ConfigFactory();
$newFactory->register( 'foo', 'GlobalVarConfig::newInstance' );
- $newFactory->register( 'bar', function() {
+ $newFactory->register( 'bar', function () {
return new HashConfig();
} );
CONTENT_MODEL_CSS => 'CssContentHandler',
CONTENT_MODEL_TEXT => 'TextContentHandler',
'testing' => 'DummyContentHandlerForTesting',
- 'testing-callbacks' => function( $modelId ) {
+ 'testing-callbacks' => function ( $modelId ) {
return new DummyContentHandlerForTesting( $modelId );
}
],
$searchEngine->expects( $this->any() )
->method( 'makeSearchFieldMapping' )
- ->will( $this->returnCallback( function( $name, $type ) {
+ ->will( $this->returnCallback( function ( $name, $type ) {
return new DummySearchIndexFieldDefinition( $name, $type );
} ) );
*
* @file
* @author Antoine Musso
- * @author Bryan Davis
* @copyright © 2013 Antoine Musso
- * @copyright © 2013 Bryan Davis
- * @copyright © 2013 Wikimedia Foundation Inc.
+ * @copyright © 2013 Wikimedia Foundation and contributors
*/
use Wikimedia\Rdbms\TransactionProfiler;
public function provideTestJobFactory() {
return [
'class name' => [ 'NullJob' ],
- 'closure' => [ function( Title $title, array $params ) {
+ 'closure' => [ function ( Title $title, array $params ) {
return new NullJob( $title, $params );
} ],
'function' => [ [ $this, 'newNullJob' ] ],
// No args
[
[
- function() {
+ function () {
return 'foo';
}
],
// Has args
[
[
- function( $i ) {
+ function ( $i ) {
return $i;
},
'bar'
* it is never converted to a string
*/
public function testCallbackNotCalled() {
- $ds = new DeferredStringifier( function() {
+ $ds = new DeferredStringifier( function () {
throw new Exception( 'This should not be reached!' );
} );
// No exception was thrown
$obj = ObjectFactory::getObjectFromSpec( [
'class' => 'ObjectFactoryTestFixture',
'args' => [
- function() {
+ function () {
return 'wrapped';
},
'unwrapped',
],
'calls' => [
- 'setter' => [ function() {
+ 'setter' => [ function () {
return 'wrapped';
}, ],
],
$obj = ObjectFactory::getObjectFromSpec( [
'class' => 'ObjectFactoryTestFixture',
'args' => [
- function() {
+ function () {
return 'wrapped';
},
'unwrapped',
],
'calls' => [
- 'setter' => [ function() {
+ 'setter' => [ function () {
return 'wrapped';
}, ],
],
$obj = ObjectFactory::getObjectFromSpec( [
'class' => 'ObjectFactoryTestFixture',
- 'args' => [ function() {
+ 'args' => [ function () {
return 'unwrapped';
}, ],
'calls' => [
- 'setter' => [ function() {
+ 'setter' => [ function () {
return 'unwrapped';
}, ],
],
/**
* @uses XhprofData
* @uses AutoLoader
- * @author Bryan Davis <bd808@wikimedia.org>
- * @copyright © 2014 Bryan Davis and Wikimedia Foundation.
+ * @copyright © 2014 Wikimedia Foundation and contributors
* @since 1.25
*/
class XhprofDataTest extends PHPUnit_Framework_TestCase {
null,
false,
[
- 'processing_instruction_handler' => function() use ( &$called ) {
+ 'processing_instruction_handler' => function () use ( &$called ) {
$called = true;
}
]
$priorValue = null;
$priorAsOf = null;
$wasSet = 0;
- $func = function( $old, &$ttl, &$opts, $asOf )
+ $func = function ( $old, &$ttl, &$opts, $asOf )
use ( &$wasSet, &$priorValue, &$priorAsOf, $value )
{
++$wasSet;
$value = wfRandomString();
$calls = 0;
- $func = function() use ( &$calls, $value, $cache, $key ) {
+ $func = function () use ( &$calls, $value, $cache, $key ) {
++$calls;
// Immediately kill any mutex rather than waiting a second
$cache->delete( $cache::MUTEX_KEY_PREFIX . $key );
$value = wfRandomString();
$calls = 0;
- $func = function( $oldValue, &$ttl, &$setOpts ) use ( &$calls, $value, $cache, $key ) {
+ $func = function ( $oldValue, &$ttl, &$setOpts ) use ( &$calls, $value, $cache, $key ) {
++$calls;
$setOpts['since'] = microtime( true ) - 10;
// Immediately kill any mutex rather than waiting a second
$busyValue = wfRandomString();
$calls = 0;
- $func = function() use ( &$calls, $value, $cache, $key ) {
+ $func = function () use ( &$calls, $value, $cache, $key ) {
++$calls;
// Immediately kill any mutex rather than waiting a second
$cache->delete( $cache::MUTEX_KEY_PREFIX . $key );
$value = wfRandomString();
$wasSet = 0;
- $func = function( $old, &$ttl ) use ( &$wasSet, $value ) {
+ $func = function ( $old, &$ttl ) use ( &$wasSet, $value ) {
++$wasSet;
return $value;
};
]
],
+ 'htmlTemplateUnknown' => $base + [
+ 'templates' => [
+ 'templates/notfound.html',
+ ]
+ ],
+
'aliasedHtmlTemplateModule' => $base + [
'templates' => [
'foo.html' => 'templates/template.html',
'bar.html' => "<div>goodbye</div>\n",
],
],
+ [
+ $modules['htmlTemplateUnknown'],
+ false,
+ ],
];
}
$rl = new ResourceLoaderFileModule( $module );
$rl->setName( 'testing' );
- $this->assertEquals( $rl->getTemplates(), $expected );
+ if ( $expected === false ) {
+ $this->setExpectedException( MWException::class );
+ $rl->getTemplates();
+ } else {
+ $this->assertEquals( $rl->getTemplates(), $expected );
+ }
}
+ /**
+ * @covers ResourceLoaderFileModule::stripBom
+ */
public function testBomConcatenation() {
$basePath = __DIR__ . '/../../data/css';
$testModule = new ResourceLoaderFileModule( [
* @covers ResourceLoader::getModule
*/
public function testGetModuleFactory() {
- $factory = function( array $info ) {
+ $factory = function ( array $info ) {
$this->assertArrayHasKey( 'kitten', $info );
return new ResourceLoaderTestModule( $info );
};
* Verify that when building module content in a load.php response,
* an exception from one module will not break script output from
* other modules.
+ *
+ * @covers ResourceLoader::makeModuleResponse
*/
public function testMakeModuleResponseError() {
$modules = [
* Verify that when building the startup module response,
* an exception from one module class will not break the entire
* startup module response. See T152266.
+ *
+ * @covers ResourceLoader::makeModuleResponse
*/
public function testMakeModuleResponseStartupError() {
$rl = new EmptyResourceLoader();
public function testSearch( array $case ) {
$this->search->setLimitOffset( 3 );
$results = $this->search->defaultPrefixSearch( $case['query'] );
- $results = array_map( function( Title $t ) {
+ $results = array_map( function ( Title $t ) {
return $t->getPrefixedText();
}, $results );
public function testSearchWithOffset( array $case ) {
$this->search->setLimitOffset( 3, 1 );
$results = $this->search->defaultPrefixSearch( $case['query'] );
- $results = array_map( function( Title $t ) {
+ $results = array_map( function ( Title $t ) {
return $t->getPrefixedText();
}, $results );
$search->setLimitOffset( 3 );
$results = $search->completionSearch( $case['query'] );
- $results = $results->map( function( SearchSuggestion $s ) {
+ $results = $results->map( function ( SearchSuggestion $s ) {
return $s->getText();
} );
$this->assertEquals( 3, $set->getBestScore() );
$this->assertEquals( 1, $suggestion->getScore() );
- $scores = $set->map( function( $s ) {
+ $scores = $set->map( function ( $s ) {
return $s->getScore();
} );
$sorted = $scores;
$this->assertEquals( 6, $set->getBestScore() );
$this->assertEquals( 6, $suggestion->getScore() );
- $scores = $set->map( function( $s ) {
+ $scores = $set->map( function ( $s ) {
return $s->getScore();
} );
$sorted = $scores;
$dbSiteStore->expects( $this->any() )
->method( 'getSites' )
- ->will( $this->returnCallback( function() {
+ ->will( $this->returnCallback( function () {
$siteList = new SiteList();
$siteList->setSite( $this->getTestSite() );
$rewrittenQuery,
array $resultTitles
) {
- $results = array_map( function( $title ) {
+ $results = array_map( function ( $title ) {
return SearchResult::newFromTitle( $title );
}, $resultTitles );
$batchSize = 2;
$reader = new BatchRowIterator( $db, 'some_table', 'id_field', $batchSize );
- $response = $this->genSelectResult( $batchSize, /*numRows*/ 5, function() {
+ $response = $this->genSelectResult( $batchSize, /*numRows*/ 5, function () {
static $i = 0;
return [ 'id_field' => ++$i ];
} );
public function testReaderSelectConditionsMultiplePrimaryKeys(
$message, $expectedSecondIteration, $primaryKeys, $batchSize = 3
) {
- $results = $this->genSelectResult( $batchSize, $batchSize * 3, function() {
+ $results = $this->genSelectResult( $batchSize, $batchSize * 3, function () {
static $i = 0, $j = 100, $k = 1000;
return [ 'id_field' => ++$i, 'foo' => ++$j, 'bar' => ++$k ];
} );
->will( $this->consecutivelyReturnFromSelect( $retvals ) );
$db->expects( $this->any() )
->method( 'addQuotes' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return "'$value'"; // not real quoting: doesn't matter in test
} ) );
{ name: 'filter8', label: 'group3filter8-label', description: 'group3filter8-desc' },
{ name: 'filter9', label: 'group3filter9-label', description: 'group3filter9-desc' }
]
+ }, {
+ name: 'group4',
+ type: 'single_option',
+ default: 'option1',
+ filters: [
+ { name: 'option1', label: 'group4option1-label', description: 'group4option1-desc' },
+ { name: 'option2', label: 'group4option2-label', description: 'group4option2-desc' },
+ { name: 'option3', label: 'group4option3-label', description: 'group4option3-desc' }
+ ]
} ],
viewsDefinition = {
namespaces: {
filter5: '1',
filter6: '0',
group3: 'filter8',
+ group4: 'option1',
namespace: ''
},
baseParamRepresentation = {
filter5: '0',
filter6: '0',
group3: '',
+ group4: '',
namespace: ''
},
baseFilterRepresentation = {
group3__filter7: false,
group3__filter8: false,
group3__filter9: false,
+ group4__option1: false,
+ group4__option2: false,
+ group4__option3: false,
namespace__0: false,
namespace__1: false,
namespace__2: false,
group3__filter7: { selected: false, conflicted: false, included: false },
group3__filter8: { selected: false, conflicted: false, included: false },
group3__filter9: { selected: false, conflicted: false, included: false },
+ group4__option1: { selected: false, conflicted: false, included: false },
+ group4__option2: { selected: false, conflicted: false, included: false },
+ group4__option3: { selected: false, conflicted: false, included: false },
namespace__0: { selected: false, conflicted: false, included: false },
namespace__1: { selected: false, conflicted: false, included: false },
namespace__2: { selected: false, conflicted: false, included: false },
} ),
'All filters selected in "string_option" group returns \'all\'.'
);
+
+ // Reset
+ model = new mw.rcfilters.dm.FiltersViewModel();
+ model.initializeFilters( filterDefinition, viewsDefinition );
+
+ // Select an option from single_option group
+ model.toggleFiltersSelected( {
+ group4__option2: true
+ } );
+ // All filters of the group are selected == this is the same as not selecting any
+ assert.deepEqual(
+ model.getParametersFromFilters(),
+ $.extend( true, {}, baseParamRepresentation, {
+ group4: 'option2'
+ } ),
+ 'Selecting an option from "single_option" group returns that option as a value.'
+ );
+
+ // Select a different option from single_option group
+ model.toggleFiltersSelected( {
+ group4__option3: true
+ } );
+ // All filters of the group are selected == this is the same as not selecting any
+ assert.deepEqual(
+ model.getParametersFromFilters(),
+ $.extend( true, {}, baseParamRepresentation, {
+ group4: 'option3'
+ } ),
+ 'Selecting a different option from "single_option" group changes the selection.'
+ );
} );
QUnit.test( 'getParametersFromFilters (custom object)', function ( assert ) {
{ name: 'filter8', label: 'Hide filter 8', description: '' },
{ name: 'filter9', label: 'Hide filter 9', description: '' }
]
+ }, {
+ name: 'group4',
+ title: 'Group 4',
+ type: 'single_option',
+ filters: [
+ { name: 'filter10', label: 'Hide filter 10', description: '' },
+ { name: 'filter11', label: 'Hide filter 11', description: '' },
+ { name: 'filter12', label: 'Hide filter 12', description: '' }
+ ]
} ],
+ baseResult = {
+ hidefilter1: '0',
+ hidefilter2: '0',
+ hidefilter3: '0',
+ hidefilter4: '0',
+ hidefilter5: '0',
+ hidefilter6: '0',
+ group3: '',
+ group4: ''
+ },
cases = [
{
// This is mocking the cases above, both
group3__filter8: true,
group3__filter9: false
},
- expected: {
+ expected: $.extend( true, {}, baseResult, {
// Group 1 (two selected, the others are true)
- hidefilter1: '0',
- hidefilter2: '0',
hidefilter3: '1',
- // Group 2 (nothing is selected, all false)
- hidefilter4: '0',
- hidefilter5: '0',
- hidefilter6: '0',
+ // Group 3 (two selected)
group3: 'filter7,filter8'
- },
+ } ),
msg: 'Given an explicit (complete) filter state object, the result is the same as if the object given represented the model state.'
},
{
input: {
group1__hidefilter1: 1
},
- expected: {
+ expected: $.extend( true, {}, baseResult, {
// Group 1 (one selected, the others are true)
- hidefilter1: '0',
hidefilter2: '1',
- hidefilter3: '1',
- // Group 2 (nothing is selected, all false)
- hidefilter4: '0',
- hidefilter5: '0',
- hidefilter6: '0',
- group3: ''
- },
+ hidefilter3: '1'
+ } ),
msg: 'Given an explicit (incomplete) filter state object, the result is the same as if the object give represented the model state.'
},
{
- input: {},
- expected: {
- hidefilter1: '0',
- hidefilter2: '0',
- hidefilter3: '0',
- hidefilter4: '0',
- hidefilter5: '0',
- hidefilter6: '0',
- group3: ''
+ input: {
+ group4__filter10: true
},
+ expected: $.extend( true, {}, baseResult, {
+ group4: 'filter10'
+ } ),
+ msg: 'Given a single value for "single_option" that option is represented in the result.'
+ },
+ {
+ input: {
+ group4__filter10: true,
+ group4__filter11: true
+ },
+ expected: $.extend( true, {}, baseResult, {
+ group4: 'filter10'
+ } ),
+ msg: 'Given more than one true value for "single_option" (which should not happen!) only the first value counts, and the second is ignored.'
+ },
+ {
+ input: {},
+ expected: baseResult,
msg: 'Given an explicit empty object, the result is all filters set to their falsey unselected value.'
}
];
} ),
'A \'string_options\' parameter containing an invalid value, results in the invalid value ignored and the valid corresponding filters checked.'
);
+
+ model.toggleFiltersSelected(
+ model.getFiltersFromParameters( {
+ group4: 'option1'
+ } )
+ );
+ assert.deepEqual(
+ model.getSelectedState(),
+ $.extend( {}, baseFilterRepresentation, {
+ group4__option1: true
+ } ),
+ 'A \'single_option\' parameter reflects a single selected value.'
+ );
+
+ assert.deepEqual(
+ model.getFiltersFromParameters( {
+ group4: 'option1,option2'
+ } ),
+ baseFilterRepresentation,
+ 'An invalid \'single_option\' parameter is ignored.'
+ );
+
+ // Change to one value
+ model.toggleFiltersSelected(
+ model.getFiltersFromParameters( {
+ group4: 'option1'
+ } )
+ );
+ // Change again to another value
+ model.toggleFiltersSelected(
+ model.getFiltersFromParameters( {
+ group4: 'option2'
+ } )
+ );
+ assert.deepEqual(
+ model.getSelectedState(),
+ $.extend( {}, baseFilterRepresentation, {
+ group4__option2: true
+ } ),
+ 'A \'single_option\' parameter always reflects the latest selected value.'
+ );
} );
QUnit.test( 'sanitizeStringOptionGroup', function ( assert ) {