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


PHP ApiResult::addValue方法代码示例

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


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

示例1: setResult

 /**
  * Call this method to initialize output data. See execute()
  * @param ApiResult $result
  * @param object $feed An instance of one of the $wgFeedClasses classes
  * @param array $feedItems Array of FeedItem objects
  */
 public static function setResult($result, $feed, $feedItems)
 {
     // Store output in the Result data.
     // This way we can check during execution if any error has occurred
     // Disable size checking for this because we can't continue
     // cleanly; size checking would cause more problems than it'd
     // solve
     $result->addValue(null, '_feed', $feed, ApiResult::NO_VALIDATE);
     $result->addValue(null, '_feeditems', $feedItems, ApiResult::NO_VALIDATE);
 }
开发者ID:jpena88,项目名称:mediawiki-dokku-deploy,代码行数:16,代码来源:ApiFormatFeedWrapper.php

示例2: doTag

 private function doTag($tagName, $hitcount)
 {
     static $count = 0;
     static $doneTags = array();
     if (in_array($tagName, $doneTags)) {
         return true;
     }
     if (++$count > $this->limit) {
         $this->setContinueEnumParameter('continue', $tagName);
         return false;
     }
     $tag = array();
     $tag['name'] = $tagName;
     if ($this->fld_displayname) {
         $tag['displayname'] = ChangeTags::tagDescription($tagName);
     }
     if ($this->fld_description) {
         $msg = wfMessage("tag-{$tagName}-description");
         $tag['description'] = $msg->exists() ? $msg->text() : '';
     }
     if ($this->fld_hitcount) {
         $tag['hitcount'] = $hitcount;
     }
     $doneTags[] = $tagName;
     $fit = $this->result->addValue(array('query', $this->getModuleName()), null, $tag);
     if (!$fit) {
         $this->setContinueEnumParameter('continue', $tagName);
         return false;
     }
     return true;
 }
开发者ID:Grprashanthkumar,项目名称:ColfusionWeb,代码行数:31,代码来源:ApiQueryTags.php

