This repository has been archived by the owner on Sep 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create wikis in a background process
* The form now points to start.php, which converts allowed POST data to environment variables and sends them to new.php * The output is written to log files in log/*.html which are then polled by the JS for new content every second * Logs are only deleted when the wiki is deleted, allowing for debugging and inspection by other users. Fixes #399, #336
- Loading branch information
Showing
9 changed files
with
304 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* global OO, pd */ | ||
( function () { | ||
window.pd = window.pd || {}; | ||
|
||
var installProgressField = OO.ui.infuse( | ||
document.getElementsByClassName( 'installProgressField' )[ 0 ] | ||
); | ||
|
||
installProgressField.fieldWidget.pushPending(); | ||
|
||
var openWiki = OO.ui.infuse( | ||
document.getElementsByClassName( 'openWiki' )[ 0 ] | ||
); | ||
|
||
function endProgress() { | ||
installProgressField.fieldWidget.popPending(); | ||
pd.finished = true; | ||
} | ||
|
||
pd.abandon = function ( html ) { | ||
installProgressField.fieldWidget.setDisabled( true ); | ||
installProgressField.setErrors( [ new OO.ui.HtmlSnippet( html ) ] ); | ||
pd.notify( 'Your PatchDemo wiki failed to build', html ); | ||
endProgress(); | ||
}; | ||
|
||
pd.setProgress = function ( pc, label ) { | ||
installProgressField.fieldWidget.setProgress( pc ); | ||
installProgressField.setLabel( label ); | ||
if ( pc === 100 ) { | ||
openWiki.setDisabled( false ); | ||
pd.notify( 'Your PatchDemo wiki is ready!' ); | ||
endProgress(); | ||
} | ||
}; | ||
|
||
pd.notify = function ( message, body ) { | ||
if ( 'Notification' in window && +localStorage.getItem( 'patchdemo-notifications' ) ) { | ||
// eslint-disable-next-line no-new | ||
new Notification( | ||
message, | ||
{ | ||
icon: './images/favicon-32x32.png', | ||
body: body | ||
} | ||
); | ||
} | ||
}; | ||
|
||
$( function () { | ||
// eslint-disable-next-line no-jquery/no-global-selector | ||
var $log = $( '.newWikiLog' ); | ||
var log = ''; | ||
var offset = 0; | ||
function poll() { | ||
$.get( 'log.php', { | ||
wiki: pd.wiki, | ||
offset: offset | ||
} ).then( function ( result ) { | ||
if ( result ) { | ||
// result can be unbalanced HTML, so store it in | ||
// a string and rewrite the whole thing each time | ||
log += result; | ||
$log.html( log ); | ||
offset += result.length; | ||
} | ||
if ( !pd.finished ) { | ||
setTimeout( poll, 1000 ); | ||
} | ||
} ); | ||
} | ||
|
||
poll(); | ||
|
||
// Add wiki to URL so that page can be shared/reloaded | ||
history.replaceState( null, '', 'start.php?wiki=' + pd.wiki ); | ||
} ); | ||
|
||
}() ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
$offset = $_GET['offset']; | ||
$wiki = $_GET['wiki']; | ||
|
||
if ( !preg_match( '/^[0-9a-f]{10,32}$/', $wiki ) ) { | ||
die( 'Invalid wiki name.' ); | ||
} | ||
|
||
$file = 'logs/' . $wiki . '.html'; | ||
|
||
if ( file_exists( $file ) ) { | ||
echo file_get_contents( | ||
$file, | ||
false, | ||
null, | ||
$offset | ||
); | ||
} else { | ||
echo "<script>pd.abandon( 'Log not found.' );</script>"; | ||
} |
Oops, something went wrong.