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

Commit 556f118

Browse files
committed
Allow site config to be overridden by JSON
Fixes #19
1 parent fad4d87 commit 556f118

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

LocalSettings.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,16 @@ $wgGENewcomerTasksRemoteApiUrl = 'https://en.wikipedia.org/w/api.php';
6363
$wgGENewcomerTasksTopicType = 'ores';
6464
$wgWelcomeSurveyExperimentalGroups['exp2_target_specialpage']['range'] = '0-9';
6565
$wgGEHomepageMentorsList = 'Project:GrowthExperiments_mentors';
66+
67+
// Apply config.json
68+
$config = json_decode(
69+
file_get_contents( 'config.json' ),
70+
true
71+
);
72+
if ( $config ) {
73+
foreach ( $config as $key => $value ) {
74+
$name = "wg$key";
75+
$$name = $value;
76+
}
77+
}
78+

createwiki.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ date +%s > $PATCHDEMO/wikis/$NAME/created.txt
4949
# apply our default settings
5050
cat $PATCHDEMO/LocalSettings.txt >> $PATCHDEMO/wikis/$NAME/w/LocalSettings.php
5151

52+
# add site config
53+
echo "$SITECONFIG" >> $PATCHDEMO/wikis/$NAME/w/config.json
54+
5255
# update Main_Page
5356
sleep 1 # Ensure edit appears after creation in history
5457
echo "$MAINPAGE" | php $PATCHDEMO/wikis/$NAME/w/maintenance/edit.php "Main_Page"

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,26 @@
22
// TODO: Use infuse to control OOUI widgets
33
var myWikis, wikisTable, branchSelect,
44
form = document.getElementById( 'new-form' ),
5-
submit = form.querySelector( 'button[type=submit]' );
5+
submit = form.querySelector( 'button[type=submit]' ),
6+
siteConfig = form.querySelector( '[name=siteConfig]' );
67

78
function setDisabled( input, disabled ) {
89
input.disabled = disabled;
910
input.parentNode.classList.toggle( 'oo-ui-widget-disabled', !!disabled );
1011
input.parentNode.classList.toggle( 'oo-ui-widget-enabled', !disabled );
1112
}
1213

13-
form.addEventListener( 'submit', function () {
14+
form.addEventListener( 'submit', function ( e ) {
15+
if ( siteConfig.value.trim() ) {
16+
try {
17+
JSON.parse( siteConfig.value );
18+
} catch ( err ) {
19+
e.preventDefault();
20+
// eslint-disable-next-line no-alert
21+
alert( 'Invalid JSON: ' + err.message );
22+
return;
23+
}
24+
}
1425
setDisabled( submit, true );
1526
return false;
1627
} );

index.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,29 @@
6868
'align' => 'left',
6969
]
7070
),
71+
new OOUI\FieldLayout(
72+
new OOUI\MultilineTextInputWidget( [
73+
'name' => 'siteConfig',
74+
'placeholder' => "{\n \"Sitename\": \"Test wiki\"\n}",
75+
'rows' => 4,
76+
] ),
77+
[
78+
'label' => 'Site config:',
79+
'help' => new OOUI\HtmlSnippet( 'All keys will be given a <strong><code>$wg</code></strong> prefix.<br/>This file will be <strong>public</strong>.' ),
80+
'helpInline' => true,
81+
'align' => 'left',
82+
]
83+
),
7184
new DetailsFieldLayout(
7285
new OOUI\CheckboxMultiselectInputWidget( [
7386
'name' => 'repos[]',
7487
'options' => $repoOptions,
7588
'value' => array_keys( $repoData ),
7689
] ),
7790
[
78-
'label' => 'Choose extensions to enable (default: all):',
91+
'label' => 'Choose extensions to enable:',
92+
'help' => new OOUI\HtmlSnippet( '<br/>Defaults to all' ),
93+
'helpInline' => true,
7994
'align' => 'left',
8095
]
8196
),
@@ -157,6 +172,8 @@
157172
}
158173
$creator = get_creator( $dir );
159174
$created = get_created( $dir );
175+
$siteConfig = get_if_file_exists( 'wikis/' . $dir . '/w/config.json' );
176+
$hasConfig = $siteConfig && strlen( trim( $siteConfig ) );
160177

161178
if ( !$created ) {
162179
// Add created.txt to old wikis
@@ -169,7 +186,8 @@
169186
$wikis[ $dir ] = [
170187
'mtime' => $created,
171188
'title' => $title,
172-
'creator' => $creator
189+
'creator' => $creator,
190+
'hasConfig' => $hasConfig,
173191
];
174192
}
175193
}
@@ -190,7 +208,13 @@
190208
$anyCanDelete = $anyCanDelete || $canDelete;
191209
$rows .= '<tr' . ( $creator !== $username ? ' class="other"' : '' ) . '>' .
192210
'<td class="title">' . ( $title ?: '<em>No patches</em>' ) . '</td>' .
193-
'<td><a href="wikis/' . $wiki . '/w">' . $wiki . '</a></td>' .
211+
'<td>' .
212+
( !empty( $data[ 'hasConfig' ] ) ?
213+
'<a href="wikis/' . $wiki . '/w/config.json">JSON</a>' :
214+
''
215+
) .
216+
'</td>' .
217+
'<td><a href="wikis/' . $wiki . '/w">' . substr( $wiki, 0, 20 ) . '&hellip;</a></td>' .
194218
'<td class="date">' . date( 'c', $data[ 'mtime' ] ) . '</td>' .
195219
( $useOAuth ? '<td>' . ( $creator ? user_link( $creator ) : '?' ) . '</td>' : '' ) .
196220
( $canDelete ?
@@ -202,6 +226,7 @@
202226

203227
echo '<tr>' .
204228
'<th>Patches</th>' .
229+
'<th>Config</th>' .
205230
'<th>Link</th>' .
206231
'<th>Time</th>' .
207232
( $useOAuth ? '<th>Creator</th>' : '' ) .

new.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
$branch = trim( $_POST['branch'] );
88
$patches = trim( $_POST['patches'] );
9+
$siteConfig = trim( $_POST['siteConfig'] );
910

1011
$namePath = md5( $branch . $patches . time() );
1112
$server = ( isset( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'];
@@ -180,6 +181,7 @@
180181
'WIKINAME' => $wikiName,
181182
'CREATOR' => $user ? $user->username : '',
182183
'MAINPAGE' => $mainPage,
184+
'SITECONFIG' => $siteConfig,
183185
'SERVER' => $server,
184186
'SERVERPATH' => $serverPath,
185187
'COMPOSER_HOME' => __DIR__ . '/composer',

0 commit comments

Comments
 (0)