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

Commit 75dba6b

Browse files
committed
Allow site config to be overridden by trusted users
Fixes #19
1 parent 52424fa commit 75dba6b

File tree

6 files changed

+73
-1
lines changed

6 files changed

+73
-1
lines changed

config.default.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414
'key' => null,
1515
'secret' => null,
1616
// OAuth admins can delete any wiki
17-
'admins' => []
17+
'admins' => [],
18+
// These users can override site configs. This is the same level of trust as V+2,
19+
// as those users can also execute arbitrary code.
20+
'configurers' => [],
21+
// Same as above, but regexes e.g. / \(WMF\)$/
22+
'configurersMatch' => [],
23+
// Instructions to request 'configurers' user status, e.g. "File a request <a href=...>here</a>."
24+
'configurersRequestHtml' => '',
1825
],
1926
// Conduit API key for bot cross-posting to Phabricator
2027
'conduitApiKey' => null,

css/common.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ summary > .oo-ui-labelElement-label:not( .oo-ui-inline-help ) {
143143
max-width: 10em;
144144
}
145145

146+
.form-siteConfig .oo-ui-inputWidget-input {
147+
font-family: monospace, monospace;
148+
}
149+
150+
.form-siteConfig-message {
151+
font-style: italic;
152+
}
153+
146154
@media ( min-width: 721px ) {
147155
.enableNotifications {
148156
margin-left: 40%;

includes.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
include 'config.default.php';
1313
if ( file_exists( 'config.php' ) ) {
1414
include 'config.php';
15+
// TODO: Make this recursive
1516
$config = array_merge( $config, $localConfig );
1617
}
1718

@@ -399,6 +400,27 @@ function can_delete( string $creator = null ): bool {
399400
return ( $username && $username === $creator ) || can_admin();
400401
}
401402

403+
function can_configure(): bool {
404+
global $config, $user, $useOAuth;
405+
if ( !$useOAuth ) {
406+
// Unauthenticated site
407+
return true;
408+
}
409+
$username = $user ? $user->username : null;
410+
$admins = $config[ 'oauth' ][ 'admins' ];
411+
$configurers = $config[ 'oauth' ][ 'configurers' ];
412+
if ( $username && in_array( $username, $admins, true ) ) {
413+
return true;
414+
}
415+
$configurersMatch = $config[ 'oauth' ][ 'configurersMatch' ];
416+
foreach ( $configurersMatch as $pattern ) {
417+
if ( preg_match( $pattern, $username ) ) {
418+
return true;
419+
}
420+
}
421+
return false;
422+
}
423+
402424
function can_admin(): bool {
403425
global $config, $user, $useOAuth;
404426
if ( !$useOAuth ) {

index.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@
139139
'align' => 'left',
140140
]
141141
),
142+
new OOUI\FieldLayout(
143+
can_configure() ?
144+
new OOUI\MultilineTextInputWidget( [
145+
'classes' => [ 'form-siteConfig' ],
146+
'name' => 'siteConfig',
147+
'placeholder' => "e.g. \$wgSitename = 'Test wiki';",
148+
'rows' => 3,
149+
] ) :
150+
new OOUI\LabelWidget( [
151+
'classes' => [ 'form-siteConfig-message' ],
152+
'label' => new OOUI\HtmlSnippet( 'Only approved users can modify site config. ' . $config['oauth']['configurersRequestHtml'] ),
153+
] ),
154+
[
155+
'label' => 'Site config:',
156+
'help' => new OOUI\HtmlSnippet( 'This config will be <strong>public</strong> on the wiki\'s main page.' ),
157+
'helpInline' => true,
158+
'align' => 'left',
159+
]
160+
),
142161
new DetailsFieldLayout(
143162
new OOUI\CheckboxMultiselectInputWidget( [
144163
'classes' => [ 'form-repos' ],

new.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
$patches = trim( $_POST['patches'] );
2222
$announce = !empty( $_POST['announce'] );
2323
$language = trim( $_POST['language'] );
24+
$siteConfig = can_configure() ? trim( $_POST['siteConfig'] ) : '';
2425

2526
$namePath = substr( md5( $branch . $patches . time() ), 0, 10 );
2627
$server = detectProtocol() . '://' . $_SERVER['HTTP_HOST'];
@@ -301,6 +302,17 @@ function set_progress( float $pc, string $label ) {
301302
$allowedRepos[] = 'mediawiki/extensions/MobileFrontendContentProvider';
302303
}
303304

305+
if ( $siteConfig ) {
306+
$mainPage .= "\n;Extra config\n";
307+
$tag = 'pre';
308+
$attrs = '';
309+
if ( in_array( 'mediawiki/extensions/SyntaxHighlight_GeSHi', $allowedRepos ) ) {
310+
$tag = 'syntaxhighlight';
311+
$attrs = ' lang="php"';
312+
}
313+
$mainPage .= "<$tag$attrs style=\"margin-left: 1.6em\">\n$siteConfig\n</$tag>";
314+
}
315+
304316
foreach ( array_keys( $repos ) as $repo ) {
305317
// Unchecked the checkbox
306318
if ( $repo !== 'mediawiki/core' && !in_array( $repo, $allowedRepos ) ) {
@@ -363,6 +375,7 @@ function set_progress( float $pc, string $label ) {
363375
'SERVERPATH' => $serverPath,
364376
'LANGUAGE' => $language,
365377
'REPOSITORIES' => $reposString,
378+
'SITECONFIG' => $siteConfig,
366379
]
367380
);
368381
if ( $error ) {

new/install.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ while IFS=' ' read -r repo dir; do
2727
fi
2828
done <<< "$REPOSITORIES"
2929

30+
# apply settings from install form
31+
echo "$SITECONFIG" >> $PATCHDEMO/wikis/$NAME/w/LocalSettings.php
32+
3033
# create htaccess
3134
echo "RewriteEngine On
3235
# main rewrite rule

0 commit comments

Comments
 (0)