diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c8f60ae --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/new.txt diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/COPYING @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md index 8297d7e..7c404ec 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # File-renamers-queue -https://tools.wmflabs.org/steinsplitter/renaming/ +https://steinsplitter.toolforge.org/renaming/ diff --git a/index.php b/index.php index 675a888..3076eb3 100644 --- a/index.php +++ b/index.php @@ -14,26 +14,34 @@ fputs( $fp , "$hii[0]" ); fclose( $fp ); -$tools_pw = posix_getpwuid ( posix_getuid () ); -$tools_mycnf = parse_ini_file( $tools_pw['dir'] . "/replica.my.cnf" ); -$db = new mysqli( 'commonswiki.web.db.svc.eqiad.wmflabs', $tools_mycnf['user'], $tools_mycnf['password'], 'commonswiki_p' ); -if ( $db->connect_errno ) - die( "Failed to connect to labsdb: (" . $db->connect_errno . ") " . $db->connect_error ); -$r = $db->query( 'SELECT REPLACE(page_title, \'_\', \' \'), actor_user, DATE_FORMAT(rev_timestamp, \'%H:%i:%s %b %d %Y\') FROM page JOIN categorylinks ON page_id = cl_from JOIN revision ON page_latest = rev_id JOIN revision_actor_temp ON revactor_rev = rev_id JOIN actor_revision ON actor_id = revactor_actor WHERE page_is_redirect = 0 AND cl_to = \'Media_requiring_renaming\' AND page_namespace = \'6\'' ); -$num = $r->num_rows; -unset( $tools_mycnf, $tools_pw ); -$data = date('H:i:s (m-d-Y)', time()); +/** + * Query the data from the database. Sensitive information (DB password) is stored + * in local variables so that it’s cleared as soon as possible. + */ +function query(): mysqli_result { + mysqli_report( MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT ); + $tools_pw = posix_getpwuid ( posix_getuid () ); + $tools_mycnf = parse_ini_file( $tools_pw['dir'] . "/replica.my.cnf" ); + $db = new mysqli( 'commonswiki.web.db.svc.eqiad.wmflabs', $tools_mycnf['user'], $tools_mycnf['password'], 'commonswiki_p' ); + $sql = <<query( $sql ); +} if (isset($_GET['api'])) { $answer = array(); $elements = array(); + $r = query(); while ( $row = $r->fetch_row() ) { - $elements[] = array('title' => utf8_encode($row[0]), 'user' => utf8_encode($row[1]), 'date' => $row[2]); + $elements[] = array('title' => str_replace('_', ' ', $row[0]), 'user' => $row[1], 'date' => $row[2]); } $answer['len'] = count($elements); $answer['elements'] = $elements; - echo json_encode($answer); header('Content-Type: application/json;charset=utf-8'); + echo json_encode($answer); exit(0); } ?> @@ -86,6 +94,10 @@

num_rows; +$data = date('H:i:s (m-d-Y)'); + echo '

There are currently '.$num.' move requests in the queue.

Data as of '.$data.' (UTC).'; if ( $num == 0 ) echo "

No requests: There are zero filemove requests. No backlog. Cool :-).
";