Add applicable protection types to the prop=info API
authorRicordisamoa <ricordisamoa@openmailbox.org>
Fri, 26 Dec 2014 22:13:50 +0000 (23:13 +0100)
committerRicordisamoa <ricordisamoa@openmailbox.org>
Mon, 5 Jan 2015 21:03:45 +0000 (22:03 +0100)
Disabled by default, enabled with inprop=protections,
returned as 'restrictiontypes', also for non-existing titles.

Change-Id: I98604b60626b84bd8cb601a4149b80db1b6787b7

RELEASE-NOTES-1.25
includes/api/ApiQueryInfo.php

index 4a6ee94..0a37680 100644 (file)
@@ -165,6 +165,8 @@ production.
 * (T78737) action=expandtemplates can now return page properties.
 * (T78690) list=allimages now accepts multiple pipe-separated values
   for the 'aimime' parameter.
+* prop=info with inprop=protections will now return applicable protection types
+  with the 'restrictiontypes' key.
 
 === Action API internal changes in 1.25 ===
 * ApiHelp has been rewritten to support i18n and paginated HTML output.
index e6667b4..05a1a15 100644 (file)
@@ -42,7 +42,7 @@ class ApiQueryInfo extends ApiQueryBase {
        private $pageRestrictions, $pageIsRedir, $pageIsNew, $pageTouched,
                $pageLatest, $pageLength;
 
-       private $protections, $watched, $watchers, $notificationtimestamps,
+       private $protections, $restrictionTypes, $watched, $watchers, $notificationtimestamps,
                $talkids, $subjectids, $displaytitles;
        private $showZeroWatchers = false;
 
@@ -419,6 +419,13 @@ class ApiQueryInfo extends ApiQueryBase {
                                        $this->protections[$ns][$dbkey];
                        }
                        $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
+
+                       $pageInfo['restrictiontypes'] = array();
+                       if ( isset( $this->restrictionTypes[$ns][$dbkey] ) ) {
+                               $pageInfo['restrictiontypes'] =
+                                       $this->restrictionTypes[$ns][$dbkey];
+                       }
+                       $this->getResult()->setIndexedTagName( $pageInfo['restrictiontypes'], 'rt' );
                }
 
                if ( $this->fld_watched && isset( $this->watched[$ns][$dbkey] ) ) {
@@ -568,7 +575,8 @@ class ApiQueryInfo extends ApiQueryBase {
                        }
                }
 
-               // Cascading protections
+               // Separate good and missing titles into files and other pages
+               // and populate $this->restrictionTypes
                $images = $others = array();
                foreach ( $this->everything as $title ) {
                        if ( $title->getNamespace() == NS_FILE ) {
@@ -576,6 +584,9 @@ class ApiQueryInfo extends ApiQueryBase {
                        } else {
                                $others[] = $title;
                        }
+                       // Applicable protection types
+                       $this->restrictionTypes[$title->getNamespace()][$title->getDBkey()] =
+                               array_values( $title->getRestrictionTypes() );
                }
 
                if ( count( $others ) ) {