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


PHP ApiMain::execute方法代码示例

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


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

示例1: 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

示例2: execute

 public function execute()
 {
     $this->mParams = $this->extractRequestParams();
     $fauxRequest = new FauxRequest(['action' => 'query', 'list' => 'querypage', 'qppage' => 'Mostlinkedtemplates', 'qplimit' => 50, 'qpoffset' => $this->mParams['offset']]);
     $api = new ApiMain($fauxRequest);
     $api->execute();
     $resultData = $api->getResultData();
     $results = $resultData['query']['querypage']['results'];
     $templates = [];
     foreach ($results as $template) {
         $title = Title::newFromText($template['title']);
         if (is_object($title)) {
             $titleText = $title->getText();
             if (strlen($titleText) > 1) {
                 $templates[] = ['title' => $titleText, 'uses' => $template['value']];
             }
         }
     }
     $this->getResult()->setIndexedTagName($templates, 'templates');
     $this->getResult()->addValue(null, 'templates', $templates);
     if (isset($resultData['query-continue'])) {
         $queryContinue = $resultData['query-continue']['querypage']['qpoffset'];
         $this->getResult()->addValue(null, 'query-continue', $queryContinue);
     }
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:25,代码来源:ApiTemplateSuggestions.php

示例3: execute

 public function execute()
 {
     global $wgFeedClasses, $wgSitename, $wgServer;
     try {
         $params = $this->extractRequestParams();
         $fauxReqArr = array("action" => "query", "list" => "activityfeed");
         $fauxReq = new FauxRequest($fauxReqArr);
         $module = new ApiMain($fauxReq);
         $module->execute();
         $data = $module->getResultData();
         $feedItems = array();
         foreach ((array) $data["query"]["activityfeed"] as $info) {
             $feedItems[] = $this->createFeedItem($info);
         }
         $feed = new $wgFeedClasses[$params["feedformat"]]("{$wgSitename} - activity feed", "", $wgServer);
         ApiFormatFeedWrapper::setResult($this->getResult(), $feed, $feedItems);
     } catch (Exception $e) {
         $this->getMain()->setCacheMaxAge(0);
         $feedFormat = isset($params["feedformat"]) ? $params["feedformat"] : "rss";
         $feed = new $wgFeedClasses[$feedFormat]("{$wgSitename} - error - activity feed", "", $wgServer);
         if ($e instanceof UsageException) {
             $errorCode = $e->getCodeString();
         } else {
             $errorCode = "internal_api_error";
         }
         $errorText = $e->getMessage();
         $feedItems[] = new FeedItem("Error ({$errorCode})", $errorText, "", "", "");
         ApiFormatFeedWrapper::setResult($this->getResult(), $feed, $feedItems);
     }
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:30,代码来源:ApiFeedActivityFeed.php

示例4: execute

 public function execute()
 {
     $search = null;
     extract($this->ExtractRequestParams());
     // Open search results may be stored for a very long time
     $this->getMain()->setCacheMaxAge(1200);
     $title = Title::newFromText($search);
     if (!$title) {
         return;
     }
     // Return empty result
     // Prepare nested request
     $params = new FauxRequest(array('action' => 'query', 'list' => 'allpages', 'apnamespace' => $title->getNamespace(), 'aplimit' => 10, 'apprefix' => $title->getDBkey()));
     // Execute
     $module = new ApiMain($params);
     $module->execute();
     // Get resulting data
     $data = $module->getResultData();
     // Reformat useful data for future printing by JSON engine
     $srchres = array();
     foreach ($data['query']['allpages'] as &$pageinfo) {
         // Note: this data will no be printable by the xml engine
         // because it does not support lists of unnamed items
         $srchres[] = $pageinfo['title'];
     }
     // Set top level elements
     $result = $this->getResult();
     $result->addValue(null, 0, $search);
     $result->addValue(null, 1, $srchres);
 }
开发者ID:negabaro,项目名称:alfresco,代码行数:30,代码来源:ApiOpenSearch.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: getPreviewImage

 /**
  * Gets the HTML for the preview image or null if there is none.
  *
  * @since 2.3.3
  *
  * @param string $imageName
  *
  * @return string|null
  */
 protected static function getPreviewImage($imageName)
 {
     $previewImage = null;
     $imageTitle = Title::newFromText($imageName, NS_FILE);
     if (!is_object($imageTitle)) {
         return $previewImage;
     }
     $api = new ApiMain(new FauxRequest(array('action' => 'query', 'format' => 'json', 'prop' => 'imageinfo', 'iiprop' => 'url', 'titles' => $imageTitle->getFullText(), 'iiurlwidth' => 200), true), true);
     $api->execute();
     $result = $api->getResultData();
     $url = false;
     if (array_key_exists('query', $result) && array_key_exists('pages', $result['query'])) {
         foreach ($result['query']['pages'] as $page) {
             if (array_key_exists('imageinfo', $page)) {
                 foreach ($page['imageinfo'] as $imageInfo) {
                     $url = $imageInfo['thumburl'];
                     break;
                 }
             }
         }
     }
     if ($url !== false) {
         $previewImage = Html::element('img', array('src' => $url));
     }
     return $previewImage;
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:35,代码来源:SF_TextInput.php

示例7: 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

示例8: execute

    function execute($par)
    {
        global $wgRequest, $wgOut, $wgBoilerplatefactorydefaultpage, $wgBoilerplatefactorycategorie, $wgBoilerplatefactorynamespace;
        $this->setHeaders();
        ### new page name
        $wgOut->addHTML(' <form name="boilerplatefactory" id="boilerplatefactory" class="boilerplatefactory" action="/index.php" method="get">
		  <input name="title" class="createboxInput" value="' . $wgBoilerplatefactorydefaultpage . '" type="text"><br>');
        ### list of existing pages using as Boilerplate
        $params = new FauxRequest(array('action' => 'query', 'list' => 'categorymembers', 'cmlimit' => 100, 'cmtitle' => $wgBoilerplatefactorycategorie));
        $api = new ApiMain($params);
        $api->execute();
        $wgBoilerplatefactorycategories =& $api->getResultData();
        foreach ($wgBoilerplatefactorycategories[query][categorymembers] as $categ) {
            $params = new FauxRequest(array('action' => 'query', 'list' => 'categorymembers', 'cmlimit' => 100, 'cmtitle' => $categ[title], 'cmnamespace' => $wgBoilerplatefactorynamespace));
            $api = new ApiMain($params);
            $api->execute();
            $boilerarray =& $api->getResultData();
            $wgOut->addHTML("\n <div>\n  <h2 class=\"{$categ['title']}\" >{$categ['title']}</h2>\n");
            foreach ($boilerarray[query][categorymembers] as $boiler) {
                $wgOut->addHTML("  <input type='checkbox' name='blrchc[]' value='" . $boiler[title] . "' > <a href='http://" . $_SERVER[HTTP_HOST] . "/index.php?title=" . $boiler[title] . "' >" . $boiler[title] . "</a><br />\n");
            }
            $wgOut->addHTML("</div>\n");
        }
        ### subst check send
        $wgOut->addHTML(" <fieldset><legend>" . wfMsg('boilerplatefactory-setting') . "</legend>\n\n\t\t  <input type='checkbox' name='blrsubst' value='' checked >" . wfMsg('boilerplatefactory-subst') . "<br />\n\t\t  <input type='checkbox' name='blrnotoc' value='' >" . wfMsg('boilerplatefactory-notoc') . "<br />\n\t\t  <input type='checkbox' name='blrndtscton' value='' checked >" . wfMsg('boilerplatefactory-noeditsection') . "<br />\n\t\t  <input type='checkbox' name='blrnoNSh2' value='' checked >" . wfMsg('boilerplatefactory-nonamespaceh2') . "<br />\n\t\t  <input name='action' value='edit' type='hidden' >\n  \n\t\t  <input name='create' class='createboxButton' value='" . wfMsg('boilerplatefactory-send') . "' type='submit'>\n </fieldset>\n </form>");
        return true;
    }
开发者ID:klml,项目名称:Boilerplatefactory,代码行数:27,代码来源:Boilerplatefactory_body.php

示例9: 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

示例10: 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

示例11: 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

示例12: execute

 /**
  * Make a nested call to the API to request watchlist items in the last $hours.
  * Wrap the result as an RSS/Atom feed.
  */
 public function execute()
 {
     global $wgFeedClasses, $wgFeedLimit, $wgSitename, $wgLanguageCode;
     try {
         $params = $this->extractRequestParams();
         // limit to the number of hours going from now back
         $endTime = wfTimestamp(TS_MW, time() - intval($params['hours'] * 60 * 60));
         // Prepare parameters for nested request
         $fauxReqArr = array('action' => 'query', 'meta' => 'siteinfo', 'siprop' => 'general', 'list' => 'watchlist', 'wlprop' => 'title|user|comment|timestamp', 'wldir' => 'older', 'wlend' => $endTime, 'wllimit' => 50 > $wgFeedLimit ? $wgFeedLimit : 50);
         if (!is_null($params['wlowner'])) {
             $fauxReqArr['wlowner'] = $params['wlowner'];
         }
         if (!is_null($params['wltoken'])) {
             $fauxReqArr['wltoken'] = $params['wltoken'];
         }
         // Support linking to diffs instead of article
         if ($params['linktodiffs']) {
             $this->linkToDiffs = true;
             $fauxReqArr['wlprop'] .= '|ids';
         }
         // Check for 'allrev' parameter, and if found, show all revisions to each page on wl.
         if (!is_null($params['allrev'])) {
             $fauxReqArr['wlallrev'] = '';
         }
         // Create the request
         $fauxReq = new FauxRequest($fauxReqArr);
         // Execute
         $module = new ApiMain($fauxReq);
         $module->execute();
         // Get data array
         $data = $module->getResultData();
         $feedItems = array();
         foreach ((array) $data['query']['watchlist'] as $info) {
             $feedItems[] = $this->createFeedItem($info);
         }
         $feedTitle = $wgSitename . ' - ' . wfMsgForContent('watchlist') . ' [' . $wgLanguageCode . ']';
         $feedUrl = SpecialPage::getTitleFor('Watchlist')->getFullURL();
         $feed = new $wgFeedClasses[$params['feedformat']]($feedTitle, htmlspecialchars(wfMsgForContent('watchlist')), $feedUrl);
         ApiFormatFeedWrapper::setResult($this->getResult(), $feed, $feedItems);
     } catch (Exception $e) {
         // Error results should not be cached
         $this->getMain()->setCacheMaxAge(0);
         $feedTitle = $wgSitename . ' - Error - ' . wfMsgForContent('watchlist') . ' [' . $wgLanguageCode . ']';
         $feedUrl = SpecialPage::getTitleFor('Watchlist')->getFullURL();
         $feedFormat = isset($params['feedformat']) ? $params['feedformat'] : 'rss';
         $feed = new $wgFeedClasses[$feedFormat]($feedTitle, htmlspecialchars(wfMsgForContent('watchlist')), $feedUrl);
         if ($e instanceof UsageException) {
             $errorCode = $e->getCodeString();
         } else {
             // Something is seriously wrong
             $errorCode = 'internal_api_error';
         }
         $errorText = $e->getMessage();
         $feedItems[] = new FeedItem("Error ({$errorCode})", $errorText, '', '', '');
         ApiFormatFeedWrapper::setResult($this->getResult(), $feed, $feedItems);
     }
 }
开发者ID:GodelDesign,项目名称:Godel,代码行数:61,代码来源:ApiFeedWatchlist.php

示例13: execute

	public function execute() {
		$pageSet = $this->getPageSet();
		$pages = $pageSet->getGoodTitles();
		if ( !count( $pages ) ) {
			return true;
		}

		$pageNamespaceId = ProofreadPage::getPageNamespaceId();
		$pageIds = array();
		foreach ( $pages AS $pageId => $title ) {
			if ( $title->getNamespace() == $pageNamespaceId ) {
				$pageIds[] = $pageId;
			}
		}

		if ( !count( $pageIds ) ) {
			return true;
		}

		// Determine the categories defined in MediaWiki: pages
		$qualityCategories = $qualityText = array();
		for ( $i = 0; $i < 5; $i++ ) {
			$cat = Title::makeTitleSafe( NS_CATEGORY, wfMsgForContent( "proofreadpage_quality{$i}_category" ) );
			if ( $cat ) {
				$qualityCategories[$i] = $cat->getPrefixedText();
				$qualityText[$i] = $cat->getText();
			}
		}
		$qualityLevels = array_flip( $qualityCategories );

		// <Reedy> johnduhart, it'd seem sane rather than duplicating the functionality
		$params = new FauxRequest(array(
			'action' => 'query',
			'prop' => 'categories',
			'pageids' => implode( '|', $pageIds ),
			'clcategories' => implode( '|', $qualityCategories ),
			'cllimit' => 'max'
		));

		$api = new ApiMain($params);
		$api->execute();
		$data = $api->getResultData();
		unset( $api );

		$result = $this->getResult();
		foreach ( $data['query']['pages'] as $pageid => $data) {
			$title = $data['categories'][0]['title'];
			if ( !isset( $qualityLevels[ $title ] ) ) {
				continue;
			}

			$pageQuality = $qualityLevels[ $title ];
			$val =  array( 'quality' => $pageQuality, 'quality_text' => $qualityText[ $pageQuality ] );
			$result->addValue( array( 'query', 'pages', $pageid ), 'proofread', $val );
		}
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:56,代码来源:ApiQueryProofread.php

示例14: doApiRequest

 protected function doApiRequest($params, $unused = null, $appendModule = false, $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->getResultData(), $req);
 }
开发者ID:laiello,项目名称:media-wiki-law,代码行数:10,代码来源:UploadFromUrlTest.php

示例15: 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


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