|
11 | 11 | } |
12 | 12 |
|
13 | 13 | if ( !isset( $_POST['confirm' ] ) ) { |
14 | | - echo '<form method="POST">' . |
15 | | - '<p>Are you sure you want to delete this wiki: <a href="wikis/' . $wiki . '/w">' . $wiki . '</a>?</p>' . |
16 | | - '<p>This cannot be undone.</p>' . |
17 | | - new OOUI\ButtonInputWidget( [ |
18 | | - 'type' => 'submit', |
19 | | - 'name' => 'confirm', |
20 | | - 'label' => 'Delete', |
21 | | - 'flags' => [ 'primary', 'destructive' ] |
22 | | - ] ) . |
23 | | - '</form>'; |
24 | | - die(); |
25 | | -} |
26 | 14 |
|
27 | | -ob_implicit_flush( true ); |
| 15 | + $wikilist = [ |
| 16 | + [ |
| 17 | + 'data' => '', |
| 18 | + 'label' => 'None', |
| 19 | + ] |
| 20 | + ]; |
| 21 | + $cache = load_wikicache(); |
| 22 | + if ( $cache ) { |
| 23 | + $wikis = json_decode( $cache, true ); |
| 24 | + foreach ( $wikis as $hash => $data ) { |
| 25 | + $wikilist[] = [ |
| 26 | + 'data' => $hash, |
| 27 | + 'label' => $hash . ' - ' . $data['creator'] . ' (' . date( 'c', $data[ 'mtime' ] ) . ')', |
| 28 | + ]; |
| 29 | + } |
| 30 | + } |
| 31 | + echo new OOUI\FormLayout( [ |
| 32 | + 'method' => 'POST', |
| 33 | + 'items' => [ |
| 34 | + new OOUI\FieldsetLayout( [ |
| 35 | + 'label' => new OOUI\HtmlSnippet( |
| 36 | + 'Are you sure you want to delete this wiki: <a href="wikis/' . $wiki . '/w">' . $wiki . '</a>?<br>' . |
| 37 | + 'This cannot be undone.' |
| 38 | + ), |
| 39 | + 'items' => array_filter( [ |
| 40 | + count( $wikilist ) > 1 ? |
| 41 | + new OOUI\FieldLayout( |
| 42 | + new OOUI\DropdownInputWidget( [ |
| 43 | + 'name' => 'redirect', |
| 44 | + 'options' => $wikilist, |
| 45 | + ] ), |
| 46 | + [ |
| 47 | + 'label' => 'Leave a redirect to this wiki:', |
| 48 | + 'align' => 'left', |
| 49 | + ] |
| 50 | + ) : |
| 51 | + null, |
| 52 | + new OOUI\FieldLayout( |
| 53 | + new OOUI\ButtonInputWidget( [ |
| 54 | + 'type' => 'submit', |
| 55 | + 'name' => 'confirm', |
| 56 | + 'label' => 'Delete', |
| 57 | + 'flags' => [ 'primary', 'destructive' ] |
| 58 | + ] ), |
| 59 | + [ |
| 60 | + 'label' => ' ', |
| 61 | + 'align' => 'left', |
| 62 | + ] |
| 63 | + ), |
| 64 | + ] ) |
| 65 | + ] ) |
| 66 | + ] |
| 67 | + ] ); |
28 | 68 |
|
29 | | -$error = delete_wiki( $wiki ); |
30 | | -if ( $error ) { |
31 | | - die( "Wiki not cleanly deleted, may have not been fully setup." ); |
32 | | -} |
| 69 | +} else { |
| 70 | + ob_implicit_flush( true ); |
| 71 | + |
| 72 | + $error = delete_wiki( $wiki ); |
| 73 | + if ( $error ) { |
| 74 | + echo( "Wiki not cleanly deleted, may have not been fully setup." ); |
| 75 | + } else { |
| 76 | + echo "Wiki deleted."; |
| 77 | + } |
33 | 78 |
|
34 | | -echo "Wiki deleted."; |
| 79 | + function isValidHash( $hash ) { |
| 80 | + return preg_match( '/^[0-9a-f]{32}$/', $hash ); |
| 81 | + } |
| 82 | + |
| 83 | + $redirect = $_POST['redirect'] ?? null; |
| 84 | + |
| 85 | + if ( |
| 86 | + $redirect && |
| 87 | + isValidHash( $redirect ) && |
| 88 | + isValidHash( $wiki ) |
| 89 | + ) { |
| 90 | + // TODO: Avoid duplication in redirect file |
| 91 | + file_put_contents( |
| 92 | + 'redirects.txt', |
| 93 | + $wiki . ' ' . $redirect . "\n", |
| 94 | + FILE_APPEND | LOCK_EX |
| 95 | + ); |
| 96 | + echo ' Redirected to <a href="wikis/' . $redirect . '/w">' . $redirect . '</a>.'; |
| 97 | + } |
| 98 | +} |
0 commit comments