Introduce ApiMaxLagInfo hook
authorAmir Sarabadani <ladsgroup@gmail.com>
Thu, 31 May 2018 14:03:47 +0000 (16:03 +0200)
committerAmir Sarabadani <ladsgroup@gmail.com>
Tue, 5 Jun 2018 17:46:09 +0000 (19:46 +0200)
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
docs/hooks.txt
includes/api/ApiMain.php

index 13d15c2..e363c7e 100644 (file)
@@ -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.
index 349cd4b..8c84509 100644 (file)
@@ -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.
index 914d8e9..c0c4895 100644 (file)
@@ -1258,6 +1258,8 @@ class ApiMain extends ApiBase {
                        }
                }
 
+               Hooks::runWithoutAbort( 'ApiMaxLagInfo', [ &$lagInfo ] );
+
                return $lagInfo;
        }