From 3b5cf5e825457fa0e1975d0c8d51f5943d4d4f5e Mon Sep 17 00:00:00 2001 From: tacsipacsi Date: Sun, 11 Feb 2024 12:23:18 +0100 Subject: [PATCH 1/4] Fix database query (again), more strucutred code, fix encoding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `revision_actor_temp` table was dropped in production in May 2022 (T307906), so presumably this code hasn’t worked since then... Move the query to a function, which is run just before the result is needed. This makes the `unset()` calls unnecessary (the variables that used to be unset are now local ones, so they’re automatically destroyed at the end of the function) and causes at least the header to be shown in case of an exception – the header contains the link to this repo, so interested people have a chance to submit a PR if they figure out what the problem is. Remove `utf8_encode()` calls – everything should be UTF-8 by now, so interpreting user names as ISO-8859-1 (while they are actually UTF-8) and re-encoding them as UTF-8 breaks things rather than fixing them. --- index.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/index.php b/index.php index 675a888..9370a63 100644 --- a/index.php +++ b/index.php @@ -14,21 +14,29 @@ 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; @@ -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 :-).
"; From 57903f1c7399b3a69db361dc7fe9680f3b03019c Mon Sep 17 00:00:00 2001 From: tacsipacsi Date: Sun, 11 Feb 2024 12:49:42 +0100 Subject: [PATCH 2/4] Update URL in README, add log file to .gitignore --- .gitignore | 1 + README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .gitignore 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/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/ From acf119ad12f65c02f6713c1536398c91da1fd26f Mon Sep 17 00:00:00 2001 From: tacsipacsi Date: Sun, 11 Feb 2024 12:58:29 +0100 Subject: [PATCH 3/4] Fix API: set header before body If done the other way round, an `E_WARNING` is raised with the message Cannot modify header information - headers already sent and the content type is not set. --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 9370a63..3076eb3 100644 --- a/index.php +++ b/index.php @@ -40,8 +40,8 @@ function query(): mysqli_result { } $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); } ?> From b52baa370f2a36cdfcdcd1c92f224c7a64da81c7 Mon Sep 17 00:00:00 2001 From: tacsipacsi Date: Sun, 11 Feb 2024 13:23:42 +0100 Subject: [PATCH 4/4] Add COPYING file --- COPYING | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 COPYING 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