diff --git a/LocalSettings.txt b/LocalSettings.txt index 20b58c5c..d3fb7cad 100644 --- a/LocalSettings.txt +++ b/LocalSettings.txt @@ -63,3 +63,16 @@ $wgGENewcomerTasksRemoteApiUrl = 'https://en.wikipedia.org/w/api.php'; $wgGENewcomerTasksTopicType = 'ores'; $wgWelcomeSurveyExperimentalGroups['exp2_target_specialpage']['range'] = '0-9'; $wgGEHomepageMentorsList = 'Project:GrowthExperiments_mentors'; + +// Apply config.json +$config = json_decode( + file_get_contents( 'config.json' ), + true +); +if ( $config ) { + foreach ( $config as $key => $value ) { + $name = "wg$key"; + $$name = $value; + } +} + diff --git a/createwiki.sh b/createwiki.sh index 8c9b7127..3c10a215 100755 --- a/createwiki.sh +++ b/createwiki.sh @@ -49,6 +49,9 @@ date +%s > $PATCHDEMO/wikis/$NAME/created.txt # apply our default settings cat $PATCHDEMO/LocalSettings.txt >> $PATCHDEMO/wikis/$NAME/w/LocalSettings.php +# add site config +echo "$SITECONFIG" >> $PATCHDEMO/wikis/$NAME/w/config.json + # update Main_Page sleep 1 # Ensure edit appears after creation in history echo "$MAINPAGE" | php $PATCHDEMO/wikis/$NAME/w/maintenance/edit.php "Main_Page" diff --git a/index.js b/index.js index c368fc47..4b4dc199 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,8 @@ // TODO: Use infuse to control OOUI widgets var myWikis, wikisTable, branchSelect, form = document.getElementById( 'new-form' ), - submit = form.querySelector( 'button[type=submit]' ); + submit = form.querySelector( 'button[type=submit]' ), + siteConfig = form.querySelector( '[name=siteConfig]' ); function setDisabled( input, disabled ) { input.disabled = disabled; @@ -10,7 +11,17 @@ input.parentNode.classList.toggle( 'oo-ui-widget-enabled', !disabled ); } - form.addEventListener( 'submit', function () { + form.addEventListener( 'submit', function ( e ) { + if ( siteConfig.value.trim() ) { + try { + JSON.parse( siteConfig.value ); + } catch ( err ) { + e.preventDefault(); + // eslint-disable-next-line no-alert + alert( 'Invalid JSON: ' + err.message ); + return; + } + } setDisabled( submit, true ); return false; } ); diff --git a/index.php b/index.php index af3642a5..1f3bf169 100644 --- a/index.php +++ b/index.php @@ -68,6 +68,19 @@ 'align' => 'left', ] ), + new OOUI\FieldLayout( + new OOUI\MultilineTextInputWidget( [ + 'name' => 'siteConfig', + 'placeholder' => "{\n \"Sitename\": \"Test wiki\"\n}", + 'rows' => 4, + ] ), + [ + 'label' => 'Site config:', + 'help' => new OOUI\HtmlSnippet( 'All keys will be given a $wg prefix.
This file will be public.' ), + 'helpInline' => true, + 'align' => 'left', + ] + ), new DetailsFieldLayout( new OOUI\CheckboxMultiselectInputWidget( [ 'name' => 'repos[]', @@ -75,7 +88,9 @@ 'value' => array_keys( $repoData ), ] ), [ - 'label' => 'Choose extensions to enable (default: all):', + 'label' => 'Choose extensions to enable:', + 'help' => new OOUI\HtmlSnippet( '
Defaults to all' ), + 'helpInline' => true, 'align' => 'left', ] ), @@ -157,6 +172,8 @@ } $creator = get_creator( $dir ); $created = get_created( $dir ); + $siteConfig = get_if_file_exists( 'wikis/' . $dir . '/w/config.json' ); + $hasConfig = $siteConfig && strlen( trim( $siteConfig ) ); if ( !$created ) { // Add created.txt to old wikis @@ -169,7 +186,8 @@ $wikis[ $dir ] = [ 'mtime' => $created, 'title' => $title, - 'creator' => $creator + 'creator' => $creator, + 'hasConfig' => $hasConfig, ]; } } @@ -190,7 +208,13 @@ $anyCanDelete = $anyCanDelete || $canDelete; $rows .= '' . '' . ( $title ?: 'No patches' ) . '' . - '' . $wiki . '' . + '' . + ( !empty( $data[ 'hasConfig' ] ) ? + 'JSON' : + '' + ) . + '' . + '' . substr( $wiki, 0, 20 ) . '…' . '' . date( 'c', $data[ 'mtime' ] ) . '' . ( $useOAuth ? '' . ( $creator ? user_link( $creator ) : '?' ) . '' : '' ) . ( $canDelete ? @@ -202,6 +226,7 @@ echo '' . 'Patches' . + 'Config' . 'Link' . 'Time' . ( $useOAuth ? 'Creator' : '' ) . diff --git a/new.php b/new.php index 61825a01..593f3938 100644 --- a/new.php +++ b/new.php @@ -6,6 +6,7 @@ $branch = trim( $_POST['branch'] ); $patches = trim( $_POST['patches'] ); +$siteConfig = trim( $_POST['siteConfig'] ); $namePath = md5( $branch . $patches . time() ); $server = ( isset( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST']; @@ -180,6 +181,7 @@ 'WIKINAME' => $wikiName, 'CREATOR' => $user ? $user->username : '', 'MAINPAGE' => $mainPage, + 'SITECONFIG' => $siteConfig, 'SERVER' => $server, 'SERVERPATH' => $serverPath, 'COMPOSER_HOME' => __DIR__ . '/composer',