forked from MatmaRex/patchdemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
345 lines (323 loc) · 9.53 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
<?php
require_once "includes.php";
include "header.php";
if ( $useOAuth && !$user ) {
echo oauth_signin_prompt();
} else {
$branches = get_branches( 'mediawiki/core' );
$branches = array_filter( $branches, function ( $branch ) {
return preg_match( '/^origin\/(master|wmf|REL)/', $branch );
} );
natcasesort( $branches );
// Put newest branches first
$branches = array_reverse( array_values( $branches ) );
// Move master to the top
array_unshift( $branches, array_pop( $branches ) );
$branchesOptions = array_map( 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' => $repo,
'disabled' => ( $repo === 'mediawiki/core' ),
];
}
$repoBranches = htmlspecialchars( json_encode( $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( $presets ), ENT_NOQUOTES );
echo "<script>window.presets = $presets;</script>\n";
include_once 'DetailsFieldLayout.php';
include_once 'PatchSelectWidget.php';
echo new OOUI\FormLayout( [
'infusable' => true,
'method' => 'POST',
'action' => 'new.php',
'id' => 'new-form',
'items' => [
new OOUI\FieldsetLayout( [
'label' => null,
'items' => array_filter( [
new OOUI\FieldLayout(
new OOUI\DropdownInputWidget( [
'classes' => [ 'form-branch' ],
'name' => 'branch',
'options' => $branchesOptions,
] ),
[
'label' => 'Start with version:',
'align' => 'left',
]
),
new OOUI\FieldLayout(
new PatchSelectWidget( [
'classes' => [ 'form-patches' ],
'name' => 'patches',
'rows' => 2,
'placeholder' => "e.g. 456123",
] ),
[
'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( [
'name' => 'announce',
'value' => 1,
'selected' => true
] ),
[
'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' => [
[
'data' => 'all',
'label' => 'All',
],
[
'data' => 'wikimedia',
'label' => new OOUI\HtmlSnippet( '<abbr title="Most skins and extensions installed on most Wikimedia wikis, based on MediaWiki.org">Wikimedia</abbr>' ),
],
[
'data' => 'tarball',
'label' => new OOUI\HtmlSnippet( '<abbr title="Skins and extensions included in the official MediaWiki release">Tarball</abbr>' ),
],
[
'data' => 'minimal',
'label' => new OOUI\HtmlSnippet( '<abbr title="Only MediaWiki and default skin">Minimal</abbr>' ),
],
[
'data' => 'custom',
'label' => 'Custom',
],
],
'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:',
'helpInline' => true,
'align' => 'left',
'classes' => [ 'form-repos-field' ],
]
),
new OOUI\FieldLayout(
new OOUI\CheckboxInputWidget( [
'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\CheckboxInputWidget( [
'name' => 'proxy',
'value' => 1,
'selected' => false
] ),
[
'label' => 'Proxy articles from en.wikipedia.org',
'help' => 'Any articles not local to the wiki will be pulled from English Wikipedia.',
'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' ]
] ),
[
'label' => ' ',
'align' => 'left',
]
),
new OOUI\FieldLayout(
new OOUI\HiddenInputWidget( [
'name' => 'csrf_token',
'value' => get_csrf_token(),
] )
),
] )
] ),
]
] );
$banner = banner_html();
if ( $banner ) {
echo "<p class='banner'>$banner</p>";
}
}
?>
<br/>
<h3>Previously generated wikis</h3>
<?php
if ( $user ) {
echo new OOUI\FieldLayout(
new OOUI\CheckboxInputWidget( [
'infusable' => true,
'classes' => [ 'myWikis' ]
] ),
[
'align' => 'inline',
'label' => 'Show only my wikis',
]
);
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 = [];
$results = $mysqli->query( '
SELECT wiki, creator, UNIX_TIMESTAMP( created ) created, patches, branch, announcedTasks, timeToCreate, deleted
FROM wikis
WHERE !deleted
ORDER BY created DESC
' );
if ( !$results ) {
die( $mysqli->error );
}
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' ] ?? '';
$username = $user ? $user->username : null;
$canDelete = can_delete( $creator );
$anyCanDelete = $anyCanDelete || $canDelete;
$classes = [];
if ( $creator !== $username ) {
$classes[] = 'other';
}
if ( !$closed ) {
$classes[] = 'open';
}
$rows .= '<tr class="' . implode( ' ', $classes ) . '">' .
'<td data-label="Wiki" class="wiki">' .
'<span class="wikiAnchor" id="' . substr( $wiki, 0, 10 ) . '"></span>' .
'<a href="wikis/' . $wiki . '/w" title="' . $wiki . '">' . substr( $wiki, 0, 10 ) . '</a>' .
'</td>' .
'<td data-label="Patches" class="patches">' . $patches . '</td>' .
'<td data-label="Linked tasks" class="linkedTasks">' . $linkedTasks . '</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'] ? $wikiData['timeToCreate'] . 's' : '' ) . '</td>' : '' ) .
( $canDelete ?
'<td data-label="Actions"><a href="delete.php?wiki=' . $wiki . '">Delete</a></td>' :
( $anyCanDelete ? '<td></td>' : '' )
) .
'</tr>';
if ( $username && $username === $creator && $closed ) {
$closedWikis++;
}
}
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>' .
'<th>Wiki</th>' .
'<th>Patches<br /><em>✓=Merged ✗=Abandoned</em></th>' .
'<th>Linked tasks<br /><em>✓=Resolved ✗=Declined/Invalid</em></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>';
?>
<script src="js/DetailsFieldLayout.js"></script>
<script src="js/PatchSelectWidget.js"></script>
<script src="js/index.js"></script>
<?php
echo '<script> pd.wikiPatches = ' . json_encode( $wikiPatches ) . '; </script>';
include "footer.html";