/**
  * @param ResourceLoaderContext $context
  * @return array
  */
 protected function getConfigSettings($context)
 {
     $hash = $context->getHash();
     if (isset($this->configVars[$hash])) {
         return $this->configVars[$hash];
     }
     global $wgContLang;
     $mainPage = Title::newMainPage();
     /**
      * Namespace related preparation
      * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces.
      * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive.
      */
     $namespaceIds = $wgContLang->getNamespaceIds();
     $caseSensitiveNamespaces = array();
     foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) {
         $namespaceIds[$wgContLang->lc($name)] = $index;
         if (!MWNamespace::isCapitalized($index)) {
             $caseSensitiveNamespaces[] = $index;
         }
     }
     $conf = $this->getConfig();
     // Build list of variables
     $vars = array('wgLoadScript' => wfScript('load'), 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $conf->get('StylePath'), 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $conf->get('ArticlePath'), 'wgScriptPath' => $conf->get('ScriptPath'), 'wgScriptExtension' => '.php', 'wgScript' => wfScript(), 'wgSearchType' => $conf->get('SearchType'), 'wgVariantArticlePath' => $conf->get('VariantArticlePath'), 'wgActionPaths' => (object) $conf->get('ActionPaths'), 'wgServer' => $conf->get('Server'), 'wgServerName' => $conf->get('ServerName'), 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgTranslateNumerals' => $conf->get('TranslateNumerals'), 'wgVersion' => $conf->get('Version'), 'wgEnableAPI' => $conf->get('EnableAPI'), 'wgEnableWriteAPI' => $conf->get('EnableWriteAPI'), 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $conf->get('Sitename'), 'wgDBname' => $conf->get('DBname'), 'wgExtraSignatureNamespaces' => $conf->get('ExtraSignatureNamespaces'), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $conf->get('ExtensionAssetsPath'), 'wgCookiePrefix' => $conf->get('CookiePrefix'), 'wgCookieDomain' => $conf->get('CookieDomain'), 'wgCookiePath' => $conf->get('CookiePath'), 'wgCookieExpiration' => $conf->get('CookieExpiration'), 'wgResourceLoaderMaxQueryLength' => $conf->get('ResourceLoaderMaxQueryLength'), 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgResourceLoaderStorageVersion' => $conf->get('ResourceLoaderStorageVersion'), 'wgResourceLoaderStorageEnabled' => $conf->get('ResourceLoaderStorageEnabled'), 'wgResourceLoaderLegacyModules' => self::getLegacyModules(), 'wgForeignUploadTargets' => $conf->get('ForeignUploadTargets'), 'wgEnableUploads' => $conf->get('EnableUploads'));
     Hooks::run('ResourceLoaderGetConfigVars', array(&$vars));
     $this->configVars[$hash] = $vars;
     return $this->configVars[$hash];
 }
 /**
  * @param ResourceLoaderContext $context
  * @return array
  */
 protected function getConfig($context)
 {
     $hash = $context->getHash();
     if (isset($this->configVars[$hash])) {
         return $this->configVars[$hash];
     }
     global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgVersion, $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath, $wgCookiePrefix, $wgResourceLoaderMaxQueryLength, $wgResourceLoaderStorageEnabled, $wgResourceLoaderStorageVersion, $wgSearchType;
     $mainPage = Title::newMainPage();
     /**
      * Namespace related preparation
      * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces.
      * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive.
      */
     $namespaceIds = $wgContLang->getNamespaceIds();
     $caseSensitiveNamespaces = array();
     foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) {
         $namespaceIds[$wgContLang->lc($name)] = $index;
         if (!MWNamespace::isCapitalized($index)) {
             $caseSensitiveNamespaces[] = $index;
         }
     }
     // Build list of variables
     $vars = array('wgLoadScript' => $wgLoadScript, 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $wgStylePath, 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScriptExtension' => $wgScriptExtension, 'wgScript' => $wgScript, 'wgSearchType' => $wgSearchType, 'wgVariantArticlePath' => $wgVariantArticlePath, 'wgActionPaths' => (object) $wgActionPaths, 'wgServer' => $wgServer, 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgVersion' => $wgVersion, 'wgEnableAPI' => $wgEnableAPI, 'wgEnableWriteAPI' => $wgEnableWriteAPI, 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $wgSitename, 'wgFileExtensions' => array_values(array_unique($wgFileExtensions)), 'wgDBname' => $wgDBname, 'wgFileCanRotate' => BitmapHandler::canRotate(), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $wgExtensionAssetsPath, 'wgCookiePrefix' => $wgCookiePrefix, 'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength, 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgResourceLoaderStorageVersion' => $wgResourceLoaderStorageVersion, 'wgResourceLoaderStorageEnabled' => $wgResourceLoaderStorageEnabled);
     wfRunHooks('ResourceLoaderGetConfigVars', array(&$vars));
     $this->configVars[$hash] = $vars;
     return $this->configVars[$hash];
 }
 /**
  * @param $context ResourceLoaderContext
  * @return array
  */
 protected function getConfig($context)
 {
     global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgUseAjax, $wgVersion, $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgEnableMWSuggest, $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath, $wgCookiePrefix, $wgResourceLoaderMaxQueryLength;
     $mainPage = Title::newMainPage();
     /**
      * Namespace related preparation
      * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces.
      * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive.
      */
     $namespaceIds = $wgContLang->getNamespaceIds();
     $caseSensitiveNamespaces = array();
     foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) {
         $namespaceIds[$wgContLang->lc($name)] = $index;
         if (!MWNamespace::isCapitalized($index)) {
             $caseSensitiveNamespaces[] = $index;
         }
     }
     // Build list of variables
     $vars = array('wgLoadScript' => $wgLoadScript, 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $wgStylePath, 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScriptExtension' => $wgScriptExtension, 'wgScript' => $wgScript, 'wgVariantArticlePath' => $wgVariantArticlePath, 'wgActionPaths' => (object) $wgActionPaths, 'wgServer' => $wgServer, 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgVersion' => $wgVersion, 'wgEnableAPI' => $wgEnableAPI, 'wgEnableWriteAPI' => $wgEnableWriteAPI, 'wgDefaultDateFormat' => $wgContLang->getDefaultDateFormat(), 'wgMonthNames' => $wgContLang->getMonthNamesArray(), 'wgMonthNamesShort' => $wgContLang->getMonthAbbreviationsArray(), 'wgMainPageTitle' => $mainPage ? $mainPage->getPrefixedText() : null, 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgSiteName' => $wgSitename, 'wgFileExtensions' => array_values($wgFileExtensions), 'wgDBname' => $wgDBname, 'wgFileCanRotate' => BitmapHandler::canRotate(), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $wgExtensionAssetsPath, 'wgCookiePrefix' => $wgCookiePrefix, 'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength, 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgSassParams' => SassUtil::getSassSettings());
     if ($wgUseAjax && $wgEnableMWSuggest) {
         $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
     }
     wfRunHooks('ResourceLoaderGetConfigVars', array(&$vars));
     return $vars;
 }
	public static function titleString( $title ) {
		$namespace = $title->getNsText();
		if ( $namespace != '' ) {
			$namespace .= ':';
		}
		if ( MWNamespace::isCapitalized( $title->getNamespace() ) ) {
			global $wgContLang;
			return $namespace . $wgContLang->ucfirst( $title->getText() );
		} else {
			return $namespace . $title->getText();
		}
	}
