Add ApiBeforeMain hook
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 12 Dec 2013 15:01:33 +0000 (10:01 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Thu, 12 Dec 2013 15:01:33 +0000 (10:01 -0500)
$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
api.php
docs/hooks.txt

index 7fe4762..3e77434 100644 (file)
@@ -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 8fab878..51bb2ad 100644 (file)
--- 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();
 
index e3387b5..de87963 100644 (file)
@@ -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.