示例#1
0
 /**
  * This constructs the list of all groups from multiple different
  * sources. When possible, a cache dependency is created to automatically
  * recreate the cache when configuration changes.
  * @todo Reduce the ways of which messages can be added. Target is just
  * to have three ways: Yaml files, translatable pages and with the hook.
  * @todo In conjuction with the above, reduce the number of global
  * variables like wgTranslate#C and have the message groups specify
  * their own cache dependencies.
  */
 protected static function loadGroupDefinitions()
 {
     global $wgTranslateAddMWExtensionGroups;
     global $wgEnablePageTranslation, $wgTranslateGroupFiles;
     global $wgTranslateAC, $wgTranslateEC, $wgTranslateCC;
     global $wgAutoloadClasses;
     global $wgTranslateWorkflowStates;
     $deps = array();
     $deps[] = new GlobalDependency('wgTranslateAddMWExtensionGroups');
     $deps[] = new GlobalDependency('wgEnablePageTranslation');
     $deps[] = new GlobalDependency('wgTranslateGroupFiles');
     $deps[] = new GlobalDependency('wgTranslateAC');
     $deps[] = new GlobalDependency('wgTranslateEC');
     $deps[] = new GlobalDependency('wgTranslateCC');
     $deps[] = new GlobalDependency('wgTranslateExtensionDirectory');
     $deps[] = new GlobalDependency('wgTranslateWorkflowStates');
     $deps[] = new FileDependency(dirname(__FILE__) . '/groups/mediawiki-defines.txt');
     $deps[] = new FileDependency(dirname(__FILE__) . '/groups/Wikia/extensions.txt');
     $deps[] = new FileDependency(dirname(__FILE__) . '/groups/Toolserver/toolserver-textdomains.txt');
     if ($wgTranslateAddMWExtensionGroups) {
         $a = new PremadeMediawikiExtensionGroups();
         $a->addAll();
     }
     if ($wgEnablePageTranslation) {
         $dbr = wfGetDB(DB_MASTER);
         $tables = array('page', 'revtag');
         $vars = array('page_id', 'page_namespace', 'page_title');
         $conds = array('page_id=rt_page', 'rt_type' => RevTag::getType('tp:mark'));
         $options = array('GROUP BY' => 'rt_page');
         $res = $dbr->select($tables, $vars, $conds, __METHOD__, $options);
         foreach ($res as $r) {
             $title = Title::makeTitle($r->page_namespace, $r->page_title);
             $id = TranslatablePage::getMessageGroupIdFromTitle($title);
             $wgTranslateCC[$id] = new WikiPageMessageGroup($id, $title);
             $wgTranslateCC[$id]->setLabel($title->getPrefixedText());
         }
     }
     if ($wgTranslateWorkflowStates) {
         $wgTranslateCC['translate-workflow-states'] = new WorkflowStatesMessageGroup();
     }
     $autoload = array();
     wfRunHooks('TranslatePostInitGroups', array(&$wgTranslateCC, &$deps, &$autoload));
     foreach ($wgTranslateGroupFiles as $configFile) {
         wfDebug($configFile . "\n");
         $deps[] = new FileDependency(realpath($configFile));
         $fgroups = TranslateYaml::parseGroupFile($configFile);
         foreach ($fgroups as $id => $conf) {
             if (!empty($conf['AUTOLOAD']) && is_array($conf['AUTOLOAD'])) {
                 $dir = dirname($configFile);
                 foreach ($conf['AUTOLOAD'] as $class => $file) {
                     // For this request and for caching.
                     $wgAutoloadClasses[$class] = "{$dir}/{$file}";
                     $autoload[$class] = "{$dir}/{$file}";
                 }
             }
             $group = MessageGroupBase::factory($conf);
             $wgTranslateCC[$id] = $group;
         }
     }
     $key = wfMemckey('translate-groups');
     $value = array('ac' => $wgTranslateAC, 'ec' => $wgTranslateEC, 'cc' => $wgTranslateCC, 'autoload' => $autoload);
     $wrapper = new DependencyWrapper($value, $deps);
     $wrapper->storeToCache(self::getCache(), $key, 60 * 60 * 2);
     wfDebug(__METHOD__ . "-end\n");
 }
示例#2
0
 /**
  * Attempt to get a value from the cache. If the value is expired or missing,
  * it will be generated with the callback function (if present), and the newly
  * calculated value will be stored to the cache in a wrapper.
  *
  * @param $cache BagOStuff a cache object such as $wgMemc
  * @param $key String: the cache key
  * @param $expiry Integer: the expiry timestamp or interval in seconds
  * @param $callback Mixed: the callback for generating the value, or false
  * @param $callbackParams Array: the function parameters for the callback
  * @param $deps Array: the dependencies to store on a cache miss. Note: these
  *    are not the dependencies used on a cache hit! Cache hits use the stored
  *    dependency array.
  *
  * @return mixed The value, or null if it was not present in the cache and no
  *    callback was defined.
  */
 static function getValueFromCache($cache, $key, $expiry = 0, $callback = false, $callbackParams = array(), $deps = array())
 {
     $obj = $cache->get($key);
     if (is_object($obj) && $obj instanceof DependencyWrapper && !$obj->isExpired()) {
         $value = $obj->value;
     } elseif ($callback) {
         $value = call_user_func_array($callback, $callbackParams);
         # Cache the newly-generated value
         $wrapper = new DependencyWrapper($value, $deps);
         $wrapper->storeToCache($cache, $key, $expiry);
     } else {
         $value = null;
     }
     return $value;
 }
 /**
  * This constructs the list of all groups from multiple different
  * sources. When possible, a cache dependency is created to automatically
  * recreate the cache when configuration changes.
  */
 protected function loadGroupDefinitions()
 {
     global $wgAutoloadClasses;
     $groups = $deps = $autoload = array();
     Hooks::run('TranslatePostInitGroups', array(&$groups, &$deps, &$autoload));
     // Register autoloaders for this request, both values modified by reference
     self::appendAutoloader($autoload, $wgAutoloadClasses);
     $key = wfMemckey('translate-groups');
     $value = array('cc' => $groups, 'autoload' => $autoload);
     $wrapper = new DependencyWrapper($value, $deps);
     $wrapper->storeToCache($this->getCache(), $key, 60 * 60 * 2);
     return $groups;
 }