MediaWiki
REL1_23
|
00001 <?php 00032 class ApiQuerySiteinfo extends ApiQueryBase { 00033 00034 public function __construct( $query, $moduleName ) { 00035 parent::__construct( $query, $moduleName, 'si' ); 00036 } 00037 00038 public function execute() { 00039 $params = $this->extractRequestParams(); 00040 $done = array(); 00041 $fit = false; 00042 foreach ( $params['prop'] as $p ) { 00043 switch ( $p ) { 00044 case 'general': 00045 $fit = $this->appendGeneralInfo( $p ); 00046 break; 00047 case 'namespaces': 00048 $fit = $this->appendNamespaces( $p ); 00049 break; 00050 case 'namespacealiases': 00051 $fit = $this->appendNamespaceAliases( $p ); 00052 break; 00053 case 'specialpagealiases': 00054 $fit = $this->appendSpecialPageAliases( $p ); 00055 break; 00056 case 'magicwords': 00057 $fit = $this->appendMagicWords( $p ); 00058 break; 00059 case 'interwikimap': 00060 $filteriw = isset( $params['filteriw'] ) ? $params['filteriw'] : false; 00061 $fit = $this->appendInterwikiMap( $p, $filteriw ); 00062 break; 00063 case 'dbrepllag': 00064 $fit = $this->appendDbReplLagInfo( $p, $params['showalldb'] ); 00065 break; 00066 case 'statistics': 00067 $fit = $this->appendStatistics( $p ); 00068 break; 00069 case 'usergroups': 00070 $fit = $this->appendUserGroups( $p, $params['numberingroup'] ); 00071 break; 00072 case 'extensions': 00073 $fit = $this->appendExtensions( $p ); 00074 break; 00075 case 'fileextensions': 00076 $fit = $this->appendFileExtensions( $p ); 00077 break; 00078 case 'rightsinfo': 00079 $fit = $this->appendRightsInfo( $p ); 00080 break; 00081 case 'restrictions': 00082 $fit = $this->appendRestrictions( $p ); 00083 break; 00084 case 'languages': 00085 $fit = $this->appendLanguages( $p ); 00086 break; 00087 case 'skins': 00088 $fit = $this->appendSkins( $p ); 00089 break; 00090 case 'extensiontags': 00091 $fit = $this->appendExtensionTags( $p ); 00092 break; 00093 case 'functionhooks': 00094 $fit = $this->appendFunctionHooks( $p ); 00095 break; 00096 case 'showhooks': 00097 $fit = $this->appendSubscribedHooks( $p ); 00098 break; 00099 case 'variables': 00100 $fit = $this->appendVariables( $p ); 00101 break; 00102 case 'protocols': 00103 $fit = $this->appendProtocols( $p ); 00104 break; 00105 case 'defaultoptions': 00106 $fit = $this->appendDefaultOptions( $p ); 00107 break; 00108 default: 00109 ApiBase::dieDebug( __METHOD__, "Unknown prop=$p" ); 00110 } 00111 if ( !$fit ) { 00112 // Abuse siprop as a query-continue parameter 00113 // and set it to all unprocessed props 00114 $this->setContinueEnumParameter( 'prop', implode( '|', 00115 array_diff( $params['prop'], $done ) ) ); 00116 break; 00117 } 00118 $done[] = $p; 00119 } 00120 } 00121 00122 protected function appendGeneralInfo( $property ) { 00123 global $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion; 00124 00125 $data = array(); 00126 $mainPage = Title::newMainPage(); 00127 $data['mainpage'] = $mainPage->getPrefixedText(); 00128 $data['base'] = wfExpandUrl( $mainPage->getFullURL(), PROTO_CURRENT ); 00129 $data['sitename'] = $GLOBALS['wgSitename']; 00130 00131 // wgLogo can either be a relative or an absolute path 00132 // make sure we always return an absolute path 00133 $data['logo'] = wfExpandUrl( $GLOBALS['wgLogo'], PROTO_RELATIVE ); 00134 00135 $data['generator'] = "MediaWiki {$GLOBALS['wgVersion']}"; 00136 $data['phpversion'] = phpversion(); 00137 $data['phpsapi'] = PHP_SAPI; 00138 $data['dbtype'] = $GLOBALS['wgDBtype']; 00139 $data['dbversion'] = $this->getDB()->getServerVersion(); 00140 00141 $allowFrom = array( '' ); 00142 $allowException = true; 00143 if ( !$GLOBALS['wgAllowExternalImages'] ) { 00144 if ( $GLOBALS['wgEnableImageWhitelist'] ) { 00145 $data['imagewhitelistenabled'] = ''; 00146 } 00147 $allowFrom = $GLOBALS['wgAllowExternalImagesFrom']; 00148 $allowException = !empty( $allowFrom ); 00149 } 00150 if ( $allowException ) { 00151 $data['externalimages'] = (array)$allowFrom; 00152 $this->getResult()->setIndexedTagName( $data['externalimages'], 'prefix' ); 00153 } 00154 00155 if ( !$wgDisableLangConversion ) { 00156 $data['langconversion'] = ''; 00157 } 00158 00159 if ( !$wgDisableTitleConversion ) { 00160 $data['titleconversion'] = ''; 00161 } 00162 00163 if ( $wgContLang->linkPrefixExtension() ) { 00164 $linkPrefixCharset = $wgContLang->linkPrefixCharset(); 00165 $data['linkprefixcharset'] = $linkPrefixCharset; 00166 // For backwards compatability 00167 $data['linkprefix'] = "/^((?>.*[^$linkPrefixCharset]|))(.+)$/sDu"; 00168 } else { 00169 $data['linkprefixcharset'] = ''; 00170 $data['linkprefix'] = ''; 00171 } 00172 00173 $linktrail = $wgContLang->linkTrail(); 00174 if ( $linktrail ) { 00175 $data['linktrail'] = $linktrail; 00176 } else { 00177 $data['linktrail'] = ''; 00178 } 00179 00180 $git = SpecialVersion::getGitHeadSha1( $GLOBALS['IP'] ); 00181 if ( $git ) { 00182 $data['git-hash'] = $git; 00183 } else { 00184 $svn = SpecialVersion::getSvnRevision( $GLOBALS['IP'] ); 00185 if ( $svn ) { 00186 $data['rev'] = $svn; 00187 } 00188 } 00189 00190 // 'case-insensitive' option is reserved for future 00191 $data['case'] = $GLOBALS['wgCapitalLinks'] ? 'first-letter' : 'case-sensitive'; 00192 00193 $data['lang'] = $GLOBALS['wgLanguageCode']; 00194 00195 $fallbacks = array(); 00196 foreach ( $wgContLang->getFallbackLanguages() as $code ) { 00197 $fallbacks[] = array( 'code' => $code ); 00198 } 00199 $data['fallback'] = $fallbacks; 00200 $this->getResult()->setIndexedTagName( $data['fallback'], 'lang' ); 00201 00202 if ( $wgContLang->hasVariants() ) { 00203 $variants = array(); 00204 foreach ( $wgContLang->getVariants() as $code ) { 00205 $variants[] = array( 00206 'code' => $code, 00207 'name' => $wgContLang->getVariantname( $code ), 00208 ); 00209 } 00210 $data['variants'] = $variants; 00211 $this->getResult()->setIndexedTagName( $data['variants'], 'lang' ); 00212 } 00213 00214 if ( $wgContLang->isRTL() ) { 00215 $data['rtl'] = ''; 00216 } 00217 $data['fallback8bitEncoding'] = $wgContLang->fallback8bitEncoding(); 00218 00219 if ( wfReadOnly() ) { 00220 $data['readonly'] = ''; 00221 $data['readonlyreason'] = wfReadOnlyReason(); 00222 } 00223 if ( $GLOBALS['wgEnableWriteAPI'] ) { 00224 $data['writeapi'] = ''; 00225 } 00226 00227 $tz = $GLOBALS['wgLocaltimezone']; 00228 $offset = $GLOBALS['wgLocalTZoffset']; 00229 if ( is_null( $tz ) ) { 00230 $tz = 'UTC'; 00231 $offset = 0; 00232 } elseif ( is_null( $offset ) ) { 00233 $offset = 0; 00234 } 00235 $data['timezone'] = $tz; 00236 $data['timeoffset'] = intval( $offset ); 00237 $data['articlepath'] = $GLOBALS['wgArticlePath']; 00238 $data['scriptpath'] = $GLOBALS['wgScriptPath']; 00239 $data['script'] = $GLOBALS['wgScript']; 00240 $data['variantarticlepath'] = $GLOBALS['wgVariantArticlePath']; 00241 $data['server'] = $GLOBALS['wgServer']; 00242 $data['wikiid'] = wfWikiID(); 00243 $data['time'] = wfTimestamp( TS_ISO_8601, time() ); 00244 00245 if ( $GLOBALS['wgMiserMode'] ) { 00246 $data['misermode'] = ''; 00247 } 00248 00249 $data['maxuploadsize'] = UploadBase::getMaxUploadSize(); 00250 00251 $data['thumblimits'] = $GLOBALS['wgThumbLimits']; 00252 $this->getResult()->setIndexedTagName( $data['thumblimits'], 'limit' ); 00253 $data['imagelimits'] = array(); 00254 $this->getResult()->setIndexedTagName( $data['imagelimits'], 'limit' ); 00255 foreach ( $GLOBALS['wgImageLimits'] as $k => $limit ) { 00256 $data['imagelimits'][$k] = array( 'width' => $limit[0], 'height' => $limit[1] ); 00257 } 00258 00259 if ( !empty( $GLOBALS['wgFavicon'] ) ) { 00260 // wgFavicon can either be a relative or an absolute path 00261 // make sure we always return an absolute path 00262 $data['favicon'] = wfExpandUrl( $GLOBALS['wgFavicon'], PROTO_RELATIVE ); 00263 } 00264 00265 wfRunHooks( 'APIQuerySiteInfoGeneralInfo', array( $this, &$data ) ); 00266 00267 return $this->getResult()->addValue( 'query', $property, $data ); 00268 } 00269 00270 protected function appendNamespaces( $property ) { 00271 global $wgContLang; 00272 $data = array(); 00273 foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) { 00274 $data[$ns] = array( 00275 'id' => intval( $ns ), 00276 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive', 00277 ); 00278 ApiResult::setContent( $data[$ns], $title ); 00279 $canonical = MWNamespace::getCanonicalName( $ns ); 00280 00281 if ( MWNamespace::hasSubpages( $ns ) ) { 00282 $data[$ns]['subpages'] = ''; 00283 } 00284 00285 if ( $canonical ) { 00286 $data[$ns]['canonical'] = strtr( $canonical, '_', ' ' ); 00287 } 00288 00289 if ( MWNamespace::isContent( $ns ) ) { 00290 $data[$ns]['content'] = ''; 00291 } 00292 00293 if ( MWNamespace::isNonincludable( $ns ) ) { 00294 $data[$ns]['nonincludable'] = ''; 00295 } 00296 00297 $contentmodel = MWNamespace::getNamespaceContentModel( $ns ); 00298 if ( $contentmodel ) { 00299 $data[$ns]['defaultcontentmodel'] = $contentmodel; 00300 } 00301 } 00302 00303 $this->getResult()->setIndexedTagName( $data, 'ns' ); 00304 00305 return $this->getResult()->addValue( 'query', $property, $data ); 00306 } 00307 00308 protected function appendNamespaceAliases( $property ) { 00309 global $wgNamespaceAliases, $wgContLang; 00310 $aliases = array_merge( $wgNamespaceAliases, $wgContLang->getNamespaceAliases() ); 00311 $namespaces = $wgContLang->getNamespaces(); 00312 $data = array(); 00313 foreach ( $aliases as $title => $ns ) { 00314 if ( $namespaces[$ns] == $title ) { 00315 // Don't list duplicates 00316 continue; 00317 } 00318 $item = array( 00319 'id' => intval( $ns ) 00320 ); 00321 ApiResult::setContent( $item, strtr( $title, '_', ' ' ) ); 00322 $data[] = $item; 00323 } 00324 00325 sort( $data ); 00326 00327 $this->getResult()->setIndexedTagName( $data, 'ns' ); 00328 00329 return $this->getResult()->addValue( 'query', $property, $data ); 00330 } 00331 00332 protected function appendSpecialPageAliases( $property ) { 00333 global $wgContLang; 00334 $data = array(); 00335 $aliases = $wgContLang->getSpecialPageAliases(); 00336 foreach ( SpecialPageFactory::getList() as $specialpage => $stuff ) { 00337 if ( isset( $aliases[$specialpage] ) ) { 00338 $arr = array( 'realname' => $specialpage, 'aliases' => $aliases[$specialpage] ); 00339 $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' ); 00340 $data[] = $arr; 00341 } 00342 } 00343 $this->getResult()->setIndexedTagName( $data, 'specialpage' ); 00344 00345 return $this->getResult()->addValue( 'query', $property, $data ); 00346 } 00347 00348 protected function appendMagicWords( $property ) { 00349 global $wgContLang; 00350 $data = array(); 00351 foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) { 00352 $caseSensitive = array_shift( $aliases ); 00353 $arr = array( 'name' => $magicword, 'aliases' => $aliases ); 00354 if ( $caseSensitive ) { 00355 $arr['case-sensitive'] = ''; 00356 } 00357 $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' ); 00358 $data[] = $arr; 00359 } 00360 $this->getResult()->setIndexedTagName( $data, 'magicword' ); 00361 00362 return $this->getResult()->addValue( 'query', $property, $data ); 00363 } 00364 00365 protected function appendInterwikiMap( $property, $filter ) { 00366 $local = null; 00367 if ( $filter === 'local' ) { 00368 $local = 1; 00369 } elseif ( $filter === '!local' ) { 00370 $local = 0; 00371 } elseif ( $filter ) { 00372 ApiBase::dieDebug( __METHOD__, "Unknown filter=$filter" ); 00373 } 00374 00375 $params = $this->extractRequestParams(); 00376 $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : ''; 00377 $langNames = Language::fetchLanguageNames( $langCode ); 00378 00379 $getPrefixes = Interwiki::getAllPrefixes( $local ); 00380 $data = array(); 00381 00382 foreach ( $getPrefixes as $row ) { 00383 $prefix = $row['iw_prefix']; 00384 $val = array(); 00385 $val['prefix'] = $prefix; 00386 if ( $row['iw_local'] == '1' ) { 00387 $val['local'] = ''; 00388 } 00389 if ( $row['iw_trans'] == '1' ) { 00390 $val['trans'] = ''; 00391 } 00392 if ( isset( $langNames[$prefix] ) ) { 00393 $val['language'] = $langNames[$prefix]; 00394 } 00395 $val['url'] = wfExpandUrl( $row['iw_url'], PROTO_CURRENT ); 00396 if ( isset( $row['iw_wikiid'] ) ) { 00397 $val['wikiid'] = $row['iw_wikiid']; 00398 } 00399 if ( isset( $row['iw_api'] ) ) { 00400 $val['api'] = $row['iw_api']; 00401 } 00402 00403 $data[] = $val; 00404 } 00405 00406 $this->getResult()->setIndexedTagName( $data, 'iw' ); 00407 00408 return $this->getResult()->addValue( 'query', $property, $data ); 00409 } 00410 00411 protected function appendDbReplLagInfo( $property, $includeAll ) { 00412 global $wgShowHostnames; 00413 $data = array(); 00414 $lb = wfGetLB(); 00415 if ( $includeAll ) { 00416 if ( !$wgShowHostnames ) { 00417 $this->dieUsage( 00418 'Cannot view all servers info unless $wgShowHostnames is true', 00419 'includeAllDenied' 00420 ); 00421 } 00422 00423 $lags = $lb->getLagTimes(); 00424 foreach ( $lags as $i => $lag ) { 00425 $data[] = array( 00426 'host' => $lb->getServerName( $i ), 00427 'lag' => $lag 00428 ); 00429 } 00430 } else { 00431 list( , $lag, $index ) = $lb->getMaxLag(); 00432 $data[] = array( 00433 'host' => $wgShowHostnames 00434 ? $lb->getServerName( $index ) 00435 : '', 00436 'lag' => intval( $lag ) 00437 ); 00438 } 00439 00440 $result = $this->getResult(); 00441 $result->setIndexedTagName( $data, 'db' ); 00442 00443 return $this->getResult()->addValue( 'query', $property, $data ); 00444 } 00445 00446 protected function appendStatistics( $property ) { 00447 global $wgDisableCounters; 00448 $data = array(); 00449 $data['pages'] = intval( SiteStats::pages() ); 00450 $data['articles'] = intval( SiteStats::articles() ); 00451 if ( !$wgDisableCounters ) { 00452 $data['views'] = intval( SiteStats::views() ); 00453 } 00454 $data['edits'] = intval( SiteStats::edits() ); 00455 $data['images'] = intval( SiteStats::images() ); 00456 $data['users'] = intval( SiteStats::users() ); 00457 $data['activeusers'] = intval( SiteStats::activeUsers() ); 00458 $data['admins'] = intval( SiteStats::numberingroup( 'sysop' ) ); 00459 $data['jobs'] = intval( SiteStats::jobs() ); 00460 00461 wfRunHooks( 'APIQuerySiteInfoStatisticsInfo', array( &$data ) ); 00462 00463 return $this->getResult()->addValue( 'query', $property, $data ); 00464 } 00465 00466 protected function appendUserGroups( $property, $numberInGroup ) { 00467 global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups; 00468 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf; 00469 00470 $data = array(); 00471 $result = $this->getResult(); 00472 foreach ( $wgGroupPermissions as $group => $permissions ) { 00473 $arr = array( 00474 'name' => $group, 00475 'rights' => array_keys( $permissions, true ), 00476 ); 00477 00478 if ( $numberInGroup ) { 00479 global $wgAutopromote; 00480 00481 if ( $group == 'user' ) { 00482 $arr['number'] = SiteStats::users(); 00483 // '*' and autopromote groups have no size 00484 } elseif ( $group !== '*' && !isset( $wgAutopromote[$group] ) ) { 00485 $arr['number'] = SiteStats::numberInGroup( $group ); 00486 } 00487 } 00488 00489 $groupArr = array( 00490 'add' => $wgAddGroups, 00491 'remove' => $wgRemoveGroups, 00492 'add-self' => $wgGroupsAddToSelf, 00493 'remove-self' => $wgGroupsRemoveFromSelf 00494 ); 00495 00496 foreach ( $groupArr as $type => $rights ) { 00497 if ( isset( $rights[$group] ) ) { 00498 $arr[$type] = $rights[$group]; 00499 $result->setIndexedTagName( $arr[$type], 'group' ); 00500 } 00501 } 00502 00503 $result->setIndexedTagName( $arr['rights'], 'permission' ); 00504 $data[] = $arr; 00505 } 00506 00507 $result->setIndexedTagName( $data, 'group' ); 00508 00509 return $result->addValue( 'query', $property, $data ); 00510 } 00511 00512 protected function appendFileExtensions( $property ) { 00513 global $wgFileExtensions; 00514 00515 $data = array(); 00516 foreach ( array_unique( $wgFileExtensions ) as $ext ) { 00517 $data[] = array( 'ext' => $ext ); 00518 } 00519 $this->getResult()->setIndexedTagName( $data, 'fe' ); 00520 00521 return $this->getResult()->addValue( 'query', $property, $data ); 00522 } 00523 00524 protected function appendExtensions( $property ) { 00525 global $wgExtensionCredits; 00526 $data = array(); 00527 foreach ( $wgExtensionCredits as $type => $extensions ) { 00528 foreach ( $extensions as $ext ) { 00529 $ret = array(); 00530 $ret['type'] = $type; 00531 if ( isset( $ext['name'] ) ) { 00532 $ret['name'] = $ext['name']; 00533 } 00534 if ( isset( $ext['description'] ) ) { 00535 $ret['description'] = $ext['description']; 00536 } 00537 if ( isset( $ext['descriptionmsg'] ) ) { 00538 // Can be a string or array( key, param1, param2, ... ) 00539 if ( is_array( $ext['descriptionmsg'] ) ) { 00540 $ret['descriptionmsg'] = $ext['descriptionmsg'][0]; 00541 $ret['descriptionmsgparams'] = array_slice( $ext['descriptionmsg'], 1 ); 00542 $this->getResult()->setIndexedTagName( $ret['descriptionmsgparams'], 'param' ); 00543 } else { 00544 $ret['descriptionmsg'] = $ext['descriptionmsg']; 00545 } 00546 } 00547 if ( isset( $ext['author'] ) ) { 00548 $ret['author'] = is_array( $ext['author'] ) ? 00549 implode( ', ', $ext['author'] ) : $ext['author']; 00550 } 00551 if ( isset( $ext['url'] ) ) { 00552 $ret['url'] = $ext['url']; 00553 } 00554 if ( isset( $ext['version'] ) ) { 00555 $ret['version'] = $ext['version']; 00556 } elseif ( isset( $ext['svn-revision'] ) && 00557 preg_match( '/\$(?:Rev|LastChangedRevision|Revision): *(\d+)/', 00558 $ext['svn-revision'], $m ) 00559 ) { 00560 $ret['version'] = 'r' . $m[1]; 00561 } 00562 if ( isset( $ext['path'] ) ) { 00563 $extensionPath = dirname( $ext['path'] ); 00564 $gitInfo = new GitInfo( $extensionPath ); 00565 $vcsVersion = $gitInfo->getHeadSHA1(); 00566 if ( $vcsVersion !== false ) { 00567 $ret['vcs-system'] = 'git'; 00568 $ret['vcs-version'] = $vcsVersion; 00569 $ret['vcs-url'] = $gitInfo->getHeadViewUrl(); 00570 $vcsDate = $gitInfo->getHeadCommitDate(); 00571 if ( $vcsDate !== false ) { 00572 $ret['vcs-date'] = wfTimestamp( TS_ISO_8601, $vcsDate ); 00573 } 00574 } else { 00575 $svnInfo = SpecialVersion::getSvnInfo( $extensionPath ); 00576 if ( $svnInfo !== false ) { 00577 $ret['vcs-system'] = 'svn'; 00578 $ret['vcs-version'] = $svnInfo['checkout-rev']; 00579 $ret['vcs-url'] = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : ''; 00580 } 00581 } 00582 00583 if ( SpecialVersion::getExtLicenseFileName( $extensionPath ) ) { 00584 $ret['license-name'] = isset( $ext['license-name'] ) ? $ext['license-name'] : ''; 00585 $ret['license'] = SpecialPage::getTitleFor( 00586 'Version', 00587 "License/{$ext['name']}" 00588 )->getLinkURL(); 00589 } 00590 00591 if ( SpecialVersion::getExtAuthorsFileName( $extensionPath ) ) { 00592 $ret['credits'] = SpecialPage::getTitleFor( 00593 'Version', 00594 "Credits/{$ext['name']}" 00595 )->getLinkURL(); 00596 } 00597 } 00598 $data[] = $ret; 00599 } 00600 } 00601 00602 $this->getResult()->setIndexedTagName( $data, 'ext' ); 00603 00604 return $this->getResult()->addValue( 'query', $property, $data ); 00605 } 00606 00607 protected function appendRightsInfo( $property ) { 00608 global $wgRightsPage, $wgRightsUrl, $wgRightsText; 00609 $title = Title::newFromText( $wgRightsPage ); 00610 $url = $title ? wfExpandUrl( $title->getFullURL(), PROTO_CURRENT ) : $wgRightsUrl; 00611 $text = $wgRightsText; 00612 if ( !$text && $title ) { 00613 $text = $title->getPrefixedText(); 00614 } 00615 00616 $data = array( 00617 'url' => $url ? $url : '', 00618 'text' => $text ? $text : '' 00619 ); 00620 00621 return $this->getResult()->addValue( 'query', $property, $data ); 00622 } 00623 00624 protected function appendRestrictions( $property ) { 00625 global $wgRestrictionTypes, $wgRestrictionLevels, 00626 $wgCascadingRestrictionLevels, $wgSemiprotectedRestrictionLevels; 00627 00628 $data = array( 00629 'types' => $wgRestrictionTypes, 00630 'levels' => $wgRestrictionLevels, 00631 'cascadinglevels' => $wgCascadingRestrictionLevels, 00632 'semiprotectedlevels' => $wgSemiprotectedRestrictionLevels, 00633 ); 00634 00635 $this->getResult()->setIndexedTagName( $data['types'], 'type' ); 00636 $this->getResult()->setIndexedTagName( $data['levels'], 'level' ); 00637 $this->getResult()->setIndexedTagName( $data['cascadinglevels'], 'level' ); 00638 $this->getResult()->setIndexedTagName( $data['semiprotectedlevels'], 'level' ); 00639 00640 return $this->getResult()->addValue( 'query', $property, $data ); 00641 } 00642 00643 public function appendLanguages( $property ) { 00644 $params = $this->extractRequestParams(); 00645 $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : ''; 00646 $langNames = Language::fetchLanguageNames( $langCode ); 00647 00648 $data = array(); 00649 00650 foreach ( $langNames as $code => $name ) { 00651 $lang = array( 'code' => $code ); 00652 ApiResult::setContent( $lang, $name ); 00653 $data[] = $lang; 00654 } 00655 $this->getResult()->setIndexedTagName( $data, 'lang' ); 00656 00657 return $this->getResult()->addValue( 'query', $property, $data ); 00658 } 00659 00660 public function appendSkins( $property ) { 00661 $data = array(); 00662 $allowed = Skin::getAllowedSkins(); 00663 $default = Skin::normalizeKey( 'default' ); 00664 foreach ( Skin::getSkinNames() as $name => $displayName ) { 00665 $skin = array( 'code' => $name ); 00666 ApiResult::setContent( $skin, $displayName ); 00667 if ( !isset( $allowed[$name] ) ) { 00668 $skin['unusable'] = ''; 00669 } 00670 if ( $name === $default ) { 00671 $skin['default'] = ''; 00672 } 00673 $data[] = $skin; 00674 } 00675 $this->getResult()->setIndexedTagName( $data, 'skin' ); 00676 00677 return $this->getResult()->addValue( 'query', $property, $data ); 00678 } 00679 00680 public function appendExtensionTags( $property ) { 00681 global $wgParser; 00682 $wgParser->firstCallInit(); 00683 $tags = array_map( array( $this, 'formatParserTags' ), $wgParser->getTags() ); 00684 $this->getResult()->setIndexedTagName( $tags, 't' ); 00685 00686 return $this->getResult()->addValue( 'query', $property, $tags ); 00687 } 00688 00689 public function appendFunctionHooks( $property ) { 00690 global $wgParser; 00691 $wgParser->firstCallInit(); 00692 $hooks = $wgParser->getFunctionHooks(); 00693 $this->getResult()->setIndexedTagName( $hooks, 'h' ); 00694 00695 return $this->getResult()->addValue( 'query', $property, $hooks ); 00696 } 00697 00698 public function appendVariables( $property ) { 00699 $variables = MagicWord::getVariableIDs(); 00700 $this->getResult()->setIndexedTagName( $variables, 'v' ); 00701 00702 return $this->getResult()->addValue( 'query', $property, $variables ); 00703 } 00704 00705 public function appendProtocols( $property ) { 00706 global $wgUrlProtocols; 00707 // Make a copy of the global so we don't try to set the _element key of it - bug 45130 00708 $protocols = array_values( $wgUrlProtocols ); 00709 $this->getResult()->setIndexedTagName( $protocols, 'p' ); 00710 00711 return $this->getResult()->addValue( 'query', $property, $protocols ); 00712 } 00713 00714 public function appendDefaultOptions( $property ) { 00715 return $this->getResult()->addValue( 'query', $property, User::getDefaultOptions() ); 00716 } 00717 00718 private function formatParserTags( $item ) { 00719 return "<{$item}>"; 00720 } 00721 00722 public function appendSubscribedHooks( $property ) { 00723 global $wgHooks; 00724 $myWgHooks = $wgHooks; 00725 ksort( $myWgHooks ); 00726 00727 $data = array(); 00728 foreach ( $myWgHooks as $hook => $hooks ) { 00729 $arr = array( 00730 'name' => $hook, 00731 'subscribers' => array_map( array( 'SpecialVersion', 'arrayToString' ), $hooks ), 00732 ); 00733 00734 $this->getResult()->setIndexedTagName( $arr['subscribers'], 's' ); 00735 $data[] = $arr; 00736 } 00737 00738 $this->getResult()->setIndexedTagName( $data, 'hook' ); 00739 00740 return $this->getResult()->addValue( 'query', $property, $data ); 00741 } 00742 00743 public function getCacheMode( $params ) { 00744 return 'public'; 00745 } 00746 00747 public function getAllowedParams() { 00748 return array( 00749 'prop' => array( 00750 ApiBase::PARAM_DFLT => 'general', 00751 ApiBase::PARAM_ISMULTI => true, 00752 ApiBase::PARAM_TYPE => array( 00753 'general', 00754 'namespaces', 00755 'namespacealiases', 00756 'specialpagealiases', 00757 'magicwords', 00758 'interwikimap', 00759 'dbrepllag', 00760 'statistics', 00761 'usergroups', 00762 'extensions', 00763 'fileextensions', 00764 'rightsinfo', 00765 'restrictions', 00766 'languages', 00767 'skins', 00768 'extensiontags', 00769 'functionhooks', 00770 'showhooks', 00771 'variables', 00772 'protocols', 00773 'defaultoptions', 00774 ) 00775 ), 00776 'filteriw' => array( 00777 ApiBase::PARAM_TYPE => array( 00778 'local', 00779 '!local', 00780 ) 00781 ), 00782 'showalldb' => false, 00783 'numberingroup' => false, 00784 'inlanguagecode' => null, 00785 ); 00786 } 00787 00788 public function getParamDescription() { 00789 $p = $this->getModulePrefix(); 00790 00791 return array( 00792 'prop' => array( 00793 'Which sysinfo properties to get:', 00794 ' general - Overall system information', 00795 ' namespaces - List of registered namespaces and their canonical names', 00796 ' namespacealiases - List of registered namespace aliases', 00797 ' specialpagealiases - List of special page aliases', 00798 ' magicwords - List of magic words and their aliases', 00799 ' statistics - Returns site statistics', 00800 ' interwikimap - Returns interwiki map ' . 00801 "(optionally filtered, (optionally localised by using {$p}inlanguagecode))", 00802 ' dbrepllag - Returns database server with the highest replication lag', 00803 ' usergroups - Returns user groups and the associated permissions', 00804 ' extensions - Returns extensions installed on the wiki', 00805 ' fileextensions - Returns list of file extensions allowed to be uploaded', 00806 ' rightsinfo - Returns wiki rights (license) information if available', 00807 ' restrictions - Returns information on available restriction (protection) types', 00808 ' languages - Returns a list of languages MediaWiki supports' . 00809 "(optionally localised by using {$p}inlanguagecode)", 00810 ' skins - Returns a list of all enabled skins', 00811 ' extensiontags - Returns a list of parser extension tags', 00812 ' functionhooks - Returns a list of parser function hooks', 00813 ' showhooks - Returns a list of all subscribed hooks (contents of $wgHooks)', 00814 ' variables - Returns a list of variable IDs', 00815 ' protocols - Returns a list of protocols that are allowed in external links.', 00816 ' defaultoptions - Returns the default values for user preferences.', 00817 ), 00818 'filteriw' => 'Return only local or only nonlocal entries of the interwiki map', 00819 'showalldb' => 'List all database servers, not just the one lagging the most', 00820 'numberingroup' => 'Lists the number of users in user groups', 00821 'inlanguagecode' => 'Language code for localised language names ' . 00822 '(best effort, use CLDR extension)', 00823 ); 00824 } 00825 00826 public function getDescription() { 00827 return 'Return general information about the site.'; 00828 } 00829 00830 public function getPossibleErrors() { 00831 return array_merge( parent::getPossibleErrors(), array( array( 00832 'code' => 'includeAllDenied', 00833 'info' => 'Cannot view all servers info unless $wgShowHostnames is true' 00834 ), ) ); 00835 } 00836 00837 public function getExamples() { 00838 return array( 00839 'api.php?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics', 00840 'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local', 00841 'api.php?action=query&meta=siteinfo&siprop=dbrepllag&sishowalldb=', 00842 ); 00843 } 00844 00845 public function getHelpUrls() { 00846 return 'https://www.mediawiki.org/wiki/API:Meta#siteinfo_.2F_si'; 00847 } 00848 }