mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-24 00:05:00 +00:00
Handle session loss in the console
If the session data gets lost, the console forgets the content and previous commands. Detect this situation and handle it. Change-Id: I82fb5e111c09091d4f9a87d2e1b1c245eced1420
This commit is contained in:
parent
fddf05c056
commit
e878314048
|
@ -32,6 +32,7 @@ $1',
|
|||
'scribunto-console-previous-src' => 'previous console input',
|
||||
'scribunto-console-clear' => 'Clear',
|
||||
'scribunto-console-cleared' => 'The console state was cleared because the module was updated.',
|
||||
'scribunto-console-cleared-session-lost' => 'The console state was cleared because the session data was lost.',
|
||||
|
||||
|
||||
'scribunto-common-error-category' => 'Pages with script errors',
|
||||
|
@ -89,6 +90,8 @@ $messages['qqq'] = array(
|
|||
'scribunto-common-timeout' => 'Error message displayed when script execution has passed a threshold.',
|
||||
'scribunto-common-oom' => 'Error message displayed when the script requires more memory than the threshold.',
|
||||
'scribunto-common-backtrace' => 'A backtrace is a list of the function calls that are currently active in a thread. This message is followed by a backtrace.',
|
||||
'scribunto-console-cleared' => 'Message displayed in the console when the module source has been changed.',
|
||||
'scribunto-console-cleared-session-lost' => 'Message displayed in the console when the session has expired.',
|
||||
'scribunto-lua-in-function' => 'Reference to a function name. Parameters:
|
||||
* $1 is a function name.',
|
||||
'scribunto-lua-in-main' => 'Part of the backtrace creation routines. Refers to the main part of the code.',
|
||||
|
|
|
@ -82,6 +82,7 @@ $wgResourceModules['ext.scribunto.edit'] = $sbtpl + array(
|
|||
'scribunto-console-intro',
|
||||
'scribunto-console-clear',
|
||||
'scribunto-console-cleared',
|
||||
'scribunto-console-cleared-session-lost',
|
||||
),
|
||||
);
|
||||
$wgAPIModules['scribunto-console'] = 'ApiScribuntoConsole';
|
||||
|
|
|
@ -26,11 +26,13 @@ class ApiScribuntoConsole extends ApiBase {
|
|||
$sessionKey = wfMemcKey( 'scribunto-console', $wgUser->getId(), $sessionId );
|
||||
$cache = ObjectCache::getInstance( CACHE_ANYTHING );
|
||||
$session = null;
|
||||
$sessionIsNew = false;
|
||||
if ( $params['session'] ) {
|
||||
$session = $cache->get( $sessionKey );
|
||||
}
|
||||
if ( !isset( $session['version'] ) ) {
|
||||
$session = $this->newSession();
|
||||
$sessionIsNew = true;
|
||||
}
|
||||
|
||||
// Create a variable holding the session which will be stored if there
|
||||
|
@ -73,6 +75,9 @@ class ApiScribuntoConsole extends ApiBase {
|
|||
$result['session'] = $sessionId;
|
||||
$result['sessionSize'] = $newSession['size'];
|
||||
$result['sessionMaxSize'] = self::SC_MAX_SIZE;
|
||||
if ( $sessionIsNew ) {
|
||||
$result['sessionIsNew'] = '';
|
||||
}
|
||||
foreach ( $result as $key => $value ) {
|
||||
$this->getResult()->addValue( null, $key, $value );
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
}
|
||||
|
||||
if ( getContent() !== sessionContent ) {
|
||||
printClearBar();
|
||||
printClearBar( 'scribunto-console-cleared' );
|
||||
clearNextRequest = true;
|
||||
}
|
||||
}
|
||||
|
@ -128,10 +128,10 @@
|
|||
div.insertBefore( head, div.firstChild );
|
||||
}
|
||||
|
||||
function printClearBar() {
|
||||
function printClearBar( msg ) {
|
||||
$( '<div/>' )
|
||||
.attr( 'class', 'mw-scribunto-clear' )
|
||||
.text( mw.msg( 'scribunto-console-cleared' ) )
|
||||
.text( mw.msg( msg ) )
|
||||
.appendTo( _out );
|
||||
}
|
||||
|
||||
|
@ -251,9 +251,11 @@
|
|||
};
|
||||
|
||||
var content = getContent();
|
||||
var sentContent = false;
|
||||
if ( !sessionKey || sessionContent !== content ) {
|
||||
params.clear = true;
|
||||
params.content = content;
|
||||
sentContent = true;
|
||||
}
|
||||
if ( sessionKey ) {
|
||||
params.session = sessionKey;
|
||||
|
@ -268,6 +270,15 @@
|
|||
|
||||
api.post( params, {
|
||||
ok: function ( result ) {
|
||||
if ( result.sessionIsNew === '' && !sentContent ) {
|
||||
// Session was lost. Resend query, with content
|
||||
printClearBar( 'scribunto-console-cleared-session-lost' );
|
||||
sessionContent = null;
|
||||
clearPending();
|
||||
_in.value = params.question;
|
||||
go();
|
||||
return;
|
||||
}
|
||||
sessionKey = result.session;
|
||||
sessionContent = content;
|
||||
if ( result.type === 'error' ) {
|
||||
|
|
Loading…
Reference in a new issue