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


PHP ApiMain::getResult方法代码示例

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


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

示例1: parseWikitext

 protected function parseWikitext($title, $newRevId)
 {
     $apiParams = array('action' => 'parse', 'page' => $title->getPrefixedDBkey(), 'oldid' => $newRevId, 'prop' => 'text|revid|categorieshtml|displaytitle|modules|jsconfigvars');
     $api = new ApiMain(new DerivativeRequest($this->getRequest(), $apiParams, false), true);
     $api->execute();
     if (defined('ApiResult::META_CONTENT')) {
         $result = $api->getResult()->getResultData(null, array('BC' => array(), 'Types' => array(), 'Strip' => 'all'));
     } else {
         $result = $api->getResultData();
     }
     $content = isset($result['parse']['text']['*']) ? $result['parse']['text']['*'] : false;
     $categorieshtml = isset($result['parse']['categorieshtml']['*']) ? $result['parse']['categorieshtml']['*'] : false;
     $links = isset($result['parse']['links']) ? $result['parse']['links'] : array();
     $revision = Revision::newFromId($result['parse']['revid']);
     $timestamp = $revision ? $revision->getTimestamp() : wfTimestampNow();
     $displaytitle = isset($result['parse']['displaytitle']) ? $result['parse']['displaytitle'] : false;
     $modules = isset($result['parse']['modules']) ? $result['parse']['modules'] : array();
     $jsconfigvars = isset($result['parse']['jsconfigvars']) ? $result['parse']['jsconfigvars'] : array();
     if ($content === false || strlen($content) && $revision === null) {
         return false;
     }
     if ($displaytitle !== false) {
         // Escape entities as in OutputPage::setPageTitle()
         $displaytitle = Sanitizer::normalizeCharReferences(Sanitizer::removeHTMLtags($displaytitle));
     }
     return array('content' => $content, 'categorieshtml' => $categorieshtml, 'basetimestamp' => $timestamp, 'starttimestamp' => wfTimestampNow(), 'displayTitleHtml' => $displaytitle, 'modules' => $modules, 'jsconfigvars' => $jsconfigvars);
 }
开发者ID:sammykumar,项目名称:TheVRForums,代码行数:27,代码来源:ApiVisualEditorEdit.php

示例2: testCrossDomainMangling

 public function testCrossDomainMangling()
 {
     $config = new HashConfig(array('MangleFlashPolicy' => false));
     $context = new RequestContext();
     $context->setConfig(new MultiConfig(array($config, $context->getConfig())));
     $main = new ApiMain($context);
     $main->getResult()->addValue(null, null, '< Cross-Domain-Policy >');
     if (!function_exists('wfOutputHandler')) {
         function wfOutputHandler($s)
         {
             return $s;
         }
     }
     $printer = $main->createPrinterByName('php');
     ob_start('wfOutputHandler');
     $printer->initPrinter();
     $printer->execute();
     $printer->closePrinter();
     $ret = ob_get_clean();
     $this->assertSame('a:1:{i:0;s:23:"< Cross-Domain-Policy >";}', $ret);
     $config->set('MangleFlashPolicy', true);
     $printer = $main->createPrinterByName('php');
     ob_start('wfOutputHandler');
     try {
         $printer->initPrinter();
         $printer->execute();
         $printer->closePrinter();
         ob_end_clean();
         $this->fail('Expected exception not thrown');
     } catch (UsageException $ex) {
         ob_end_clean();
         $this->assertSame('This response cannot be represented using format=php. See https://phabricator.wikimedia.org/T68776', $ex->getMessage(), 'Expected exception');
     }
 }
开发者ID:ngertrudiz,项目名称:mediawiki,代码行数:34,代码来源:ApiFormatPhpTest.php

