本文整理汇总了PHP中ApiResult::setContent方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiResult::setContent方法的具体用法?PHP ApiResult::setContent怎么用?PHP ApiResult::setContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiResult
的用法示例。
在下文中一共展示了ApiResult::setContent方法的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']);
$de = new DifferenceEngine($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');
} else {
ApiResult::setContent($vals, $difftext);
}
$this->getResult()->addValue(null, $this->getModuleName(), $vals);
}
示例2: 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}");
}
}
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
示例7: execute
public function execute()
{
if ($this->getPageSet()->getGoodTitleCount() == 0) {
return;
}
$params = $this->extractRequestParams();
$this->addFields(array('el_from', 'el_to'));
$this->addTables('externallinks');
$this->addWhereFld('el_from', array_keys($this->getPageSet()->getGoodTitles()));
// 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');
}
$this->addOption('LIMIT', $params['limit'] + 1);
if (!is_null($params['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', @$params['offset'] + $params['limit']);
break;
}
$entry = array();
ApiResult::setContent($entry, $row->el_to);
$fit = $this->addPageSubItem($row->el_from, $entry);
if (!$fit) {
$this->setContinueEnumParameter('offset', @$params['offset'] + $count - 1);
break;
}
}
}
示例8: execute
public function execute()
{
if ($this->getPageSet()->getGoodTitleCount() == 0) {
return;
}
$params = $this->extractRequestParams();
$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']);
if (count($cont) != 2) {
$this->dieUsage("Invalid continue param. You should pass the " . "original value returned by the previous query", "_badcontinue");
}
$llfrom = intval($cont[0]);
$lllang = $this->getDB()->strencode($cont[1]);
$this->addWhere("ll_from > {$llfrom} OR " . "(ll_from = {$llfrom} AND " . "ll_lang >= '{$lllang}')");
}
# 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');
} else {
$this->addOption('ORDER BY', 'll_from, ll_lang');
}
$this->addOption('LIMIT', $params['limit'] + 1);
$res = $this->select(__METHOD__);
$data = array();
$lastId = 0;
// database has no ID 0
$count = 0;
$db = $this->getDB();
while ($row = $db->fetchObject($res)) {
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;
}
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);
}
示例9: 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::setContent($entry, $to);
$fit = $this->addPageSubItem($row->el_from, $entry);
if (!$fit) {
$this->setContinueEnumParameter('offset', $offset + $count - 1);
break;
}
}
}
示例10: execute
public function execute()
{
if ($this->getPageSet()->getGoodTitleCount() == 0) {
return;
}
$params = $this->extractRequestParams();
$this->addFields(array('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']);
if (count($cont) != 3) {
$this->dieUsage('Invalid continue param. You should pass the ' . 'original value returned by the previous query', '_badcontinue');
}
$iwlfrom = intval($cont[0]);
$iwlprefix = $this->getDB()->strencode($cont[1]);
$iwltitle = $this->getDB()->strencode($this->titleToKey($cont[2]));
$this->addWhere("iwl_from > {$iwlfrom} OR " . "(iwl_from = {$iwlfrom} AND " . "(iwl_prefix > '{$iwlprefix}' OR " . "(iwl_prefix = '{$iwlprefix}' AND " . "iwl_title >= '{$iwltitle}')))");
}
// 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');
} else {
$this->addOption('ORDER BY', 'iwl_from, iwl_prefix');
}
$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 = array('prefix' => $row->iwl_prefix);
if (!is_null($params['url'])) {
$title = Title::newFromText("{$row->iwl_prefix}:{$row->iwl_title}");
if ($title) {
$entry['url'] = $title->getFullURL();
}
}
ApiResult::setContent($entry, $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;
}
}
}
示例11: execute
public function execute()
{
if ($this->getPageSet()->getGoodTitleCount() == 0) {
return;
}
$params = $this->extractRequestParams();
$this->addFields(array('el_from', 'el_to'));
$this->addTables('externallinks');
$this->addWhereFld('el_from', array_keys($this->getPageSet()->getGoodTitles()));
# 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');
}
$this->addOption('LIMIT', $params['limit'] + 1);
if (!is_null($params['offset'])) {
$this->addOption('OFFSET', $params['offset']);
}
$db = $this->getDB();
$res = $this->select(__METHOD__);
$data = array();
$lastId = 0;
// database has no ID 0
$count = 0;
while ($row = $db->fetchObject($res)) {
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', @$params['offset'] + $params['limit']);
break;
}
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);
}
示例12: 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');
}
}
示例13: appendVariables
protected function appendVariables($property)
{
$data = array();
foreach ($this->variablesList as $id => $variableName) {
$data[$id] = array('id' => $variableName);
$value = array_key_exists($variableName, $GLOBALS) && !is_null($GLOBALS[$variableName]) ? $GLOBALS[$variableName] : "";
if (is_array($value)) {
$loop = 0;
foreach ($value as $key => $v) {
$data[$id]["value" . $loop] = array('id' => $key);
ApiResult::setContent($data[$id]["value" . $loop], $v);
$loop++;
}
} else {
ApiResult::setContent($data[$id], $value);
}
}
$result = $this->getResult();
$result->setIndexedTagName($data, $property);
$result->addValue('query', $property, $data);
}
示例14: execute
public function execute() {
$params = $this->extractRequestParams();
$titles = $this->getPageSet()->getGoodTitles();
if (count($titles) == 0)
return;
$this->addTables( 'page_props' );
$this->addFields( array( 'pp_page', 'pp_value' ) );
$this->addWhere( array(
'pp_page' => array_keys( $titles ),
'pp_propname' => 'templateinfo'
) );
if ( !is_null( $params['continue'] ) )
{
$fromid = intval( $params['continue'] );
$this->addWhere( "pp_page >= $fromid" );
}
$this->addOption( 'ORDER BY', 'pp_page' );
$res = $this->select(__METHOD__);
while ( $row = $this->getDB()->fetchObject( $res ) ) {
$vals = array( );
$template_info = $row->pp_value;
// determine whether this is actual XML or an error
// message by checking whether the first character
// is '<' - this is an interim solution until there's
// a better storage format in place
if (substr($template_info, 0, 1) == '<')
ApiResult::setContent( $vals, $row->pp_value );
else
// add error message as an "error=" attribute
$vals['error'] = $row->pp_value;
$fit = $this->addPageSubItems( $row->pp_page, $vals );
if( !$fit ) {
$this->setContinueEnumParameter( 'continue', $row->pp_page );
break;
}
}
}
示例15: 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();
// Create title for parser
$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);
}
if ($params['generatexml']) {
$wgParser->startExternalParse($title_obj, $options, OT_PREPROCESS);
$dom = $wgParser->preprocessToDom($params['text']);
if (is_callable(array($dom, 'saveXML'))) {
$xml = $dom->saveXML();
} else {
$xml = $dom->__toString();
}
$xml_result = array();
ApiResult::setContent($xml_result, $xml);
$result->addValue(null, 'parsetree', $xml_result);
}
$retval = $wgParser->preprocess($params['text'], $title_obj, $options);
// Return result
$retval_array = array();
ApiResult::setContent($retval_array, $retval);
$result->addValue(null, $this->getModuleName(), $retval_array);
}