From 04a1021425e0b9a88c1b7c205a525982472170bc Mon Sep 17 00:00:00 2001 From: bsitu Date: Tue, 3 Sep 2013 13:43:40 -0700 Subject: [PATCH] Add a deferrable update class for callback/closure udpates Change-Id: Ifdf2a0937df50eb2f04d514b5cc2ef39a54ebe8f --- RELEASE-NOTES-1.22 | 1 + includes/AutoLoader.php | 1 + includes/CallableUpdate.php | 30 ++++++++++++++++++++++++++++++ includes/DeferredUpdates.php | 10 ++++++++++ 4 files changed, 42 insertions(+) create mode 100644 includes/CallableUpdate.php diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index b88e323dd4..24aaceb6a4 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -208,6 +208,7 @@ production. and Special:AllMyUploads respectively. * IPv6 addresses in X-Forwarded-For headers are now normalised before checking against allowed proxy lists. +* Add deferrable update support for callback/closure === Bug fixes in 1.22 === * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 82d204b138..677bed3f31 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -68,6 +68,7 @@ $wgAutoloadLocalClasses = array( 'CurlHttpRequest' => 'includes/HttpFunctions.php', 'DeferrableUpdate' => 'includes/DeferredUpdates.php', 'DeferredUpdates' => 'includes/DeferredUpdates.php', + 'MWCallableUpdate' => 'includes/CallableUpdate.php', 'DeprecatedGlobal' => 'includes/DeprecatedGlobal.php', 'DerivativeRequest' => 'includes/WebRequest.php', 'DiffHistoryBlob' => 'includes/HistoryBlob.php', diff --git a/includes/CallableUpdate.php b/includes/CallableUpdate.php new file mode 100644 index 0000000000..6eb5541393 --- /dev/null +++ b/includes/CallableUpdate.php @@ -0,0 +1,30 @@ +callback = $callback; + } + + /** + * Run the update + */ + public function doUpdate() { + call_user_func( $this->callback ); + } + +} diff --git a/includes/DeferredUpdates.php b/includes/DeferredUpdates.php index 89c4df68f8..a321414ae5 100644 --- a/includes/DeferredUpdates.php +++ b/includes/DeferredUpdates.php @@ -63,6 +63,16 @@ class DeferredUpdates { self::addUpdate( new HTMLCacheUpdate( $title, $table ) ); } + /** + * Add a callable update. In a lot of cases, we just need a callback/closure, + * defining a new DeferrableUpdate object is not necessary + * @see MWCallableUpdate::__construct() + * @param callable $callable + */ + public static function addCallableUpdate( $callable ) { + self::addUpdate( new MWCallableUpdate( $callable ) ); + } + /** * Do any deferred updates and clear the list * -- 2.20.1