From 5a7e9ba954c9b0556269be941080cd8c8fd10ff0 Mon Sep 17 00:00:00 2001 From: Amir Sarabadani Date: Thu, 31 May 2018 16:03:47 +0200 Subject: [PATCH] Introduce ApiMaxLagInfo hook This will be useful when an extension does something expensive and wants to make sure users don't put too much pressure on the system. Bug: T194950 Change-Id: I8a396d07c2d5764a680d0e5536cd1f99edbe141e --- RELEASE-NOTES-1.32 | 2 ++ docs/hooks.txt | 12 ++++++++++++ includes/api/ApiMain.php | 2 ++ 3 files changed, 16 insertions(+) diff --git a/RELEASE-NOTES-1.32 b/RELEASE-NOTES-1.32 index 13d15c2ebd..e363c7e8bf 100644 --- a/RELEASE-NOTES-1.32 +++ b/RELEASE-NOTES-1.32 @@ -33,6 +33,7 @@ production. temporary user groups. * (T152462) A cookie can now be set when an IP user is blocked to track that user if they move to a new IP address. This is disabled by default. +* (T194950) Added 'ApiMaxLagInfo' hook. === External library changes in 1.32 === * … @@ -66,6 +67,7 @@ production. * Added 'ApiParseMakeOutputPage' hook. * Parameter names may no longer contain '{' or '}', as these are now used for templated parameters. +* (T194950) Added 'ApiMaxLagInfo' hook. === Languages updated in 1.32 === MediaWiki supports over 350 languages. Many localisations are updated regularly. diff --git a/docs/hooks.txt b/docs/hooks.txt index 349cd4b5e6..8c84509b56 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2265,6 +2265,18 @@ $wcOnlySysopsCanPatrol: config setting indicating whether the user must be a sysop to patrol the edit. $auto: true if the edit is being marked as patrolled automatically +'ApiMaxLagInfo': When lag information is being requested via API. Use this to +override lag information. Generally a hook function should only replace +$lagInfo if the new $lagInfo['lag'] is greater than the current $lagInfo['lag']. +&$lagInfo: Maximum lag information array. Fields in the array are: + 'lag' is the number of seconds of lag. + 'host' is the host name on which the lag exists. + 'type' is an indication of the type of lag, + e.g. "db" for database replication lag or "jobqueue" for job queue size + converted to pseudo-seconds. + It is possible to add more fields and they will be returned to the user in + the API response. + 'MediaWikiPerformAction': Override MediaWiki::performAction(). Use this to do something completely different, after the basic globals have been set up, but before ordinary actions take place. diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 914d8e9786..c0c489555d 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1258,6 +1258,8 @@ class ApiMain extends ApiBase { } } + Hooks::runWithoutAbort( 'ApiMaxLagInfo', [ &$lagInfo ] ); + return $lagInfo; } -- 2.20.1