ApiQuerySiteinfo: Add prop=restrictions for protection information
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 6 Feb 2014 15:30:00 +0000 (16:30 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 6 Feb 2014 15:51:37 +0000 (16:51 +0100)
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

RELEASE-NOTES-1.23
includes/api/ApiQuerySiteinfo.php

index 59118bd..42fd16b 100644 (file)
@@ -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 ===
 
index 9cf3afd..a078013 100644 (file)
@@ -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',