From 68597a13452820b6e457a3ee8e4f6fe2aa9da00d Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Sat, 2 Jun 2012 22:34:18 +0200 Subject: [PATCH] Allow API meta=siteinfo to return list of know variable IDs To know whether something like {{foo}} is a template, variable, or function, you have to first check if it's a magic word, and then look up the magic word ID in the list of variables and the list of function hooks. The API already can return the list of known magic word mappings (siprop=magicwords) and function hooks (siprop=functionhooks), this completes the set by allowing siprop=variables. Change-Id: If13df9c3796ea6815393d847a3c6f70380bba58a --- RELEASE-NOTES-1.20 | 1 + includes/api/ApiQuerySiteinfo.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index cff8a8c5c6..a62a471e6a 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -175,6 +175,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki. * (bug 32382) Allow descending order for list=iwbacklinks * (bug 32381) Allow descending order for list=backlinks, list=embeddedin and list=imageusage * (bug 32383) Allow descending order for list=langbacklinks +* API meta=siteinfo can now return the list of known variable IDs === Languages updated in 1.20 === diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 38e37c0186..5316006031 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -93,6 +93,9 @@ class ApiQuerySiteinfo extends ApiQueryBase { case 'showhooks': $fit = $this->appendSubscribedHooks( $p ); break; + case 'variables': + $fit = $this->appendVariables( $p ); + break; default: ApiBase::dieDebug( __METHOD__, "Unknown prop=$p" ); } @@ -532,6 +535,12 @@ class ApiQuerySiteinfo extends ApiQueryBase { return $this->getResult()->addValue( 'query', $property, $hooks ); } + public function appendVariables( $property ) { + $variables = MagicWord::getVariableIDs(); + $this->getResult()->setIndexedTagName( $variables, 'v' ); + return $this->getResult()->addValue( 'query', $property, $variables ); + } + private function formatParserTags( $item ) { return "<{$item}>"; } @@ -583,6 +592,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { 'extensiontags', 'functionhooks', 'showhooks', + 'variables', ) ), 'filteriw' => array( @@ -618,7 +628,8 @@ class ApiQuerySiteinfo extends ApiQueryBase { ' skins - Returns a list of all enabled skins', ' extensiontags - Returns a list of parser extension tags', ' functionhooks - Returns a list of parser function hooks', - ' showhooks - Returns a list of all subscribed hooks (contents of $wgHooks)' + ' showhooks - Returns a list of all subscribed hooks (contents of $wgHooks)', + ' variables - Returns a list of variable IDs', ), 'filteriw' => 'Return only local or only nonlocal entries of the interwiki map', 'showalldb' => 'List all database servers, not just the one lagging the most', -- 2.20.1