本文整理汇总了PHP中ApiBase类的典型用法代码示例。如果您正苦于以下问题:PHP ApiBase类的具体用法?PHP ApiBase怎么用?PHP ApiBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ApiBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setGeneratorMode
/**
* Switch this module to generator mode. By default, generator mode is
* switched off and the module acts like a normal query module.
* @since 1.21 requires pageset parameter
* @param ApiPageSet $generatorPageSet ApiPageSet object that the module will get
* by calling getPageSet() when in generator mode.
*/
public function setGeneratorMode(ApiPageSet $generatorPageSet)
{
if ($generatorPageSet === null) {
ApiBase::dieDebug(__METHOD__, 'Required parameter missing - $generatorPageSet');
}
$this->mGeneratorPageSet = $generatorPageSet;
}
示例2: execute
public function execute()
{
global $wgUser;
$this->checkPermission($wgUser);
$params = $this->extractRequestParams();
$res = array();
$concurrencyCheck = new ConcurrencyCheck($params['resourcetype'], $wgUser);
switch ($params['ccaction']) {
case 'checkout':
case 'checkin':
if ($concurrencyCheck->{$params}['ccaction']($params['record'])) {
$res['result'] = 'success';
} else {
$res['result'] = 'failure';
}
// data to be utilized by the caller for checkout
if ($params['ccaction'] === 'checkout') {
$lastCheckout = $concurrencyCheck->checkoutResult();
if ($res['result'] === 'success') {
$user = $wgUser;
} else {
$user = User::newFromId(intval($lastCheckout['userId']));
}
if (!$user->isAnon()) {
$res['userid'] = $user->getId();
$res['username'] = $user->getName();
}
$res['expiration'] = $lastCheckout['expiration'];
}
break;
default:
ApiBase::dieDebug(__METHOD__, "Unhandled concurrency action: {$params['ccaction']}");
}
$this->getResult()->addValue(null, $this->getModuleName(), $res);
}
示例3: 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}");
}
}
}
示例4: getFinalDescription
public function getFinalDescription()
{
// A bit of a hack to append 'api-help-authmanager-general-usage'
$msgs = parent::getFinalDescription();
$msgs[] = ApiBase::makeMessage('api-help-authmanager-general-usage', $this->getContext(), [$this->getModulePrefix(), $this->getModuleName(), $this->getModulePath(), AuthManager::ACTION_LOGIN, self::needsToken()]);
return $msgs;
}
示例5: __construct
public function __construct($query, $moduleName)
{
switch ($moduleName) {
case 'alllinks':
$prefix = 'al';
$this->table = 'pagelinks';
$this->tablePrefix = 'pl_';
$this->dfltNamespace = NS_MAIN;
$this->indexTag = 'l';
$this->description = 'Enumerate all links that point to a given namespace';
$this->descriptionLink = 'link';
$this->descriptionLinked = 'linked';
$this->descriptionLinking = 'linking';
break;
case 'alltransclusions':
$prefix = 'at';
$this->table = 'templatelinks';
$this->tablePrefix = 'tl_';
$this->dfltNamespace = NS_TEMPLATE;
$this->indexTag = 't';
$this->description = 'List all transclusions (pages embedded using {{x}}), including non-existing';
$this->descriptionLink = 'transclusion';
$this->descriptionLinked = 'transcluded';
$this->descriptionLinking = 'transcluding';
break;
default:
ApiBase::dieDebug(__METHOD__, 'Unknown module name');
}
parent::__construct($query, $moduleName, $prefix);
}
示例6: run
private function run($resultPageSet = null)
{
if ($this->getPageSet()->getGoodTitleCount() == 0) {
return;
}
// nothing to do
$params = $this->extractRequestParams();
$prop = $params['prop'];
$this->addFields(array('cl_from', 'cl_to'));
$fld_sortkey = false;
if (!is_null($prop)) {
foreach ($prop as $p) {
switch ($p) {
case 'sortkey':
$this->addFields('cl_sortkey');
$fld_sortkey = true;
break;
default:
ApiBase::dieDebug(__METHOD__, "Unknown prop={$p}");
}
}
}
$this->addTables('categorylinks');
$this->addWhereFld('cl_from', array_keys($this->getPageSet()->getGoodTitles()));
$this->addOption('ORDER BY', "cl_from, cl_to");
$db = $this->getDB();
$res = $this->select(__METHOD__);
if (is_null($resultPageSet)) {
$data = array();
$lastId = 0;
// database has no ID 0
while ($row = $db->fetchObject($res)) {
if ($lastId != $row->cl_from) {
if ($lastId != 0) {
$this->addPageSubItems($lastId, $data);
$data = array();
}
$lastId = $row->cl_from;
}
$title = Title::makeTitle(NS_CATEGORY, $row->cl_to);
$vals = array();
ApiQueryBase::addTitleInfo($vals, $title);
if ($fld_sortkey) {
$vals['sortkey'] = $row->cl_sortkey;
}
$data[] = $vals;
}
if ($lastId != 0) {
$this->addPageSubItems($lastId, $data);
}
} else {
$titles = array();
while ($row = $db->fetchObject($res)) {
$titles[] = Title::makeTitle(NS_CATEGORY, $row->cl_to);
}
$resultPageSet->populateFromTitles($titles);
}
$db->freeResult($res);
}
示例7: execute
public function execute()
{
$data = $this->getResultData();
if (isset($data['error'])) {
$this->mErrorFallback->execute();
return;
}
if (!isset($data['text'])) {
ApiBase::dieDebug(__METHOD__, 'No text given for raw formatter');
}
$this->printText($data['text']);
}
示例8: addTables
protected function addTables($tables, $alias = null)
{
if (is_array($tables)) {
if (!is_null($alias)) {
ApiBase::dieDebug(__METHOD__, 'Multiple table aliases not supported');
}
$this->tables = array_merge($this->tables, $tables);
} else {
if (!is_null($alias)) {
$tables = $this->getDB()->tableName($tables) . ' ' . $alias;
}
$this->tables[] = $tables;
}
}
示例9: execute
public function execute()
{
$data = $this->getResult()->getResultData();
if (isset($data['error'])) {
$this->errorFallback->execute();
return;
}
if (isset($data['file'])) {
$this->file = $data['file'];
} elseif (isset($data['text'])) {
$this->printText($data['text']);
} else {
ApiBase::dieDebug(__METHOD__, 'No text or file given for file formatter');
}
}
示例10: __construct
public function __construct($query, $moduleName)
{
switch ($moduleName) {
case self::LINKS:
$this->table = 'pagelinks';
$this->prefix = 'pl';
$this->description = 'link';
break;
case self::TEMPLATES:
$this->table = 'templatelinks';
$this->prefix = 'tl';
$this->description = 'template';
break;
default:
ApiBase::dieDebug(__METHOD__, 'Unknown module name');
}
parent::__construct($query, $moduleName, $this->prefix);
}
示例11: __construct
public function __construct(ApiQuery $query, $moduleName)
{
switch ($moduleName) {
case self::LINKS:
$this->table = 'pagelinks';
$this->prefix = 'pl';
$this->titlesParam = 'titles';
$this->helpUrl = 'https://www.mediawiki.org/wiki/API:Links';
break;
case self::TEMPLATES:
$this->table = 'templatelinks';
$this->prefix = 'tl';
$this->titlesParam = 'templates';
$this->helpUrl = 'https://www.mediawiki.org/wiki/API:Templates';
break;
default:
ApiBase::dieDebug(__METHOD__, 'Unknown module name');
}
parent::__construct($query, $moduleName, $this->prefix);
}
示例12: Execute
public function Execute($method = null)
{
if ($method == null) {
$method = UrlUtils::RequestMethod();
if (UrlUtils::ExistRequestParam("method")) {
$method = strtolower(UrlUtils::GetRequestParam("method"));
}
}
$availableMethods = get_class_methods(get_class($this));
$function = "do" . $method;
try {
if (in_array($function, $availableMethods)) {
$this->{$function}();
} else {
ApiBase::ReturnError("Invalid method", 405);
}
} catch (Exception $ex) {
ApiBase::ReturnError($ex->getMessage(), 500);
}
}
示例13: execute
public function execute()
{
global $wgUser;
$this->checkPermission($wgUser);
$params = $this->extractRequestParams();
$res = array();
$concurrencyCheck = new ConcurrencyCheck($params['resourcetype'], $wgUser);
switch ($params['ccaction']) {
case 'checkout':
case 'checkin':
if ($concurrencyCheck->{$params}['ccaction']($params['record'])) {
$res['result'] = 'success';
} else {
$res['result'] = 'failure';
}
break;
default:
ApiBase::dieDebug(__METHOD__, "Unhandled concurrency action: {$params['ccaction']}");
}
$this->getResult()->addValue(null, $this->getModuleName(), $res);
}
示例14: execute
public function execute()
{
$name = $password = $domain = null;
extract($this->extractRequestParams());
$params = new FauxRequest(array('wpName' => $name, 'wpPassword' => $password, 'wpDomain' => $domain, 'wpRemember' => ''));
$result = array();
$loginForm = new LoginForm($params);
switch ($loginForm->authenticateUserData()) {
case LoginForm::SUCCESS:
global $wgUser;
$wgUser->setOption('rememberpassword', 1);
$wgUser->setCookies();
$result['result'] = 'Success';
$result['lguserid'] = $_SESSION['wsUserID'];
$result['lgusername'] = $_SESSION['wsUserName'];
$result['lgtoken'] = $_SESSION['wsToken'];
break;
case LoginForm::NO_NAME:
$result['result'] = 'NoName';
break;
case LoginForm::ILLEGAL:
$result['result'] = 'Illegal';
break;
case LoginForm::WRONG_PLUGIN_PASS:
$result['result'] = 'WrongPluginPass';
break;
case LoginForm::NOT_EXISTS:
$result['result'] = 'NotExists';
break;
case LoginForm::WRONG_PASS:
$result['result'] = 'WrongPass';
break;
case LoginForm::EMPTY_PASS:
$result['result'] = 'EmptyPass';
break;
default:
ApiBase::dieDebug(__METHOD__, 'Unhandled case value');
}
$this->getResult()->addValue(null, 'login', $result);
}
示例15: getDescriptionMessage
protected function getDescriptionMessage()
{
if (!$this->hasAnyRoutes()) {
return 'apihelp-resetpassword-description-noroutes';
}
return parent::getDescriptionMessage();
}