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


PHP MessageGroups::labelExists方法代码示例

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


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

示例1: execute

 public function execute()
 {
     if (!$this->getUser()->isAllowed(self::$right)) {
         $this->dieUsage('Permission denied', 'permissiondenied');
     }
     $params = $this->extractRequestParams();
     $action = $params['do'];
     $output = array();
     if ($action === 'associate' || $action === 'dissociate') {
         // Group is mandatory only for these two actions
         if (!isset($params['group'])) {
             $this->dieUsageMsg(array('missingparam', 'group'));
         }
         if (!isset($params['aggregategroup'])) {
             $this->dieUsageMsg(array('missingparam', 'aggregategroup'));
         }
         $aggregateGroup = $params['aggregategroup'];
         $subgroups = TranslateMetadata::getSubgroups($aggregateGroup);
         if (count($subgroups) === 0) {
             // For newly created groups the subgroups value might be empty,
             // but check that.
             if (TranslateMetadata::get($aggregateGroup, 'name') === false) {
                 $this->dieUsage('Invalid aggregate message group', 'invalidaggregategroup');
             }
             $subgroups = array();
         }
         $subgroupId = $params['group'];
         $group = MessageGroups::getGroup($subgroupId);
         // Add or remove from the list
         if ($action === 'associate') {
             if (!$group instanceof WikiPageMessageGroup) {
                 $this->dieUsage('Group does not exist or invalid', 'invalidgroup');
             }
             $subgroups[] = $subgroupId;
             $subgroups = array_unique($subgroups);
         } elseif ($action === 'dissociate') {
             // Allow removal of non-existing groups
             $subgroups = array_flip($subgroups);
             unset($subgroups[$subgroupId]);
             $subgroups = array_flip($subgroups);
         }
         TranslateMetadata::setSubgroups($aggregateGroup, $subgroups);
         $logParams = array('aggregategroup' => TranslateMetadata::get($aggregateGroup, 'name'), 'aggregategroup-id' => $aggregateGroup);
         /* Note that to allow removing no longer existing groups from
          * aggregate message groups, the message group object $group
          * might not always be available. In this case we need to fake
          * some title. */
         $title = $group ? $group->getTitle() : Title::newFromText("Special:Translate/{$subgroupId}");
         $entry = new ManualLogEntry('pagetranslation', $action);
         $entry->setPerformer($this->getUser());
         $entry->setTarget($title);
         // @todo
         // $entry->setComment( $comment );
         $entry->setParameters($logParams);
         $logid = $entry->insert();
         $entry->publish($logid);
     } elseif ($action === 'remove') {
         if (!isset($params['aggregategroup'])) {
             $this->dieUsageMsg(array('missingparam', 'aggregategroup'));
         }
         TranslateMetadata::deleteGroup($params['aggregategroup']);
         // @todo Logging
     } elseif ($action === 'add') {
         if (!isset($params['groupname'])) {
             $this->dieUsageMsg(array('missingparam', 'groupname'));
         }
         $name = trim($params['groupname']);
         if (strlen($name) === 0) {
             $this->dieUsage('Invalid aggregate message group name', 'invalidaggregategroupname');
         }
         if (!isset($params['groupdescription'])) {
             $this->dieUsageMsg(array('missingparam', 'groupdescription'));
         }
         $desc = trim($params['groupdescription']);
         $aggregateGroupId = self::generateAggregateGroupId($name);
         // Throw error if group already exists
         $nameExists = MessageGroups::labelExists($name);
         if ($nameExists) {
             $this->dieUsage('Message group already exists', 'duplicateaggregategroup');
         }
         // ID already exists- Generate a new ID by adding a number to it.
         $idExists = MessageGroups::getGroup($aggregateGroupId);
         if ($idExists) {
             $i = 1;
             while ($idExists) {
                 $tempId = $aggregateGroupId . "-" . $i;
                 $idExists = MessageGroups::getGroup($tempId);
                 $i++;
             }
             $aggregateGroupId = $tempId;
         }
         TranslateMetadata::set($aggregateGroupId, 'name', $name);
         TranslateMetadata::set($aggregateGroupId, 'description', $desc);
         TranslateMetadata::setSubgroups($aggregateGroupId, array());
         // Once new aggregate group added, we need to show all the pages that can be added to that.
         $output['groups'] = self::getAllPages();
         $output['aggregategroupId'] = $aggregateGroupId;
         // @todo Logging
     } elseif ($action === 'update') {
         if (!isset($params['groupname'])) {
//.........这里部分代码省略.........
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:101,代码来源:ApiAggregateGroups.php


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