Skip to content
This repository was archived by the owner on Sep 23, 2023. It is now read-only.

Allow site config to be overridden by JSON #60

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions LocalSettings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

3 changes: 3 additions & 0 deletions createwiki.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@
// 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;
input.parentNode.classList.toggle( 'oo-ui-widget-disabled', !!disabled );
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;
} );
Expand Down
31 changes: 28 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,29 @@
'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 <strong><code>$wg</code></strong> prefix.<br/>This file will be <strong>public</strong>.' ),
'helpInline' => true,
'align' => 'left',
]
),
new DetailsFieldLayout(
new OOUI\CheckboxMultiselectInputWidget( [
'name' => 'repos[]',
'options' => $repoOptions,
'value' => array_keys( $repoData ),
] ),
[
'label' => 'Choose extensions to enable (default: all):',
'label' => 'Choose extensions to enable:',
'help' => new OOUI\HtmlSnippet( '<br/>Defaults to all' ),
'helpInline' => true,
'align' => 'left',
]
),
Expand Down Expand Up @@ -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
Expand All @@ -169,7 +186,8 @@
$wikis[ $dir ] = [
'mtime' => $created,
'title' => $title,
'creator' => $creator
'creator' => $creator,
'hasConfig' => $hasConfig,
];
}
}
Expand All @@ -190,7 +208,13 @@
$anyCanDelete = $anyCanDelete || $canDelete;
$rows .= '<tr' . ( $creator !== $username ? ' class="other"' : '' ) . '>' .
'<td class="title">' . ( $title ?: '<em>No patches</em>' ) . '</td>' .
'<td><a href="wikis/' . $wiki . '/w">' . $wiki . '</a></td>' .
'<td>' .
( !empty( $data[ 'hasConfig' ] ) ?
'<a href="wikis/' . $wiki . '/w/config.json">JSON</a>' :
''
) .
'</td>' .
'<td><a href="wikis/' . $wiki . '/w">' . substr( $wiki, 0, 20 ) . '&hellip;</a></td>' .
'<td class="date">' . date( 'c', $data[ 'mtime' ] ) . '</td>' .
( $useOAuth ? '<td>' . ( $creator ? user_link( $creator ) : '?' ) . '</td>' : '' ) .
( $canDelete ?
Expand All @@ -202,6 +226,7 @@

echo '<tr>' .
'<th>Patches</th>' .
'<th>Config</th>' .
'<th>Link</th>' .
'<th>Time</th>' .
( $useOAuth ? '<th>Creator</th>' : '' ) .
Expand Down
2 changes: 2 additions & 0 deletions new.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -180,6 +181,7 @@
'WIKINAME' => $wikiName,
'CREATOR' => $user ? $user->username : '',
'MAINPAGE' => $mainPage,
'SITECONFIG' => $siteConfig,
'SERVER' => $server,
'SERVERPATH' => $serverPath,
'COMPOSER_HOME' => __DIR__ . '/composer',
Expand Down