示例3: saveCat

 static function saveCat($filename, $category)
 {
     global $wgContLang, $wgUser;
     $mediaString = strtolower($wgContLang->getNsText(NS_FILE));
     $title = $mediaString . ':' . $filename;
     $text = "\n[[" . $category . "]]";
     $wgEnableWriteAPI = true;
     $params = new FauxRequest(array('action' => 'edit', 'section' => 'new', 'title' => $title, 'text' => $text, 'token' => $wgUser->editToken()), true, $_SESSION);
     $enableWrite = true;
     // This is set to false by default, in the ApiMain constructor
     $api = new ApiMain($params, $enableWrite);
     $api->execute();
     if (defined('ApiResult::META_CONTENT')) {
         $data = $api->getResult()->getResultData();
     } else {
         $data =& $api->getResultData();
     }
     return $mediaString;
     /* This code does the same and is better, but for some reason it doesn't update the categorylinks table
     		global $wgContLang, $wgUser;
     		$title = Title::newFromText( $filename, NS_FILE );
     		$page = new WikiPage( $title );
     		$text = $page->getText();
     		$text .= "\n\n[[" . $category . "]]";
     		$summary = wfMessage( 'msu-comment' );
     		$status = $page->doEditContent( $text, $summary, EDIT_UPDATE, false, $wgUser );
     		$value = $status->value;
     		$revision = $value['revision'];
     		$page->doEditUpdates( $revision, $wgUser );
     		return true;
     */
 }
开发者ID:Reasno,项目名称:MsUpload,代码行数:32,代码来源:MsUpload.body.php

