Niharika29 has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/379832 )
Change subject: Add some docs for SiteMatrixApi
......................................................................
Add some docs for SiteMatrixApi
Change-Id: I59ed4a7a95074786df89bf3798acec062aeca35f
---
M SiteMatrixApi.php
1 file changed, 46 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SiteMatrix
refs/changes/32/379832/1
diff --git a/SiteMatrixApi.php b/SiteMatrixApi.php
index 2debcdd..891bc06 100644
--- a/SiteMatrixApi.php
+++ b/SiteMatrixApi.php
@@ -6,19 +6,31 @@
*/
class ApiSiteMatrix extends ApiBase {
+ /**
+ * ApiSiteMatrix constructor.
+ *
+ * @param \ApiMain $main
+ * @param string $moduleName
+ */
public function __construct( ApiMain $main, $moduleName ) {
parent::__construct( $main, $moduleName, 'sm' );
}
+ /**
+ * Execute API request
+ */
public function execute() {
$result = $this->getResult();
$matrix = new SiteMatrix();
+ // Fetch list of language codes and names
$langNames = Language::fetchLanguageNames();
$matrix_out = [ 'count' => $matrix->getCount() ];
+ // Fetch list of language names in given language, if they exist
$localLanguageNames = Language::fetchLanguageNames(
$this->getLanguage()->getCode() );
+ // Extract request params
$params = $this->extractRequestParams();
$type = array_flip( $params['type'] );
$state = array_flip( $params['state'] );
@@ -37,6 +49,7 @@
$nonglobal = isset( $state['nonglobal'] );
$count = 0;
+ // For smtype=language, fetch info about all language wikis
if ( isset( $type['language'] ) && $continue[0] == 'language' )
{
foreach ( $matrix->getLangList() as $lang ) {
$langhost = str_replace( '_', '-', $lang );
@@ -47,17 +60,21 @@
$this->setContinueEnumParameter(
'continue', "language|$langhost" );
break;
}
+ // Compute the language property values to
return
$language = [
- 'code' => $langhost,
- 'name' => isset( $langNames[$lang] ) ?
$langNames[$lang] : null,
- 'site' => [],
- 'dir' => Language::factory( $langhost
)->getDir()
+ 'code' => $langhost, // Language code
+ 'name' => isset( $langNames[$lang] ) ?
$langNames[$lang] : null, // Language name
+ 'site' => [], // Site(s) info (see
below)
+ 'dir' => Language::factory( $langhost
)->getDir() // Language direction
];
+ // Add language name in local language, if
available
if ( isset( $localLanguageNames[$lang] ) ) {
$language['localname'] =
$localLanguageNames[$lang];
}
+ // Return stuff user asked for
$language = array_intersect_key( $language,
$langProp );
+ // Generate site information
if ( isset( $language['site'] ) ) {
foreach ( $matrix->getSites() as $site
) {
if ( $matrix->exist( $lang,
$site ) ) {
@@ -69,11 +86,12 @@
$url =
$matrix->getCanonicalUrl( $lang, $site );
$site_out = [
- 'url' => $url,
- 'dbname' =>
$matrix->getDBName( $lang, $site ),
- 'code' => $site,
- 'sitename' =>
$matrix->getSitename( $lang, $site ),
+ 'url' => $url,
// Website url
+ 'dbname' =>
$matrix->getDBName( $lang, $site ), // Shortcode for the wiki
+ 'code' =>
$site, // Wiki type (wiktionary, wiki, wikibooks etc.)
+ 'sitename' =>
$matrix->getSitename( $lang, $site ), // Site name in local language
];
+ // Return stuff user
asked for
$site_out =
array_intersect_key( $site_out, $siteProp );
if ( $matrix->isClosed(
$lang, $site ) ) {
$site_out['closed'] = true;
@@ -99,6 +117,7 @@
$result->setIndexedTagName( $matrix_out, 'language' );
$result->addValue( null, "sitematrix", $matrix_out );
+ // For smtype=language, fetch info about all special wikis
(such as arbcom wikis)
if ( isset( $type['special'] ) && $count < $limit ) {
$specials = [];
foreach ( $matrix->getSpecials() as $special ) {
@@ -165,6 +184,12 @@
}
}
+ /**
+ * Set continue param
+ *
+ * @param $paramName
+ * @param $paramValue
+ */
protected function setContinueEnumParameter( $paramName, $paramValue ) {
$paramName = $this->encodeParamName( $paramName );
$msg = [ $paramName => $paramValue ];
@@ -172,6 +197,11 @@
$result->addValue( 'query-continue', $this->getModuleName(),
$msg, ApiResult::NO_SIZE_CHECK );
}
+ /**
+ * Allowed params for API queries
+ *
+ * @return array Array of acceptable param strings
+ */
public function getAllowedParams() {
return [
'type' => [
@@ -228,9 +258,16 @@
}
/**
+ * Example API query strings
+ *
* @see ApiBase::getExamplesMessages()
*/
protected function getExamplesMessages() {
- return [ 'action=sitematrix' => 'apihelp-sitematrix-example-1',
];
+ return [
+ 'action=sitematrix' => 'apihelp-sitematrix-example-1',
+ 'action=sitematrix&smsiteprop=dbname|code' =>
'apihelp-sitematrix-example-2',
+
'action=sitematrix&smtype=special&smlangprop=code|name|dir&smlimit=50' =>
+ 'apihelp-sitematrix-example-3',
+ ];
}
}
--
To view, visit https://gerrit.wikimedia.org/r/379832
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I59ed4a7a95074786df89bf3798acec062aeca35f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SiteMatrix
Gerrit-Branch: master
Gerrit-Owner: Niharika29 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits