From 32083235eb332c419df2063cf966b3400be7ee8a Mon Sep 17 00:00:00 2001 From: Ricordisamoa Date: Fri, 26 Dec 2014 23:13:50 +0100 Subject: [PATCH] Add applicable protection types to the prop=info API Disabled by default, enabled with inprop=protections, returned as 'restrictiontypes', also for non-existing titles. Change-Id: I98604b60626b84bd8cb601a4149b80db1b6787b7 --- RELEASE-NOTES-1.25 | 2 ++ includes/api/ApiQueryInfo.php | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 4a6ee94750..0a37680d7b 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -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. diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index e6667b4026..05a1a15604 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -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 ) ) { -- 2.20.1