From: umherirrender Date: Wed, 26 Sep 2012 08:30:53 +0000 (+0200) Subject: Add warning for unused params inside api X-Git-Tag: 1.31.0-rc.0~22196 X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=f53780d1a4201e4af9d4fd2f61db695b5f1f852a;p=lhc%2Fweb%2Fwiklou.git Add warning for unused params inside api Now MediaWiki knows all used params, it can be helpful to get a list of unused params. This can be spelling issues or the missing 'g' for generator modules. When the client knows about this, he can correct them. Change-Id: I221b7cd02bed4a38aba161dc3f85eb8fd2aad52c --- diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index bfc49336e8..87a287b31a 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -821,6 +821,8 @@ class ApiMain extends ApiBase { $module->profileOut(); if ( !$this->mInternalMode ) { + // Report unused params + $this->reportUnusedParams(); //append Debug information MWDebug::appendDebugInfoToApiResult( $this->getContext(), $this->getResult() ); @@ -897,6 +899,21 @@ class ApiMain extends ApiBase { return $this->getRequest()->getCheck( $name ); } + /** + * Report unused parameters, so the client gets a hint in case it gave us parameters we don't know, + * for example in case of spelling mistakes or a missing 'g' prefix for generators. + */ + protected function reportUnusedParams() { + $paramsUsed = $this->getParamsUsed(); + $allParams = $this->getRequest()->getValueNames(); + + $unusedParams = array_diff( $allParams, $paramsUsed ); + if( count( $unusedParams ) ) { + $s = count( $unusedParams ) > 1 ? 's' : ''; + $this->setWarning( "Unrecognized parameter$s: '" . implode( $unusedParams, "', '" ) . "'" ); + } + } + /** * Print results using the current printer *