示例4: encodeData

 /**
  * Get the formatter output for the given input data
  * @param array $params Query parameters
  * @param array $data Data to encode
  * @param string $class Printer class to use instead of the normal one
  * @return string
  * @throws Exception
  */
 protected function encodeData(array $params, array $data, $class = null)
 {
     $context = new RequestContext();
     $context->setRequest(new FauxRequest($params, true));
     $main = new ApiMain($context);
     if ($class !== null) {
         $main->getModuleManager()->addModule($this->printerName, 'format', $class);
     }
     $result = $main->getResult();
     $result->addArrayType(null, 'default');
     foreach ($data as $k => $v) {
         $result->addValue(null, $k, $v);
     }
     $printer = $main->createPrinterByName($this->printerName);
     $printer->initPrinter();
     $printer->execute();
     ob_start();
     try {
         $printer->closePrinter();
         return ob_get_clean();
     } catch (Exception $ex) {
         ob_end_clean();
         throw $ex;
     }
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:33,代码来源:ApiFormatTestBase.php

示例5: testTokenRetrieval

 /** @dataProvider provideTokenClasses */
 public function testTokenRetrieval($id, $class)
 {
     // Make sure we have the right to get the token
     global $wgGroupPermissions;
     $wgGroupPermissions['*'][$class::getRight()] = true;
     RequestContext::getMain()->getUser()->clearInstanceCache();
     // Reread above global
     // We should be getting anonymous user token
     $expected = $class::getToken();
     $this->assertNotSame(false, $expected, 'We did not get a valid token');
     $actionString = TranslateUtils::getTokenAction($id);
     $params = wfCgiToArray($actionString);
     $req = new FauxRequest($params);
     $api = new ApiMain($req);
     $api->execute();
     if (defined('ApiResult::META_CONTENT')) {
         $data = $api->getResult()->getResultData(null, array('Strip' => 'all'));
     } else {
         $data = $api->getResultData();
     }
     if (isset($data['query'])) {
         foreach ($data['query']['pages'] as $page) {
             $this->assertSame($expected, $page[$id . 'token']);
         }
     } else {
         $this->assertArrayHasKey('tokens', $data, 'Result has tokens');
         $this->assertSame($expected, $data['tokens'][$id . 'token']);
     }
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:30,代码来源:ApiTokensTest.php

示例6: doApiRequest

 /**
  * Does the API request and returns the result.
  *
  * The returned value is an array containing
  * - the result data (array)
  * - the request (WebRequest)
  * - the session data of the request (array)
  * - if $appendModule is true, the Api module $module
  *
  * @param array $params
  * @param array|null $session
  * @param bool $appendModule
  * @param User|null $user
  *
  * @return array
  */
 protected function doApiRequest(array $params, array $session = null, $appendModule = false, User $user = null)
 {
     global $wgRequest, $wgUser;
     if (is_null($session)) {
         // re-use existing global session by default
         $session = $wgRequest->getSessionArray();
     }
     // set up global environment
     if ($user) {
         $wgUser = $user;
     }
     $wgRequest = new FauxRequest($params, true, $session);
     RequestContext::getMain()->setRequest($wgRequest);
     RequestContext::getMain()->setUser($wgUser);
     // set up local environment
     $context = $this->apiContext->newTestContext($wgRequest, $wgUser);
     $module = new ApiMain($context, true);
     // run it!
     $module->execute();
     // construct result
     $results = array($module->getResult()->getResultData(null, array('Strip' => 'all')), $context->getRequest(), $context->getRequest()->getSessionArray());
     if ($appendModule) {
         $results[] = $module;
     }
     return $results;
 }
开发者ID:lourinaldi,项目名称:mediawiki,代码行数:42,代码来源:ApiTestCase.php

示例7: run

 public function run()
 {
     $scope = RequestContext::importScopedSession($this->params['session']);
     $context = RequestContext::getMain();
     try {
         $user = $context->getUser();
         if (!$user->isLoggedIn()) {
             $this->setLastError("Could not load the author user from session.");
             return false;
         }
         if (count($_SESSION) === 0) {
             // Empty session probably indicates that we didn't associate
             // with the session correctly. Note that being able to load
             // the user does not necessarily mean the session was loaded.
             // Most likely cause by suhosin.session.encrypt = On.
             $this->setLastError("Error associating with user session. " . "Try setting suhosin.session.encrypt = Off");
             return false;
         }
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Poll', 'stage' => 'publish', 'status' => Status::newGood()));
         $upload = new UploadFromStash($user);
         // @todo initialize() causes a GET, ideally we could frontload the antivirus
         // checks and anything else to the stash stage (which includes concatenation and
         // the local file is thus already there). That way, instead of GET+PUT, there could
         // just be a COPY operation from the stash to the public zone.
         $upload->initialize($this->params['filekey'], $this->params['filename']);
         // Check if the local file checks out (this is generally a no-op)
         $verification = $upload->verifyUpload();
         if ($verification['status'] !== UploadBase::OK) {
             $status = Status::newFatal('verification-error');
             $status->value = array('verification' => $verification);
             UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Failure', 'stage' => 'publish', 'status' => $status));
             $this->setLastError("Could not verify upload.");
             return false;
         }
         // Upload the stashed file to a permanent location
         $status = $upload->performUpload($this->params['comment'], $this->params['text'], $this->params['watch'], $user);
         if (!$status->isGood()) {
             UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Failure', 'stage' => 'publish', 'status' => $status));
             $this->setLastError($status->getWikiText());
             return false;
         }
         // Build the image info array while we have the local reference handy
         $apiMain = new ApiMain();
         // dummy object (XXX)
         $imageInfo = $upload->getImageInfo($apiMain->getResult());
         // Cleanup any temporary local file
         $upload->cleanupTempFile();
         // Cache the info so the user doesn't have to wait forever to get the final info
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Success', 'stage' => 'publish', 'filename' => $upload->getLocalFile()->getName(), 'imageinfo' => $imageInfo, 'status' => Status::newGood()));
     } catch (MWException $e) {
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Failure', 'stage' => 'publish', 'status' => Status::newFatal('api-error-publishfailed')));
         $this->setLastError(get_class($e) . ": " . $e->getText());
         // To prevent potential database referential integrity issues.
         // See bug 32551.
         MWExceptionHandler::rollbackMasterChangesAndLog($e);
         return false;
     }
     return true;
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:59,代码来源:PublishStashedFileJob.php

示例8: testApi

 /**
  * Test that the API will accept a FauxRequest and execute.
  */
 public function testApi()
 {
     $api = new ApiMain(new FauxRequest(array('action' => 'query', 'meta' => 'siteinfo')));
     $api->execute();
     $data = $api->getResult()->getResultData();
     $this->assertInternalType('array', $data);
     $this->assertArrayHasKey('query', $data);
 }
开发者ID:Acidburn0zzz,项目名称:mediawiki,代码行数:11,代码来源:ApiMainTest.php

示例9: doApiRequest

 protected function doApiRequest(array $params, array $unused = null, $appendModule = false, User $user = null)
 {
     global $wgRequest;
     $req = new FauxRequest($params, true, $wgRequest->getSession());
     $module = new ApiMain($req, true);
     $module->execute();
     return array($module->getResult()->getResultData(null, array('Strip' => 'all')), $req);
 }
开发者ID:paladox,项目名称:2,代码行数:8,代码来源:UploadFromUrlTest.php

示例10: make_fake_request

 /**
  *
  * @param <type> $params the array of keys and values that would have appeared in the URL if this were a normal request. See API documentation
  * @return <type>
  */
 public function make_fake_request($params)
 {
     $request = new FauxRequest($params, true);
     $api = new ApiMain($request);
     // Process data & use an output buffer to capture the resutls
     $api->execute();
     $result = $api->getResult();
     $data =& $result->getData();
     return $data;
 }
开发者ID:hampusb,项目名称:mediawiki2wordpress,代码行数:15,代码来源:MediaWikiAPIWrapper.php

示例11: doApiRequest

 protected function doApiRequest(array $params, array $unused = null, $appendModule = false, User $user = null)
 {
     $sessionId = session_id();
     session_write_close();
     $req = new FauxRequest($params, true, $_SESSION);
     $module = new ApiMain($req, true);
     $module->execute();
     wfSetupSession($sessionId);
     return array($module->getResult()->getResultData(null, array('Strip' => 'all')), $req);
 }
开发者ID:hallowelt,项目名称:mediawiki,代码行数:10,代码来源:UploadFromUrlTest.php

示例12: run

 public function run()
 {
     $scope = RequestContext::importScopedSession($this->params['session']);
     $this->addTeardownCallback(function () use(&$scope) {
         ScopedCallback::consume($scope);
         // T126450
     });
     $context = RequestContext::getMain();
     $user = $context->getUser();
     try {
         if (!$user->isLoggedIn()) {
             $this->setLastError("Could not load the author user from session.");
             return false;
         }
         UploadBase::setSessionStatus($user, $this->params['filekey'], ['result' => 'Poll', 'stage' => 'publish', 'status' => Status::newGood()]);
         $upload = new UploadFromStash($user);
         // @todo initialize() causes a GET, ideally we could frontload the antivirus
         // checks and anything else to the stash stage (which includes concatenation and
         // the local file is thus already there). That way, instead of GET+PUT, there could
         // just be a COPY operation from the stash to the public zone.
         $upload->initialize($this->params['filekey'], $this->params['filename']);
         // Check if the local file checks out (this is generally a no-op)
         $verification = $upload->verifyUpload();
         if ($verification['status'] !== UploadBase::OK) {
             $status = Status::newFatal('verification-error');
             $status->value = ['verification' => $verification];
             UploadBase::setSessionStatus($user, $this->params['filekey'], ['result' => 'Failure', 'stage' => 'publish', 'status' => $status]);
             $this->setLastError("Could not verify upload.");
             return false;
         }
         // Upload the stashed file to a permanent location
         $status = $upload->performUpload($this->params['comment'], $this->params['text'], $this->params['watch'], $user, isset($this->params['tags']) ? $this->params['tags'] : []);
         if (!$status->isGood()) {
             UploadBase::setSessionStatus($user, $this->params['filekey'], ['result' => 'Failure', 'stage' => 'publish', 'status' => $status]);
             $this->setLastError($status->getWikiText(false, false, 'en'));
             return false;
         }
         // Build the image info array while we have the local reference handy
         $apiMain = new ApiMain();
         // dummy object (XXX)
         $imageInfo = $upload->getImageInfo($apiMain->getResult());
         // Cleanup any temporary local file
         $upload->cleanupTempFile();
         // Cache the info so the user doesn't have to wait forever to get the final info
         UploadBase::setSessionStatus($user, $this->params['filekey'], ['result' => 'Success', 'stage' => 'publish', 'filename' => $upload->getLocalFile()->getName(), 'imageinfo' => $imageInfo, 'status' => Status::newGood()]);
     } catch (Exception $e) {
         UploadBase::setSessionStatus($user, $this->params['filekey'], ['result' => 'Failure', 'stage' => 'publish', 'status' => Status::newFatal('api-error-publishfailed')]);
         $this->setLastError(get_class($e) . ": " . $e->getMessage());
         // To prevent potential database referential integrity issues.
         // See bug 32551.
         MWExceptionHandler::rollbackMasterChangesAndLog($e);
         return false;
     }
     return true;
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:55,代码来源:PublishStashedFileJob.php

示例13: getAPIResultData

 /**
  * Gets ApiContributionTracking's response in array format, for the given
  * $request params.
  * @global FauxRequest $wgRequest used to shoehorn in our own request vars.
  * @param <type> $request Request vars we are sending to
  * ApiContributionTracking.
  * @return array Values to be returned by ApiContributionTracking
  */
 function getAPIResultData($request)
 {
     global $wgRequest;
     $request['format'] = 'xml';
     $request['action'] = 'contributiontracking';
     $wgRequest = new FauxRequest($request);
     $ctapi = new ApiMain($wgRequest, true);
     $ctapi->execute();
     $api_response = $ctapi->getResult()->getData();
     return $api_response;
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:19,代码来源:ContributionTrackingAPITest.php

示例14: getLanguages

 /**
  * Returns an array of languages that the page is available in
  * @return array
  */
 private function getLanguages()
 {
     $api = new ApiMain(new DerivativeRequest($this->getRequest(), array('action' => 'query', 'prop' => 'langlinks', 'llprop' => 'url', 'lllimit' => 'max', 'titles' => $this->title->getPrefixedText())));
     $api->execute();
     if (defined('ApiResult::META_CONTENT')) {
         $data = (array) $api->getResult()->getResultData(array('query', 'pages'), array('Strip' => 'all'));
     } else {
         $data = $api->getResult()->getData();
         // Paranoia
         if (!isset($data['query']['pages'])) {
             return array();
         }
         $data = $data['query']['pages'];
     }
     // Silly strict php
     $pages = array_values($data);
     $page = array_shift($pages);
     if (isset($page['langlinks'])) {
         // Set the name of each lanugage based on the system list of language names
         $languageMap = Language::fetchLanguageNames();
         $languages = $page['langlinks'];
         foreach ($page['langlinks'] as $code => $langObject) {
             if (!isset($languageMap[$langObject['lang']])) {
                 // Bug T93500: DB might still have preantiquated rows with bogus languages
                 unset($languages[$code]);
                 continue;
             }
             $langObject['langname'] = $languageMap[$langObject['lang']];
             $langObject['url'] = MobileContext::singleton()->getMobileUrl($langObject['url']);
             $languages[$code] = $langObject;
         }
         return $languages;
     } else {
         // No langlinks available
         return array();
     }
 }
开发者ID:micha6554,项目名称:mediawiki-extensions-MobileFrontend,代码行数:41,代码来源:SpecialMobileLanguages.php

示例15: run

 public function run()
 {
     $scope = RequestContext::importScopedSession($this->params['session']);
     $context = RequestContext::getMain();
     try {
         $user = $context->getUser();
         if (!$user->isLoggedIn()) {
             $this->setLastError("Could not load the author user from session.");
             return false;
         }
         if (count($_SESSION) === 0) {
             // Empty session probably indicates that we didn't associate
             // with the session correctly. Note that being able to load
             // the user does not necessarily mean the session was loaded.
             // Most likely cause by suhosin.session.encrypt = On.
             $this->setLastError("Error associating with user session. " . "Try setting suhosin.session.encrypt = Off");
             return false;
         }
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Poll', 'stage' => 'assembling', 'status' => Status::newGood()));
         $upload = new UploadFromChunks($user);
         $upload->continueChunks($this->params['filename'], $this->params['filekey'], $context->getRequest());
         // Combine all of the chunks into a local file and upload that to a new stash file
         $status = $upload->concatenateChunks();
         if (!$status->isGood()) {
             UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Failure', 'stage' => 'assembling', 'status' => $status));
             $this->setLastError($status->getWikiText());
             return false;
         }
         // We have a new filekey for the fully concatenated file
         $newFileKey = $upload->getLocalFile()->getFileKey();
         // Remove the old stash file row and first chunk file
         $upload->stash->removeFileNoAuth($this->params['filekey']);
         // Build the image info array while we have the local reference handy
         $apiMain = new ApiMain();
         // dummy object (XXX)
         $imageInfo = $upload->getImageInfo($apiMain->getResult());
         // Cleanup any temporary local file
         $upload->cleanupTempFile();
         // Cache the info so the user doesn't have to wait forever to get the final info
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Success', 'stage' => 'assembling', 'filekey' => $newFileKey, 'imageinfo' => $imageInfo, 'status' => Status::newGood()));
     } catch (MWException $e) {
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Failure', 'stage' => 'assembling', 'status' => Status::newFatal('api-error-stashfailed')));
         $this->setLastError(get_class($e) . ": " . $e->getText());
         // To be extra robust.
         MWExceptionHandler::rollbackMasterChangesAndLog($e);
         return false;
     }
     return true;
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:49,代码来源:AssembleUploadChunksJob.php


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