示例#5
0
 public function execute()
 {
     $this->user = User::newSystemUser('Conversion script', ['steal' => true]);
     $this->namespace = intval($this->getOption('namespace', 0));
     if (MWNamespace::isCapitalized($this->namespace)) {
         $this->output("Will be moving pages to first letter capitalized titles");
         $callback = 'processRowToUppercase';
     } else {
         $this->output("Will be moving pages to first letter lowercase titles");
         $callback = 'processRowToLowercase';
     }
     $this->dryrun = $this->hasOption('dry-run');
     $this->runTable(['table' => 'page', 'conds' => ['page_namespace' => $this->namespace], 'index' => 'page_id', 'callback' => $callback]);
 }
示例#6
0
 function register()
 {
     global $wgContLang, $wgNamespaceAliases, $wgNonincludableNamespaces;
     $lib = array('loadSiteStats' => array($this, 'loadSiteStats'), 'getNsIndex' => array($this, 'getNsIndex'), 'pagesInCategory' => array($this, 'pagesInCategory'), 'pagesInNamespace' => array($this, 'pagesInNamespace'), 'usersInGroup' => array($this, 'usersInGroup'));
     $info = array('siteName' => $GLOBALS['wgSitename'], 'server' => $GLOBALS['wgServer'], 'scriptPath' => $GLOBALS['wgScriptPath'], 'stylePath' => $GLOBALS['wgStylePath'], 'currentVersion' => SpecialVersion::getVersion());
     if (!self::$namespacesCache) {
         $namespaces = array();
         $namespacesByName = array();
         foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
             $canonical = MWNamespace::getCanonicalName($ns);
             $namespaces[$ns] = array('id' => $ns, 'name' => $title, 'canonicalName' => strtr($canonical, '_', ' '), 'hasSubpages' => MWNamespace::hasSubpages($ns), 'hasGenderDistinction' => MWNamespace::hasGenderDistinction($ns), 'isCapitalized' => MWNamespace::isCapitalized($ns), 'isContent' => MWNamespace::isContent($ns), 'isIncludable' => !($wgNonincludableNamespaces && in_array($ns, $wgNonincludableNamespaces)), 'isMovable' => MWNamespace::isMovable($ns), 'isSubject' => MWNamespace::isSubject($ns), 'isTalk' => MWNamespace::isTalk($ns), 'aliases' => array());
             if ($ns >= NS_MAIN) {
                 $namespaces[$ns]['subject'] = MWNamespace::getSubject($ns);
                 $namespaces[$ns]['talk'] = MWNamespace::getTalk($ns);
                 $namespaces[$ns]['associated'] = MWNamespace::getAssociated($ns);
             } else {
                 $namespaces[$ns]['subject'] = $ns;
             }
             $namespacesByName[strtr($title, ' ', '_')] = $ns;
             if ($canonical) {
                 $namespacesByName[$canonical] = $ns;
             }
         }
         $aliases = array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases());
         foreach ($aliases as $title => $ns) {
             if (!isset($namespacesByName[$title])) {
                 $ct = count($namespaces[$ns]['aliases']);
                 $namespaces[$ns]['aliases'][$ct + 1] = $title;
                 $namespacesByName[$title] = $ns;
             }
         }
         $namespaces[NS_MAIN]['displayName'] = wfMessage('blanknamespace')->text();
         self::$namespacesCache = $namespaces;
     }
     $info['namespaces'] = self::$namespacesCache;
     if (self::$siteStatsLoaded) {
         $stats = $this->loadSiteStats();
         $info['stats'] = $stats[0];
     }
     $this->getEngine()->registerInterface('mw.site.lua', $lib, $info);
 }
