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


PHP ApiResult::setContentValue方法代码示例

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


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

示例1: execute

 public function execute()
 {
     $params = $this->extractRequestParams();
     $rev1 = $this->revisionOrTitleOrId($params['fromrev'], $params['fromtitle'], $params['fromid']);
     $rev2 = $this->revisionOrTitleOrId($params['torev'], $params['totitle'], $params['toid']);
     $revision = Revision::newFromId($rev1);
     if (!$revision) {
         $this->dieUsage('The diff cannot be retrieved, ' . 'one revision does not exist or you do not have permission to view it.', 'baddiff');
     }
     $contentHandler = $revision->getContentHandler();
     $de = $contentHandler->createDifferenceEngine($this->getContext(), $rev1, $rev2, null, true, false);
     $vals = array();
     if (isset($params['fromtitle'])) {
         $vals['fromtitle'] = $params['fromtitle'];
     }
     if (isset($params['fromid'])) {
         $vals['fromid'] = $params['fromid'];
     }
     $vals['fromrevid'] = $rev1;
     if (isset($params['totitle'])) {
         $vals['totitle'] = $params['totitle'];
     }
     if (isset($params['toid'])) {
         $vals['toid'] = $params['toid'];
     }
     $vals['torevid'] = $rev2;
     $difftext = $de->getDiffBody();
     if ($difftext === false) {
         $this->dieUsage('The diff cannot be retrieved. Maybe one or both revisions do ' . 'not exist or you do not have permission to view them.', 'baddiff');
     }
     ApiResult::setContentValue($vals, 'body', $difftext);
     $this->getResult()->addValue(null, $this->getModuleName(), $vals);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:33,代码来源:ApiComparePages.php

示例2: execute

 public function execute()
 {
     if ($this->getPageSet()->getGoodTitleCount() == 0) {
         return;
     }
     $params = $this->extractRequestParams();
     $query = $params['query'];
     $protocol = ApiQueryExtLinksUsage::getProtocolPrefix($params['protocol']);
     $this->addFields(array('el_from', 'el_to'));
     $this->addTables('externallinks');
     $this->addWhereFld('el_from', array_keys($this->getPageSet()->getGoodTitles()));
     $whereQuery = $this->prepareUrlQuerySearchString($query, $protocol);
     if ($whereQuery !== null) {
         $this->addWhere($whereQuery);
     }
     // Don't order by el_from if it's constant in the WHERE clause
     if (count($this->getPageSet()->getGoodTitles()) != 1) {
         $this->addOption('ORDER BY', 'el_from');
     }
     // If we're querying all protocols, use DISTINCT to avoid repeating protocol-relative links twice
     if ($protocol === null) {
         $this->addOption('DISTINCT');
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $offset = isset($params['offset']) ? $params['offset'] : 0;
     if ($offset) {
         $this->addOption('OFFSET', $params['offset']);
     }
     $res = $this->select(__METHOD__);
     $count = 0;
     foreach ($res as $row) {
         if (++$count > $params['limit']) {
             // We've reached the one extra which shows that
             // there are additional pages to be had. Stop here...
             $this->setContinueEnumParameter('offset', $offset + $params['limit']);
             break;
         }
         $entry = array();
         $to = $row->el_to;
         // expand protocol-relative urls
         if ($params['expandurl']) {
             $to = wfExpandUrl($to, PROTO_CANONICAL);
         }
         ApiResult::setContentValue($entry, 'url', $to);
         $fit = $this->addPageSubItem($row->el_from, $entry);
         if (!$fit) {
             $this->setContinueEnumParameter('offset', $offset + $count - 1);
             break;
         }
     }
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:51,代码来源:ApiQueryExternalLinks.php

示例3: 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');
     }
     $namespace = $title->getNamespace();
     $pageInfo = self::getTranslations($handle);
     $result = $this->getResult();
     $count = 0;
     foreach ($pageInfo as $key => $info) {
         if (++$count <= $params['offset']) {
             continue;
         }
         $tTitle = Title::makeTitle($namespace, $key);
         $tHandle = new MessageHandle($tTitle);
         $data = array('title' => $tTitle->getPrefixedText(), 'language' => $tHandle->getCode(), 'lasttranslator' => $info[1]);
         $fuzzy = MessageHandle::hasFuzzyString($info[0]) || $tHandle->isFuzzy();
         if ($fuzzy) {
             $data['fuzzy'] = 'fuzzy';
         }
         $translation = str_replace(TRANSLATE_FUZZY, '', $info[0]);
         if (defined('ApiResult::META_CONTENT')) {
             ApiResult::setContentValue($data, 'translation', $translation);
         } else {
             ApiResult::setContent($data, $translation);
         }
         $fit = $result->addValue(array('query', $this->getModuleName()), null, $data);
         if (!$fit) {
             $this->setContinueEnumParameter('offset', $count);
             break;
         }
     }
     if (defined('ApiResult::META_CONTENT')) {
         $result->addIndexedTagName(array('query', $this->getModuleName()), 'message');
     } else {
         $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'message');
     }
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:44,代码来源:ApiQueryMessageTranslations.php

示例4: extractRevisionInfo


//.........这里部分代码省略.........
             $anyHidden = true;
         } elseif (!$content) {
             $vals['textmissing'] = true;
         }
     }
     if ($this->fld_content && $content) {
         $text = null;
         if ($this->generateXML) {
             if ($content->getModel() === CONTENT_MODEL_WIKITEXT) {
                 $t = $content->getNativeData();
                 # note: don't set $text
                 $wgParser->startExternalParse($title, ParserOptions::newFromContext($this->getContext()), Parser::OT_PREPROCESS);
                 $dom = $wgParser->preprocessToDom($t);
                 if (is_callable(array($dom, 'saveXML'))) {
                     $xml = $dom->saveXML();
                 } else {
                     $xml = $dom->__toString();
                 }
                 $vals['parsetree'] = $xml;
             } else {
                 $vals['badcontentformatforparsetree'] = true;
                 $this->setWarning("Conversion to XML is supported for wikitext only, " . $title->getPrefixedDBkey() . " uses content model " . $content->getModel());
             }
         }
         if ($this->expandTemplates && !$this->parseContent) {
             #XXX: implement template expansion for all content types in ContentHandler?
             if ($content->getModel() === CONTENT_MODEL_WIKITEXT) {
                 $text = $content->getNativeData();
                 $text = $wgParser->preprocess($text, $title, ParserOptions::newFromContext($this->getContext()));
             } else {
                 $this->setWarning("Template expansion is supported for wikitext only, " . $title->getPrefixedDBkey() . " uses content model " . $content->getModel());
                 $vals['badcontentformat'] = true;
                 $text = false;
             }
         }
         if ($this->parseContent) {
             $po = $content->getParserOutput($title, $revision->getId(), ParserOptions::newFromContext($this->getContext()));
             $text = $po->getText();
         }
         if ($text === null) {
             $format = $this->contentFormat ? $this->contentFormat : $content->getDefaultFormat();
             $model = $content->getModel();
             if (!$content->isSupportedFormat($format)) {
                 $name = $title->getPrefixedDBkey();
                 $this->setWarning("The requested format {$this->contentFormat} is not " . "supported for content model {$model} used by {$name}");
                 $vals['badcontentformat'] = true;
                 $text = false;
             } else {
                 $text = $content->serialize($format);
                 // always include format and model.
                 // Format is needed to deserialize, model is needed to interpret.
                 $vals['contentformat'] = $format;
                 $vals['contentmodel'] = $model;
             }
         }
         if ($text !== false) {
             ApiResult::setContentValue($vals, 'content', $text);
         }
     }
     if ($content && (!is_null($this->diffto) || !is_null($this->difftotext))) {
         static $n = 0;
         // Number of uncached diffs we've had
         if ($n < $this->getConfig()->get('APIMaxUncachedDiffs')) {
             $vals['diff'] = array();
             $context = new DerivativeContext($this->getContext());
             $context->setTitle($title);
             $handler = $revision->getContentHandler();
             if (!is_null($this->difftotext)) {
                 $model = $title->getContentModel();
                 if ($this->contentFormat && !ContentHandler::getForModelID($model)->isSupportedFormat($this->contentFormat)) {
                     $name = $title->getPrefixedDBkey();
                     $this->setWarning("The requested format {$this->contentFormat} is not " . "supported for content model {$model} used by {$name}");
                     $vals['diff']['badcontentformat'] = true;
                     $engine = null;
                 } else {
                     $difftocontent = ContentHandler::makeContent($this->difftotext, $title, $model, $this->contentFormat);
                     $engine = $handler->createDifferenceEngine($context);
                     $engine->setContent($content, $difftocontent);
                 }
             } else {
                 $engine = $handler->createDifferenceEngine($context, $revision->getID(), $this->diffto);
                 $vals['diff']['from'] = $engine->getOldid();
                 $vals['diff']['to'] = $engine->getNewid();
             }
             if ($engine) {
                 $difftext = $engine->getDiffBody();
                 ApiResult::setContentValue($vals['diff'], 'body', $difftext);
                 if (!$engine->wasCacheHit()) {
                     $n++;
                 }
             }
         } else {
             $vals['diff']['notcached'] = true;
         }
     }
     if ($anyHidden && $revision->isDeleted(Revision::DELETED_RESTRICTED)) {
         $vals['suppressed'] = true;
     }
     return $vals;
 }
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:101,代码来源:ApiQueryRevisionsBase.php

