|
34 | 34 | '</tr>' . |
35 | 35 | '</table>'; |
36 | 36 |
|
| 37 | + $username = $user ? $user->username : null; |
| 38 | + $wikilist = [ |
| 39 | + [ |
| 40 | + 'data' => '', |
| 41 | + 'label' => 'None', |
| 42 | + ] |
| 43 | + ]; |
| 44 | + $stmt = $mysqli->prepare( ' |
| 45 | + SELECT wiki, creator, UNIX_TIMESTAMP( created ) created |
| 46 | + FROM wikis |
| 47 | + WHERE !deleted |
| 48 | + ORDER BY IF( creator = ?, 1, 0 ) DESC, created DESC |
| 49 | + ' ); |
| 50 | + if ( !$stmt ) { |
| 51 | + die( $mysqli->error ); |
| 52 | + } |
| 53 | + $stmt->bind_param( 's', $username ); |
| 54 | + $stmt->execute(); |
| 55 | + $results = $stmt->get_result(); |
| 56 | + if ( !$results ) { |
| 57 | + die( $mysqli->error ); |
| 58 | + } |
| 59 | + $shownMyWikis = false; |
| 60 | + $shownOtherWikis = false; |
| 61 | + while ( $data = $results->fetch_assoc() ) { |
| 62 | + if ( $data[ 'wiki' ] === $wiki ) { |
| 63 | + continue; |
| 64 | + } |
| 65 | + $creator = $data[ 'creator' ] ?? ''; |
| 66 | + if ( !$shownMyWikis && $creator === $username ) { |
| 67 | + $wikilist[] = [ 'optgroup' => 'My wikis' ]; |
| 68 | + $shownMyWikis = true; |
| 69 | + } |
| 70 | + if ( $shownMyWikis && !$shownOtherWikis && $creator !== $username ) { |
| 71 | + $wikilist[] = [ 'optgroup' => 'Other wikis' ]; |
| 72 | + $shownOtherWikis = true; |
| 73 | + } |
| 74 | + $wikilist[] = [ |
| 75 | + 'data' => $data[ 'wiki' ], |
| 76 | + 'label' => substr( $data[ 'wiki' ], 0, 10 ) . ' - ' . $data[ 'creator' ] . ' (' . date( 'Y-m-d H:i:s', $data[ 'created' ] ) . ')', |
| 77 | + ]; |
| 78 | + } |
37 | 79 | echo new OOUI\FormLayout( [ |
38 | 80 | 'method' => 'POST', |
39 | 81 | 'items' => [ |
|
42 | 84 | '<br>Are you sure you want to delete this wiki? This cannot be undone.' |
43 | 85 | ), |
44 | 86 | 'items' => array_filter( [ |
| 87 | + count( $wikilist ) > 1 ? |
| 88 | + new OOUI\FieldLayout( |
| 89 | + new OOUI\DropdownInputWidget( [ |
| 90 | + 'name' => 'redirect', |
| 91 | + 'options' => $wikilist, |
| 92 | + ] ), |
| 93 | + [ |
| 94 | + 'label' => 'Leave a redirect to another wiki (optional):', |
| 95 | + 'align' => 'left', |
| 96 | + ] |
| 97 | + ) : |
| 98 | + null, |
45 | 99 | new OOUI\FieldLayout( |
46 | 100 | new OOUI\ButtonInputWidget( [ |
47 | 101 | 'type' => 'submit', |
|
51 | 105 | ] ), |
52 | 106 | [ |
53 | 107 | 'label' => ' ', |
54 | | - 'align' => 'inline', |
| 108 | + 'align' => 'left', |
55 | 109 | ] |
56 | 110 | ), |
57 | 111 | new OOUI\FieldLayout( |
|
70 | 124 | die( "Invalid session." ); |
71 | 125 | } |
72 | 126 |
|
| 127 | + $redirect = $_POST['redirect'] ?: null; |
| 128 | + |
73 | 129 | ob_implicit_flush( true ); |
74 | 130 |
|
75 | 131 | echo '<div class="consoleLog">'; |
76 | | - $error = delete_wiki( $wiki ); |
| 132 | + $error = delete_wiki( $wiki, $redirect ); |
77 | 133 | echo '</div>'; |
78 | 134 |
|
79 | 135 | if ( $error ) { |
|
88 | 144 | if ( $wikiData['deleted'] ) { |
89 | 145 | echo '<p>Wiki deleted.</p>'; |
90 | 146 | } |
| 147 | + |
| 148 | +if ( $wikiData['redirect'] ) { |
| 149 | + echo '<p>Redirected to <a href="wikis/' . $wikiData['redirect'] . '/w">' . $wikiData['redirect'] . '</a>.</p>'; |
| 150 | +} |
0 commit comments