示例#7
0
 function register()
 {
     global $wgContLang, $wgNamespaceAliases, $wgDisableCounters;
     $lib = array('getNsIndex' => array($this, 'getNsIndex'), 'pagesInCategory' => array($this, 'pagesInCategory'), 'pagesInNamespace' => array($this, 'pagesInNamespace'), 'usersInGroup' => array($this, 'usersInGroup'), 'interwikiMap' => array($this, 'interwikiMap'));
     $info = array('siteName' => $GLOBALS['wgSitename'], 'server' => $GLOBALS['wgServer'], 'scriptPath' => $GLOBALS['wgScriptPath'], 'stylePath' => $GLOBALS['wgStylePath'], 'currentVersion' => SpecialVersion::getVersion());
     if (!self::$namespacesCache || self::$namespacesCacheLang !== $wgContLang->getCode()) {
         $namespaces = array();
         $namespacesByName = array();
         foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
             $canonical = MWNamespace::getCanonicalName($ns);
             $namespaces[$ns] = array('id' => $ns, 'name' => $title, 'canonicalName' => strtr($canonical, '_', ' '), 'hasSubpages' => MWNamespace::hasSubpages($ns), 'hasGenderDistinction' => MWNamespace::hasGenderDistinction($ns), 'isCapitalized' => MWNamespace::isCapitalized($ns), 'isContent' => MWNamespace::isContent($ns), 'isIncludable' => !MWNamespace::isNonincludable($ns), 'isMovable' => MWNamespace::isMovable($ns), 'isSubject' => MWNamespace::isSubject($ns), 'isTalk' => MWNamespace::isTalk($ns), 'defaultContentModel' => MWNamespace::getNamespaceContentModel($ns), 'aliases' => array());
             if ($ns >= NS_MAIN) {
                 $namespaces[$ns]['subject'] = MWNamespace::getSubject($ns);
                 $namespaces[$ns]['talk'] = MWNamespace::getTalk($ns);
                 $namespaces[$ns]['associated'] = MWNamespace::getAssociated($ns);
             } else {
                 $namespaces[$ns]['subject'] = $ns;
             }
             $namespacesByName[strtr($title, ' ', '_')] = $ns;
             if ($canonical) {
                 $namespacesByName[$canonical] = $ns;
             }
         }
         $aliases = array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases());
         foreach ($aliases as $title => $ns) {
             if (!isset($namespacesByName[$title]) && isset($namespaces[$ns])) {
                 $ct = count($namespaces[$ns]['aliases']);
                 $namespaces[$ns]['aliases'][$ct + 1] = $title;
                 $namespacesByName[$title] = $ns;
             }
         }
         $namespaces[NS_MAIN]['displayName'] = wfMessage('blanknamespace')->inContentLanguage()->text();
         self::$namespacesCache = $namespaces;
         self::$namespacesCacheLang = $wgContLang->getCode();
     }
     $info['namespaces'] = self::$namespacesCache;
     $info['stats'] = array('pages' => (int) SiteStats::pages(), 'articles' => (int) SiteStats::articles(), 'files' => (int) SiteStats::images(), 'edits' => (int) SiteStats::edits(), 'views' => $wgDisableCounters ? null : (int) SiteStats::views(), 'users' => (int) SiteStats::users(), 'activeUsers' => (int) SiteStats::activeUsers(), 'admins' => (int) SiteStats::numberingroup('sysop'));
     return $this->getEngine()->registerInterface('mw.site.lua', $lib, $info);
 }
