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

Commit d44b456

Browse files
committed
Allow site config to be overridden by trusted users
Fixes #19
1 parent 117dfe8 commit d44b456

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
@@ -156,6 +156,14 @@ summary > .oo-ui-labelElement-label:not( .oo-ui-inline-help ) {
156156
padding-left: 2px;
157157
}
158158

159+
.form-siteConfig .oo-ui-inputWidget-input {
160+
font-family: monospace, monospace;
161+
}
162+
163+
.form-siteConfig-message {
164+
font-style: italic;
165+
}
166+
159167
@media ( min-width: 721px ) {
160168
.enableNotifications {
161169
margin-left: 40%;

includes.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
include 'config.default.php';
1515
if ( file_exists( 'config.php' ) ) {
1616
include 'config.php';
17+
// TODO: Make this recursive
1718
$config = array_merge( $config, $localConfig );
1819
}
1920

@@ -406,6 +407,27 @@ function can_delete( string $creator = null ): bool {
406407
return ( $username && $username === $creator ) || can_admin();
407408
}
408409

410+
function can_configure(): bool {
411+
global $config, $user, $useOAuth;
412+
if ( !$useOAuth ) {
413+
// Unauthenticated site
414+
return true;
415+
}
416+
$username = $user ? $user->username : null;
417+
$admins = $config[ 'oauth' ][ 'admins' ];
418+
$configurers = $config[ 'oauth' ][ 'configurers' ];
419+
if ( $username && in_array( $username, $admins, true ) ) {
420+
return true;
421+
}
422+
$configurersMatch = $config[ 'oauth' ][ 'configurersMatch' ];
423+
foreach ( $configurersMatch as $pattern ) {
424+
if ( preg_match( $pattern, $username ) ) {
425+
return true;
426+
}
427+
}
428+
return false;
429+
}
430+
409431
function can_admin(): bool {
410432
global $config, $user, $useOAuth;
411433
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
@@ -23,6 +23,7 @@
2323
$patches = trim( $_POST['patches'] );
2424
$announce = !empty( $_POST['announce'] );
2525
$language = trim( $_POST['language'] );
26+
$siteConfig = can_configure() ? trim( $_POST['siteConfig'] ) : '';
2627

2728
$namePath = substr( md5( $branch . $patches . time() ), 0, 10 );
2829
$server = detectProtocol() . '://' . $_SERVER['HTTP_HOST'];
@@ -303,6 +304,17 @@ function set_progress( float $pc, string $label ) {
303304
$allowedRepos[] = 'mediawiki/extensions/MobileFrontendContentProvider';
304305
}
305306

307+
if ( $siteConfig ) {
308+
$mainPage .= "\n;Extra config\n";
309+
$tag = 'pre';
310+
$attrs = '';
311+
if ( in_array( 'mediawiki/extensions/SyntaxHighlight_GeSHi', $allowedRepos ) ) {
312+
$tag = 'syntaxhighlight';
313+
$attrs = ' lang="php"';
314+
}
315+
$mainPage .= "<$tag$attrs style=\"margin-left: 1.6em\">\n$siteConfig\n</$tag>";
316+
}
317+
306318
foreach ( array_keys( $repos ) as $repo ) {
307319
// Unchecked the checkbox
308320
if ( $repo !== 'mediawiki/core' && !in_array( $repo, $allowedRepos ) ) {
@@ -416,6 +428,7 @@ static function ( string $repo ) use ( $repos ): bool {
416428
'SERVERPATH' => $serverPath,
417429
'LANGUAGE' => $language,
418430
'REPOSITORIES' => $reposString,
431+
'SITECONFIG' => $siteConfig,
419432
]
420433
);
421434
if ( $error ) {

new/install.sh

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

33+
# apply settings from install form
34+
echo "$SITECONFIG" >> $PATCHDEMO/wikis/$NAME/w/LocalSettings.php
35+
3336
# create htaccess
3437
echo "RewriteEngine On
3538
# main rewrite rule

0 commit comments

Comments
 (0)