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
271 additions
and
158 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,57 @@ | ||
/* global OO, pd */ | ||
( function () { | ||
window.pd = window.pd || {}; | ||
|
||
pd.installProgressField = OO.ui.infuse( | ||
document.getElementsByClassName( 'installProgressField' )[ 0 ] | ||
); | ||
|
||
pd.installProgressField.fieldWidget.pushPending(); | ||
|
||
pd.openWiki = OO.ui.infuse( | ||
document.getElementsByClassName( 'openWiki' )[ 0 ] | ||
); | ||
|
||
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 () { | ||
var log = ''; | ||
var offset = 0; | ||
// eslint-disable-next-line no-jquery/no-global-selector | ||
var $log = $( '.newWikiLog' ); | ||
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,33 @@ | ||
<?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 { | ||
// TODO: De-duplicate with new.php | ||
$err = 'Log not found.'; | ||
echo $err; | ||
$errJson = json_encode( $err ); | ||
echo <<<EOT | ||
<script> | ||
pd.installProgressField.fieldWidget.setDisabled( true ); | ||
pd.installProgressField.fieldWidget.popPending(); | ||
pd.installProgressField.setErrors( [ new OO.ui.HtmlSnippet( $errJson ) ] ); | ||
pd.notify( 'Your PatchDemo wiki failed to build', $errJson ); | ||
pd.finished = true; | ||
</script> | ||
EOT; | ||
} |
Oops, something went wrong.