示例#8
0
 /**
  * Add upload JS to the OutputPage
  */
 protected function addUploadJS()
 {
     $config = $this->getConfig();
     $useAjaxDestCheck = $config->get('UseAjax') && $config->get('AjaxUploadDestCheck');
     $useAjaxLicensePreview = $config->get('UseAjax') && $config->get('AjaxLicensePreview') && $config->get('EnableAPI');
     $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
     $scriptVars = array('wgAjaxUploadDestCheck' => $useAjaxDestCheck, 'wgAjaxLicensePreview' => $useAjaxLicensePreview, 'wgUploadAutoFill' => !$this->mForReUpload && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds, 'wgCheckFileExtensions' => $config->get('CheckFileExtensions'), 'wgStrictFileExtensions' => $config->get('StrictFileExtensions'), 'wgFileExtensions' => array_values(array_unique($config->get('FileExtensions'))), 'wgCapitalizeUploads' => MWNamespace::isCapitalized(NS_FILE), 'wgMaxUploadSize' => $this->mMaxUploadSize, 'wgFileCanRotate' => SpecialUpload::rotationEnabled());
     $out = $this->getOutput();
     $out->addJsConfigVars($scriptVars);
     $out->addModules(array('mediawiki.action.edit', 'mediawiki.special.upload'));
 }
示例#9
0
 /**
  * Add upload JS to the OutputPage
  */
 protected function addUploadJS()
 {
     global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI, $wgStrictFileExtensions;
     $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
     $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI;
     $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
     $scriptVars = array('wgAjaxUploadDestCheck' => $useAjaxDestCheck, 'wgAjaxLicensePreview' => $useAjaxLicensePreview, 'wgUploadAutoFill' => !$this->mForReUpload && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds, 'wgStrictFileExtensions' => $wgStrictFileExtensions, 'wgCapitalizeUploads' => MWNamespace::isCapitalized(NS_FILE), 'wgMaxUploadSize' => $this->mMaxUploadSize);
     $out = $this->getOutput();
     $out->addJsConfigVars($scriptVars);
     $out->addModules(array('mediawiki.action.edit', 'mediawiki.legacy.upload', 'mediawiki.special.upload'));
 }
示例#10
0
 /**
  * Get the name of an image from its title object
  *
  * @param $title Title
  */
 public function getNameFromTitle(Title $title)
 {
     global $wgContLang;
     if ($this->initialCapital != MWNamespace::isCapitalized(NS_FILE)) {
         $name = $title->getUserCaseDBKey();
         if ($this->initialCapital) {
             $name = $wgContLang->ucfirst($name);
         }
     } else {
         $name = $title->getDBkey();
     }
     return $name;
 }
