From f53780d1a4201e4af9d4fd2f61db695b5f1f852a Mon Sep 17 00:00:00 2001 From: umherirrender Date: Wed, 26 Sep 2012 10:30:53 +0200 Subject: [PATCH] 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 --- includes/api/ApiMain.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 * -- 2.20.1