/**
  * Returns all config parameters, after parsing the wikitext based ones
  *
  * @since 1.3
  *
  * @return array
  */
 public function getParsedConfig($lang = null)
 {
     global $wgMemc;
     if ($lang === null) {
         $lang = $this->context->getLanguage();
     }
     // We check if the parsed config for this campaign is cached. If it is available in cache,
     // we then check to make sure that it is the latest version - by verifying that its
     // timestamp is greater than or equal to the timestamp of the last time an invalidate was
     // issued.
     $memKey = wfMemcKey('uploadwizard', 'campaign', $this->getName(), 'parsed-config', $lang->getCode());
     $memValue = $wgMemc->get($memKey);
     if ($memValue !== false) {
         $invalidateTimestamp = $wgMemc->get($this->makeInvalidateTimestampKey());
         if ($invalidateTimestamp === false || $memValue['timestamp'] >= $invalidateTimestamp) {
             $this->parsedConfig = $memValue['config'];
         }
     }
     wfProfileIn(__METHOD__);
     if ($this->parsedConfig === null) {
         $parsedConfig = array();
         foreach ($this->config as $key => $value) {
             switch ($key) {
                 case "title":
                 case "description":
                     $parsedConfig[$key] = $this->parseValue($value, $lang);
                     break;
                 case "display":
                     $parsedConfig['display'] = $this->parseArrayValues($value, $lang);
                     break;
                 case "fields":
                     $parsedConfig['fields'] = array();
                     foreach ($value as $field) {
                         $parsedConfig['fields'][] = $this->parseArrayValues($field, $lang, array('label'));
                     }
                     break;
                 default:
                     $parsedConfig[$key] = $value;
                     break;
             }
         }
         $this->parsedConfig = $parsedConfig;
         $wgMemc->set($memKey, array('timestamp' => time(), 'config' => $parsedConfig));
     }
     wfProfileOut(__METHOD__);
     return $this->parsedConfig;
 }
 function setUp()
 {
     global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection, $parserMemc;
     $tmpGlobals = array();
     $tmpGlobals['wgScript'] = '/index.php';
     $tmpGlobals['wgScriptPath'] = '/';
     $tmpGlobals['wgArticlePath'] = '/wiki/$1';
     $tmpGlobals['wgStyleSheetPath'] = '/skins';
     $tmpGlobals['wgStylePath'] = '/skins';
     $tmpGlobals['wgThumbnailScriptPath'] = false;
     $tmpGlobals['wgLocalFileRepo'] = array('class' => 'LocalRepo', 'name' => 'local', 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false, 'backend' => new FSFileBackend(array('name' => 'local-backend', 'lockManager' => 'fsLockManager', 'containerPaths' => array('local-public' => wfTempDir() . '/test-repo/public', 'local-thumb' => wfTempDir() . '/test-repo/thumb', 'local-temp' => wfTempDir() . '/test-repo/temp', 'local-deleted' => wfTempDir() . '/test-repo/delete'))));
     foreach ($tmpGlobals as $var => $val) {
         if (array_key_exists($var, $GLOBALS)) {
             $this->savedGlobals[$var] = $GLOBALS[$var];
         }
         $GLOBALS[$var] = $val;
     }
     $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
     $wgNamespaceAliases['Image'] = NS_FILE;
     $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
     $wgEnableParserCache = false;
     DeferredUpdates::clearPendingUpdates();
     $wgMemc = wfGetMainCache();
     $messageMemc = wfGetMessageCacheStorage();
     $parserMemc = wfGetParserCacheStorage();
     // $wgContLang = new StubContLang;
     $wgUser = new User();
     $context = new RequestContext();
     $wgLang = $context->getLanguage();
     $wgOut = $context->getOutput();
     $wgParser = new StubObject('wgParser', $wgParserConf['class'], array($wgParserConf));
     $wgRequest = $context->getRequest();
     if ($wgStyleDirectory === false) {
         $wgStyleDirectory = "{$IP}/skins";
     }
     RepoGroup::destroySingleton();
     FileBackendGroup::destroySingleton();
 }