示例#11
0
 /**
  * Some namespaces are always capitalized per code definition
  * in MWNamespace::$alwaysCapitalizedNamespaces
  */
 public function testIsCapitalizedHardcodedAssertions()
 {
     // NS_MEDIA and NS_FILE are treated the same
     $this->assertEquals(MWNamespace::isCapitalized(NS_MEDIA), MWNamespace::isCapitalized(NS_FILE), 'NS_MEDIA and NS_FILE have same capitalization rendering');
     // Boths are capitalized by default
     $this->assertIsCapitalized(NS_MEDIA);
     $this->assertIsCapitalized(NS_FILE);
     // Always capitalized namespaces
     // @see MWNamespace::$alwaysCapitalizedNamespaces
     $this->assertIsCapitalized(NS_SPECIAL);
     $this->assertIsCapitalized(NS_USER);
     $this->assertIsCapitalized(NS_MEDIAWIKI);
 }
示例#12
0
 protected function appendNamespaces($property)
 {
     global $wgContLang;
     $data = array(ApiResult::META_TYPE => 'assoc');
     foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
         $data[$ns] = array('id' => intval($ns), 'case' => MWNamespace::isCapitalized($ns) ? 'first-letter' : 'case-sensitive');
         ApiResult::setContentValue($data[$ns], 'name', $title);
         $canonical = MWNamespace::getCanonicalName($ns);
         $data[$ns]['subpages'] = MWNamespace::hasSubpages($ns);
         if ($canonical) {
             $data[$ns]['canonical'] = strtr($canonical, '_', ' ');
         }
         $data[$ns]['content'] = MWNamespace::isContent($ns);
         $data[$ns]['nonincludable'] = MWNamespace::isNonincludable($ns);
         $contentmodel = MWNamespace::getNamespaceContentModel($ns);
         if ($contentmodel) {
             $data[$ns]['defaultcontentmodel'] = $contentmodel;
         }
     }
     ApiResult::setIndexedTagName($data, 'ns');
     return $this->getResult()->addValue('query', $property, $data);
 }
示例#13
0
 /**
  * Capitalize a text string for a title if it belongs to a namespace that capitalizes
  *
  * @param string $text Containing title to capitalize
  * @param int $ns Namespace index, defaults to NS_MAIN
  * @return string Containing capitalized title
  */
 public static function capitalize($text, $ns = NS_MAIN)
 {
     global $wgContLang;
     if (MWNamespace::isCapitalized($ns)) {
         return $wgContLang->ucfirst($text);
     } else {
         return $text;
     }
 }
