/**
  * @param array $in
  * @return array
  */
 protected function classifyPages(array $in)
 {
     $out = array('proposed' => array(), 'active' => array(), 'broken' => array(), 'discouraged' => array());
     foreach ($in as $index => $page) {
         if (!isset($page['tp:mark'])) {
             // Never marked, check that the latest version is ready
             if ($page['tp:tag'] === $page['latest']) {
                 $out['proposed'][$index] = $page;
             }
             // Otherwise ignore such pages
         } elseif ($page['tp:tag'] === $page['latest']) {
             // Marked and latest version if fine
             $out['active'][$index] = $page;
         } else {
             // Marked but latest version if not fine
             $out['broken'][$index] = $page;
         }
     }
     // broken and proposed take preference over discouraged status
     foreach ($out['active'] as $index => $page) {
         $id = TranslatablePage::getMessageGroupIdFromTitle($page['title']);
         $group = MessageGroups::getGroup($id);
         if (MessageGroups::getPriority($group) === 'discouraged') {
             $out['discouraged'][$index] = $page;
             unset($out['active'][$index]);
         }
     }
     return $out;
 }
Beispiel #2
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");
 }
 public static function getTranslatablePages(array &$groups, array &$deps, array &$autoload)
 {
     global $wgEnablePageTranslation;
     $deps[] = new GlobalDependency('wgEnablePageTranslation');
     if (!$wgEnablePageTranslation) {
         return;
     }
     $db = 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 = $db->select($tables, $vars, $conds, __METHOD__, $options);
     foreach ($res as $r) {
         $title = Title::newFromRow($r);
         $id = TranslatablePage::getMessageGroupIdFromTitle($title);
         $groups[$id] = new WikiPageMessageGroup($id, $title);
         $groups[$id]->setLabel($title->getPrefixedText());
     }
 }