(bug 45684) Add support for pausing timers

Sometimes a PHP callback will need to do things that shouldn't be
counted against the normal Lua usage timer. Support this by adding
methods pauseUsageTimer() and unpauseUsageTimer() to the LuaSandbox
class.

Note this doesn't actually close bug 45684, but it is necessary for the
change to the Scribunto extension that will close it.

== Timers ==

Pausing affects the "normal" CPU limit and the usage reported by
getCPUUsage() in PHP and os.clock() in Lua. The "emergency" CPU limit is
*not* affected.

To avoid issues with precision when timers are repeatedly stopped and
started, the timer for the "normal" limit is not actually stopped when
the timer is paused. Instead, the pause timestamp is recorded on pause,
and the delta is accumulated on unpause. The accumulated delta is folded
into the usage and the normal limit time remaining when the timers
actually are stopped, when the limit is reset, or when the normal timer
expires.

Since the normal limit timer is not actually stopped, there are three
possibilities when the timer fires:
1. Timers are paused: A flag is set, so the normal limit timer can be
   restarted with the accumulated delta on unpause.
2. There is an accumulated delta: The timer is restarted with that
   delta.
3. Otherwise, the normal "timeout error" hook is hooked.

== PHP interface ==

Inside a PHP callback from Lua, pauseUsageTimer() may be called to pause
the timers as described above, and unpauseUsageTimer() may be called to
unpause them. In addition, the timers will be automatically unpaused
when the PHP callback returns. If the PHP callback having timers paused
itself calls back into Lua, the timers will be unpaused for the duration
of the Lua call and automatically paused again when the Lua call
returns, before control returns to PHP.

pauseUsageTimer() will be disabled whenever a PHP callback not having
timers paused itself calls back into Lua. This prevents offloading of
expensive processing via something like this:

 -- This is cheap, because the underlying PHP call for __index uses
 -- pauseUsageTimer()
 function cheap( frame )
     return frame.args[1]
 end

 -- This would be expensive, because the underlying PHP call does not
 -- use pauseUsageTimer()
 function expensive( frame )
     frame:preprocess( '{{expensive}}' )
 end

 -- Here, the cost of processing '{{expensive}}' is offloaded into
 -- cheap's access of frame.args[1] where it wouldn't count against the
 -- CPU limit.
 -- Disabling pauseUsageTimer() when preprocess calls cheap closes the
 -- hole.
 function cheat( frame )
     frame:preprocess( '{{#invoke:Cheater|cheap| {{expensive}} }}' )
 end

Bug: 45684
Change-Id: I11881232527c341e4329f041247d5b2bbbdee8c7