示例#14
0
 /**
  * Counter part for MWNamespace::testIsCapitalizedWithWgCapitalLinks() now
  * testing the $wgCapitalLinkOverrides global.
  *
  * @todo split groups of assertions in autonomous testing functions
  */
 public function testIsCapitalizedWithWgCapitalLinkOverrides()
 {
     global $wgCapitalLinkOverrides;
     // Save the global to easily reset to MediaWiki default settings
     $savedGlobal = $wgCapitalLinkOverrides;
     // Test default settings
     $this->assertTrue(MWNamespace::isCapitalized(NS_PROJECT));
     $this->assertTrue(MWNamespace::isCapitalized(NS_PROJECT_TALK));
     // hardcoded namespaces (see above function) are capitalized:
     $this->assertTrue(MWNamespace::isCapitalized(NS_SPECIAL));
     $this->assertTrue(MWNamespace::isCapitalized(NS_USER));
     $this->assertTrue(MWNamespace::isCapitalized(NS_MEDIAWIKI));
     // Hardcoded namespaces remains capitalized
     $wgCapitalLinkOverrides[NS_SPECIAL] = false;
     $wgCapitalLinkOverrides[NS_USER] = false;
     $wgCapitalLinkOverrides[NS_MEDIAWIKI] = false;
     $this->assertTrue(MWNamespace::isCapitalized(NS_SPECIAL));
     $this->assertTrue(MWNamespace::isCapitalized(NS_USER));
     $this->assertTrue(MWNamespace::isCapitalized(NS_MEDIAWIKI));
     $wgCapitalLinkOverrides = $savedGlobal;
     $wgCapitalLinkOverrides[NS_PROJECT] = false;
     $this->assertFalse(MWNamespace::isCapitalized(NS_PROJECT));
     $wgCapitalLinkOverrides[NS_PROJECT] = true;
     $this->assertTrue(MWNamespace::isCapitalized(NS_PROJECT));
     unset($wgCapitalLinkOverrides[NS_PROJECT]);
     $this->assertTrue(MWNamespace::isCapitalized(NS_PROJECT));
     // reset global state:
     $wgCapitalLinkOverrides = $savedGlobal;
 }
	/**
	 * @param $context ResourceLoaderContext
	 * @return array
	 */
	protected function getConfig( $context ) {
		global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension,
			$wgArticlePath, $wgScriptPath, $wgServer, $wgContLang,
			$wgVariantArticlePath, $wgActionPaths, $wgVersion,
			$wgEnableAPI, $wgEnableWriteAPI, $wgDBname,
			$wgSitename, $wgFileExtensions, $wgExtensionAssetsPath,
			$wgCookiePrefix, $wgResourceLoaderMaxQueryLength;

		$mainPage = Title::newMainPage();

		/**
		 * Namespace related preparation
		 * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces.
		 * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive.
		 */
		$namespaceIds = $wgContLang->getNamespaceIds();
		$caseSensitiveNamespaces = array();
		foreach ( MWNamespace::getCanonicalNamespaces() as $index => $name ) {
			$namespaceIds[$wgContLang->lc( $name )] = $index;
			if ( !MWNamespace::isCapitalized( $index ) ) {
				$caseSensitiveNamespaces[] = $index;
			}
		}

		// Build list of variables
		$vars = array(
			'wgLoadScript' => $wgLoadScript,
			'debug' => $context->getDebug(),
			'skin' => $context->getSkin(),
			'stylepath' => $wgStylePath,
			'wgUrlProtocols' => wfUrlProtocols(),
			'wgArticlePath' => $wgArticlePath,
			'wgScriptPath' => $wgScriptPath,
			'wgScriptExtension' => $wgScriptExtension,
			'wgScript' => $wgScript,
			'wgVariantArticlePath' => $wgVariantArticlePath,
			// Force object to avoid "empty" associative array from
			// becoming [] instead of {} in JS (bug 34604)
			'wgActionPaths' => (object)$wgActionPaths,
			'wgServer' => $wgServer,
			'wgUserLanguage' => $context->getLanguage(),
			'wgContentLanguage' => $wgContLang->getCode(),
			'wgVersion' => $wgVersion,
			'wgEnableAPI' => $wgEnableAPI,
			'wgEnableWriteAPI' => $wgEnableWriteAPI,
			'wgMainPageTitle' => $mainPage->getPrefixedText(),
			'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
			'wgNamespaceIds' => $namespaceIds,
			'wgSiteName' => $wgSitename,
			'wgFileExtensions' => array_values( array_unique( $wgFileExtensions ) ),
			'wgDBname' => $wgDBname,
			// This sucks, it is only needed on Special:Upload, but I could
			// not find a way to add vars only for a certain module
			'wgFileCanRotate' => BitmapHandler::canRotate(),
			'wgAvailableSkins' => Skin::getSkinNames(),
			'wgExtensionAssetsPath' => $wgExtensionAssetsPath,
			// MediaWiki sets cookies to have this prefix by default
			'wgCookiePrefix' => $wgCookiePrefix,
			'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength,
			'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces,
			'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass( Title::legalChars() ),
		);

		wfRunHooks( 'ResourceLoaderGetConfigVars', array( &$vars ) );

		return $vars;
	}
 protected function showChanges($allowed, $limit)
 {
     global $wgContLang;
     $diff = new DifferenceEngine($this->getContext());
     $diff->showDiffStyle();
     $diff->setReducedLineNumbers();
     $this->diff = $diff;
     $out = $this->getOutput();
     $out->addHtml('' . Html::openElement('form', array('method' => 'post')) . Html::hidden('title', $this->getPageTitle()->getPrefixedText()) . Html::hidden('token', $this->getUser()->getEditToken()) . $this->getLegend());
     // The above count as two
     $limit = $limit - 2;
     $changefile = TranslateUtils::cacheFile(self::CHANGEFILE);
     $reader = CdbReader::open($changefile);
     $groups = unserialize($reader->get('#keys'));
     foreach ($groups as $id) {
         $group = MessageGroups::getGroup($id);
         if (!$group) {
             continue;
         }
         $changes = unserialize($reader->get($id));
         $out->addHtml(Html::element('h2', array(), $group->getLabel()));
         // Reduce page existance queries to one per group
         $lb = new LinkBatch();
         $ns = $group->getNamespace();
         $isCap = MWNamespace::isCapitalized($ns);
         foreach ($changes as $code => $subchanges) {
             foreach ($subchanges as $messages) {
                 foreach ($messages as $params) {
                     // Constructing title objects is way slower
                     $key = $params['key'];
                     if ($isCap) {
                         $key = $wgContLang->ucfirst($key);
                     }
                     $lb->add($ns, "{$key}/{$code}");
                 }
             }
         }
         $lb->execute();
         foreach ($changes as $code => $subchanges) {
             foreach ($subchanges as $type => $messages) {
                 foreach ($messages as $params) {
                     $change = $this->formatChange($group, $code, $type, $params, $limit);
                     $out->addHtml($change);
                     if ($limit <= 0) {
                         // We need to restrict the changes per page per form submission
                         // limitations as well as performance.
                         $out->wrapWikiMsg("<div class=warning>\n\$1\n</div>", 'translate-smg-more');
                         break 4;
                     }
                 }
             }
         }
     }
     $attribs = array('type' => 'submit', 'class' => 'mw-translate-smg-submit');
     if (!$allowed) {
         $attribs['disabled'] = 'disabled';
         $attribs['title'] = $this->msg('translate-smg-notallowed')->text();
     }
     $button = Html::element('button', $attribs, $this->msg('translate-smg-submit')->text());
     $out->addHtml($button);
     $out->addHtml(Html::closeElement('form'));
 }
