From 76c61632f79b6b3aa834ccaba73c845a75c75b40 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 12 Dec 2013 10:01:33 -0500 Subject: [PATCH] Add ApiBeforeMain hook $wgExtensionFunctions is called before the RequestContext is really available (i.e. getTitle() is null, accessing the User object may fail because other extensions' UserLoadFromSession hooks don't expect to be called that early, etc). The index.php code path has BeforeInitialize to take action after RequestContext is available but before much else happens, but the API doesn't (yet) have anything similar. Bug: 58380 Change-Id: I0a167faaa4166da381194c53373d82e038848924 --- RELEASE-NOTES-1.23 | 3 +++ api.php | 3 +++ docs/hooks.txt | 3 +++ 3 files changed, 9 insertions(+) diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index 7fe476202e..3e7743454c 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -54,6 +54,9 @@ production. * (bug 52005) Special pages RecentChanges, RecentChangesLinked and Watchlist now include a legend describing the symbols used in lists of changes. * Improved the accessibility of the tabs in Special:Preferences. +* Added ApiBeforeMain hook, roughly equivalent to the BeforeInitialize hook: + it's called after everything is set up but before any major processing + happens. === Bug fixes in 1.23 === * (bug 41759) The "updated since last visit" markers (on history pages, recent diff --git a/api.php b/api.php index 8fab878cfa..51bb2ad31a 100644 --- a/api.php +++ b/api.php @@ -69,6 +69,9 @@ $wgTitle = Title::makeTitle( NS_MAIN, 'API' ); */ $processor = new ApiMain( RequestContext::getMain(), $wgEnableWriteAPI ); +// Last chance hook before executing the API +wfRunHooks( 'ApiBeforeMain', array( &$processor ) ); + // Process data & print results $processor->execute(); diff --git a/docs/hooks.txt b/docs/hooks.txt index e3387b5578..de87963b62 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -347,6 +347,9 @@ $body: Body of the message this to extend core API modules. &$module: Module object +'ApiBeforeMain': Before calling ApiMain's execute() method in api.php. +&$main: ApiMain object + 'ApiCheckCanExecute': Called during ApiMain::checkCanExecute. Use to further authenticate and authorize API clients before executing the module. Return false and set a message to cancel the request. -- 2.20.1