@@ -77,7 +77,7 @@ function get_wiki_data( string $wiki ): array {
7777 global $ mysqli ;
7878
7979 $ stmt = $ mysqli ->prepare ( '
80- SELECT wiki, creator, UNIX_TIMESTAMP( created ) created, patches, branch, announcedTasks, timeToCreate, deleted
80+ SELECT wiki, creator, UNIX_TIMESTAMP( created ) created, patches, branch, announcedTasks, timeToCreate, deleted, redirect
8181 FROM wikis WHERE wiki = ?
8282 ' );
8383 if ( !$ stmt ) {
@@ -316,7 +316,11 @@ function shell( $cmd, array $env = [] ): ?string {
316316 return $ error ? null : $ process ->getOutput ();
317317}
318318
319- function delete_wiki ( string $ wiki ): ?string {
319+ function is_valid_hash ( string $ hash ): bool {
320+ return preg_match ( '/^[0-9a-f]{10,32}$/ ' , $ hash ) !== false ;
321+ }
322+
323+ function delete_wiki ( string $ wiki , ?string $ redirect = null ): ?string {
320324 global $ mysqli ;
321325
322326 $ wikiData = get_wiki_data ( $ wiki );
@@ -346,12 +350,16 @@ function delete_wiki( string $wiki ): ?string {
346350 );
347351 }
348352
353+ if ( $ redirect && !is_valid_hash ( $ redirect ) ) {
354+ $ redirect = null ;
355+ }
356+
349357 $ stmt = $ mysqli ->prepare ( '
350358 UPDATE wikis
351- SET deleted = 1
359+ SET deleted = 1, redirect = ?
352360 WHERE wiki = ?
353361 ' );
354- $ stmt ->bind_param ( 's ' , $ wiki );
362+ $ stmt ->bind_param ( 'ss ' , $ redirect , $ wiki );
355363 $ stmt ->execute ();
356364 $ stmt ->close ();
357365
0 commit comments