Пример #3
0
 /**
  * Set up the global variables for a consistent environment for each test.
  * Ideally this should replace the global configuration entirely.
  */
 protected function setupGlobals($opts = '', $config = '')
 {
     global $wgFileBackends;
     # Find out values for some special options.
     $lang = self::getOptionValue('language', $opts, 'en');
     $variant = self::getOptionValue('variant', $opts, false);
     $maxtoclevel = self::getOptionValue('wgMaxTocLevel', $opts, 999);
     $linkHolderBatchSize = self::getOptionValue('wgLinkHolderBatchSize', $opts, 1000);
     $uploadDir = $this->getUploadDir();
     if ($this->getCliArg('use-filebackend=')) {
         if (self::$backendToUse) {
             $backend = self::$backendToUse;
         } else {
             $name = $this->getCliArg('use-filebackend=');
             $useConfig = array();
             foreach ($wgFileBackends as $conf) {
                 if ($conf['name'] == $name) {
                     $useConfig = $conf;
                 }
             }
             $useConfig['name'] = 'local-backend';
             // swap name
             $class = $conf['class'];
             self::$backendToUse = new $class($useConfig);
             $backend = self::$backendToUse;
         }
     } else {
         $backend = new FSFileBackend(array('name' => 'local-backend', 'lockManager' => 'nullLockManager', 'containerPaths' => array('local-public' => "{$uploadDir}", 'local-thumb' => "{$uploadDir}/thumb")));
     }
     $settings = array('wgServer' => 'http://Britney-Spears', 'wgScript' => '/index.php', 'wgScriptPath' => '/', 'wgArticlePath' => '/wiki/$1', 'wgExtensionAssetsPath' => '/extensions', 'wgActionPaths' => array(), 'wgLocalFileRepo' => array('class' => 'LocalRepo', 'name' => 'local', 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false, 'backend' => $backend), 'wgEnableUploads' => self::getOptionValue('wgEnableUploads', $opts, true), 'wgStylePath' => '/skins', 'wgStyleSheetPath' => '/skins', 'wgSitename' => 'MediaWiki', 'wgLanguageCode' => $lang, 'wgDBprefix' => $this->db->getType() != 'oracle' ? 'unittest_' : 'ut_', 'wgRawHtml' => isset($opts['rawhtml']), 'wgLang' => null, 'wgContLang' => null, 'wgNamespacesWithSubpages' => array(0 => isset($opts['subpage'])), 'wgMaxTocLevel' => $maxtoclevel, 'wgCapitalLinks' => true, 'wgNoFollowLinks' => true, 'wgNoFollowDomainExceptions' => array(), 'wgThumbnailScriptPath' => false, 'wgUseImageResize' => false, 'wgUseTeX' => isset($opts['math']), 'wgMathDirectory' => $uploadDir . '/math', 'wgLocaltimezone' => 'UTC', 'wgAllowExternalImages' => true, 'wgUseTidy' => false, 'wgDefaultLanguageVariant' => $variant, 'wgVariantArticlePath' => false, 'wgGroupPermissions' => array('*' => array('createaccount' => true, 'read' => true, 'edit' => true, 'createpage' => true, 'createtalk' => true)), 'wgNamespaceProtection' => array(NS_MEDIAWIKI => 'editinterface'), 'wgDefaultExternalStore' => array(), 'wgForeignFileRepos' => array(), 'wgLinkHolderBatchSize' => $linkHolderBatchSize, 'wgExperimentalHtmlIds' => false, 'wgExternalLinkTarget' => false, 'wgAlwaysUseTidy' => false, 'wgHtml5' => true, 'wgCleanupPresentationalAttributes' => true, 'wgWellFormedXml' => true, 'wgAllowMicrodataAttributes' => true, 'wgAdaptiveMessageCache' => true, 'wgUseDatabaseMessages' => true);
     if ($config) {
         $configLines = explode("\n", $config);
         foreach ($configLines as $line) {
             list($var, $value) = explode('=', $line, 2);
             $settings[$var] = eval("return {$value};");
             //???
         }
     }
     $this->savedGlobals = array();
     foreach ($settings as $var => $val) {
         if (array_key_exists($var, $GLOBALS)) {
             $this->savedGlobals[$var] = $GLOBALS[$var];
         }
         $GLOBALS[$var] = $val;
     }
     $langObj = Language::factory($lang);
     $GLOBALS['wgContLang'] = $langObj;
     $context = new RequestContext();
     $GLOBALS['wgLang'] = $context->getLanguage();
     $GLOBALS['wgMemc'] = new EmptyBagOStuff();
     $GLOBALS['wgOut'] = $context->getOutput();
     $GLOBALS['wgUser'] = $context->getUser();
     global $wgHooks;
     $wgHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
     $wgHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp';
     MagicWord::clearCache();
     RepoGroup::destroySingleton();
     FileBackendGroup::destroySingleton();
     # Create dummy files in storage
     $this->setupUploads();
     # Publish the articles after we have the final language set
     $this->publishTestArticles();
     # The entries saved into RepoGroup cache with previous globals will be wrong.
     RepoGroup::destroySingleton();
     FileBackendGroup::destroySingleton();
     MessageCache::singleton()->destroyInstance();
     return $context;
 }
 /**
  * Returns all config parameters, after parsing the wikitext based ones
  *
  * @since 1.3
  *
  * @return array
  */
 public function getParsedConfig($lang = null)
 {
     if ($lang === null) {
         $lang = $this->context->getLanguage();
     }
     // We check if the parsed config for this campaign is cached. If it is available in cache,
     // we then check to make sure that it is the latest version - by verifying that its
     // timestamp is greater than or equal to the timestamp of the last time an invalidate was
     // issued.
     $cache = ObjectCache::getMainWANInstance();
     $memKey = wfMemcKey('uploadwizard', 'campaign', $this->getName(), 'parsed-config', $lang->getCode());
     $depKeys = array($this->makeInvalidateTimestampKey());
     $curTTL = null;
     $memValue = $cache->get($memKey, $curTTL, $depKeys);
     if (is_array($memValue) && $curTTL > 0) {
         $this->parsedConfig = $memValue['config'];
     }
     if ($this->parsedConfig === null) {
         $parsedConfig = array();
         foreach ($this->config as $key => $value) {
             switch ($key) {
                 case "title":
                 case "description":
                     $parsedConfig[$key] = $this->parseValue($value, $lang);
                     break;
                 case "display":
                     foreach ($value as $option => $optionValue) {
                         if (is_array($optionValue)) {
                             $parsedConfig['display'][$option] = $this->parseArrayValues($optionValue, $lang, array('label'));
                         } else {
                             $parsedConfig['display'][$option] = $this->parseValue($optionValue, $lang);
                         }
                     }
                     break;
                 case "fields":
                     $parsedConfig['fields'] = array();
                     foreach ($value as $field) {
                         $parsedConfig['fields'][] = $this->parseArrayValues($field, $lang, array('label', 'options'));
                     }
                     break;
                 case "whileActive":
                 case "afterActive":
                 case "beforeActive":
                     if (array_key_exists('display', $value)) {
                         $value['display'] = $this->parseArrayValues($value['display'], $lang);
                     }
                     $parsedConfig[$key] = $value;
                     break;
                 default:
                     $parsedConfig[$key] = $value;
                     break;
             }
         }
         $this->parsedConfig = $parsedConfig;
         $cache->set($memKey, array('timestamp' => time(), 'config' => $parsedConfig));
     }
     $uwDefaults = UploadWizardConfig::getSetting('defaults');
     if (array_key_exists('objref', $uwDefaults)) {
         $this->applyObjectReferenceToButtons($uwDefaults['objref']);
     }
     $this->modifyIfNecessary();
     return $this->parsedConfig;
 }