本文整理汇总了PHP中ExtensionRegistry类的典型用法代码示例。如果您正苦于以下问题:PHP ExtensionRegistry类的具体用法?PHP ExtensionRegistry怎么用?PHP ExtensionRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExtensionRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onParserFirstCallSetup
static function onParserFirstCallSetup(Parser $parser)
{
if (!ExtensionRegistry::getInstance()->isLoaded('Math')) {
die("The DMath extension requires the Math extension, please include it.");
}
$parser->setHook('dmath', 'DMathParse::dmathTagHook');
$parser->setHook('math', 'DMathParse::mathTagHook');
}
示例2: __construct
public function __construct()
{
parent::__construct();
$paths = [];
// Autodiscover extension unit tests
$registry = ExtensionRegistry::getInstance();
foreach ($registry->getAllThings() as $info) {
$paths[] = dirname($info['path']) . '/tests/phpunit';
}
// Extensions can return a list of files or directories
Hooks::run('UnitTestsList', [&$paths]);
foreach (array_unique($paths) as $path) {
if (is_dir($path)) {
// If the path is a directory, search for test cases.
// @since 1.24
$suffixes = ['Test.php'];
$fileIterator = new File_Iterator_Facade();
$matchingFiles = $fileIterator->getFilesAsArray($path, $suffixes);
$this->addTestFiles($matchingFiles);
} elseif (file_exists($path)) {
// Add a single test case or suite class
$this->addTestFile($path);
}
}
if (!$paths) {
$this->addTest(new DummyExtensionsTest('testNothing'));
}
}
示例3: getInstance
/**
* @return ExtensionRegistry
*/
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
示例4: providePassesValidation
public static function providePassesValidation()
{
$values = [];
foreach (ExtensionRegistry::getInstance()->getAllThings() as $thing) {
$values[] = [$thing['path']];
}
return $values;
}
示例5: testGetName
/**
* @dataProvider getNameProvider
*/
public function testGetName($lang, $in, $expected)
{
if ($in !== null && !\ExtensionRegistry::getInstance()->isLoaded('CLDR')) {
$this->markTestSkipped('CLDR extension required for full language name support');
}
$languageNameLookup = new LanguageNameLookup($in);
$name = $languageNameLookup->getName($lang);
$this->assertSame($expected, $name);
}
示例6: getEditActionArgs
private function getEditActionArgs()
{
// default is wikitext editor
$args = array('name' => 'action', 'value' => 'edit');
// check, if VE is installed and VE editor is requested
if (ExtensionRegistry::getInstance()->isLoaded('VisualEditor') && $this->mUseVE) {
$args = array('name' => 'veaction', 'value' => 'edit');
}
return $args;
}
示例7: loadFromDefinition
protected function loadFromDefinition()
{
if ($this->definition === null) {
return;
}
// Core default themes
$themes = array('default' => 'mediawiki');
$themes += ExtensionRegistry::getInstance()->getAttribute('SkinOOUIThemes');
$name = $this->definition['name'];
$rootPath = $this->definition['rootPath'];
$definition = array();
foreach ($themes as $skin => $theme) {
// TODO Allow extensions to specify this path somehow
$dataPath = $this->localBasePath . '/' . $rootPath . '/' . $theme . '/' . $name . '.json';
if (file_exists($dataPath)) {
$data = json_decode(file_get_contents($dataPath), true);
$fixPath = function (&$path) use($rootPath, $theme) {
// TODO Allow extensions to specify this path somehow
$path = $rootPath . '/' . $theme . '/' . $path;
};
array_walk($data['images'], function (&$value) use($fixPath) {
if (is_string($value['file'])) {
$fixPath($value['file']);
} elseif (is_array($value['file'])) {
array_walk_recursive($value['file'], $fixPath);
}
});
} else {
$data = array();
}
foreach ($data as $key => $value) {
switch ($key) {
case 'images':
case 'variants':
$definition[$key][$skin] = $data[$key];
break;
default:
if (!isset($definition[$key])) {
$definition[$key] = $data[$key];
} elseif ($definition[$key] !== $data[$key]) {
throw new Exception("Mismatched OOUI theme definitions are not supported: trying to load {$key} of {$theme} theme");
}
break;
}
}
}
// Fields from definition silently override keys from JSON files
$this->definition += $definition;
parent::loadFromDefinition();
}
示例8: onBeforePageDisplay
public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin)
{
// Enable only if the user has turned it on in Beta Preferences, or BetaFeatures is not installed.
// Will only be loaded if PageImages & TextExtracts extensions are installed.
$registry = ExtensionRegistry::getInstance();
if (!$registry->isLoaded('TextExtracts') || !class_exists('ApiQueryPageImages')) {
$logger = LoggerFactory::getInstance('popups');
$logger->error('Popups requires the PageImages and TextExtracts extensions.');
return true;
}
if (self::getConfig()->get('PopupsBetaFeature') === true) {
if (!class_exists('BetaFeatures')) {
$logger = LoggerFactory::getInstance('popups');
$logger->error('PopupsMode cannot be used as a beta feature unless ' . 'the BetaFeatures extension is present.');
return true;
}
if (!BetaFeatures::isFeatureEnabled($skin->getUser(), 'popups')) {
return true;
}
}
$out->addModules(array('ext.popups', 'schema.Popups'));
return true;
}
示例9: prepareTrackingCategoriesData
/**
* Read the global and extract title objects from the corresponding messages
* @return array Array( 'msg' => Title, 'cats' => Title[] )
*/
private function prepareTrackingCategoriesData()
{
$categories = array_merge(self::$coreTrackingCategories, ExtensionRegistry::getInstance()->getAttribute('TrackingCategories'), $this->getConfig()->get('TrackingCategories'));
$trackingCategories = [];
foreach ($categories as $catMsg) {
/*
* Check if the tracking category varies by namespace
* Otherwise only pages in the current namespace will be displayed
* If it does vary, show pages considering all namespaces
*/
$msgObj = $this->msg($catMsg)->inContentLanguage();
$allCats = [];
$catMsgTitle = Title::makeTitleSafe(NS_MEDIAWIKI, $catMsg);
if (!$catMsgTitle) {
continue;
}
// Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
// False positives are ok, this is just an efficiency shortcut
if (strpos($msgObj->plain(), '{{') !== false) {
$ns = MWNamespace::getValidNamespaces();
foreach ($ns as $namesp) {
$tempTitle = Title::makeTitleSafe($namesp, $catMsg);
if (!$tempTitle) {
continue;
}
$catName = $msgObj->title($tempTitle)->text();
# Allow tracking categories to be disabled by setting them to "-"
if ($catName !== '-') {
$catTitle = Title::makeTitleSafe(NS_CATEGORY, $catName);
if ($catTitle) {
$allCats[] = $catTitle;
}
}
}
} else {
$catName = $msgObj->text();
# Allow tracking categories to be disabled by setting them to "-"
if ($catName !== '-') {
$catTitle = Title::makeTitleSafe(NS_CATEGORY, $catName);
if ($catTitle) {
$allCats[] = $catTitle;
}
}
}
$trackingCategories[$catMsg] = ['cats' => $allCats, 'msg' => $catMsgTitle];
}
return $trackingCategories;
}
示例10: die
<?php
if (!defined('MEDIAWIKI')) {
die('Not an entry point.');
}
$GLOBALS['wgExtensionCredits']['wikibase'][] = array('path' => __FILE__, 'name' => 'Wikibase View', 'version' => WIKIBASE_VIEW_VERSION, 'author' => array('[http://www.snater.com H. Snater]'), 'url' => 'https://git.wikimedia.org/summary/mediawiki%2Fextensions%2FWikibaseView', 'description' => 'Wikibase View', 'license-name' => 'GPL-2.0+');
include 'resources.php';
include 'resources.test.php';
$GLOBALS['wgHooks']['UnitTestsList'][] = function (array &$paths) {
$paths[] = __DIR__ . '/tests/phpunit';
};
/**
* Register ResourceLoader modules with dynamic dependencies.
*
* @param ResourceLoader $resourceLoader
*
* @return bool
*/
$GLOBALS['wgHooks']['ResourceLoaderRegisterModules'][] = function (ResourceLoader $resourceLoader) {
preg_match('+' . preg_quote(DIRECTORY_SEPARATOR) . '(?:vendor|extensions)' . preg_quote(DIRECTORY_SEPARATOR) . '.*+', __DIR__, $remoteExtPath);
$moduleTemplate = array('localBasePath' => __DIR__, 'remoteExtPath' => '..' . $remoteExtPath[0], 'position' => 'top');
$modules = array('jquery.util.getDirectionality' => $moduleTemplate + array('scripts' => array('resources/jquery/jquery.util.getDirectionality.js'), 'dependencies' => array()), 'wikibase.getLanguageNameByCode' => $moduleTemplate + array('scripts' => array('resources/wikibase/wikibase.getLanguageNameByCode.js'), 'dependencies' => array('wikibase')));
$isUlsLoaded = ExtensionRegistry::getInstance()->isLoaded('UniversalLanguageSelector');
if ($isUlsLoaded) {
$modules['jquery.util.getDirectionality']['dependencies'][] = 'ext.uls.mediawiki';
$modules['wikibase.getLanguageNameByCode']['dependencies'][] = 'ext.uls.mediawiki';
}
$resourceLoader->register($modules);
return true;
};
示例11: foreach
foreach ($mmfl['setupFiles'] as $fileName) {
if (strval($fileName) === '') {
continue;
}
if (empty($mmfl['quiet'])) {
fwrite(STDERR, "Loading data from {$fileName}\n");
}
// Using extension.json or skin.json
if (substr($fileName, -strlen('.json')) === '.json') {
$queue[$fileName] = 1;
} else {
require_once $fileName;
}
}
if ($queue) {
$registry = new ExtensionRegistry();
$data = $registry->readFromQueue($queue);
foreach (array('wgExtensionMessagesFiles', 'wgMessagesDirs') as $var) {
if (isset($data['globals'][$var])) {
$GLOBALS[$var] = array_merge($data['globals'][$var], $GLOBALS[$var]);
}
}
}
fwrite(STDERR, "\n");
$s = "<" . "?php\n" . "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" . "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" . '$wgExtensionMessagesFiles = ' . var_export($wgExtensionMessagesFiles, true) . ";\n\n" . '$wgMessagesDirs = ' . var_export($wgMessagesDirs, true) . ";\n\n";
$dirs = array($IP, dirname(__DIR__), realpath($IP));
foreach ($dirs as $dir) {
$s = preg_replace("/'" . preg_quote($dir, '/') . "([^']*)'/", '"$IP\\1"', $s);
}
if (isset($mmfl['output'])) {
file_put_contents($mmfl['output'], $s);
示例12: wfLoadSkins
/**
* Load multiple skins at once
*
* @see wfLoadExtensions
* @param string[] $skins Array of extension names to load
*/
function wfLoadSkins(array $skins)
{
global $wgStyleDirectory;
$registry = ExtensionRegistry::getInstance();
foreach ($skins as $skin) {
$registry->queue("{$wgStyleDirectory}/{$skin}/skin.json");
}
}
示例13: getModuleSourceInfo
/**
* Returns information about the source of this module, if known
*
* Returned array is an array with the following keys:
* - path: Install path
* - name: Extension name, or "MediaWiki" for core
* - namemsg: (optional) i18n message key for a display name
* - license-name: (optional) Name of license
*
* @return array|null
*/
protected function getModuleSourceInfo()
{
global $IP;
if ($this->mModuleSource !== false) {
return $this->mModuleSource;
}
// First, try to find where the module comes from...
$rClass = new ReflectionClass($this);
$path = $rClass->getFileName();
if (!$path) {
// No path known?
$this->mModuleSource = null;
return null;
}
$path = realpath($path) ?: $path;
// Build map of extension directories to extension info
if (self::$extensionInfo === null) {
self::$extensionInfo = array(realpath(__DIR__) ?: __DIR__ => array('path' => $IP, 'name' => 'MediaWiki', 'license-name' => 'GPL-2.0+'), realpath("{$IP}/extensions") ?: "{$IP}/extensions" => null);
$keep = array('path' => null, 'name' => null, 'namemsg' => null, 'license-name' => null);
foreach ($this->getConfig()->get('ExtensionCredits') as $group) {
foreach ($group as $ext) {
if (!isset($ext['path']) || !isset($ext['name'])) {
// This shouldn't happen, but does anyway.
continue;
}
$extpath = $ext['path'];
if (!is_dir($extpath)) {
$extpath = dirname($extpath);
}
self::$extensionInfo[realpath($extpath) ?: $extpath] = array_intersect_key($ext, $keep);
}
}
foreach (ExtensionRegistry::getInstance()->getAllThings() as $ext) {
$extpath = $ext['path'];
if (!is_dir($extpath)) {
$extpath = dirname($extpath);
}
self::$extensionInfo[realpath($extpath) ?: $extpath] = array_intersect_key($ext, $keep);
}
}
// Now traverse parent directories until we find a match or run out of
// parents.
do {
if (array_key_exists($path, self::$extensionInfo)) {
// Found it!
$this->mModuleSource = self::$extensionInfo[$path];
return $this->mModuleSource;
}
$oldpath = $path;
$path = dirname($path);
} while ($path !== $oldpath);
// No idea what extension this might be.
$this->mModuleSource = null;
return null;
}
示例14: checkRequiredExtensions
/**
* Verify that the required extensions are installed
*
* @since 1.28
*/
public function checkRequiredExtensions()
{
$registry = ExtensionRegistry::getInstance();
$missing = [];
foreach ($this->requiredExtensions as $name) {
if (!$registry->isLoaded($name)) {
$missing[] = $name;
}
}
if ($missing) {
$joined = implode(', ', $missing);
$msg = "The following extensions are required to be installed " . "for this script to run: {$joined}. Please enable them and then try again.";
$this->error($msg, 1);
}
}
示例15: getCSS
/**
* Get the stylesheet of the MediaWiki skin.
*
* @return string
*/
public function getCSS()
{
global $wgStyleDirectory;
$moduleNames = array('mediawiki.legacy.shared', 'mediawiki.skinning.interface');
$resourceLoader = new ResourceLoader();
if (file_exists("{$wgStyleDirectory}/Vector/skin.json")) {
// Force loading Vector skin if available as a fallback skin
// for whatever ResourceLoader wants to have as the default.
$registry = new ExtensionRegistry();
$data = $registry->readFromQueue(array("{$wgStyleDirectory}/Vector/skin.json" => 1));
if (isset($data['globals']['wgResourceModules'])) {
$resourceLoader->register($data['globals']['wgResourceModules']);
}
$moduleNames[] = 'skins.vector.styles';
}
$moduleNames[] = 'mediawiki.legacy.config';
$rlContext = new ResourceLoaderContext($resourceLoader, new FauxRequest(array('debug' => 'true', 'lang' => $this->getLanguageCode(), 'only' => 'styles')));
$styles = array();
foreach ($moduleNames as $moduleName) {
/** @var ResourceLoaderFileModule $module */
$module = $resourceLoader->getModule($moduleName);
if (!$module) {
// T98043: Don't fatal, but it won't look as pretty.
continue;
}
// Based on: ResourceLoaderFileModule::getStyles (without the DB query)
$styles = array_merge($styles, ResourceLoader::makeCombinedStyles($module->readStyleFiles($module->getStyleFiles($rlContext), $module->getFlip($rlContext))));
}
return implode("\n", $styles);
}