示例#17
0
	/**
	 * Add upload JS to the OutputPage
	 */
	protected function addUploadJS() {
		global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI, $wgStrictFileExtensions;

		$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
		$useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI;
		$this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();

		$scriptVars = array(
			'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
			'wgAjaxLicensePreview' => $useAjaxLicensePreview,
			'wgUploadAutoFill' => !$this->mForReUpload &&
				// If we received mDestFile from the request, don't autofill
				// the wpDestFile textbox
				$this->mDestFile === '',
			'wgUploadSourceIds' => $this->mSourceIds,
			'wgStrictFileExtensions' => $wgStrictFileExtensions,
			'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
			'wgMaxUploadSize' => $this->mMaxUploadSize,
		);

		$out = $this->getOutput();
		$out->addJsConfigVars( $scriptVars );

		$out->addModules( array(
			'mediawiki.action.edit', // For <charinsert> support
			'mediawiki.legacy.upload', // Old form stuff...
			'mediawiki.special.upload', // Newer extras for thumbnail preview.
		) );
	}
示例#18
0
 protected function appendNamespaces($property)
 {
     global $wgContLang;
     $data = array();
     foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
         $data[$ns] = array('id' => intval($ns), 'case' => MWNamespace::isCapitalized($ns) ? 'first-letter' : 'case-sensitive');
         ApiResult::setContent($data[$ns], $title);
         $canonical = MWNamespace::getCanonicalName($ns);
         if (MWNamespace::hasSubpages($ns)) {
             $data[$ns]['subpages'] = '';
         }
         if ($canonical) {
             $data[$ns]['canonical'] = strtr($canonical, '_', ' ');
         }
         if (MWNamespace::isContent($ns)) {
             $data[$ns]['content'] = '';
         }
     }
     $this->getResult()->setIndexedTagName($data, 'ns');
     return $this->getResult()->addValue('query', $property, $data);
 }
示例#19
0
 /**
  * Add upload JS to OutputPage
  * 
  * @param bool $autofill Whether or not to autofill the destination
  * 	filename text box
  */
 protected function addUploadJS($autofill = true)
 {
     global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
     global $wgStrictFileExtensions, $wgMaxUploadSize;
     $scriptVars = array('wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck, 'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview, 'wgUploadAutoFill' => (bool) $autofill && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds, 'wgStrictFileExtensions' => $wgStrictFileExtensions, 'wgCapitalizeUploads' => MWNamespace::isCapitalized(NS_FILE), 'wgMaxUploadSize' => $wgMaxUploadSize);
     $this->getOutput()->addScript(Skin::makeVariablesScript($scriptVars));
 }
示例#20
0
 /**
  * @return string
  */
 function namespaces()
 {
     global $wgContLang;
     $spaces = "<namespaces>\n";
     foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
         $spaces .= '      ' . Xml::element('namespace', array('key' => $ns, 'case' => MWNamespace::isCapitalized($ns) ? 'first-letter' : 'case-sensitive'), $title) . "\n";
     }
     $spaces .= "    </namespaces>";
     return $spaces;
 }
