本文整理汇总了PHP中ApiResult类的典型用法代码示例。如果您正苦于以下问题:PHP ApiResult类的具体用法?PHP ApiResult怎么用?PHP ApiResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ApiResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateOutput
/**
* Generate service output json format
* @param ApiResult $result
*/
public static function generateOutput($result)
{
assert('$result instanceof ApiResult');
$output = $result->convertToArray();
echo json_encode($output);
return;
}
示例2: testErrorFormatterBC
/**
* @covers ApiErrorFormatter_BackCompat
*/
public function testErrorFormatterBC()
{
$mainpagePlain = wfMessage('mainpage')->useDatabase(false)->plain();
$parensPlain = wfMessage('parentheses', 'foobar')->useDatabase(false)->plain();
$result = new ApiResult(8388608);
$formatter = new ApiErrorFormatter_BackCompat($result);
$formatter->addWarning('string', 'mainpage');
$formatter->addError('err', 'mainpage');
$this->assertSame(array('error' => array('code' => 'mainpage', 'info' => $mainpagePlain), 'warnings' => array('string' => array('warnings' => $mainpagePlain, ApiResult::META_CONTENT => 'warnings')), ApiResult::META_TYPE => 'assoc'), $result->getResultData(), 'Simple test');
$result->reset();
$formatter->addWarning('foo', 'mainpage');
$formatter->addWarning('foo', 'mainpage');
$formatter->addWarning('foo', array('parentheses', 'foobar'));
$msg1 = wfMessage('mainpage');
$formatter->addWarning('message', $msg1);
$msg2 = new ApiMessage('mainpage', 'overriddenCode', array('overriddenData' => true));
$formatter->addWarning('messageWithData', $msg2);
$formatter->addError('errWithData', $msg2);
$this->assertSame(array('error' => array('code' => 'overriddenCode', 'info' => $mainpagePlain, 'overriddenData' => true), 'warnings' => array('messageWithData' => array('warnings' => $mainpagePlain, ApiResult::META_CONTENT => 'warnings'), 'message' => array('warnings' => $mainpagePlain, ApiResult::META_CONTENT => 'warnings'), 'foo' => array('warnings' => "{$mainpagePlain}\n{$parensPlain}", ApiResult::META_CONTENT => 'warnings')), ApiResult::META_TYPE => 'assoc'), $result->getResultData(), 'Complex test');
$result->reset();
$status = Status::newGood();
$status->warning('mainpage');
$status->warning('parentheses', 'foobar');
$status->warning($msg1);
$status->warning($msg2);
$status->error('mainpage');
$status->error('parentheses', 'foobar');
$formatter->addMessagesFromStatus('status', $status);
$this->assertSame(array('error' => array('code' => 'parentheses', 'info' => $parensPlain), 'warnings' => array('status' => array('warnings' => "{$mainpagePlain}\n{$parensPlain}", ApiResult::META_CONTENT => 'warnings')), ApiResult::META_TYPE => 'assoc'), $result->getResultData(), 'Status test');
$I = ApiResult::META_INDEXED_TAG_NAME;
$this->assertSame(array(array('type' => 'error', 'message' => 'mainpage', 'params' => array($I => 'param')), array('type' => 'error', 'message' => 'parentheses', 'params' => array('foobar', $I => 'param')), $I => 'error'), $formatter->arrayFromStatus($status, 'error'), 'arrayFromStatus test for error');
$this->assertSame(array(array('type' => 'warning', 'message' => 'mainpage', 'params' => array($I => 'param')), array('type' => 'warning', 'message' => 'parentheses', 'params' => array('foobar', $I => 'param')), array('message' => 'mainpage', 'params' => array($I => 'param'), 'type' => 'warning'), array('message' => 'mainpage', 'params' => array($I => 'param'), 'type' => 'warning'), $I => 'warning'), $formatter->arrayFromStatus($status, 'warning'), 'arrayFromStatus test for warning');
}
示例3: generateOutput
/**
* Generate service output json format
* @param ApiResult $result
*/
public static function generateOutput($result)
{
assert('$result instanceof ApiResult');
$data = $result->convertToArray();
$xml = Array2XML::createXML('zurmoMessage', $data);
echo $xml->saveXML();
return;
}
示例4: 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;
}
示例5: 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()]));
}
示例6: 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);
}
示例7: execute
public function execute()
{
$prop = null;
extract($this->extractRequestParams());
foreach ($prop as $p) {
switch ($p) {
case 'general':
global $wgSitename, $wgVersion, $wgCapitalLinks;
$data = array();
$mainPage = Title::newFromText(wfMsgForContent('mainpage'));
$data['mainpage'] = $mainPage->getText();
$data['base'] = $mainPage->getFullUrl();
$data['sitename'] = $wgSitename;
$data['generator'] = "MediaWiki {$wgVersion}";
$data['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive';
// 'case-insensitive' option is reserved for future
$this->getResult()->addValue('query', $p, $data);
break;
case 'namespaces':
global $wgContLang;
$data = array();
foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
$data[$ns] = array('id' => $ns);
ApiResult::setContent($data[$ns], $title);
}
ApiResult::setIndexedTagName($data, 'ns');
$this->getResult()->addValue('query', $p, $data);
break;
default:
ApiBase::dieDebug(__METHOD__, "Unknown prop={$p}");
}
}
}
示例8: execute
public function execute()
{
if (!$this->hasAnyRoutes()) {
$this->dieUsage('No password reset routes are available.', 'moduledisabled');
}
$params = $this->extractRequestParams() + ['user' => null, 'email' => null];
$this->requireOnlyOneParameter($params, 'user', 'email');
$passwordReset = new PasswordReset($this->getConfig(), AuthManager::singleton());
$status = $passwordReset->isAllowed($this->getUser(), $params['capture']);
if (!$status->isOK()) {
$this->dieStatus(Status::wrap($status));
}
$status = $passwordReset->execute($this->getUser(), $params['user'], $params['email'], $params['capture']);
if (!$status->isOK()) {
$status->value = null;
$this->dieStatus(Status::wrap($status));
}
$result = $this->getResult();
$result->addValue(['resetpassword'], 'status', 'success');
if ($params['capture']) {
$passwords = $status->getValue() ?: [];
ApiResult::setArrayType($passwords, 'kvp', 'user');
ApiResult::setIndexedTagName($passwords, 'p');
$result->addValue(['resetpassword'], 'passwords', $passwords);
}
}
示例9: execute
public function execute()
{
$this->addFields(array('ll_from', 'll_lang', 'll_title'));
$this->addTables('langlinks');
$this->addWhereFld('ll_from', array_keys($this->getPageSet()->getGoodTitles()));
$this->addOption('ORDER BY', "ll_from, ll_lang");
$res = $this->select(__METHOD__);
$data = array();
$lastId = 0;
// database has no ID 0
$db = $this->getDB();
while ($row = $db->fetchObject($res)) {
if ($lastId != $row->ll_from) {
if ($lastId != 0) {
$this->addPageSubItems($lastId, $data);
$data = array();
}
$lastId = $row->ll_from;
}
$entry = array('lang' => $row->ll_lang);
ApiResult::setContent($entry, $row->ll_title);
$data[] = $entry;
}
if ($lastId != 0) {
$this->addPageSubItems($lastId, $data);
}
$db->freeResult($res);
}
示例10: addModulesInfo
/**
* If the type is requested in parameters, adds a section to res with module info.
* @param array $params user parameters array
* @param string $type parameter name
* @param array $res store results in this array
* @param ApiResult $resultObj results object to set indexed tag.
*/
private function addModulesInfo($params, $type, &$res, $resultObj)
{
if (!is_array($params[$type])) {
return;
}
$isQuery = $type === 'querymodules';
if ($isQuery) {
$mgr = $this->queryObj->getModuleManager();
} else {
$mgr = $this->getMain()->getModuleManager();
}
$res[$type] = array();
foreach ($params[$type] as $mod) {
if (!$mgr->isDefined($mod)) {
$res[$type][] = array('name' => $mod, 'missing' => '');
continue;
}
$obj = $mgr->getModule($mod);
$item = $this->getClassInfo($obj);
$item['name'] = $mod;
if ($isQuery) {
$item['querytype'] = $mgr->getModuleGroup($mod);
}
$res[$type][] = $item;
}
$resultObj->setIndexedTagName($res[$type], 'module');
}
示例11: execute
/**
* main function
*/
public function execute()
{
#--- blank variables
$wikia = $group = $variable = null;
extract($this->extractRequestParams());
#--- database instance
$db =& $this->getDB();
$db->selectDB('wikicities');
list($tbl_cvg, $tbl_cvp, $tbl_cv) = $db->tableNamesN("city_variables_groups", "city_variables_pool", "city_variables");
if (!is_null($wikia)) {
$this->addTables("{$tbl_cvp} JOIN {$tbl_cvg} ON cv_variable_group = cv_group_id JOIN {$tbl_cv} ON cv_id = cv_variable_id");
$this->addFields(array("cv_group_id", "cv_group_name"));
$this->addWhereFld("cv_city_id", $wikia);
if (!is_null($wikia)) {
$this->addWhereFld("cv_id", $variable);
}
} else {
$this->addTables("{$tbl_cvg}");
$this->addFields(array("cv_group_id", "cv_group_name"));
}
$data = array();
$res = $this->select(__METHOD__);
while ($row = $db->fetchObject($res)) {
$data[$row->cv_group_id] = array("id" => $row->cv_group_id, "name" => $row->cv_group_name);
ApiResult::setContent($data[$row->cv_group_id], $row->cv_group_name);
}
$db->freeResult($res);
$this->getResult()->setIndexedTagName($data, 'item');
$this->getResult()->addValue('query', $this->getModuleName(), $data);
}
示例12: execute
public function execute()
{
$params = $this->extractRequestParams();
$modules = array();
foreach ($params['modules'] as $path) {
$modules[] = $this->getModuleFromPath($path);
}
// Get the help
$context = new DerivativeContext($this->getMain()->getContext());
$context->setSkin(SkinFactory::getDefaultInstance()->makeSkin('apioutput'));
$context->setLanguage($this->getMain()->getLanguage());
$context->setTitle(SpecialPage::getTitleFor('ApiHelp'));
$out = new OutputPage($context);
$out->setCopyrightUrl('https://www.mediawiki.org/wiki/Special:MyLanguage/Copyright');
$context->setOutput($out);
self::getHelp($context, $modules, $params);
// Grab the output from the skin
ob_start();
$context->getOutput()->output();
$html = ob_get_clean();
$result = $this->getResult();
if ($params['wrap']) {
$data = array('mime' => 'text/html', 'help' => $html);
ApiResult::setSubelementsList($data, 'help');
$result->addValue(null, $this->getModuleName(), $data);
} else {
$result->reset();
$result->addValue(null, 'text', $html, ApiResult::NO_SIZE_CHECK);
$result->addValue(null, 'mime', 'text/html', ApiResult::NO_SIZE_CHECK);
}
}
示例13: 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);
}
示例14: execute
public function execute()
{
$this->addFields(array('el_from', 'el_to'));
$this->addTables('externallinks');
$this->addWhereFld('el_from', array_keys($this->getPageSet()->getGoodTitles()));
$db = $this->getDB();
$res = $this->select(__METHOD__);
$data = array();
$lastId = 0;
// database has no ID 0
while ($row = $db->fetchObject($res)) {
if ($lastId != $row->el_from) {
if ($lastId != 0) {
$this->addPageSubItems($lastId, $data);
$data = array();
}
$lastId = $row->el_from;
}
$entry = array();
ApiResult::setContent($entry, $row->el_to);
$data[] = $entry;
}
if ($lastId != 0) {
$this->addPageSubItems($lastId, $data);
}
$db->freeResult($res);
}
示例15: execute
public function execute()
{
global $wgUser;
// Before doing anything at all, let's check permissions
if (!$wgUser->isAllowed('codereview-use')) {
$this->dieUsage('You don\'t have permission to view code paths', 'permissiondenied');
}
$params = $this->extractRequestParams();
$repo = CodeRepository::newFromName($params['repo']);
if (!$repo instanceof CodeRepository) {
$this->dieUsage("Invalid repo ``{$params['repo']}''", 'invalidrepo');
}
$this->addTables('code_paths');
$this->addFields('DISTINCT cp_path');
$this->addWhere(array('cp_repo_id' => $repo->getId()));
$db = $this->getDB();
$this->addWhere('cp_path ' . $db->buildLike($params['path'], $db->anyString()));
$this->addOption('USE INDEX', 'repo_path');
$this->addOption('LIMIT', 10);
$res = $this->select(__METHOD__);
$result = $this->getResult();
$data = array();
foreach ($res as $row) {
$item = array();
ApiResult::setContent($item, $row->cp_path);
$data[] = $item;
}
$result->setIndexedTagName($data, 'paths');
$result->addValue('query', $this->getModuleName(), $data);
}