This repository was archived by the owner on Sep 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.php
485 lines (460 loc) · 14.3 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
<?php
require_once "includes.php";
include "header.php";
$presetLabels = [
'all' => [
'title' => 'All',
],
'wikimedia' => [
'title' => 'Wikimedia',
'description' => 'Most skins and extensions installed on most Wikimedia wikis, based on MediaWiki.org',
],
'tarball' => [
'title' => 'Tarball',
'description' => 'Skins and extensions included in the official MediaWiki release',
],
'minimal' => [
'title' => 'Minimal',
'description' => 'Only MediaWiki and default skin with anti-spam configuration',
],
'custom' => [
'title' => 'Custom',
]
];
$canCreate = !$useOAuth || $user;
$branches = get_branches_sorted( 'mediawiki/core' );
$branchOptions = array_map( static function ( $branch ) {
return [
'label' => preg_replace( '/^origin\//', '', $branch ),
'data' => $branch,
];
}, $branches );
$repoBranches = [];
$repoOptions = [];
$repoData = get_repo_data();
ksort( $repoData );
foreach ( $repoData as $repo => $path ) {
$repoBranches[$repo] = get_branches( $repo );
$repo = htmlspecialchars( $repo );
$repoOptions[] = [
'data' => $repo,
'label' => get_repo_label( $repo ),
'disabled' => ( $repo === 'mediawiki/core' ),
];
}
$repoBranches = htmlspecialchars( json_encode_clean( $repoBranches ), ENT_NOQUOTES );
echo "<script>window.repoBranches = $repoBranches;</script>\n";
$presets = get_repo_presets();
$reposValid = array_keys( $repoData );
foreach ( $presets as $name => $repos ) {
$presets[$name] = array_values( array_intersect( $repos, $reposValid ) );
}
$presets = htmlspecialchars( json_encode_clean( $presets ), ENT_NOQUOTES );
echo "<script>window.presets = $presets;</script>\n";
include_once 'ComboBoxInputWidget.php';
include_once 'DetailsFieldLayout.php';
include_once 'PatchSelectWidget.php';
$presetOptions = array_map( static function ( $data, $preset ) {
$option = [
'data' => $data
];
if ( isset( $preset[ 'description' ] ) ) {
$option[ 'label' ] = new OOUI\HtmlSnippet(
'<abbr title="' . htmlspecialchars( $preset[ 'description' ] ) . '">' . htmlspecialchars( $preset[ 'title' ] ) . '</abbr>'
);
} else {
$option[ 'label' ] = $preset[ 'title' ];
}
return $option;
}, array_keys( $presetLabels ), array_values( $presetLabels ) );
echo new OOUI\FormLayout( [
'infusable' => true,
'method' => 'POST',
'action' => 'new.php',
'id' => 'new-form',
'classes' => ( $canCreate ? [] : [ 'form-disabled' ] ),
'items' => [
new OOUI\FieldsetLayout( [
'label' => null,
'items' => array_filter( [
new OOUI\FieldLayout(
new OOUI\DropdownInputWidget( [
'classes' => [ 'form-branch' ],
'name' => 'branch',
'options' => $branchOptions,
'value' => !empty( $_GET['branch' ] ) ? 'origin/' . $_GET['branch' ] : null
] ),
[
'label' => 'Start with version:',
'align' => 'left',
]
),
new OOUI\FieldLayout(
new PatchSelectWidget( [
'classes' => [ 'form-patches' ],
'name' => 'patches',
'rows' => 2,
'placeholder' => "e.g. 456123",
'value' => !empty( $_GET['patches'] ) ? str_replace( ',', "\n", $_GET['patches'] ) : null
] ),
[
'classes' => [ 'form-patches-layout' ],
'infusable' => true,
'label' => 'Then, apply patches:',
'help' => 'Gerrit changeset number or Change-Id, one per line',
'helpInline' => true,
'align' => 'left',
]
),
$config['conduitApiKey'] ?
new OOUI\FieldLayout(
new OOUI\CheckboxInputWidget( [
'classes' => [ 'form-announce' ],
'name' => 'announce',
'value' => 1,
'selected' => true
] ),
[
'classes' => [ 'form-announce-layout' ],
'label' => 'Announce wiki on Phabricator:',
'help' => 'Any tasks linked to from patches applied will get a comment announcing this wiki.',
'helpInline' => true,
'align' => 'left',
]
) :
null,
new OOUI\FieldLayout(
new OOUI\RadioSelectInputWidget( [
'classes' => [ 'form-preset' ],
'name' => 'preset',
'options' => $presetOptions,
'value' => 'wikimedia',
] ),
[
'label' => 'Choose configuration preset:',
'align' => 'left',
]
),
new DetailsFieldLayout(
new OOUI\CheckboxMultiselectInputWidget( [
'classes' => [ 'form-repos' ],
'name' => 'repos[]',
'options' => $repoOptions,
'value' => get_repo_presets()[ 'wikimedia' ],
] ),
[
'label' => 'Choose included repos:',
'help' => new OOUI\HtmlSnippet( 'If your extension is not listed, please create a <a href="https://gitlab.wikimedia.org/repos/ci-tools/patchdemo/-/issues/new">new issue</a>.' ),
'helpInline' => true,
'align' => 'inline',
'classes' => [ 'form-repos-field' ],
]
),
new OOUI\FieldLayout(
new OOUI\CheckboxInputWidget( [
'classes' => [ 'form-instantCommons' ],
'name' => 'instantCommons',
'value' => 1,
'selected' => true
] ),
[
'label' => 'Load images from Commons',
'help' => 'Any images not local to the wiki will be pulled from Wikimedia Commons.',
'helpInline' => true,
'align' => 'left',
]
),
new OOUI\FieldLayout(
new OOUI\DropdownInputWidget( [
'classes' => [ 'form-instantCommonsMethod' ],
'name' => 'instantCommonsMethod',
'options' => [
[ 'data' => 'quick', 'label' => 'QuickInstantCommons' ],
[ 'data' => 'full', 'label' => 'InstantCommons' ],
]
] ),
[
'label' => 'Method for loading images from Commons',
'help' => new OOUI\HtmlSnippet(
'<a href="https://www.mediawiki.org/wiki/Extension:QuickInstantCommons">QuickInstantCommons</a> is much faster than using full <a href="https://www.mediawiki.org/wiki/InstantCommons">InstantCommons</a> but may lack some advanced image viewing features.'
),
'helpInline' => true,
'align' => 'left',
]
),
new OOUI\FieldLayout(
new ComboBoxInputWidget( [
'placeholder' => 'Main Page',
'classes' => [ 'form-landingPage' ],
'name' => 'landingPage',
'options' => array_map( static function ( string $page ) {
return [ 'data' => $page ];
}, get_known_pages() ),
'menu' => [
'filterFromInput' => true
],
'value' => !empty( $_GET['landingPage' ] ) ? $_GET['landingPage' ] : null
] ),
[
'label' => 'Landing page:',
'help' => 'The page linked to from this page, and any announcement posts.',
'helpInline' => true,
'align' => 'left',
]
),
new OOUI\FieldLayout(
new OOUI\TextInputWidget( [
'name' => 'language',
'value' => 'en',
'classes' => [ 'form-language' ]
] ),
[
'label' => 'Language code',
'help' => 'Will be used as the content language and default interface language.',
'helpInline' => true,
'align' => 'left',
]
),
new OOUI\FieldLayout(
new OOUI\CheckboxInputWidget( [
'name' => 'proxy',
'value' => 1,
'selected' => false
] ),
[
'label' => 'Proxy articles from wikipedia.org',
'help' => 'Any articles not local to the wiki will be pulled from Wikipedia, using the language code above.',
'helpInline' => true,
'align' => 'left',
]
),
new OOUI\FieldLayout(
new OOUI\CheckboxInputWidget( [
'name' => 'tempuser',
'value' => 1,
'selected' => false
] ),
[
'label' => "Enable temporary user account creation (IP\u{00A0}Masking)",
'help' => 'Anonymous editors will have a temporary user account created for them.',
'helpInline' => true,
'align' => 'left',
]
),
new OOUI\FieldLayout(
// Placeholder, will be replaced by a ToggleButtonWidget in JS
new OOUI\ButtonWidget( [
'icon' => 'bell',
'disabled' => 'true'
] ),
[
'align' => 'inline',
'classes' => [ 'enableNotifications' ],
'label' => 'Get a browser notification when your wikis are ready',
'infusable' => true,
]
),
new OOUI\FieldLayout(
new OOUI\ButtonInputWidget( [
'classes' => [ 'form-submit' ],
'label' => 'Create demo',
'type' => 'submit',
// 'disabled' => true,
'flags' => [ 'progressive', 'primary' ]
] ),
[
'classes' => [ 'createField' ],
'warnings' => $config[ 'newWikiWarning' ] ? [ new OOUI\HtmlSnippet( $config[ 'newWikiWarning' ] ) ] : [],
'label' => ' ',
'align' => 'left',
]
),
new OOUI\FieldLayout(
new OOUI\HiddenInputWidget( [
'name' => 'csrf_token',
'value' => get_csrf_token(),
] )
),
] )
] ),
]
] );
if ( !$canCreate ) {
echo oauth_signin_prompt();
}
?>
<br/>
<h3>Previously generated wikis</h3>
<?php
if ( $user ) {
echo new OOUI\FieldLayout(
new OOUI\CheckboxInputWidget( [
'infusable' => true,
'classes' => [ 'closedWikis' ]
] ),
[
'align' => 'inline',
'label' => 'Show only wikis where all patches are merged or abandoned',
]
);
}
?>
<?php
$rows = '';
$anyCanDelete = false;
$closedWikis = 0;
$canAdmin = can_admin();
$wikiPatches = [];
$username = $user ? $user->username : null;
$stmt = $mysqli->prepare( '
SELECT wiki, creator, UNIX_TIMESTAMP( created ) created, patches, branch, repos, announcedTasks, landingPage, timeToCreate, deleted, ready
FROM wikis
WHERE !deleted
ORDER BY IF( creator = ?, 1, 0 ) DESC, created DESC
' );
if ( !$stmt ) {
die( $mysqli->error );
}
$stmt->bind_param( 's', $username );
$stmt->execute();
$results = $stmt->get_result();
if ( !$results ) {
die( $mysqli->error );
}
$shownMyWikis = false;
$shownOtherWikis = false;
while ( $data = $results->fetch_assoc() ) {
$wikiData = get_wiki_data_from_row( $data );
$wiki = $data['wiki'];
$wikiPatches[$wiki] = $wikiData['patches'];
$closed = false;
$patches = format_patch_list( $wikiData['patchList'], $wikiData['branch'], $closed );
$linkedTasks = format_linked_tasks( $wikiData['linkedTaskList'] );
$creator = $wikiData[ 'creator' ] ?? '';
$canDelete = can_delete( $creator );
$anyCanDelete = $anyCanDelete || $canDelete;
if ( !$shownMyWikis && $creator === $username ) {
$rows .= '<tr class="wikiSection"><th colspan="99">My wikis</th></tr>';
$shownMyWikis = true;
}
if ( $shownMyWikis && !$shownOtherWikis && $creator !== $username ) {
$rows .= '<tr class="wikiSection"><th colspan="99">Other wikis</th></tr>';
$shownOtherWikis = true;
}
$classes = [];
if ( $creator !== $username ) {
$classes[] = 'other';
}
if ( !$closed ) {
$classes[] = 'open';
}
$actions = [];
if ( $canDelete ) {
$actions[] = '<a href="delete.php?wiki=' . $wiki . '">Delete</a>';
}
if ( $canCreate ) {
$patchList = array_map( static function ( $data ) {
return htmlspecialchars( $data['r'] );
}, $wikiData['patchList'] );
if (
count( $patchList ) ||
$wikiData[ 'branch' ] !== 'master' ||
$wikiData[ 'repos' ][ 'preset' ] === 'custom'
) {
$repos = $wikiData[ 'repos' ];
$actions[] = '<a class="copyWiki" href="?' .
http_build_query( [
'patches' => implode( ',', $patchList ),
'branch' => $wikiData[ 'branch' ],
'preset' => $repos[ 'preset' ] !== 'unknown' ? $repos[ 'preset' ] : null,
'repos' => isset( $repos[ 'repos' ] ) ? implode( ',', $repos[ 'repos' ] ) : null,
'landingPage' => $wikiData[ 'landingPage' ],
], '', '&' ) .
'">Copy</a>';
}
}
if ( !$data['ready'] ) {
$classes[] = 'notReady';
}
$repos = '';
$preset = $wikiData[ 'repos' ][ 'preset' ];
switch ( $preset ) {
case 'unknown':
$repos = '?';
break;
case 'custom':
$repoList = implode( ', ',
array_map( static function ( $repo ) {
return get_repo_label( $repo );
}, $wikiData[ 'repos' ][ 'repos' ] )
);
$repos = '<abbr title="' . htmlspecialchars( $repoList ) . '">' . $presetLabels[ $preset ][ 'title' ] . '</abbr>';
break;
default:
$repos = htmlspecialchars( $presetLabels[ $preset ][ 'title' ] );
break;
}
$rows .= '<tr class="' . implode( ' ', $classes ) . '">' .
'<td data-label="Wiki" class="wiki">' .
'<span class="wikiAnchor" id="' . substr( $wiki, 0, 10 ) . '"></span>' .
get_wiki_link( $wiki, $wikiData['landingPage'], $wikiData['ready'] ) .
'</td>' .
'<td data-label="Patches" class="patches">' . $patches . '</td>' .
'<td data-label="Linked tasks" class="linkedTasks">' . $linkedTasks . '</td>' .
'<td data-label="Repos" class="repos">' . $repos . '</td>' .
'<td data-label="Time" class="date">' . date( 'Y-m-d H:i:s', $wikiData[ 'created' ] ) . '</td>' .
( $useOAuth ? '<td data-label="Creator">' . ( $creator ? user_link( $creator ) : '?' ) . '</td>' : '' ) .
( $canAdmin ? '<td data-label="Time to create">' . ( $wikiData['timeToCreate'] ? format_duration( $wikiData['timeToCreate'] ) : '' ) . '</td>' : '' ) .
( count( $actions ) ?
'<td data-label="Actions">' . implode( ' · ', $actions ) . '</td>' :
'<!-- EMPTY ACTIONS -->'
) .
'</tr>';
if ( $username && $username === $creator && $closed ) {
$closedWikis++;
}
}
$stmt->close();
$rows = str_replace( '<!-- EMPTY ACTIONS -->', $anyCanDelete ? '<td></td>' : '', $rows );
if ( $closedWikis ) {
echo new OOUI\MessageWidget( [
'classes' => [ 'showClosed' ],
'type' => 'warning',
'label' => new OOUI\HtmlSnippet(
new OOUI\ButtonWidget( [
'infusable' => true,
'label' => 'Show',
'classes' => [ 'showClosedButton' ],
] ) .
'You have created ' . $closedWikis . ' ' . ( $closedWikis > 1 ? 'wikis' : 'wiki' ) . ' where all the patches ' .
'have been merged or abandoned and therefore can be deleted.'
)
] );
}
echo '<table class="wikis">' .
'<tr class="headerRow">' .
'<th>Wiki</th>' .
'<th>Patches<br /><em>✓=Merged ✗=Abandoned 🛇=<abbr title="Open patches marked with \'DNM\' or \'DO NOT MERGE\'">Do not merge</abbr></em></th>' .
'<th>Linked tasks<br /><em>✓=Resolved ✗=Declined/Invalid</em></th>' .
'<th>Repos</th>' .
'<th>Time</th>' .
( $useOAuth ? '<th>Creator</th>' : '' ) .
( $canAdmin ? '<th><abbr title="Time to create">TTC</abbr></th>' : '' ) .
( $anyCanDelete ? '<th>Actions</th>' : '' ) .
'</tr>' .
$rows .
'</table>';
echo '<script>
window.pd = window.pd || {};
pd.wikiPatches = ' . json_encode_clean( $wikiPatches ) . ';
pd.config = ' . json_encode_clean( [
'phabricatorUrl' => $config['phabricatorUrl'],
'gerritUrl' => $config['gerritUrl'],
] ) . ';
</script>';
?>
<script src="js/DetailsFieldLayout.js"></script>
<script src="js/PatchSelectWidget.js"></script>
<script src="js/index.js"></script>
<?php
include "footer.html";