当前位置: 首页>>代码示例>>PHP>>正文


PHP MessageGroups::singleton方法代码示例

本文整理汇总了PHP中MessageGroups::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP MessageGroups::singleton方法的具体用法?PHP MessageGroups::singleton怎么用?PHP MessageGroups::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessageGroups的用法示例。


在下文中一共展示了MessageGroups::singleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: openHandles

	/**
	 * Itterate through all groups, loading current data from the existing
	 * extension and opening message files for message output.
	 *  - If the group does not define a special page alias file or magic
	 *    words file, or that file does not exist, it is ignored silently.
	 *  - If the file does contain a data array (e.g. $aliases) then the
	 *    program exits.
	 */
	protected function openHandles() {
		$this->output( "Opening file handles and loading current data...\n" );

		$groups = MessageGroups::singleton()->getGroups();
		$filename = null;
		foreach ( $groups as $group ) {
			if ( !$group instanceof ExtensionMessageGroup ) {
				continue;
			}

			switch ( $this->type ) {
				case 'special':
					$filename = $group->getAliasFile();
					break;
				case 'magic':
					$filename = $group->getMagicFile();
					break;
			}

			if ( $filename === null ) {
				continue;
			}

			global $wgTranslateExtensionDirectory;
			$inFile = "$wgTranslateExtensionDirectory/$filename";

			if ( !file_exists( $inFile ) )  {
				continue;
			}

			include( $inFile );
			switch( $this->type ) {
				case 'special':
					if ( isset( $aliases ) ) {
						$this->messagesOld[$group->getId()] = $aliases;
						unset( $aliases );
					} elseif ( isset( $specialPageAliases ) ) {
						$this->messagesOld[$group->getId()] = $specialPageAliases;
						unset( $specialPageAliases );
					} else {
						die( "File '$inFile' does not contain an aliases array.\n" );
					}
					break;
				case 'magic':
					if ( !isset( $magicWords ) ) {
						die( "File '$inFile' does not contain a magic words array.\n" );
					}
					$this->messagesOld[$group->getId()] = $magicWords;
					unset( $magicWords );
					break;
			}

			$outFile = $this->target . '/' . $filename;
			wfMkdirParents( dirname( $outFile ), null, __METHOD__ );
			$this->handles[$group->getId()] = fopen( $outFile, 'w' );
			fwrite( $this->handles[$group->getId()], $this->readHeader( $inFile ) );

			$this->output( "\t{$group->getId()}\n" );
		}
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:68,代码来源:magic-export.php

示例2: rebuild

 public function rebuild($scratch = false)
 {
     $groups = MessageGroups::singleton()->getGroups();
     $new = $old = array();
     if (!$scratch) {
         // To avoid inifinite recursion
         $old = $this->retrieve();
     }
     $postponed = array();
     STDOUT("Working with ", 'main');
     foreach ($groups as $g) {
         if (!$g->exists()) {
             continue;
         }
         # Skip meta thingies
         if ($g->isMeta()) {
             $postponed[] = $g;
             continue;
         }
         $this->checkAndAdd($new, $g);
     }
     foreach ($postponed as $g) {
         $this->checkAndAdd($new, $g, true);
     }
     $this->store($new);
     $this->clearMessageGroupStats($old, $new);
     return $new;
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:28,代码来源:MessageIndex.php

示例3: displayNavigation

 private function displayNavigation()
 {
     global $wgOut;
     $groupSelector = new XmlSelect('group', 'group-select');
     // pull groups
     $groups = MessageGroups::singleton()->getGroups();
     foreach ($groups as $group) {
         if (!$group->isMeta()) {
             continue;
         }
         $groupSelector->addOption($group->getLabel(), $group->getId());
     }
     $fields = array();
     $fields['transstats-choose-group'] = $groupSelector->getHTML();
     $fields['transstats-group-mode-all'] = Xml::radio('mode', 0, empty($this->mMode));
     $fields['transstats-group-mode-supress0'] = Xml::radio('mode', 1, $this->mMode == 1);
     $fields['transstats-group-mode-supress100'] = Xml::radio('mode', 2, $this->mMode == 2);
     $fields['transstats-group-mode-only100'] = Xml::radio('mode', 3, $this->mMode == 3);
     $fields['transstats-group-langlist'] = Xml::input('langlist', false, $this->mLanglistPlain);
     $out = Xml::openElement('form');
     $out .= Xml::buildForm($fields);
     $out .= Html::hidden('title', 'Special:' . $this->getName());
     // FIXME: this is silly...
     $out .= Xml::submitButton(wfMsg('transstats-submit'));
     $out .= Xml::closeElement('form');
     $wgOut->addHTML($out);
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:27,代码来源:SpecialGroupStats.body.php

示例4: getPercentageTranslated

	/**
	 * Returns translated percentage for message group in given
	 * languages
	 *
	 * @param $group \string Unique key identifying the group
	 * @param $languages \array List of language codes
	 * @param $threshold \int Minimum required percentage translated to
	 * return. Other given language codes will not be returned.
	 * @param $simple \bool Return only codes or code/pecentage pairs
	 *
	 * @return \array Array of key value pairs code (string)/percentage
	 * (float) or array of codes, depending on $simple
	 */
	public static function getPercentageTranslated( $group, $languages, $threshold = false, $simple = false ) {
		$stats = array();

		$g = MessageGroups::singleton()->getGroup( $group );

		$collection = $g->initCollection( 'en' );
		foreach ( $languages as $code ) {
			$collection->resetForNewLanguage( $code );
			// Initialise messages
			$collection->filter( 'ignored' );
			$collection->filter( 'optional' );
			// Store the count of real messages for later calculation.
			$total = count( $collection );
			$collection->filter( 'translated', false );
			$translated = count( $collection );

			$translatedPercentage = ( $translated * 100 ) / $total;
			if ( $translatedPercentage >= $threshold ) {
				if ( $simple ) {
					$stats[] = $code;
				} else {
					$stats[$code] = $translatedPercentage;
				}
			}
		}

		return $stats;
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:41,代码来源:TranslationStats.php

示例5: execute

 public function execute()
 {
     $server = TTMServer::primary();
     if ($server instanceof FakeTTMServer) {
         $this->error("Translation memory is not configured properly", 1);
     }
     $dbw = $server->getDB(DB_MASTER);
     $this->statusLine('Deleting sources.. ', 1);
     $dbw->delete('translate_tms', '*', __METHOD__);
     $this->output('translations.. ', 1);
     $dbw->delete('translate_tmt', '*', __METHOD__);
     $this->output('fulltext.. ', 1);
     $dbw->delete('translate_tmf', '*', __METHOD__);
     $table = $dbw->tableName('translate_tmf');
     $dbw->query("DROP INDEX tmf_text ON {$table}");
     $this->output('done!', 1);
     $this->statusLine('Loading groups... ', 2);
     $groups = MessageGroups::singleton()->getGroups();
     $this->output('done!', 2);
     $threads = $this->getOption('threads', 1);
     $pids = array();
     foreach ($groups as $id => $group) {
         if ($group->isMeta()) {
             continue;
         }
         // Fork to avoid unbounded memory usage growth
         $pid = pcntl_fork();
         if ($pid === 0) {
             // Child, reseed because there is no bug in PHP:
             // http://bugs.php.net/bug.php?id=42465
             mt_srand(getmypid());
             $this->exportGroup($group, $threads > 1);
             exit;
         } elseif ($pid === -1) {
             // Fork failed do it serialized
             $this->exportGroup($group);
         } else {
             $this->statusLine("Forked thread {$pid} to handle {$id}\n");
             $pids[$pid] = true;
             // If we hit the thread limit, wait for any child to finish.
             if (count($pids) >= $threads) {
                 $status = 0;
                 $pid = pcntl_wait($status);
                 unset($pids[$pid]);
             }
         }
     }
     // Return control after all threads have finished.
     foreach (array_keys($pids) as $pid) {
         $status = 0;
         pcntl_waitpid($pid, $status);
     }
     $this->statusLine('Adding fulltext index...', 9);
     $table = $dbw->tableName('translate_tmf');
     $dbw->query("CREATE FULLTEXT INDEX tmf_text ON {$table} (tmf_text)");
     $this->output(' done!', 9);
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:57,代码来源:ttmserver-export.php

示例6: testHaveSingleSourceLanguage

 public function testHaveSingleSourceLanguage()
 {
     $this->setMwGlobals(array('wgTranslateGroupFiles' => array(__DIR__ . '/data/MixedSourceLanguageGroups.yaml')));
     MessageGroups::singleton()->recache();
     $enGroup1 = MessageGroups::getGroup('EnglishGroup1');
     $enGroup2 = MessageGroups::getGroup('EnglishGroup2');
     $teGroup1 = MessageGroups::getGroup('TeluguGroup1');
     $this->assertEquals('en', MessageGroups::haveSingleSourceLanguage(array($enGroup1, $enGroup2)));
     $this->assertEquals('', MessageGroups::haveSingleSourceLanguage(array($enGroup1, $enGroup2, $teGroup1)));
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:10,代码来源:MessageGroupsTest.php

示例7: setUp

 protected function setUp()
 {
     parent::setUp();
     global $wgHooks;
     $this->setMwGlobals(array('wgHooks' => $wgHooks, 'wgTranslateTranslationServices' => array()));
     $wgHooks['TranslatePostInitGroups'] = array(array($this, 'getTestGroups'));
     $mg = MessageGroups::singleton();
     $mg->setCache(wfGetCache('hash'));
     $mg->recache();
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:10,代码来源:ApiQueryMessageGroupsTest.php

示例8: setUp

 public function setUp()
 {
     parent::setUp();
     global $wgHooks;
     $this->setMwGlobals(array('wgHooks' => $wgHooks, 'wgTranslateTranslationServices' => array(), 'wgTranslateDelayedMessageIndexRebuild' => false));
     $wgHooks['TranslatePostInitGroups'] = array();
     $mg = MessageGroups::singleton();
     $mg->setCache(wfGetCache('hash'));
     $mg->recache();
     MessageIndex::setInstance(new HashMessageIndex());
     MessageIndex::singleton()->rebuild();
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:12,代码来源:MessageIndexRebuildJobTest.php

示例9: setUp

 protected function setUp()
 {
     parent::setUp();
     global $wgHooks;
     $this->setMwGlobals(array('wgHooks' => $wgHooks, 'wgTranslateTranslationServices' => array(), 'wgTranslateCacheDirectory' => $this->getNewTempDirectory()));
     $wgHooks['TranslatePostInitGroups'] = array();
     $mg = MessageGroups::singleton();
     $mg->setCache(wfGetCache('hash'));
     $mg->recache();
     MessageIndex::setInstance(new HashMessageIndex());
     MessageIndex::singleton()->rebuild();
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:12,代码来源:SpecialPagesTest.php

示例10: setUp

 protected function setUp()
 {
     parent::setUp();
     global $wgHooks;
     $this->setMwGlobals(array('wgHooks' => $wgHooks, 'wgGroupPermissions' => array(), 'wgTranslateMessageNamespaces' => array(NS_MEDIAWIKI)));
     $wgHooks['TranslatePostInitGroups'] = array(array($this, 'getTestGroups'));
     $mg = MessageGroups::singleton();
     $mg->setCache(wfGetCache('hash'));
     $mg->recache();
     MessageIndex::setInstance(new HashMessageIndex());
     MessageIndex::singleton()->rebuild();
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:12,代码来源:ApiTranslationReviewTest.php

示例11: openHandles

 /**
  * Iterate through all groups, loading current data from the existing
  * extension and opening message files for message output.
  *  - If the group does not define a special page alias file or magic
  *    words file, or that file does not exist, it is ignored silently.
  *  - If the file does contain a data array (e.g. $aliases) then the
  *    program exits.
  */
 protected function openHandles()
 {
     $this->output("Opening file handles and loading current data...\n");
     $groups = MessageGroups::singleton()->getGroups();
     foreach ($groups as $group) {
         if (!$group instanceof MediaWikiExtensionMessageGroup) {
             continue;
         }
         $conf = $group->getConfiguration();
         $inFile = $outFile = null;
         if ($this->type === 'special' && isset($conf['FILES']['aliasFile'])) {
             $inFile = $conf['FILES']['aliasFileSource'];
             $outFile = $conf['FILES']['aliasFile'];
         }
         if ($this->type === 'magic' && isset($conf['FILES']['magicFile'])) {
             $inFile = $conf['FILES']['magicFileSource'];
             $outFile = $conf['FILES']['magicFile'];
         }
         if ($inFile === null) {
             continue;
         }
         $inFile = $group->replaceVariables($inFile, 'en');
         $outFile = $this->target . '/' . $outFile;
         include $inFile;
         switch ($this->type) {
             case 'special':
                 if (isset($aliases)) {
                     $this->messagesOld[$group->getId()] = $aliases;
                     unset($aliases);
                 } elseif (isset($specialPageAliases)) {
                     $this->messagesOld[$group->getId()] = $specialPageAliases;
                     unset($specialPageAliases);
                 } else {
                     $this->error("File '{$inFile}' does not contain an aliases array.");
                     continue;
                 }
                 break;
             case 'magic':
                 if (!isset($magicWords)) {
                     $this->error("File '{$inFile}' does not contain a magic words array.");
                     continue;
                 }
                 $this->messagesOld[$group->getId()] = $magicWords;
                 unset($magicWords);
                 break;
         }
         wfMkdirParents(dirname($outFile), null, __METHOD__);
         $this->handles[$group->getId()] = fopen($outFile, 'w');
         fwrite($this->handles[$group->getId()], $this->readHeader($inFile));
         $this->output("\t{$group->getId()}\n");
     }
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:60,代码来源:magic-export.php

示例12: populateStats

 public static function populateStats()
 {
     // remove all records
     $dbw = wfGetDB(DB_MASTER);
     $dbw->delete('groupstats', '*');
     $groups = MessageGroups::singleton()->getGroups();
     // iterate over all groups
     foreach ($groups as $g) {
         /* @var $g MessageGroup */
         echo "Populating " . $g->getId() . "...\n";
         self::forGroup($g->getId());
     }
     echo "Done!\n";
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:14,代码来源:MessageGroupStatistics.php

示例13: execute

	public function execute() {
		$this->files = array();
		$groups = MessageGroups::singleton()->getGroups();
		$target = $this->getOption( 'path' );
		foreach ( $groups as $group ) {
			if ( !$group instanceof ExtensionMessageGroup ) continue;
			if ( $target && $group->getPath() !== $target ) continue;
			$this->addPaths( $group->getMessageFile( 'en' ) );
			$this->addPaths( $group->getAliasFile( 'en' ) );
			$this->addPaths( $group->getMagicFile( 'en' ) );
		}

		$files = array_keys( $this->files );
		$this->output( trim( implode( "\n", $files ) . "\n" ) );
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:15,代码来源:list-mwext-i18n-files.php

示例14: execute

 public function execute()
 {
     $groups = MessageGroups::singleton()->getGroups();
     /** @var MessageGroup $group */
     foreach ($groups as $group) {
         if (!$group instanceof WikiPageMessageGroup) {
             continue;
         }
         // Get all translation subpages and refresh each one of them
         $page = TranslatablePage::newFromTitle($group->getTitle());
         $translationPages = $page->getTranslationPages();
         foreach ($translationPages as $subpage) {
             $job = TranslateRenderJob::newJob($subpage);
             $job->run();
         }
     }
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:17,代码来源:refresh-translatable-pages.php

示例15: testTranslationPageRestrictions

 public function testTranslationPageRestrictions()
 {
     $superUser = new MockSuperUser();
     $title = Title::newFromText('Translatable page');
     $page = WikiPage::factory($title);
     $content = ContentHandler::makeContent('<translate>Hello</translate>', $title);
     $status = $page->doEditContent($content, 'New page', 0, false, $superUser);
     $revision = $status->value['revision']->getId();
     $translatablePage = TranslatablePage::newFromRevision($title, $revision);
     $translatablePage->addMarkedTag($revision);
     MessageGroups::singleton()->recache();
     $translationPage = Title::newFromText('Translatable page/fi');
     TranslateRenderJob::newJob($translationPage)->run();
     $this->assertTrue($translationPage->userCan('read', $superUser), 'Users can read existing translation pages');
     $this->assertFalse($translationPage->userCan('edit', $superUser), 'Users can not edit existing translation pages');
     $translationPage = Title::newFromText('Translatable page/ab');
     $this->assertTrue($translationPage->userCan('read', $superUser), 'Users can read non-existing translation pages');
     $this->assertFalse($translationPage->userCan('edit', $superUser), 'Users can not edit non-existing translation pages');
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:19,代码来源:PageTranslationTaggingTest.php


注:本文中的MessageGroups::singleton方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。