From: Bartosz DziewoƄski Date: Thu, 6 Feb 2014 15:30:00 +0000 (+0100) Subject: ApiQuerySiteinfo: Add prop=restrictions for protection information X-Git-Tag: 1.31.0-rc.0~16989^2 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=b73b5883d486db0e9278ef16733551f28d9e096d;p=lhc%2Fweb%2Fwiklou.git ApiQuerySiteinfo: Add prop=restrictions for protection information As pointed out on VPT, we previously had no way to find out about these. This just dumps the raw config variables for now. They are documented in DefaultSettings as having some magic applied to them when used, maybe we should apply this magic here too, or in Setup.php? https://en.wikipedia.org/w/index.php?title=Wikipedia:Village_pump_(technical)&oldid=594218538#API_query_to_list_available_protection_levels_for_a_wiki.3F Change-Id: I4c1303f2a6fe6b60b44e960cc1253c555fc658dc --- diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index 59118bdfd4..42fd16b052 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -158,6 +158,8 @@ production. * (bug 32151) ApiWatch now has pageset capabilities (titles/pageids/generators). Title parameter is now deprecated. * (bug 23005) Added action=revisiondelete. +* Added siprop=restrictions to API action=query&meta=siteinfo for querying + possible page restriction (protection) levels and types. === Languages updated in 1.23 === diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 9cf3afd563..a07801369e 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -78,6 +78,9 @@ class ApiQuerySiteinfo extends ApiQueryBase { case 'rightsinfo': $fit = $this->appendRightsInfo( $p ); break; + case 'restrictions': + $fit = $this->appendRestrictions( $p ); + break; case 'languages': $fit = $this->appendLanguages( $p ); break; @@ -615,6 +618,25 @@ class ApiQuerySiteinfo extends ApiQueryBase { return $this->getResult()->addValue( 'query', $property, $data ); } + protected function appendRestrictions( $property ) { + global $wgRestrictionTypes, $wgRestrictionLevels, + $wgCascadingRestrictionLevels, $wgSemiprotectedRestrictionLevels; + + $data = array( + 'types' => $wgRestrictionTypes, + 'levels' => $wgRestrictionLevels, + 'cascadinglevels' => $wgCascadingRestrictionLevels, + 'semiprotectedlevels' => $wgSemiprotectedRestrictionLevels, + ); + + $this->getResult()->setIndexedTagName( $data['types'], 'type' ); + $this->getResult()->setIndexedTagName( $data['levels'], 'level' ); + $this->getResult()->setIndexedTagName( $data['cascadinglevels'], 'level' ); + $this->getResult()->setIndexedTagName( $data['semiprotectedlevels'], 'level' ); + + return $this->getResult()->addValue( 'query', $property, $data ); + } + public function appendLanguages( $property ) { $params = $this->extractRequestParams(); $langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : ''; @@ -737,6 +759,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { 'extensions', 'fileextensions', 'rightsinfo', + 'restrictions', 'languages', 'skins', 'extensiontags', @@ -778,6 +801,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { ' extensions - Returns extensions installed on the wiki', ' fileextensions - Returns list of file extensions allowed to be uploaded', ' rightsinfo - Returns wiki rights (license) information if available', + ' restrictions - Returns information on available restriction (protection) types', ' languages - Returns a list of languages MediaWiki supports' . "(optionally localised by using {$p}inlanguagecode)", ' skins - Returns a list of all enabled skins',