本文整理汇总了PHP中ExtensionRegistry::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ExtensionRegistry::getInstance方法的具体用法?PHP ExtensionRegistry::getInstance怎么用?PHP ExtensionRegistry::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExtensionRegistry
的用法示例。
在下文中一共展示了ExtensionRegistry::getInstance方法的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: providePassesValidation
public static function providePassesValidation()
{
$values = [];
foreach (ExtensionRegistry::getInstance()->getAllThings() as $thing) {
$values[] = [$thing['path']];
}
return $values;
}
示例4: 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);
}
示例5: 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;
}
示例6: 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();
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
};
示例10: setupOOUI
/**
* Helper function to setup the PHP implementation of OOUI to use in this request.
*
* @since 1.26
* @param String $skinName The Skin name to determine the correct OOUI theme
* @param String $dir Language direction
*/
public static function setupOOUI($skinName = '', $dir = 'ltr')
{
$themes = ExtensionRegistry::getInstance()->getAttribute('SkinOOUIThemes');
// Make keys (skin names) lowercase for case-insensitive matching.
$themes = array_change_key_case($themes, CASE_LOWER);
$theme = isset($themes[$skinName]) ? $themes[$skinName] : 'MediaWiki';
// For example, 'OOUI\MediaWikiTheme'.
$themeClass = "OOUI\\{$theme}Theme";
OOUI\Theme::setSingleton(new $themeClass());
OOUI\Element::setDefaultDir($dir);
}
示例11: exit
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
use MediaWiki\MediaWikiServices;
/**
* This file is not a valid entry point, perform no further processing unless
* MEDIAWIKI is defined
*/
if (!defined('MEDIAWIKI')) {
exit(1);
}
$fname = 'Setup.php';
$ps_setup = Profiler::instance()->scopedProfileIn($fname);
// If any extensions are still queued, force load them
ExtensionRegistry::getInstance()->loadFromQueue();
// Check to see if we are at the file scope
if (!isset($wgVersion)) {
echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
die(1);
}
mb_internal_encoding('UTF-8');
// Set various default paths sensibly...
$ps_default = Profiler::instance()->scopedProfileIn($fname . '-defaults');
if ($wgScript === false) {
$wgScript = "{$wgScriptPath}/index.php";
}
if ($wgLoadScript === false) {
$wgLoadScript = "{$wgScriptPath}/load.php";
}
if ($wgArticlePath === false) {
示例12: getCanonicalNamespaces
/**
* Returns array of all defined namespaces with their canonical
* (English) names.
*
* @param bool $rebuild Rebuild namespace list (default = false). Used for testing.
*
* @return array
* @since 1.17
*/
public static function getCanonicalNamespaces($rebuild = false)
{
static $namespaces = null;
if ($namespaces === null || $rebuild) {
global $wgExtraNamespaces, $wgCanonicalNamespaceNames;
$namespaces = [NS_MAIN => ''] + $wgCanonicalNamespaceNames;
// Add extension namespaces
$namespaces += ExtensionRegistry::getInstance()->getAttribute('ExtensionNamespaces');
if (is_array($wgExtraNamespaces)) {
$namespaces += $wgExtraNamespaces;
}
Hooks::run('CanonicalNamespaces', [&$namespaces]);
}
return $namespaces;
}
示例13: getenv
// Check the MW_INSTALL_PATH environment variable, to see if it is set. If so,
// this is the root folder of the MediaWiki installation.
$MWPath = getenv("MW_INSTALL_PATH");
if ($MWPath === false) {
// if it is not set, then assume the default location
$MWPath = dirname(__FILE__) . "/../../..";
// if the guess was wrong, then die
if (!file_exists($MWPath . MWEntryPoint)) {
die("Unable to locate MediaWiki installation. " . "Try setting the MW_INSTALL_PATH environment variable to the mediawiki folder.\n");
}
} elseif (!file_exists($MWPath . MWEntryPoint)) {
// if it was set and the maintence directory still can't be found, then die
die("MediaWiki not found at MW_INSTALL_PATH (" . $MWPath . ").\n");
}
// If we get here, then MediaWiki was found, so load Maintenance.php
require_once $MWPath . MWEntryPoint;
if (!ExtensionRegistry::getInstance()->isLoaded('ContentReferencer')) {
die("This script requries that the ContentReferencer extension is loaded. \n Please add `wfLoadExtension('ContentReferencer')` to your LocalSettings.php file.");
}
// load the database
wfWaitForSlaves(false);
$DB =& wfGetDB(DB_MASTER);
// check if the ContentReferencer table exists
$hasContentRefTable = $DB->tableExists(ContentReferencerTableName);
if (!$hasContentRefTable) {
echo "Creating table \"" . ContentReferencerTableName . "\".\n";
// now we need to actually create the table
$DB->query("\n CREATE TABLE IF NOT EXISTS " . ContentReferencerTableName . "(\n reference_name varchar(255),\n reference_page_name varchar(255),\n \n PRIMARY KEY (reference_name)\n )\n ");
} else {
echo "Table \"" . ContentReferencerTableName . "\" already exists, not creating.\n";
}
示例14: renderHook
/**
* Hook into Content::getParserOutput to provide syntax highlighting for
* script content.
*
* @return bool
* @since MW 1.21
*/
public static function renderHook(Content $content, Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
{
global $wgSyntaxHighlightModels, $wgUseSiteCss, $wgParser, $wgTextModelsToParse;
$highlightModels = ExtensionRegistry::getInstance()->getAttribute('SyntaxHighlightModels');
// Determine the language
$model = $content->getModel();
if (!isset($highlightModels[$model]) && !isset($wgSyntaxHighlightModels[$model])) {
// We don't care about this model, carry on.
return true;
}
if (!$generateHtml) {
// Nothing special for us to do, let MediaWiki handle this.
return true;
}
// Hope that $wgSyntaxHighlightModels does not contain silly types.
$text = ContentHandler::getContentText($content);
if ($text === null || $text === false) {
// Oops! Non-text content? Let MediaWiki handle this.
return true;
}
// Parse using the standard parser to get links etc. into the database, HTML is replaced below.
// We could do this using $content->fillParserOutput(), but alas it is 'protected'.
if ($content instanceof TextContent && in_array($model, $wgTextModelsToParse)) {
$output = $wgParser->parse($text, $title, $options, true, true, $revId);
}
if (isset($highlightModels[$model])) {
$lang = $highlightModels[$model];
} else {
// TODO: Add deprecation warning after a while?
$lang = $wgSyntaxHighlightModels[$model];
}
// Attempt to format
$geshi = self::prepare($text, $lang);
if ($geshi instanceof GeSHi) {
$out = $geshi->parse_code();
if (!$geshi->error()) {
// Done
$output->addModuleStyles("ext.geshi.language.{$lang}");
$output->setText("<div dir=\"ltr\">{$out}</div>");
if ($wgUseSiteCss) {
$output->addModuleStyles('ext.geshi.local');
}
// Inform MediaWiki that we have parsed this page and it shouldn't mess with it.
return false;
}
}
// Bottle out
return true;
}
示例15: 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);
}
}