From 909203b36658999d5012d2834aa3cb8b8400e560 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sun, 4 May 2008 15:10:58 +0000 Subject: [PATCH] (bug 13945) API: Retrieve cascading protection sources via inprop=protection --- RELEASE-NOTES | 1 + includes/api/ApiQueryInfo.php | 71 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2b2e4c05f3..554ff11b3e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -298,6 +298,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 13836) Fixed fatal errors resulting from combining iiprop=metadata with format=xml * (bug 13735) Added prop=categoryinfo module +* (bug 13945) Retrieve cascading protection sources via inprop=protection === Languages updated in 1.13 === diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index adc8449597..b25d9afb18 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -103,6 +103,77 @@ class ApiQueryInfo extends ApiQueryBase { $protections[$row->pr_page][] = $a; } $db->freeResult($res); + + $imageIds = array(); + foreach ($titles as $id => $title) + if ($title->getNamespace() == NS_IMAGE) + $imageIds[] = $id; + + if (count($imageIds) != count($titles)) { + // Check for cascading protection for non images + $this->resetQueryParams(); + $this->addTables(array('page_restrictions', 'templatelinks')); + $this->addTables('page', 'page_source'); + $this->addTables('page', 'page_target'); + $this->addFields(array('pr_type', 'pr_level', 'pr_expiry', + 'page_target.page_id AS page_target_id', + 'page_source.page_namespace AS page_source_namespace', + 'page_source.page_title AS page_source_title')); + $this->addWhere(array('tl_from = pr_page', + 'page_target.page_namespace = tl_namespace', + 'page_target.page_title = tl_title', + 'page_source.page_id = pr_page' + )); + $this->addWhereFld('pr_cascade', 1); + $this->addWhereFld('page_target.page_id', array_diff(array_keys($titles), $imageIds)); + + $res = $this->select(__METHOD__); + while($row = $db->fetchObject($res)) { + $source = Title::makeTitle($row->page_source_namespace, $row->page_source_title); + $a = array( + 'type' => $row->pr_type, + 'level' => $row->pr_level, + 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ), + 'source' => $source->getPrefixedText() + ); + $protections[$row->page_target_id][] = $a; + } + $db->freeResult($res); + } + + if (count($imageIds) != 0) { + // Check for cascading protection for non images + $this->resetQueryParams(); + $this->addTables(array('page_restrictions', 'imagelinks')); + $this->addTables('page', 'page_source'); + $this->addTables('page', 'page_target'); + $this->addFields(array('pr_type', 'pr_level', 'pr_expiry', + 'page_target.page_id AS page_target_id', + 'page_source.page_namespace AS page_source_namespace', + 'page_source.page_title AS page_source_title')); + $this->addWhere(array('il_from = pr_page', + 'page_target.page_namespace = '.NS_IMAGE, + 'page_target.page_title = il_to', + 'page_source.page_id = pr_page' + )); + $this->addWhereFld('pr_cascade', 1); + $this->addWhereFld('page_target.page_id', $imageIds); + + $res = $this->select(__METHOD__); + while($row = $db->fetchObject($res)) { + $source = Title::makeTitle($row->page_source_namespace, $row->page_source_title); + $a = array( + 'type' => $row->pr_type, + 'level' => $row->pr_level, + 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ), + + 'source' => $source->getPrefixedText() + ); + $protections[$row->page_target_id][] = $a; + } + $db->freeResult($res); + } + } // We don't need to check for pt stuff if there are no nonexistent titles if($fld_protection && !empty($missing)) -- 2.20.1