示例3: addWarningOrError

 /**
  * Actually add the warning or error to the result
  * @param string $tag 'warning' or 'error'
  * @param string $moduleName
  * @param ApiMessage|ApiRawMessage $msg
  */
 protected function addWarningOrError($tag, $moduleName, $msg)
 {
     $value = ['code' => $msg->getApiCode()];
     switch ($this->format) {
         case 'wikitext':
             $value += ['text' => $msg->text(), ApiResult::META_CONTENT => 'text'];
             break;
         case 'html':
             $value += ['html' => $msg->parse(), ApiResult::META_CONTENT => 'html'];
             break;
         case 'raw':
             $value += ['message' => $msg->getKey(), 'params' => $msg->getParams()];
             ApiResult::setIndexedTagName($value['params'], 'param');
             break;
         case 'none':
             break;
     }
     $value += $msg->getApiData();
     $path = [$tag . 's', $moduleName];
     $existing = $this->result->getResultData($path);
     if ($existing === null || !in_array($value, $existing)) {
         $flags = ApiResult::NO_SIZE_CHECK;
         if ($existing === null) {
             $flags |= ApiResult::ADD_ON_TOP;
         }
         $this->result->addValue($path, null, $value, $flags);
         $this->result->addIndexedTagName($path, $tag);
     }
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:35,代码来源:ApiErrorFormatter.php

示例4: testRedirectMergePolicyWithApiResult

 /**
  * @dataProvider provideRedirectMergePolicy
  */
 public function testRedirectMergePolicyWithApiResult($mergePolicy, $expect)
 {
     list($target, $pageSet) = $this->createPageSetWithRedirect();
     $pageSet->setRedirectMergePolicy($mergePolicy);
     $result = new ApiResult(false);
     $result->addValue(null, 'pages', [$target->getArticleID() => []]);
     $pageSet->populateGeneratorData($result, ['pages']);
     $this->assertEquals($expect, $result->getResultData(['pages', $target->getArticleID()]));
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:12,代码来源:ApiPageSetTest.php

示例5: addPageProps

 /**
  * Add page properties to an ApiResult, adding a continue
  * parameter if it doesn't fit.
  *
  * @param ApiResult $result
  * @param int $page
  * @param array $props
  * @return bool True if it fits in the result
  */
 private function addPageProps($result, $page, $props)
 {
     ApiResult::setArrayType($props, 'assoc');
     $fit = $result->addValue(['query', 'pages', $page], 'pageprops', $props);
     if (!$fit) {
         $this->setContinueEnumParameter('continue', $page);
     }
     return $fit;
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:18,代码来源:ApiQueryPageProps.php

示例6: appendDebugInfoToApiResult

 /**
  * Append the debug info to given ApiResult
  *
  * @param $context IContextSource
  * @param $result ApiResult
  */
 public static function appendDebugInfoToApiResult(IContextSource $context, ApiResult $result)
 {
     if (!self::$enabled) {
         return;
     }
     // output errors as debug info, when display_errors is on
     // this is necessary for all non html output of the api, because that clears all errors first
     $obContents = ob_get_contents();
     if ($obContents) {
         $obContentArray = explode('<br />', $obContents);
         foreach ($obContentArray as $obContent) {
             if (trim($obContent)) {
                 self::debugMsg(Sanitizer::stripAllTags($obContent));
             }
         }
     }
     MWDebug::log('MWDebug output complete');
     $debugInfo = self::getDebugInfo($context);
     $result->setIndexedTagName($debugInfo, 'debuginfo');
     $result->setIndexedTagName($debugInfo['log'], 'line');
     $result->setIndexedTagName($debugInfo['debugLog'], 'msg');
     $result->setIndexedTagName($debugInfo['queries'], 'query');
     $result->setIndexedTagName($debugInfo['includes'], 'queries');
     $result->addValue(null, 'debuginfo', $debugInfo);
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:31,代码来源:Debug.php

示例7: doExport

 /**
  * @param ApiPageSet $pageSet Pages to be exported
  * @param ApiResult $result Result to output to
  */
 private function doExport($pageSet, $result)
 {
     $exportTitles = array();
     $titles = $pageSet->getGoodTitles();
     if (count($titles)) {
         $user = $this->getUser();
         /** @var $title Title */
         foreach ($titles as $title) {
             if ($title->userCan('read', $user)) {
                 $exportTitles[] = $title;
             }
         }
     }
     $exporter = new WikiExporter($this->getDB());
     // WikiExporter writes to stdout, so catch its
     // output with an ob
     ob_start();
     $exporter->openStream();
     foreach ($exportTitles as $title) {
         $exporter->pageByTitle($title);
     }
     $exporter->closeStream();
     $exportxml = ob_get_contents();
     ob_end_clean();
     // Don't check the size of exported stuff
     // It's not continuable, so it would cause more
     // problems than it'd solve
     if ($this->mParams['exportnowrap']) {
         $result->reset();
         // Raw formatter will handle this
         $result->addValue(null, 'text', $exportxml, ApiResult::NO_SIZE_CHECK);
         $result->addValue(null, 'mime', 'text/xml', ApiResult::NO_SIZE_CHECK);
     } else {
         $r = array();
         ApiResult::setContent($r, $exportxml);
         $result->addValue('query', 'export', $r, ApiResult::NO_SIZE_CHECK);
     }
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:42,代码来源:ApiQuery.php

示例8: addPageProps

 /**
  * Add page properties to an ApiResult, adding a continue
  * parameter if it doesn't fit.
  *
  * @param ApiResult $result
  * @param int $page
  * @param array $props
  * @return bool True if it fits in the result
  */
 private function addPageProps($result, $page, $props)
 {
     $fit = $result->addValue(array('query', 'pages', $page), 'pageprops', $props);
     if (!$fit) {
         $this->setContinueEnumParameter('continue', $page);
     }
     return $fit;
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:17,代码来源:ApiQueryPageProps.php

示例9: testDeprecatedFunctions

 /**
  * @covers ApiResult
  */
 public function testDeprecatedFunctions()
 {
     // Ignore ApiResult deprecation warnings during this test
     set_error_handler(function ($errno, $errstr) use(&$warnings) {
         if (preg_match('/Use of ApiResult::\\S+ was deprecated in MediaWiki \\d+.\\d+\\./', $errstr)) {
             return true;
         }
         if (preg_match('/Use of ApiMain to ApiResult::__construct ' . 'was deprecated in MediaWiki \\d+.\\d+\\./', $errstr)) {
             return true;
         }
         return false;
     });
     $reset = new ScopedCallback('restore_error_handler');
     $context = new DerivativeContext(RequestContext::getMain());
     $context->setConfig(new HashConfig(array('APIModules' => array(), 'APIFormatModules' => array(), 'APIMaxResultSize' => 42)));
     $main = new ApiMain($context);
     $result = TestingAccessWrapper::newFromObject(new ApiResult($main));
     $this->assertSame(42, $result->maxSize);
     $this->assertSame($main->getErrorFormatter(), $result->errorFormatter);
     $this->assertSame($main, $result->mainForContinuation);
     $result = new ApiResult(8388608);
     $result->addContentValue(null, 'test', 'content');
     $result->addContentValue(array('foo', 'bar'), 'test', 'content');
     $result->addIndexedTagName(null, 'itn');
     $result->addSubelementsList(null, array('sub'));
     $this->assertSame(array('foo' => array('bar' => array('*' => 'content')), '*' => 'content'), $result->getData());
     $result->setRawMode();
     $this->assertSame(array('foo' => array('bar' => array('*' => 'content')), '*' => 'content', '_element' => 'itn', '_subelements' => array('sub')), $result->getData());
     $arr = array();
     ApiResult::setContent($arr, 'value');
     ApiResult::setContent($arr, 'value2', 'foobar');
     $this->assertSame(array(ApiResult::META_CONTENT => 'content', 'content' => 'value', 'foobar' => array(ApiResult::META_CONTENT => 'content', 'content' => 'value2')), $arr);
     $result = new ApiResult(3);
     $formatter = new ApiErrorFormatter_BackCompat($result);
     $result->setErrorFormatter($formatter);
     $result->disableSizeCheck();
     $this->assertTrue($result->addValue(null, 'foo', '1234567890'));
     $result->enableSizeCheck();
     $this->assertSame(0, $result->getSize());
     $this->assertFalse($result->addValue(null, 'foo', '1234567890'));
     $arr = array('foo' => array('bar' => 1));
     $result->setIndexedTagName_recursive($arr, 'itn');
     $this->assertSame(array('foo' => array('bar' => 1, ApiResult::META_INDEXED_TAG_NAME => 'itn')), $arr);
     $status = Status::newGood();
     $status->fatal('parentheses', '1');
     $status->fatal('parentheses', '2');
     $status->warning('parentheses', '3');
     $status->warning('parentheses', '4');
     $this->assertSame(array(array('type' => 'error', 'message' => 'parentheses', 'params' => array(0 => '1', ApiResult::META_INDEXED_TAG_NAME => 'param')), array('type' => 'error', 'message' => 'parentheses', 'params' => array(0 => '2', ApiResult::META_INDEXED_TAG_NAME => 'param')), ApiResult::META_INDEXED_TAG_NAME => 'error'), $result->convertStatusToArray($status, 'error'));
     $this->assertSame(array(array('type' => 'warning', 'message' => 'parentheses', 'params' => array(0 => '3', ApiResult::META_INDEXED_TAG_NAME => 'param')), array('type' => 'warning', 'message' => 'parentheses', 'params' => array(0 => '4', ApiResult::META_INDEXED_TAG_NAME => 'param')), ApiResult::META_INDEXED_TAG_NAME => 'warning'), $result->convertStatusToArray($status, 'warning'));
 }
开发者ID:ucfengzhun,项目名称:mediawiki,代码行数:54,代码来源:ApiResultTest.php

示例10: getRedirectName

 private function getRedirectName(ApiResult $result)
 {
     $res =& $result->getData();
     if (isset($res['query']) && isset($res['query']['pages'])) {
         foreach ($this->getPageSet()->getGoodTitles() as $page_id => $oTitle) {
             $res['query']['pages'][$page_id]['redirectto'] = "";
             if ($oTitle->isRedirect()) {
                 $oArticle = new Article($oTitle);
                 $oRedirTitle = $oArticle->getRedirectTarget();
                 if ($oRedirTitle instanceof Title) {
                     $result->addValue(array("query", "pages", $page_id), "redirectto", Title::makeName($oRedirTitle->getNamespace(), $oRedirTitle->getDBkey()));
                 }
             }
         }
     }
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:16,代码来源:WikiaApiQueryPageinfo.php

示例11: setContinuationIntoResult

 /**
  * Store the continuation data into the result
  * @param ApiResult $result
  */
 public function setContinuationIntoResult(ApiResult $result)
 {
     list($data, $batchcomplete) = $this->getContinuation();
     if ($data) {
         $result->addValue(null, 'continue', $data, ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK);
     }
     if ($batchcomplete) {
         $result->addValue(null, 'batchcomplete', true, ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK);
     }
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:14,代码来源:ApiContinuationManager.php

示例12: testTransformations

 /**
  * @covers ApiResult
  * @dataProvider provideTransformations
  * @param string $label
  * @param array $input
  * @param array $transforms
  * @param array|Exception $expect
  */
 public function testTransformations($label, $input, $transforms, $expect)
 {
     $result = new ApiResult(false);
     $result->addValue(null, 'test', $input);
     if ($expect instanceof Exception) {
         try {
             $output = $result->getResultData('test', $transforms);
             $this->fail('Expected exception not thrown', $label);
         } catch (Exception $ex) {
             $this->assertEquals($ex, $expect, $label);
         }
     } else {
         $output = $result->getResultData('test', $transforms);
         $this->assertEquals($expect, $output, $label);
     }
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:24,代码来源:ApiResultTest.php

示例13: doExport

 /**
  * @param ApiPageSet $pageSet Pages to be exported
  * @param ApiResult $result Result to output to
  */
 private function doExport($pageSet, $result)
 {
     $exportTitles = [];
     $titles = $pageSet->getGoodTitles();
     if (count($titles)) {
         $user = $this->getUser();
         /** @var $title Title */
         foreach ($titles as $title) {
             if ($title->userCan('read', $user)) {
                 $exportTitles[] = $title;
             }
         }
     }
     $exporter = new WikiExporter($this->getDB());
     $sink = new DumpStringOutput();
     $exporter->setOutputSink($sink);
     $exporter->openStream();
     foreach ($exportTitles as $title) {
         $exporter->pageByTitle($title);
     }
     $exporter->closeStream();
     // Don't check the size of exported stuff
     // It's not continuable, so it would cause more
     // problems than it'd solve
     if ($this->mParams['exportnowrap']) {
         $result->reset();
         // Raw formatter will handle this
         $result->addValue(null, 'text', $sink, ApiResult::NO_SIZE_CHECK);
         $result->addValue(null, 'mime', 'text/xml', ApiResult::NO_SIZE_CHECK);
     } else {
         $result->addValue('query', 'export', $sink, ApiResult::NO_SIZE_CHECK);
         $result->addValue('query', ApiResult::META_BC_SUBELEMENTS, ['export']);
     }
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:38,代码来源:ApiQuery.php


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