示例5: execute

 public function execute()
 {
     if ($this->getPageSet()->getGoodTitleCount() == 0) {
         return;
     }
     $params = $this->extractRequestParams();
     $prop = array_flip((array) $params['prop']);
     if (isset($params['title']) && !isset($params['lang'])) {
         $this->dieUsageMsg(array('missingparam', 'lang'));
     }
     // Handle deprecated param
     $this->requireMaxOneParameter($params, 'url', 'prop');
     if ($params['url']) {
         $prop = array('url' => 1);
     }
     $this->addFields(array('ll_from', 'll_lang', 'll_title'));
     $this->addTables('langlinks');
     $this->addWhereFld('ll_from', array_keys($this->getPageSet()->getGoodTitles()));
     if (!is_null($params['continue'])) {
         $cont = explode('|', $params['continue']);
         $this->dieContinueUsageIf(count($cont) != 2);
         $op = $params['dir'] == 'descending' ? '<' : '>';
         $llfrom = intval($cont[0]);
         $lllang = $this->getDB()->addQuotes($cont[1]);
         $this->addWhere("ll_from {$op} {$llfrom} OR " . "(ll_from = {$llfrom} AND " . "ll_lang {$op}= {$lllang})");
     }
     // FIXME: (follow-up) To allow extensions to add to the language links, we need
     //       to load them all, add the extra links, then apply paging.
     //       Should not be terrible, it's not going to be more than a few hundred links.
     // Note that, since (ll_from, ll_lang) is a unique key, we don't need
     // to sort by ll_title to ensure deterministic ordering.
     $sort = $params['dir'] == 'descending' ? ' DESC' : '';
     if (isset($params['lang'])) {
         $this->addWhereFld('ll_lang', $params['lang']);
         if (isset($params['title'])) {
             $this->addWhereFld('ll_title', $params['title']);
         }
         $this->addOption('ORDER BY', 'll_from' . $sort);
     } else {
         // Don't order by ll_from if it's constant in the WHERE clause
         if (count($this->getPageSet()->getGoodTitles()) == 1) {
             $this->addOption('ORDER BY', 'll_lang' . $sort);
         } else {
             $this->addOption('ORDER BY', array('ll_from' . $sort, 'll_lang' . $sort));
         }
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $res = $this->select(__METHOD__);
     $count = 0;
     foreach ($res as $row) {
         if (++$count > $params['limit']) {
             // We've reached the one extra which shows that
             // there are additional pages to be had. Stop here...
             $this->setContinueEnumParameter('continue', "{$row->ll_from}|{$row->ll_lang}");
             break;
         }
         $entry = array('lang' => $row->ll_lang);
         if (isset($prop['url'])) {
             $title = Title::newFromText("{$row->ll_lang}:{$row->ll_title}");
             if ($title) {
                 $entry['url'] = wfExpandUrl($title->getFullURL(), PROTO_CURRENT);
             }
         }
         if (isset($prop['langname'])) {
             $entry['langname'] = Language::fetchLanguageName($row->ll_lang, $params['inlanguagecode']);
         }
         if (isset($prop['autonym'])) {
             $entry['autonym'] = Language::fetchLanguageName($row->ll_lang);
         }
         ApiResult::setContentValue($entry, 'title', $row->ll_title);
         $fit = $this->addPageSubItem($row->ll_from, $entry);
         if (!$fit) {
             $this->setContinueEnumParameter('continue', "{$row->ll_from}|{$row->ll_lang}");
             break;
         }
     }
 }
开发者ID:Acidburn0zzz,项目名称:mediawiki,代码行数:77,代码来源:ApiQueryLangLinks.php

示例6: getCurrentUserInfo

 protected function getCurrentUserInfo()
 {
     $user = $this->getUser();
     $result = $this->getResult();
     $vals = array();
     $vals['id'] = intval($user->getId());
     $vals['name'] = $user->getName();
     if ($user->isAnon()) {
         $vals['anon'] = true;
     }
     if (isset($this->prop['blockinfo'])) {
         if ($user->isBlocked()) {
             $block = $user->getBlock();
             $vals['blockid'] = $block->getId();
             $vals['blockedby'] = $block->getByName();
             $vals['blockedbyid'] = $block->getBy();
             $vals['blockreason'] = $user->blockedFor();
             $vals['blockedtimestamp'] = wfTimestamp(TS_ISO_8601, $block->mTimestamp);
             $vals['blockexpiry'] = $block->getExpiry() === 'infinity' ? 'infinite' : wfTimestamp(TS_ISO_8601, $block->getExpiry());
         }
     }
     if (isset($this->prop['hasmsg'])) {
         $vals['messages'] = $user->getNewtalk();
     }
     if (isset($this->prop['groups'])) {
         $vals['groups'] = $user->getEffectiveGroups();
         ApiResult::setArrayType($vals['groups'], 'array');
         // even if empty
         ApiResult::setIndexedTagName($vals['groups'], 'g');
         // even if empty
     }
     if (isset($this->prop['implicitgroups'])) {
         $vals['implicitgroups'] = $user->getAutomaticGroups();
         ApiResult::setArrayType($vals['implicitgroups'], 'array');
         // even if empty
         ApiResult::setIndexedTagName($vals['implicitgroups'], 'g');
         // even if empty
     }
     if (isset($this->prop['rights'])) {
         // User::getRights() may return duplicate values, strip them
         $vals['rights'] = array_values(array_unique($user->getRights()));
         ApiResult::setArrayType($vals['rights'], 'array');
         // even if empty
         ApiResult::setIndexedTagName($vals['rights'], 'r');
         // even if empty
     }
     if (isset($this->prop['changeablegroups'])) {
         $vals['changeablegroups'] = $user->changeableGroups();
         ApiResult::setIndexedTagName($vals['changeablegroups']['add'], 'g');
         ApiResult::setIndexedTagName($vals['changeablegroups']['remove'], 'g');
         ApiResult::setIndexedTagName($vals['changeablegroups']['add-self'], 'g');
         ApiResult::setIndexedTagName($vals['changeablegroups']['remove-self'], 'g');
     }
     if (isset($this->prop['options'])) {
         $vals['options'] = $user->getOptions();
         $vals['options'][ApiResult::META_BC_BOOLS] = array_keys($vals['options']);
     }
     if (isset($this->prop['preferencestoken'])) {
         $p = $this->getModulePrefix();
         $this->setWarning("{$p}prop=preferencestoken has been deprecated. Please use action=query&meta=tokens instead.");
     }
     if (isset($this->prop['preferencestoken']) && !$this->lacksSameOriginSecurity() && $user->isAllowed('editmyoptions')) {
         $vals['preferencestoken'] = $user->getEditToken('', $this->getMain()->getRequest());
     }
     if (isset($this->prop['editcount'])) {
         // use intval to prevent null if a non-logged-in user calls
         // api.php?format=jsonfm&action=query&meta=userinfo&uiprop=editcount
         $vals['editcount'] = intval($user->getEditCount());
     }
     if (isset($this->prop['ratelimits'])) {
         $vals['ratelimits'] = $this->getRateLimits();
     }
     if (isset($this->prop['realname']) && !in_array('realname', $this->getConfig()->get('HiddenPrefs'))) {
         $vals['realname'] = $user->getRealName();
     }
     if ($user->isAllowed('viewmyprivateinfo')) {
         if (isset($this->prop['email'])) {
             $vals['email'] = $user->getEmail();
             $auth = $user->getEmailAuthenticationTimestamp();
             if (!is_null($auth)) {
                 $vals['emailauthenticated'] = wfTimestamp(TS_ISO_8601, $auth);
             }
         }
     }
     if (isset($this->prop['registrationdate'])) {
         $regDate = $user->getRegistration();
         if ($regDate !== false) {
             $vals['registrationdate'] = wfTimestamp(TS_ISO_8601, $regDate);
         }
     }
     if (isset($this->prop['acceptlang'])) {
         $langs = $this->getRequest()->getAcceptLang();
         $acceptLang = array();
         foreach ($langs as $lang => $val) {
             $r = array('q' => $val);
             ApiResult::setContentValue($r, 'code', $lang);
             $acceptLang[] = $r;
         }
         ApiResult::setIndexedTagName($acceptLang, 'lang');
         $vals['acceptlang'] = $acceptLang;
//.........这里部分代码省略.........
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:101,代码来源:ApiQueryUserInfo.php

示例7: execute

 public function execute()
 {
     // Cache may vary on $wgUser because ParserOptions gets data from it
     $this->getMain()->setCacheMode('anon-public-user-private');
     // Get parameters
     $params = $this->extractRequestParams();
     $this->requireMaxOneParameter($params, 'prop', 'generatexml');
     if ($params['prop'] === null) {
         $this->logFeatureUsage('action=expandtemplates&!prop');
         $this->setWarning('Because no values have been specified for the prop parameter, a ' . 'legacy format has been used for the output. This format is deprecated, and in ' . 'the future, a default value will be set for the prop parameter, causing the new' . 'format to always be used.');
         $prop = array();
     } else {
         $prop = array_flip($params['prop']);
     }
     // Get title and revision ID for parser
     $revid = $params['revid'];
     if ($revid !== null) {
         $rev = Revision::newFromId($revid);
         if (!$rev) {
             $this->dieUsage("There is no revision ID {$revid}", 'missingrev');
         }
         $title_obj = $rev->getTitle();
     } else {
         $title_obj = Title::newFromText($params['title']);
         if (!$title_obj || $title_obj->isExternal()) {
             $this->dieUsageMsg(array('invalidtitle', $params['title']));
         }
     }
     $result = $this->getResult();
     // Parse text
     global $wgParser;
     $options = ParserOptions::newFromContext($this->getContext());
     if ($params['includecomments']) {
         $options->setRemoveComments(false);
     }
     $retval = array();
     if (isset($prop['parsetree']) || $params['generatexml']) {
         if (!isset($prop['parsetree'])) {
             $this->logFeatureUsage('action=expandtemplates&generatexml');
         }
         $wgParser->startExternalParse($title_obj, $options, Parser::OT_PREPROCESS);
         $dom = $wgParser->preprocessToDom($params['text']);
         if (is_callable(array($dom, 'saveXML'))) {
             $xml = $dom->saveXML();
         } else {
             $xml = $dom->__toString();
         }
         if (isset($prop['parsetree'])) {
             unset($prop['parsetree']);
             $retval['parsetree'] = $xml;
         } else {
             // the old way
             $result->addValue(null, 'parsetree', $xml);
             $result->addValue(null, ApiResult::META_BC_SUBELEMENTS, array('parsetree'));
         }
     }
     // if they didn't want any output except (probably) the parse tree,
     // then don't bother actually fully expanding it
     if ($prop || $params['prop'] === null) {
         $wgParser->startExternalParse($title_obj, $options, Parser::OT_PREPROCESS);
         $frame = $wgParser->getPreprocessor()->newFrame();
         $wikitext = $wgParser->preprocess($params['text'], $title_obj, $options, $revid, $frame);
         if ($params['prop'] === null) {
             // the old way
             ApiResult::setContentValue($retval, 'wikitext', $wikitext);
         } else {
             if (isset($prop['categories'])) {
                 $categories = $wgParser->getOutput()->getCategories();
                 if ($categories) {
                     $categories_result = array();
                     foreach ($categories as $category => $sortkey) {
                         $entry = array();
                         $entry['sortkey'] = $sortkey;
                         ApiResult::setContentValue($entry, 'category', $category);
                         $categories_result[] = $entry;
                     }
                     ApiResult::setIndexedTagName($categories_result, 'category');
                     $retval['categories'] = $categories_result;
                 }
             }
             if (isset($prop['properties'])) {
                 $properties = $wgParser->getOutput()->getProperties();
                 if ($properties) {
                     ApiResult::setArrayType($properties, 'BCkvp', 'name');
                     ApiResult::setIndexedTagName($properties, 'property');
                     $retval['properties'] = $properties;
                 }
             }
             if (isset($prop['volatile'])) {
                 $retval['volatile'] = $frame->isVolatile();
             }
             if (isset($prop['ttl']) && $frame->getTTL() !== null) {
                 $retval['ttl'] = $frame->getTTL();
             }
             if (isset($prop['wikitext'])) {
                 $retval['wikitext'] = $wikitext;
             }
         }
     }
     ApiResult::setSubelementsList($retval, array('wikitext', 'parsetree'));
//.........这里部分代码省略.........
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:101,代码来源:ApiExpandTemplates.php

示例8: formatHeadItems

 private function formatHeadItems($headItems)
 {
     $result = [];
     foreach ($headItems as $tag => $content) {
         $entry = [];
         $entry['tag'] = $tag;
         ApiResult::setContentValue($entry, 'content', $content);
         $result[] = $entry;
     }
     return $result;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:11,代码来源:ApiParse.php

示例9: getCurrentUserInfo

 protected function getCurrentUserInfo()
 {
     $user = $this->getUser();
     $vals = [];
     $vals['id'] = intval($user->getId());
     $vals['name'] = $user->getName();
     if ($user->isAnon()) {
         $vals['anon'] = true;
     }
     if (isset($this->prop['blockinfo']) && $user->isBlocked()) {
         $vals = array_merge($vals, self::getBlockInfo($user->getBlock()));
     }
     if (isset($this->prop['hasmsg'])) {
         $vals['messages'] = $user->getNewtalk();
     }
     if (isset($this->prop['groups'])) {
         $vals['groups'] = $user->getEffectiveGroups();
         ApiResult::setArrayType($vals['groups'], 'array');
         // even if empty
         ApiResult::setIndexedTagName($vals['groups'], 'g');
         // even if empty
     }
     if (isset($this->prop['implicitgroups'])) {
         $vals['implicitgroups'] = $user->getAutomaticGroups();
         ApiResult::setArrayType($vals['implicitgroups'], 'array');
         // even if empty
         ApiResult::setIndexedTagName($vals['implicitgroups'], 'g');
         // even if empty
     }
     if (isset($this->prop['rights'])) {
         // User::getRights() may return duplicate values, strip them
         $vals['rights'] = array_values(array_unique($user->getRights()));
         ApiResult::setArrayType($vals['rights'], 'array');
         // even if empty
         ApiResult::setIndexedTagName($vals['rights'], 'r');
         // even if empty
     }
     if (isset($this->prop['changeablegroups'])) {
         $vals['changeablegroups'] = $user->changeableGroups();
         ApiResult::setIndexedTagName($vals['changeablegroups']['add'], 'g');
         ApiResult::setIndexedTagName($vals['changeablegroups']['remove'], 'g');
         ApiResult::setIndexedTagName($vals['changeablegroups']['add-self'], 'g');
         ApiResult::setIndexedTagName($vals['changeablegroups']['remove-self'], 'g');
     }
     if (isset($this->prop['options'])) {
         $vals['options'] = $user->getOptions();
         $vals['options'][ApiResult::META_BC_BOOLS] = array_keys($vals['options']);
     }
     if (isset($this->prop['preferencestoken'])) {
         $p = $this->getModulePrefix();
         $this->setWarning("{$p}prop=preferencestoken has been deprecated. Please use action=query&meta=tokens instead.");
     }
     if (isset($this->prop['preferencestoken']) && !$this->lacksSameOriginSecurity() && $user->isAllowed('editmyoptions')) {
         $vals['preferencestoken'] = $user->getEditToken('', $this->getMain()->getRequest());
     }
     if (isset($this->prop['editcount'])) {
         // use intval to prevent null if a non-logged-in user calls
         // api.php?format=jsonfm&action=query&meta=userinfo&uiprop=editcount
         $vals['editcount'] = intval($user->getEditCount());
     }
     if (isset($this->prop['ratelimits'])) {
         $vals['ratelimits'] = $this->getRateLimits();
     }
     if (isset($this->prop['realname']) && !in_array('realname', $this->getConfig()->get('HiddenPrefs'))) {
         $vals['realname'] = $user->getRealName();
     }
     if ($user->isAllowed('viewmyprivateinfo')) {
         if (isset($this->prop['email'])) {
             $vals['email'] = $user->getEmail();
             $auth = $user->getEmailAuthenticationTimestamp();
             if (!is_null($auth)) {
                 $vals['emailauthenticated'] = wfTimestamp(TS_ISO_8601, $auth);
             }
         }
     }
     if (isset($this->prop['registrationdate'])) {
         $regDate = $user->getRegistration();
         if ($regDate !== false) {
             $vals['registrationdate'] = wfTimestamp(TS_ISO_8601, $regDate);
         }
     }
     if (isset($this->prop['acceptlang'])) {
         $langs = $this->getRequest()->getAcceptLang();
         $acceptLang = [];
         foreach ($langs as $lang => $val) {
             $r = ['q' => $val];
             ApiResult::setContentValue($r, 'code', $lang);
             $acceptLang[] = $r;
         }
         ApiResult::setIndexedTagName($acceptLang, 'lang');
         $vals['acceptlang'] = $acceptLang;
     }
     if (isset($this->prop['unreadcount'])) {
         $store = MediaWikiServices::getInstance()->getWatchedItemStore();
         $unreadNotifications = $store->countUnreadNotifications($user, self::WL_UNREAD_LIMIT);
         if ($unreadNotifications === true) {
             $vals['unreadcount'] = self::WL_UNREAD_LIMIT . '+';
         } else {
             $vals['unreadcount'] = $unreadNotifications;
         }
//.........这里部分代码省略.........
开发者ID:claudinec,项目名称:galan-wiki,代码行数:101,代码来源:ApiQueryUserInfo.php

示例10: formatRsdApiList

 /**
  * Formats the internal list of exposed APIs into an array suitable
  * to pass to the API's XML formatter.
  *
  * @return array
  */
 protected function formatRsdApiList()
 {
     $apis = $this->getRsdApiList();
     $outputData = array();
     foreach ($apis as $name => $info) {
         $data = array('name' => $name, 'preferred' => wfBoolToStr($name == 'MediaWiki'), 'apiLink' => $info['apiLink'], 'blogID' => isset($info['blogID']) ? $info['blogID'] : '');
         $settings = array();
         if (isset($info['docs'])) {
             $settings['docs'] = $info['docs'];
             ApiResult::setSubelementsList($settings, 'docs');
         }
         if (isset($info['settings'])) {
             foreach ($info['settings'] as $setting => $val) {
                 if (is_bool($val)) {
                     $xmlVal = wfBoolToStr($val);
                 } else {
                     $xmlVal = $val;
                 }
                 $setting = array('name' => $setting);
                 ApiResult::setContentValue($setting, 'value', $xmlVal);
                 $settings[] = $setting;
             }
         }
         if (count($settings)) {
             ApiResult::setIndexedTagName($settings, 'setting');
             $data['settings'] = $settings;
         }
         $outputData[] = $data;
     }
     return $outputData;
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:37,代码来源:ApiRsd.php

示例11: testStaticDataMethods

 /**
  * @covers ApiResult
  */
 public function testStaticDataMethods()
 {
     $arr = array();
     ApiResult::setValue($arr, 'setValue', '1');
     ApiResult::setValue($arr, null, 'unnamed 1');
     ApiResult::setValue($arr, null, 'unnamed 2');
     ApiResult::setValue($arr, 'deleteValue', '2');
     ApiResult::unsetValue($arr, 'deleteValue');
     ApiResult::setContentValue($arr, 'setContentValue', '3');
     $this->assertSame(array('setValue' => '1', 'unnamed 1', 'unnamed 2', ApiResult::META_CONTENT => 'setContentValue', 'setContentValue' => '3'), $arr);
     try {
         ApiResult::setValue($arr, 'setValue', '99');
         $this->fail('Expected exception not thrown');
     } catch (RuntimeException $ex) {
         $this->assertSame('Attempting to add element setValue=99, existing value is 1', $ex->getMessage(), 'Expected exception');
     }
     try {
         ApiResult::setContentValue($arr, 'setContentValue2', '99');
         $this->fail('Expected exception not thrown');
     } catch (RuntimeException $ex) {
         $this->assertSame('Attempting to set content element as setContentValue2 when setContentValue ' . 'is already set as the content element', $ex->getMessage(), 'Expected exception');
     }
     ApiResult::setValue($arr, 'setValue', '99', ApiResult::OVERRIDE);
     $this->assertSame('99', $arr['setValue']);
     ApiResult::setContentValue($arr, 'setContentValue2', '99', ApiResult::OVERRIDE);
     $this->assertSame('setContentValue2', $arr[ApiResult::META_CONTENT]);
     $arr = array('foo' => 1, 'bar' => 1);
     ApiResult::setValue($arr, 'top', '2', ApiResult::ADD_ON_TOP);
     ApiResult::setValue($arr, null, '2', ApiResult::ADD_ON_TOP);
     ApiResult::setValue($arr, 'bottom', '2');
     ApiResult::setValue($arr, 'foo', '2', ApiResult::OVERRIDE);
     ApiResult::setValue($arr, 'bar', '2', ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP);
     $this->assertSame(array(0, 'top', 'foo', 'bar', 'bottom'), array_keys($arr));
     $arr = array();
     ApiResult::setValue($arr, 'sub', array('foo' => 1));
     ApiResult::setValue($arr, 'sub', array('bar' => 1));
     $this->assertSame(array('sub' => array('foo' => 1, 'bar' => 1)), $arr);
     try {
         ApiResult::setValue($arr, 'sub', array('foo' => 2, 'baz' => 2));
         $this->fail('Expected exception not thrown');
     } catch (RuntimeException $ex) {
         $this->assertSame('Conflicting keys (foo) when attempting to merge element sub', $ex->getMessage(), 'Expected exception');
     }
     $arr = array();
     $title = Title::newFromText("MediaWiki:Foobar");
     $obj = new stdClass();
     $obj->foo = 1;
     $obj->bar = 2;
     ApiResult::setValue($arr, 'title', $title);
     ApiResult::setValue($arr, 'obj', $obj);
     $this->assertSame(array('title' => (string) $title, 'obj' => array('foo' => 1, 'bar' => 2, ApiResult::META_TYPE => 'assoc')), $arr);
     $fh = tmpfile();
     try {
         ApiResult::setValue($arr, 'file', $fh);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         ApiResult::setValue($arr, null, $fh);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         $obj->file = $fh;
         ApiResult::setValue($arr, 'sub', $obj);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         $obj->file = $fh;
         ApiResult::setValue($arr, null, $obj);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     fclose($fh);
     try {
         ApiResult::setValue($arr, 'inf', INF);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add non-finite floats to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         ApiResult::setValue($arr, null, INF);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add non-finite floats to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         ApiResult::setValue($arr, 'nan', NAN);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add non-finite floats to ApiResult', $ex->getMessage(), 'Expected exception');
     }
//.........这里部分代码省略.........
开发者ID:ucfengzhun,项目名称:mediawiki,代码行数:101,代码来源:ApiResultTest.php

示例12: execute

 public function execute()
 {
     if ($this->getPageSet()->getGoodTitleCount() == 0) {
         return;
     }
     $params = $this->extractRequestParams();
     $prop = array_flip((array) $params['prop']);
     if (isset($params['title']) && !isset($params['prefix'])) {
         $this->dieUsageMsg(['missingparam', 'prefix']);
     }
     // Handle deprecated param
     $this->requireMaxOneParameter($params, 'url', 'prop');
     if ($params['url']) {
         $prop = ['url' => 1];
     }
     $this->addFields(['iwl_from', 'iwl_prefix', 'iwl_title']);
     $this->addTables('iwlinks');
     $this->addWhereFld('iwl_from', array_keys($this->getPageSet()->getGoodTitles()));
     if (!is_null($params['continue'])) {
         $cont = explode('|', $params['continue']);
         $this->dieContinueUsageIf(count($cont) != 3);
         $op = $params['dir'] == 'descending' ? '<' : '>';
         $db = $this->getDB();
         $iwlfrom = intval($cont[0]);
         $iwlprefix = $db->addQuotes($cont[1]);
         $iwltitle = $db->addQuotes($cont[2]);
         $this->addWhere("iwl_from {$op} {$iwlfrom} OR " . "(iwl_from = {$iwlfrom} AND " . "(iwl_prefix {$op} {$iwlprefix} OR " . "(iwl_prefix = {$iwlprefix} AND " . "iwl_title {$op}= {$iwltitle})))");
     }
     $sort = $params['dir'] == 'descending' ? ' DESC' : '';
     if (isset($params['prefix'])) {
         $this->addWhereFld('iwl_prefix', $params['prefix']);
         if (isset($params['title'])) {
             $this->addWhereFld('iwl_title', $params['title']);
             $this->addOption('ORDER BY', 'iwl_from' . $sort);
         } else {
             $this->addOption('ORDER BY', ['iwl_from' . $sort, 'iwl_title' . $sort]);
         }
     } else {
         // Don't order by iwl_from if it's constant in the WHERE clause
         if (count($this->getPageSet()->getGoodTitles()) == 1) {
             $this->addOption('ORDER BY', 'iwl_prefix' . $sort);
         } else {
             $this->addOption('ORDER BY', ['iwl_from' . $sort, 'iwl_prefix' . $sort, 'iwl_title' . $sort]);
         }
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $res = $this->select(__METHOD__);
     $count = 0;
     foreach ($res as $row) {
         if (++$count > $params['limit']) {
             // We've reached the one extra which shows that
             // there are additional pages to be had. Stop here...
             $this->setContinueEnumParameter('continue', "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}");
             break;
         }
         $entry = ['prefix' => $row->iwl_prefix];
         if (isset($prop['url'])) {
             $title = Title::newFromText("{$row->iwl_prefix}:{$row->iwl_title}");
             if ($title) {
                 $entry['url'] = wfExpandUrl($title->getFullURL(), PROTO_CURRENT);
             }
         }
         ApiResult::setContentValue($entry, 'title', $row->iwl_title);
         $fit = $this->addPageSubItem($row->iwl_from, $entry);
         if (!$fit) {
             $this->setContinueEnumParameter('continue', "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}");
             break;
         }
     }
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:70,代码来源:ApiQueryIWLinks.php

示例13: substituteResultWithError

 /**
  * Replace the result data with the information about an exception.
  * Returns the error code
  * @param Exception $e
  * @return string
  */
 protected function substituteResultWithError($e)
 {
     $result = $this->getResult();
     $config = $this->getConfig();
     $errMessage = $this->errorMessageFromException($e);
     if ($e instanceof UsageException) {
         // User entered incorrect parameters - generate error response
         $link = wfExpandUrl(wfScript('api'));
         ApiResult::setContentValue($errMessage, 'docref', "See {$link} for API usage");
     } else {
         // Something is seriously wrong
         if ($config->get('ShowExceptionDetails')) {
             ApiResult::setContentValue($errMessage, 'trace', MWExceptionHandler::getRedactedTraceAsString($e));
         }
     }
     // Remember all the warnings to re-add them later
     $warnings = $result->getResultData(['warnings']);
     $result->reset();
     // Re-add the id
     $requestid = $this->getParameter('requestid');
     if (!is_null($requestid)) {
         $result->addValue(null, 'requestid', $requestid, ApiResult::NO_SIZE_CHECK);
     }
     if ($config->get('ShowHostnames')) {
         // servedby is especially useful when debugging errors
         $result->addValue(null, 'servedby', wfHostname(), ApiResult::NO_SIZE_CHECK);
     }
     if ($warnings !== null) {
         $result->addValue(null, 'warnings', $warnings, ApiResult::NO_SIZE_CHECK);
     }
     $result->addValue(null, 'error', $errMessage, ApiResult::NO_SIZE_CHECK);
     return $errMessage['code'];
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:39,代码来源:ApiMain.php

示例14: execute


//.........这里部分代码省略.........
         if ($fld_user || $fld_userid) {
             if ($row->ar_deleted & Revision::DELETED_USER) {
                 $rev['userhidden'] = true;
                 $anyHidden = true;
             }
             if (Revision::userCanBitfield($row->ar_deleted, Revision::DELETED_USER, $user)) {
                 if ($fld_user) {
                     $rev['user'] = $row->ar_user_text;
                 }
                 if ($fld_userid) {
                     $rev['userid'] = $row->ar_user;
                 }
             }
         }
         if ($fld_comment || $fld_parsedcomment) {
             if ($row->ar_deleted & Revision::DELETED_COMMENT) {
                 $rev['commenthidden'] = true;
                 $anyHidden = true;
             }
             if (Revision::userCanBitfield($row->ar_deleted, Revision::DELETED_COMMENT, $user)) {
                 if ($fld_comment) {
                     $rev['comment'] = $row->ar_comment;
                 }
                 if ($fld_parsedcomment) {
                     $title = Title::makeTitle($row->ar_namespace, $row->ar_title);
                     $rev['parsedcomment'] = Linker::formatComment($row->ar_comment, $title);
                 }
             }
         }
         if ($fld_minor) {
             $rev['minor'] = $row->ar_minor_edit == 1;
         }
         if ($fld_len) {
             $rev['len'] = $row->ar_len;
         }
         if ($fld_sha1) {
             if ($row->ar_deleted & Revision::DELETED_TEXT) {
                 $rev['sha1hidden'] = true;
                 $anyHidden = true;
             }
             if (Revision::userCanBitfield($row->ar_deleted, Revision::DELETED_TEXT, $user)) {
                 if ($row->ar_sha1 != '') {
                     $rev['sha1'] = wfBaseConvert($row->ar_sha1, 36, 16, 40);
                 } else {
                     $rev['sha1'] = '';
                 }
             }
         }
         if ($fld_content) {
             if ($row->ar_deleted & Revision::DELETED_TEXT) {
                 $rev['texthidden'] = true;
                 $anyHidden = true;
             }
             if (Revision::userCanBitfield($row->ar_deleted, Revision::DELETED_TEXT, $user)) {
                 if (isset($row->ar_text) && !$row->ar_text_id) {
                     // Pre-1.5 ar_text row (if condition from Revision::newFromArchiveRow)
                     ApiResult::setContentValue($rev, 'text', Revision::getRevisionText($row, 'ar_'));
                 } else {
                     ApiResult::setContentValue($rev, 'text', Revision::getRevisionText($row));
                 }
             }
         }
         if ($fld_tags) {
             if ($row->ts_tags) {
                 $tags = explode(',', $row->ts_tags);
                 ApiResult::setIndexedTagName($tags, 'tag');
                 $rev['tags'] = $tags;
             } else {
                 $rev['tags'] = array();
             }
         }
         if ($anyHidden && $row->ar_deleted & Revision::DELETED_RESTRICTED) {
             $rev['suppressed'] = true;
         }
         if (!isset($pageMap[$row->ar_namespace][$row->ar_title])) {
             $pageID = $newPageID++;
             $pageMap[$row->ar_namespace][$row->ar_title] = $pageID;
             $a['revisions'] = array($rev);
             ApiResult::setIndexedTagName($a['revisions'], 'rev');
             $title = Title::makeTitle($row->ar_namespace, $row->ar_title);
             ApiQueryBase::addTitleInfo($a, $title);
             if ($fld_token) {
                 $a['token'] = $token;
             }
             $fit = $result->addValue(array('query', $this->getModuleName()), $pageID, $a);
         } else {
             $pageID = $pageMap[$row->ar_namespace][$row->ar_title];
             $fit = $result->addValue(array('query', $this->getModuleName(), $pageID, 'revisions'), null, $rev);
         }
         if (!$fit) {
             if ($mode == 'all' || $mode == 'revs') {
                 $this->setContinueEnumParameter('continue', "{$row->ar_namespace}|{$row->ar_title}|{$row->ar_timestamp}|{$row->ar_id}");
             } else {
                 $this->setContinueEnumParameter('continue', "{$row->ar_timestamp}|{$row->ar_id}");
             }
             break;
         }
     }
     $result->addIndexedTagName(array('query', $this->getModuleName()), 'page');
 }
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:101,代码来源:ApiQueryDeletedrevs.php

示例15: formatCss

 private function formatCss($css)
 {
     $result = array();
     foreach ($css as $file => $link) {
         $entry = array();
         $entry['file'] = $file;
         ApiResult::setContentValue($entry, 'link', $link);
         $result[] = $entry;
     }
     return $result;
 }
开发者ID:huatuoorg,项目名称:mediawiki,代码行数:11,代码来源:ApiParse.php


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