This repository was archived by the owner on Sep 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +46
-3
lines changed
Expand file tree Collapse file tree 5 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -46,3 +46,15 @@ $wgLogos = [
4646 ]
4747];
4848$wgFavicon = "$wgResourceBasePath/favicon.ico";
49+
50+ // Apply config.json
51+ $config = json_decode(
52+ file_get_contents( 'config.json' ),
53+ true
54+ );
55+ if ( $config ) {
56+ foreach ( $config as $key => $value ) {
57+ $name = "wg$key";
58+ $$name = $value;
59+ }
60+ }
Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ date +%s > $PATCHDEMO/wikis/$NAME/created.txt
4545# apply our default settings
4646cat $PATCHDEMO /LocalSettings.txt >> $PATCHDEMO /wikis/$NAME /w/LocalSettings.php
4747
48+ # add site config
49+ echo " $SITECONFIG " >> $PATCHDEMO /wikis/$NAME /w/config.json
50+
4851# update Main_Page
4952sleep 1 # Ensure edit appears after creation in history
5053echo " $MAINPAGE " | php $PATCHDEMO /wikis/$NAME /w/maintenance/edit.php " Main_Page"
Original file line number Diff line number Diff line change 11( function ( ) {
22 var myWikis , wikisTable ,
3- form = document . getElementById ( 'new-form' ) ;
3+ form = document . getElementById ( 'new-form' ) ,
4+ siteConfig = form . querySelector ( '[name=siteConfig]' ) ;
45
5- form . addEventListener ( 'submit' , function ( ) {
6+ form . addEventListener ( 'submit' , function ( e ) {
7+ if ( siteConfig . value . trim ( ) ) {
8+ try {
9+ JSON . parse ( siteConfig . value ) ;
10+ } catch ( err ) {
11+ e . preventDefault ( ) ;
12+ alert ( 'Invalid JSON: ' + err . message )
13+ return ;
14+ }
15+ }
616 form . querySelector ( 'button[type=submit]' ) . disabled = true ;
717 } ) ;
818
Original file line number Diff line number Diff line change 2727 <div>Then, apply patches:</div>
2828 <textarea name="patches" placeholder="Gerrit changeset number or Change-Id, one per line" rows="4" cols="50"></textarea>
2929 </label>
30+ <label>
31+ <div>Site config:<br/>All keys will be given a <code>$wg</code> prefix.<br/>This file will be <strong>public</strong>.</div>
32+ <textarea name="siteConfig" placeholder="{
33+ "Sitename": "Test wiki"
34+ }" rows="4" cols="50"></textarea>
35+ </label>
3036 <button type="submit">Create demo</button>
3137</form>
3238<br/>
8288 }
8389 $ creator = get_creator ( $ dir );
8490 $ created = get_created ( $ dir );
91+ $ siteConfig = get_if_file_exists ( 'wikis/ ' . $ dir . '/w/config.json ' );
92+ $ hasConfig = $ siteConfig && strlen ( trim ( $ siteConfig ) );
8593
8694 if ( !$ created ) {
8795 // Add created.txt to old wikis
94102 $ wikis [ $ dir ] = [
95103 'mtime ' => $ created ,
96104 'title ' => $ title ,
97- 'creator ' => $ creator
105+ 'creator ' => $ creator ,
106+ 'hasConfig ' => $ hasConfig ,
98107 ];
99108 }
100109 }
115124 $ anyCanDelete = $ anyCanDelete || $ canDelete ;
116125 $ rows .= '<tr ' . ( $ creator !== $ username ? ' class="other" ' : '' ) . '> ' .
117126 '<td class="title"> ' . $ title . '</td> ' .
127+ '<td> ' .
128+ ( $ data [ 'hasConfig ' ] ?
129+ '<a href="wikis/ ' . $ wiki . '/w/config.json">JSON</a> ' :
130+ ''
131+ ) .
132+ '</td> ' .
118133 '<td><a href="wikis/ ' . $ wiki . '/w"> ' . $ wiki . '</a></td> ' .
119134 '<td> ' . date ( 'c ' , $ data [ 'mtime ' ] ) . '</td> ' .
120135 ( $ useOAuth ? '<td> ' . ( $ creator ? user_link ( $ creator ) : '? ' ) . '</td> ' : '' ) .
127142
128143 echo '<tr> ' .
129144 '<th>Patches</th> ' .
145+ '<th>Config</th> ' .
130146 '<th>Link</th> ' .
131147 '<th>Time</th> ' .
132148 ( $ useOAuth ? '<th>Creator</th> ' : '' ) .
Original file line number Diff line number Diff line change 66
77$ branch = trim ( $ _POST ['branch ' ] );
88$ patches = $ _POST ['patches ' ];
9+ $ siteConfig = $ _POST ['siteConfig ' ];
910
1011$ namePath = md5 ( $ branch . $ patches . time () );
1112$ server = ( isset ( $ _SERVER ['HTTPS ' ] ) ? 'https:// ' : 'http:// ' ) . $ _SERVER ['HTTP_HOST ' ];
147148 'WIKINAME ' => $ wikiName ,
148149 'CREATOR ' => $ user ? $ user ->username : '' ,
149150 'MAINPAGE ' => $ mainPage ,
151+ 'SITECONFIG ' => $ siteConfig ,
150152 'SERVER ' => $ server ,
151153 'SERVERPATH ' => $ serverPath ,
152154 'COMPOSER_HOME ' => __DIR__ . '/composer ' ,
You can’t perform that action at this time.
0 commit comments