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


PHP MessageGroups类代码示例

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


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

示例1: execute

 public function execute()
 {
     $user = $this->getUser();
     $requestParams = $this->extractRequestParams();
     $group = MessageGroups::getGroup($requestParams['group']);
     $code = $requestParams['language'];
     if (!$group || MessageGroups::isDynamic($group)) {
         $this->dieUsageMsg(array('missingparam', 'group'));
     }
     $stateConfig = $group->getMessageGroupStates()->getStates();
     if (!$stateConfig) {
         $this->dieUsage('Message group review not in use', 'disabled');
     }
     if (!$user->isAllowed(self::$right)) {
         $this->dieUsage('Permission denied', 'permissiondenied');
     }
     if ($user->isBlocked()) {
         $this->dieUsage('You have been blocked', 'blocked');
     }
     $requestParams = $this->extractRequestParams();
     $languages = Language::fetchLanguageNames();
     if (!isset($languages[$code])) {
         $this->dieUsageMsg(array('missingparam', 'language'));
     }
     $targetState = $requestParams['state'];
     if (!isset($stateConfig[$targetState])) {
         $this->dieUsage('The requested state is invalid', 'invalidstate');
     }
     if (is_array($stateConfig[$targetState]) && isset($stateConfig[$targetState]['right']) && !$user->isAllowed($stateConfig[$targetState]['right'])) {
         $this->dieUsage('Permission denied', 'permissiondenied');
     }
     self::changeState($group, $code, $targetState, $user);
     $output = array('review' => array('group' => $group->getId(), 'language' => $code, 'state' => $targetState));
     $this->getResult()->addValue(null, $this->getModuleName(), $output);
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:35,代码来源:ApiGroupReview.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: setGroup

	/**
	 * Group is either MessageGroup object or group id.
	 * @param $group MessagerGroup|string
	 */
	public function setGroup( $group ) {
		if ( $group instanceof MessageGroup ) {
			$this->group = $group;
		} else {
			$this->group = MessageGroups::getGroup( $group );
		}
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:11,代码来源:MessageWebImporter.php

示例4: 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

示例5: testAPIFilterAccuracy

 public function testAPIFilterAccuracy()
 {
     $ids = array('MadeUpGroup');
     $ids += array_keys(MessageGroups::getAllGroups());
     foreach ($ids as $id) {
         list($data) = $this->doApiRequest(array('action' => 'query', 'meta' => 'messagegroups', 'mgprop' => 'id|label|class|namespace|exists', 'mgfilter' => $id, 'continue' => ''));
         if ($id === 'MadeUpGroup') {
             // Check structure (shouldn't find anything)
             $this->assertArrayNotHasKey('warnings', $data);
             $this->assertArrayHasKey('query', $data);
             $this->assertCount(1, $data['query']);
             $this->assertArrayHasKey('messagegroups', $data['query']);
             $this->assertCount(0, $data['query']['messagegroups']);
             continue;
         }
         // Check structure (filter is unique given these names)
         $this->assertArrayNotHasKey('warnings', $data);
         $this->assertArrayHasKey('query', $data);
         $this->assertCount(1, $data['query']);
         $this->assertArrayHasKey('messagegroups', $data['query']);
         $this->assertCount(1, $data['query']['messagegroups']);
         // Check content
         $item = $data['query']['messagegroups'][0];
         $this->assertCount(5, $item);
         $this->assertSame($item['id'], $id);
         $this->assertSame($item['label'], 'thelabel');
         $this->assertSame($item['exists'], true);
         $this->assertStringEndsWith('id', $item['id']);
         // theid, anotherid
         $this->assertSame($item['namespace'], 5);
         $this->assertSame($item['class'], 'WikiMessageGroup');
     }
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:33,代码来源:ApiQueryMessageGroupsTest.php

示例6: testMessage

 public function testMessage()
 {
     $user = new MockSuperUser();
     $user->setId(123);
     $title = Title::newFromText('MediaWiki:translated/fi');
     $page = WikiPage::factory($title);
     $content = ContentHandler::makeContent('pupuliini', $title);
     $status = $page->doEditContent($content, __METHOD__, 0, false, $user);
     $value = $status->getValue();
     $rev = $value['revision'];
     $revision = $rev->getId();
     $group = MessageGroups::getGroup('test-group');
     $collection = $group->initCollection('fi');
     $collection->loadTranslations();
     /** @var TMessage $translated */
     $translated = $collection['translated'];
     $this->assertInstanceof('TMessage', $translated);
     $this->assertEquals('translated', $translated->key());
     $this->assertEquals('bunny', $translated->definition());
     $this->assertEquals('pupuliini', $translated->translation());
     $this->assertEquals('SuperUser', $translated->getProperty('last-translator-text'));
     $this->assertEquals(123, $translated->getProperty('last-translator-id'));
     $this->assertEquals('translated', $translated->getProperty('status'), 'message status is translated');
     $this->assertEquals($revision, $translated->getProperty('revision'));
     /** @var TMessage $untranslated */
     $untranslated = $collection['untranslated'];
     $this->assertInstanceof('TMessage', $untranslated);
     $this->assertEquals(null, $untranslated->translation(), 'no translation is null');
     $this->assertEquals(false, $untranslated->getProperty('last-translator-text'));
     $this->assertEquals(false, $untranslated->getProperty('last-translator-id'));
     $this->assertEquals('untranslated', $untranslated->getProperty('status'), 'message status is untranslated');
     $this->assertEquals(false, $untranslated->getProperty('revision'));
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:33,代码来源:MessageCollectionTest.php

示例7: 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

示例8: execute

 public function execute()
 {
     $params = $this->extractRequestParams();
     $title = Title::newFromText($params['title']);
     if (!$title) {
         $this->dieUsage('Invalid title', 'invalidtitle');
     }
     $handle = new MessageHandle($title);
     if (!$handle->isValid()) {
         $this->dieUsage('Title does not correspond to a translatable message', 'nomessagefortitle');
     }
     if (strval($params['group']) !== '') {
         $group = MessageGroups::getGroup($params['group']);
     } else {
         $group = $handle->getGroup();
     }
     if (!$group) {
         $this->dieUsage('Invalid group', 'invalidgroup');
     }
     $data = array();
     $times = array();
     $props = $params['prop'];
     $aggregator = new QueryAggregator();
     // Figure out the intersection of supported and requested aids
     $types = $group->getTranslationAids();
     $props = array_intersect($props, array_keys($types));
     $result = $this->getResult();
     // Create list of aids, populate web services queries
     $aids = array();
     foreach ($props as $type) {
         $class = $types[$type];
         $obj = new $class($group, $handle, $this);
         if ($obj instanceof QueryAggregatorAware) {
             $obj->setQueryAggregator($aggregator);
             $obj->populateQueries();
         }
         $aids[$type] = $obj;
     }
     // Execute all web service queries asynchronously to save time
     $start = microtime(true);
     $aggregator->run();
     $times['query_aggregator'] = round(microtime(true) - $start, 3);
     // Construct the result data structure
     foreach ($aids as $type => $obj) {
         $start = microtime(true);
         try {
             $aid = $obj->getData();
         } catch (TranslationHelperException $e) {
             $aid = array('error' => $e->getMessage());
         }
         if (isset($aid['**'])) {
             $result->setIndexedTagName($aid, $aid['**']);
             unset($aid['**']);
         }
         $data[$type] = $aid;
         $times[$type] = round(microtime(true) - $start, 3);
     }
     $result->addValue(null, 'helpers', $data);
     $result->addValue(null, 'times', $times);
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:60,代码来源:ApiQueryTranslationAids.php

示例9: 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

示例10: execute

	/**
	 * Special page entry point.
	 */
	public function execute( $parameters ) {
		$this->setHeaders();

		// Security and validity checks
		if ( !$this->userCanExecute( $this->user ) ) {
			$this->displayRestrictionError();
			return;
		}

		if ( !$this->request->wasPosted() ) {
			$this->outputForm();
			return;
		}

		if ( !$this->user->matchEditToken( $this->request->getVal( 'token' ) ) ) {
			$this->out->addWikiMsg( 'session_fail_preview' );
			$this->outputForm();
			return;
		}

		if ( $this->request->getCheck( 'process' ) ) {
			$data = $this->getCachedData();
			if ( !$data ) {
				$this->out->addWikiMsg( 'session_fail_preview' );
				$this->outputForm();
				return;
			}
		} else {
			/**
			 * Proceed to loading and parsing if possible
			 * @todo: use a Status object instead?
			 */
			$file = null;
			$msg = $this->loadFile( $file );
			if ( $this->checkError( $msg ) ) return;

			$msg = $this->parseFile( $file );
			if ( $this->checkError( $msg ) ) return;

			$data = $msg[1];
			$this->setCachedData( $data );
		}

		$messages = $data['MESSAGES'];
		$group = $data['METADATA']['group'];
		$code = $data['METADATA']['code'];

		if ( !MessageGroups::exists( $group )  ) {
			$errorWrap = "<div class='error'>\n$1\n</div>";
			$this->out->wrapWikiMsg( $errorWrap, 'translate-import-err-stale-group' );
			return;
		}

		$importer = new MessageWebImporter( $this->getTitle(), $group, $code );
		$alldone = $importer->execute( $messages );

		if ( $alldone ) {
			$this->deleteCachedData();
		}
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:63,代码来源:SpecialImportTranslations.php

示例11: execute

 public function execute()
 {
     $groupIds = explode(',', trim($this->getOption('group')));
     $groupIds = MessageGroups::expandWildcards($groupIds);
     $groups = MessageGroups::getGroupsById($groupIds);
     if (!count($groups)) {
         $this->error("ESG2: No valid message groups identified.", 1);
     }
     $start = $this->getOption('start') ? strtotime($this->getOption('start')) : false;
     $end = $this->getOption('end') ? strtotime($this->getOption('end')) : false;
     $this->output("Conflict times: " . wfTimestamp(TS_ISO_8601, $start) . " - " . wfTimestamp(TS_ISO_8601, $end) . "\n");
     $codes = array_filter(array_map('trim', explode(',', $this->getOption('lang'))));
     $supportedCodes = array_keys(TranslateUtils::getLanguageNames('en'));
     ksort($supportedCodes);
     if ($codes[0] === '*') {
         $codes = $supportedCodes;
     }
     /** @var FileBasedMessageGroup $group */
     foreach ($groups as $groupId => &$group) {
         if ($group->isMeta()) {
             $this->output("Skipping meta message group {$groupId}.\n");
             continue;
         }
         $this->output("{$group->getLabel()} ", $group);
         foreach ($codes as $code) {
             // No sync possible for unsupported language codes.
             if (!in_array($code, $supportedCodes)) {
                 $this->output("Unsupported code " . $code . ": skipping.\n");
                 continue;
             }
             $file = $group->getSourceFilePath($code);
             if (!$file) {
                 continue;
             }
             if (!file_exists($file)) {
                 continue;
             }
             $cs = new ChangeSyncer($group, $this);
             $cs->setProgressCallback(array($this, 'myOutput'));
             $cs->interactive = !$this->hasOption('noask');
             $cs->nocolor = $this->hasOption('nocolor');
             $cs->norc = $this->hasOption('norc');
             # @todo FIXME: Make this auto detect.
             # Guess last modified date of the file from either git, svn or filesystem
             if ($this->hasOption('git')) {
                 $ts = $cs->getTimestampsFromGit($file);
             } else {
                 $ts = $cs->getTimestampsFromSvn($file);
             }
             if (!$ts) {
                 $ts = $cs->getTimestampsFromFs($file);
             }
             $this->output("Modify time for {$code}: " . wfTimestamp(TS_ISO_8601, $ts) . "\n");
             $cs->checkConflicts($code, $start, $end, $ts);
         }
         unset($group);
     }
     // Print timestamp if the user wants to store it
     $this->output(wfTimestamp(TS_RFC2822) . "\n");
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:60,代码来源:sync-group.php

示例12: getDefinitions

 public function getDefinitions()
 {
     $groups = MessageGroups::getAllGroups();
     $keys = array();
     /**
      * @var $g MessageGroup
      */
     foreach ($groups as $g) {
         $states = $g->getMessageGroupStates()->getStates();
         foreach (array_keys($states) as $state) {
             $keys["Translate-workflow-state-{$state}"] = $state;
         }
     }
     $defs = TranslateUtils::getContents(array_keys($keys), $this->getNamespace());
     foreach ($keys as $key => $state) {
         if (!isset($defs[$key])) {
             // @todo Use jobqueue
             $title = Title::makeTitleSafe($this->getNamespace(), $key);
             $page = new WikiPage($title);
             $content = ContentHandler::makeContent($state, $title);
             $page->doEditContent($content, wfMessage('translate-workflow-autocreated-summary', $state)->inContentLanguage()->text(), 0, false, FuzzyBot::getUser());
         } else {
             // Use the wiki translation as definition if available.
             // getContents returns array( content, last author )
             list($content, ) = $defs[$key];
             $keys[$key] = $content;
         }
     }
     return $keys;
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:30,代码来源:WorkflowStatesMessageGroup.php

示例13: __construct

	/**
	 * Contructs a new cache object for given group and language code.
	 * @param $group \types{String,FileBasedMessageGroup} Group object or id.
	 * @param $code \string Language code. Default value 'en'.
	 */
	public function __construct( $group, $code = 'en' ) {
		if ( is_object( $group ) ) {
			$this->group = $group;
		} else {
			$this->group = MessageGroups::getGroup( $group );
		}
		$this->code = $code;
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:13,代码来源:MessageGroupCache.php

示例14: isValidValue

 protected function isValidValue($value)
 {
     $group = MessageGroups::getGroup($value);
     if ($group) {
         $this->target = $group->getId();
     }
     return (bool) $group;
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:8,代码来源:SpecialMessageGroupStats.php

示例15: 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


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