示例#21
0
 /**
  * Add upload JS to $wgOut
  */
 protected function addUploadJS()
 {
     global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI, $wgStrictFileExtensions;
     global $wgOut;
     $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
     $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI;
     $scriptVars = array('wgAjaxUploadDestCheck' => $useAjaxDestCheck, 'wgAjaxLicensePreview' => $useAjaxLicensePreview, 'wgUploadAutoFill' => !$this->mForReUpload && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds, 'wgStrictFileExtensions' => $wgStrictFileExtensions, 'wgCapitalizeUploads' => MWNamespace::isCapitalized(NS_FILE));
     $wgOut->addScript(Skin::makeVariablesScript($scriptVars));
     // For <charinsert> support
     $wgOut->addModules(array('mediawiki.legacy.edit', 'mediawiki.legacy.upload'));
 }
 /**
  * Add upload JS to the OutputPage
  */
 protected function addUploadJS()
 {
     $config = $this->getConfig();
     $useAjaxDestCheck = $config->get('UseAjax') && $config->get('AjaxUploadDestCheck');
     $useAjaxLicensePreview = $config->get('UseAjax') && $config->get('AjaxLicensePreview') && $config->get('EnableAPI');
     $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
     $scriptVars = array('wgAjaxUploadDestCheck' => $useAjaxDestCheck, 'wgAjaxLicensePreview' => $useAjaxLicensePreview, 'wgUploadAutoFill' => !$this->mForReUpload && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds, 'wgCheckFileExtensions' => $config->get('CheckFileExtensions'), 'wgStrictFileExtensions' => $config->get('StrictFileExtensions'), 'wgCapitalizeUploads' => MWNamespace::isCapitalized(NS_FILE), 'wgMaxUploadSize' => $this->mMaxUploadSize);
     $out = $this->getOutput();
     $out->addJsConfigVars($scriptVars);
 }
示例#23
0
	public function execute() {
		global $wgContLang;

		$dbw = TranslationMemoryUpdater::getDatabaseHandle();
		if ( $dbw === null ) {
			$this->error( "Database file not configured" );
			$this->exit();
		}
		$dbw->setFlag( DBO_TRX ); // HUGE speed improvement

		$groups = MessageGroups::singleton()->getGroups();
		// TODO: encapsulate list of valid language codes
		$languages = Language::getLanguageNames( false );
		unset( $languages['en'] );

		foreach ( $groups as $id => $group ) {
			if ( $group->isMeta() ) {
				continue;
			}

			$this->output( "Processing: {$group->getLabel()} ", $id );
			$capitalized = MWNamespace::isCapitalized( $group->getNamespace() );
			$ns_text = $wgContLang->getNsText( $group->getNamespace() );

			$definitions = $group->load( $group->getSourceLanguage() );
			foreach ( $definitions as $key => $definition ) {
				// TODO: would be nice to do key normalisation closer to the message groups, to avoid transforming back and forth.
				// But how to preserve the original keys...
				$key = strtr( $key, ' ', '_' );
				$key = $capitalized ? $wgContLang->ucfirst( $key ) : $key;

				$dbr = wfGetDB( DB_SLAVE );
				$tables = array( 'page', 'revision', 'text' );
				// selectFields to stfu Revision class
				$vars = array_merge( Revision::selectTextFields(), array( 'page_title' ), Revision::selectFields() );
				$conds = array(
					'page_latest = rev_id',
					'rev_text_id = old_id',
					'page_namespace' => $group->getNamespace(),
					'page_title ' . $dbr->buildLike( "$key/", $dbr->anyString() )
				);

				$res = $dbr->select( $tables, $vars, $conds, __METHOD__ );
				// Assure that there is at least one translation
				if ( $res->numRows() < 1 ) {
					continue;
				}

				$insert = array(
					'text' => $definition,
					'context' => "$ns_text:$key",
					'length' => strlen( $definition ),
					'lang' => $group->getSourceLanguage(),
				);

				$source_id = $dbw->selectField( '`sources`', 'sid', $insert, __METHOD__ );
				if ( $source_id === false ) {
					$dbw->insert( '`sources`', $insert, __METHOD__ );
					$source_id = $dbw->insertId();
				}

				$this->output( ' ', $id );

				foreach ( $res as $row ) {
					list( , $code ) = TranslateUtils::figureMessage( $row->page_title );
					$revision = new Revision( $row );
					$insert = array(
						'text' => $revision->getText(),
						'lang' => $code,
						'time' => wfTimestamp(),
						'sid' => $source_id );
					// We only do SQlite which doesn't need to know unique indexes
					$dbw->replace( '`targets`', null, $insert, __METHOD__ );
				}
				$this->output( "{$res->numRows()}", $id );

			} // each translation>

			$dbw->commit();
		} // each group>
	}