From 074abe4382a19eccb752587a6f4ea8de4647ccf9 Mon Sep 17 00:00:00 2001 From: cybabun1 Date: Wed, 15 Apr 2026 10:17:47 -0600 Subject: [PATCH 1/4] Add OpenTelemetry instrumentation - Bootstrap OTel SDK in src/telemetry.php (root HTTP span per request) - Add wiki_query() wrapper in src/mysql.php for DB span per query - Replace 107 mysqli_query($mysql, ...) calls with wiki_query() - Add composer.json with opentelemetry SDK deps - Update Dockerfile.php: add php8.0-curl, install Composer, run composer install - Add extra_hosts and OTEL_* env vars to docker-compose.yml / php.env.example --- Dockerfile.php | 13 ++++++-- docker-compose.yml | 2 ++ php.env.example | 9 +++++ wwwroot/ban.php | 12 +++---- wwwroot/composer.json | 11 +++++++ wwwroot/fun/edits.php | 2 +- wwwroot/fun/names.php | 4 +-- wwwroot/fun/paginate.php | 4 +-- wwwroot/functions.php | 6 ++-- wwwroot/index.php | 58 ++++++++++++++++----------------- wwwroot/popular.php | 8 ++--- wwwroot/search.php | 6 ++-- wwwroot/src/actions/archive.php | 10 +++--- wwwroot/src/actions/diff.php | 6 ++-- wwwroot/src/actions/history.php | 18 +++++----- wwwroot/src/actions/random.php | 6 ++-- wwwroot/src/actions/recent.php | 2 +- wwwroot/src/actions/rename.php | 4 +-- wwwroot/src/actions/replace.php | 8 ++--- wwwroot/src/actions/source.php | 2 +- wwwroot/src/actions/tag.php | 20 ++++++------ wwwroot/src/actions/view.php | 6 ++-- wwwroot/src/markup/edit.php | 4 +-- wwwroot/src/markup/view.php | 4 +-- wwwroot/src/mysql.php | 27 +++++++++++++++ wwwroot/src/pages/tag-cloud.php | 6 ++-- wwwroot/src/pages/tags.php | 8 ++--- wwwroot/src/telemetry.php | 38 +++++++++++++++++++++ wwwroot/stats/edits.php | 2 +- wwwroot/stats/searches.php | 2 +- wwwroot/superpopular.php | 4 +-- wwwroot/upload.php | 2 +- 32 files changed, 205 insertions(+), 109 deletions(-) create mode 100644 wwwroot/composer.json create mode 100644 wwwroot/src/telemetry.php diff --git a/Dockerfile.php b/Dockerfile.php index 3ea07b3..c9e3f03 100644 --- a/Dockerfile.php +++ b/Dockerfile.php @@ -30,7 +30,7 @@ && echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list \ && curl -fsSL https://packages.sury.org/php/apt.gpg | apt-key add - -# install php5.6, some extensions, and nodejs +# install php8.0, some extensions, and nodejs RUN set -exu \ && DEBIAN_FRONTEND=noninteractive apt-get -yq update \ && DEBIAN_FRONTEND=noninteractive apt-get -yq install \ @@ -40,6 +40,7 @@ php8.0-mysql \ php8.0-exif \ php8.0-gd \ + php8.0-curl \ nodejs \ npm @@ -64,15 +65,23 @@ RUN set -exu \ && chown -R builder:builder /var/www +# install composer +RUN set -exu \ + && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + # switch to our nonroot user USER builder -# run npm install +# run npm install and composer install WORKDIR /var/www/src RUN set -exu \ && cd /var/www/src \ && npm install +WORKDIR /var/www +RUN set -exu \ + && composer install --no-dev --no-interaction --no-progress + # back to root USER root diff --git a/docker-compose.yml b/docker-compose.yml index c961ef3..e1754e4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,6 +30,8 @@ services: # db connection info env_file: - ./php.env + extra_hosts: + - "host-gateway:host-gateway" volumes: - ./upload:/var/www/upload:rw - ./config/php-fpm.conf:/etc/php/8.0/fpm/php-fpm.conf:ro diff --git a/php.env.example b/php.env.example index da3bd0d..4cb971f 100644 --- a/php.env.example +++ b/php.env.example @@ -22,6 +22,15 @@ BAN_PASSWORD=secret CAPTCHA_BYPASS=false +# OpenTelemetry — traces sent to FishVision's Tempo via host-gateway +# Set OTEL_SDK_DISABLED=true to disable tracing without removing config +OTEL_SERVICE_NAME=wiki +OTEL_EXPORTER_OTLP_ENDPOINT=http://host-gateway:4319 +OTEL_EXPORTER_OTLP_PROTOCOL=http/json +OTEL_TRACES_SAMPLER=parentbased_always_on +OTEL_PHP_AUTOLOAD_ENABLED=true +OTEL_SDK_DISABLED=false + # passed to json_decode() # needs to resolve as an array BANLIST='["127\.0\.0\.1", "^2600:123"]' diff --git a/wwwroot/ban.php b/wwwroot/ban.php index 6dc9ca4..339adc2 100644 --- a/wwwroot/ban.php +++ b/wwwroot/ban.php @@ -8,7 +8,7 @@ if(is_numeric($_POST['id']) and $_POST['password'] == BAN_PASSWORD) { $ID = $_POST['id']; - mysqli_query($mysql,"Update `Wiki_Accounts` set `Verified`='-1' where `ID`='$ID'"); + wiki_query("Update `Wiki_Accounts` set `Verified`='-1' where `ID`='$ID'"); echo "User banned.
"; if($_POST['revert'] == "on") @@ -16,24 +16,24 @@ $Reverted = array(); $BadAccount = $ID; - $PageQuery = mysqli_query($mysql,"SELECT `PageID` FROM `Wiki_Edits` WHERE `AccountID`='$BadAccount'"); + $PageQuery = wiki_query("SELECT `PageID` FROM `Wiki_Edits` WHERE `AccountID`='$BadAccount'"); while(list($PageID) = mysqli_fetch_array($PageQuery)) { if(empty($Reverted[$PageID])) { - $DataQuery = mysqli_query($mysql,"SELECT `Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `PageID`='$PageID' AND `AccountID`!='$BadAccount' ORDER BY `ID` DESC LIMIT 1"); + $DataQuery = wiki_query("SELECT `Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `PageID`='$PageID' AND `AccountID`!='$BadAccount' ORDER BY `ID` DESC LIMIT 1"); list($PageName, $PageDescription, $PageTitle, $PageContent) = mysqli_fetch_array($DataQuery); $Time = Time(); $Size = strlen($PageContent); - mysqli_query($mysql,"UPDATE `Wiki_Pages` SET `EditTime`='$Time',`Title`='$PageTitle',`Content`='$PageContent' WHERE `ID`='$PageID'"); + wiki_query("UPDATE `Wiki_Pages` SET `EditTime`='$Time',`Title`='$PageTitle',`Content`='$PageContent' WHERE `ID`='$PageID'"); $SQLError .= mysqli_error($mysql); - mysqli_query($mysql,"INSERT INTO `Wiki_Edits` VALUES ('NULL', '$PageID', '{$_SESSION['ID']}', '$Time', '$Size', '$PageName', 'Rachel's Super Revert: $PageDescription', '$PageTitle', '$PageContent', '')"); + wiki_query("INSERT INTO `Wiki_Edits` VALUES ('NULL', '$PageID', '{$_SESSION['ID']}', '$Time', '$Size', '$PageName', 'Rachel's Super Revert: $PageDescription', '$PageTitle', '$PageContent', '')"); $SQLError .= mysqli_error($mysql); - mysqli_query($mysql,"UPDATE `Wiki_Accounts` SET `EditTime`='$Time' WHERE `ID`='{$_SESSION['ID']}'"); + wiki_query("UPDATE `Wiki_Accounts` SET `EditTime`='$Time' WHERE `ID`='{$_SESSION['ID']}'"); $SQLError .= mysqli_error($mysql); $Reverted[$PageID] = TRUE; diff --git a/wwwroot/composer.json b/wwwroot/composer.json new file mode 100644 index 0000000..9c9cf99 --- /dev/null +++ b/wwwroot/composer.json @@ -0,0 +1,11 @@ +{ + "require": { + "open-telemetry/sdk": "^1.0", + "open-telemetry/exporter-otlp": "^1.0", + "php-http/curl-client": "^2.0", + "nyholm/psr7": "^1.0" + }, + "config": { + "sort-packages": true + } +} diff --git a/wwwroot/fun/edits.php b/wwwroot/fun/edits.php index e0dcfde..57e688b 100644 --- a/wwwroot/fun/edits.php +++ b/wwwroot/fun/edits.php @@ -59,7 +59,7 @@ if(empty($Data[$PageID])) { - $PageQuery = mysqli_query($mysql,"SELECT `Path` FROM `Wiki_Pages` WHERE `ID`='$PageID'"); + $PageQuery = wiki_query("SELECT `Path` FROM `Wiki_Pages` WHERE `ID`='$PageID'"); list($PagePath) = mysqli_fetch_array($PageQuery); $Data[$PageID] = $PagePath; diff --git a/wwwroot/fun/names.php b/wwwroot/fun/names.php index 2f71e72..2ddbadf 100644 --- a/wwwroot/fun/names.php +++ b/wwwroot/fun/names.php @@ -7,7 +7,7 @@ if(empty($ID)) $ID = $_SESSION['ID']; -$AccountQuery = mysqli_query($mysql,"Select `Name` from `Wiki_Accounts` where `ID`='$ID'"); +$AccountQuery = wiki_query("Select `Name` from `Wiki_Accounts` where `ID`='$ID'"); list($AccountName) = mysqli_fetch_array($AccountQuery); $hostname = gethostbyaddr($AccountName); @@ -26,7 +26,7 @@ $Title = "Names $hostname has edited with"; } -$NameQuery = mysqli_query($mysql,"Select `Name`, max(`EditTime`),count(*) as n +$NameQuery = wiki_query("Select `Name`, max(`EditTime`),count(*) as n from `Wiki_Edits` where `AccountID`='$ID' group by `Name` diff --git a/wwwroot/fun/paginate.php b/wwwroot/fun/paginate.php index eed6291..024a5d1 100644 --- a/wwwroot/fun/paginate.php +++ b/wwwroot/fun/paginate.php @@ -46,11 +46,11 @@ function Paginate($Query, $Limit, $Page = 1, $QueryString = '') $Start = $Page * $Limit; $paginationOffset = $Limit * 3; - $CountQuery = mysqli_query($mysql,"$Query limit $Start, $paginationOffset"); + $CountQuery = wiki_query("$Query limit $Start, $paginationOffset"); $Rows = mysqli_num_rows($CountQuery); $Pages = $Page + ceil($Rows / $Limit); - $PageQuery = mysqli_query($mysql,"$Query limit $Start, $Limit"); + $PageQuery = wiki_query("$Query limit $Start, $Limit"); while($Result = mysqli_fetch_array($PageQuery)) { $Data[] = $Result; diff --git a/wwwroot/functions.php b/wwwroot/functions.php index a2bb808..84bae1a 100644 --- a/wwwroot/functions.php +++ b/wwwroot/functions.php @@ -227,18 +227,18 @@ function RandomRow($table, $column) global $mysql; $max_sql = "SELECT max($column) AS max_id FROM $table"; - $max_row = mysqli_fetch_array(mysqli_query($mysql,$max_sql)); + $max_row = mysqli_fetch_array(wiki_query($max_sql)); $random_number = mt_rand(1, $max_row['max_id']); $random_sql = "SELECT * FROM $table WHERE $column >= $random_number ORDER BY $column ASC LIMIT 1"; - $random_row = mysqli_fetch_array(mysqli_query($mysql,$random_sql)); + $random_row = mysqli_fetch_array(wiki_query($random_sql)); while (!is_array($random_row)) { $random_sql = "SELECT * FROM $table WHERE $column < $random_number ORDER BY $column DESC LIMIT 1"; - $random_row = mysqli_fetch_array(mysqli_query($mysql,$random_sql)); + $random_row = mysqli_fetch_array(wiki_query($random_sql)); } return $random_row; diff --git a/wwwroot/index.php b/wwwroot/index.php index 99dc9f3..0bf490c 100644 --- a/wwwroot/index.php +++ b/wwwroot/index.php @@ -108,7 +108,7 @@ function PageTitler($Page) if(!empty($_SESSION['Name'])) { - $LoginQuery = mysqli_query($mysql,"SELECT `ID`,`Name`,`Password`,`Verified`,`EditTime` FROM `Wiki_Accounts` WHERE `ID`='{$_SESSION['ID']}'"); + $LoginQuery = wiki_query("SELECT `ID`,`Name`,`Password`,`Verified`,`EditTime` FROM `Wiki_Accounts` WHERE `ID`='{$_SESSION['ID']}'"); list($ID, $Name, $Password, $Verified, $EditTime) = mysqli_fetch_array($LoginQuery,MYSQLI_NUM); if($Password and $_SESSION['Password'] == $Password) @@ -130,12 +130,12 @@ function PageTitler($Page) } else { - $LoginQuery = mysqli_query($mysql,"SELECT `ID`,`Verified`,`EditTime` FROM `Wiki_Accounts` WHERE `Name`='$userIP'"); + $LoginQuery = wiki_query("SELECT `ID`,`Verified`,`EditTime` FROM `Wiki_Accounts` WHERE `Name`='$userIP'"); list($ID, $Verified, $EditTime) = mysqli_fetch_array($LoginQuery, MYSQLI_NUM); if(empty($ID)) { - mysqli_query($mysql,"INSERT INTO `Wiki_Accounts` VALUES ('NULL', '$userIP', '', '', '', '0', '')"); + wiki_query("INSERT INTO `Wiki_Accounts` VALUES ('NULL', '$userIP', '', '', '', '0', '')"); $ID = mysqli_insert_id($mysql); } @@ -167,7 +167,7 @@ function PageTitler($Page) break; case "fixtags": - $tagQuery = mysqli_query($mysql,"Select `tag` from `Wiki_Tags`"); + $tagQuery = wiki_query("Select `tag` from `Wiki_Tags`"); while(list($tag) = mysqli_fetch_array($tagQuery)) { $fixTags[$tag]++; @@ -175,7 +175,7 @@ function PageTitler($Page) foreach($fixTags as $tag => $count) { - mysqli_query($mysql,"Insert into `Wiki_Tag_Statistics` + wiki_query("Insert into `Wiki_Tag_Statistics` values ('', '$tag', '1', '0', NOW(), NOW()) on duplicate key update `count` = '$count'"); @@ -195,12 +195,12 @@ function PageTitler($Page) break; } - $PageQuery = mysqli_query($mysql,"SELECT `ID`,`Title`,`Content`,`Edits`,`Views`, `EditTime` FROM `Wiki_Pages` WHERE `Path`='$Path'"); + $PageQuery = wiki_query("SELECT `ID`,`Title`,`Content`,`Edits`,`Views`, `EditTime` FROM `Wiki_Pages` WHERE `Path`='$Path'"); list($PageID, $PageTitle, $PageContent, $PageEdits, $pageViews, $PageEditTime) = mysqli_fetch_array($PageQuery); $originalTags = array(); - $tagQuery = mysqli_query($mysql,"Select `tag` from `Wiki_Tags` where `pageID` = '$PageID'"); + $tagQuery = wiki_query("Select `tag` from `Wiki_Tags` where `pageID` = '$PageID'"); while(list($tagName) = mysqli_fetch_array($tagQuery)) { $originalTags[] = $tagName; @@ -297,28 +297,28 @@ function PageTitler($Page) if($PageID) { - mysqli_query($mysql,"UPDATE `Wiki_Pages` SET `Title`='$PageTitle',`Content`='$PageContent' WHERE `ID`='$PageID'"); + wiki_query("UPDATE `Wiki_Pages` SET `Title`='$PageTitle',`Content`='$PageContent' WHERE `ID`='$PageID'"); $SQLError .= mysqli_error($mysql); - mysqli_query($mysql,"INSERT INTO `Wiki_Edits` VALUES ('NULL', '$PageID', '{$_SESSION['ID']}', '$Time', '$Size', '$tagCount', '$tagText', '$Name', '$Description', '$PageTitle', '$PageContent', '')"); + wiki_query("INSERT INTO `Wiki_Edits` VALUES ('NULL', '$PageID', '{$_SESSION['ID']}', '$Time', '$Size', '$tagCount', '$tagText', '$Name', '$Description', '$PageTitle', '$PageContent', '')"); $SQLError .= mysqli_error($mysql); $EditID = mysqli_insert_id($mysql); } else { - mysqli_query($mysql,"INSERT INTO `Wiki_Pages` VALUES ('NULL', '1', '$Path', '$PageTitle', '$PageContent', '', '')"); + wiki_query("INSERT INTO `Wiki_Pages` VALUES ('NULL', '1', '$Path', '$PageTitle', '$PageContent', '', '')"); $SQLError .= mysqli_error($mysql); $PageID = mysqli_insert_id($mysql); - mysqli_query($mysql,"INSERT INTO `Wiki_Edits` VALUES ('NULL', '$PageID', '{$_SESSION['ID']}', '$Time', '$Size', '$tagCount', '$tagText', '$Name', '$Description', '$PageTitle', '$PageContent', '')"); + wiki_query("INSERT INTO `Wiki_Edits` VALUES ('NULL', '$PageID', '{$_SESSION['ID']}', '$Time', '$Size', '$tagCount', '$tagText', '$Name', '$Description', '$PageTitle', '$PageContent', '')"); $SQLError .= mysqli_error($mysql); $EditID = mysqli_insert_id($mysql); } - mysqli_query($mysql,"Delete from `Wiki_Tags` where `pageID`='$PageID'"); + wiki_query("Delete from `Wiki_Tags` where `pageID`='$PageID'"); foreach($newTags as $tag) { @@ -327,7 +327,7 @@ function PageTitler($Page) if($tag) { $tag = str_replace(" ", "-", $tag); - mysqli_query($mysql,"Insert into `Wiki_Tags` values('', '$PageID', '$tag')"); + wiki_query("Insert into `Wiki_Tags` values('', '$PageID', '$tag')"); $tagKey = array_search($tag, $originalTags); @@ -342,7 +342,7 @@ function PageTitler($Page) //echo "
Tag update called
"; // If the current tag doesn't exist in the original tag array, insert/update it - mysqli_query($mysql,"Insert into `Wiki_Tag_Statistics` + wiki_query("Insert into `Wiki_Tag_Statistics` values ('', '$tag', '1', '0', NOW(), NOW()) on duplicate key update `count` = `count` + 1, `modified` = NOW()"); @@ -358,7 +358,7 @@ function PageTitler($Page) // Take all the remaining original tags and subtract one from the count foreach($originalTags as $tag) { - mysqli_query($mysql,"Update `Wiki_Tag_Statistics` + wiki_query("Update `Wiki_Tag_Statistics` set `count` = `count` - 1 where `tag`='$tag'"); } @@ -381,10 +381,10 @@ function PageTitler($Page) $UserEdits = implode(",", $UserEdits); - mysqli_query($mysql,"UPDATE `Wiki_Pages` SET `Edits`='$PageEdits',`EditTime`='$Time' WHERE `ID`='$PageID'"); + wiki_query("UPDATE `Wiki_Pages` SET `Edits`='$PageEdits',`EditTime`='$Time' WHERE `ID`='$PageID'"); $SQLError .= mysqli_error($mysql); - mysqli_query($mysql,"UPDATE `Wiki_Accounts` SET `EditTime`='$Time' WHERE `ID`='{$_SESSION['ID']}'"); + wiki_query("UPDATE `Wiki_Accounts` SET `EditTime`='$Time' WHERE `ID`='{$_SESSION['ID']}'"); $SQLError .= mysqli_error($mysql); if($SQLError) @@ -510,35 +510,35 @@ function PageTitler($Page) //$BadAccount = 250481; $BadAccount = 250534; - $PageQuery = mysqli_query($mysql,"SELECT `ID`, `PageID` FROM `Wiki_Edits` WHERE `AccountID`='$BadAccount'"); + $PageQuery = wiki_query("SELECT `ID`, `PageID` FROM `Wiki_Edits` WHERE `AccountID`='$BadAccount'"); while(list($BadEditID, $PageID) = mysqli_fetch_array($PageQuery)) { if(empty($Reverted[$PageID])) { - $DataQuery = mysqli_query($mysql,"SELECT `Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `PageID`='$PageID' AND `AccountID`!='$BadAccount' AND `Archived` = '0' ORDER BY `ID` DESC LIMIT 1"); + $DataQuery = wiki_query("SELECT `Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `PageID`='$PageID' AND `AccountID`!='$BadAccount' AND `Archived` = '0' ORDER BY `ID` DESC LIMIT 1"); list($PageName, $PageDescription, $PageTitle, $PageContent) = mysqli_fetch_array($DataQuery); $Time = Time(); $Size = strlen($PageContent); - mysqli_query($mysql,"UPDATE `Wiki_Pages` SET `EditTime`='$Time',`Title`='$PageTitle',`Content`='$PageContent' WHERE `ID`='$PageID'"); + wiki_query("UPDATE `Wiki_Pages` SET `EditTime`='$Time',`Title`='$PageTitle',`Content`='$PageContent' WHERE `ID`='$PageID'"); $SQLError .= mysqli_error($mysql); - //mysqli_query($mysql,"INSERT INTO `Wiki_Edits` VALUES ('NULL', '$PageID', '{$_SESSION['ID']}', '$Time', '$Size', '$PageName', 'Rachel's Super Revert: $PageDescription', '$PageTitle', '$PageContent', '')"); + //wiki_query("INSERT INTO `Wiki_Edits` VALUES ('NULL', '$PageID', '{$_SESSION['ID']}', '$Time', '$Size', '$PageName', 'Rachel's Super Revert: $PageDescription', '$PageTitle', '$PageContent', '')"); //$SQLError .= mysqli_error($mysql); - //mysqli_query($mysql,"UPDATE `Wiki_Accounts` SET `EditTime`='$Time' WHERE `ID`='{$_SESSION['ID']}'"); + //wiki_query("UPDATE `Wiki_Accounts` SET `EditTime`='$Time' WHERE `ID`='{$_SESSION['ID']}'"); //$SQLError .= mysqli_error($mysql); - mysqli_query($mysql,"UPDATE `Wiki_Edits` SET `Archived` = 1 where `ID` = '$BadEditID'"); + wiki_query("UPDATE `Wiki_Edits` SET `Archived` = 1 where `ID` = '$BadEditID'"); $SQLError .= mysqli_error($mysql); $Reverted[$PageID] = TRUE; } else { - mysqli_query($mysql,"UPDATE `Wiki_Edits` SET `Archived` = 1 where `ID` = '$BadEditID'"); + wiki_query("UPDATE `Wiki_Edits` SET `Archived` = 1 where `ID` = '$BadEditID'"); $SQLError .= mysqli_error($mysql); } } @@ -553,7 +553,7 @@ function PageTitler($Page) case "revert": $Head = ''; - $PageQuery = mysqli_query($mysql,"SELECT `PageID`,`Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `ID`='$Action[1]'"); + $PageQuery = wiki_query("SELECT `PageID`,`Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `ID`='$Action[1]'"); list($PageID, $PageName, $PageDescription, $PageTitle, $PageContent) = mysqli_fetch_array($PageQuery); if($PageID and $_SESSION['Verified'] == 1) @@ -567,13 +567,13 @@ function PageTitler($Page) break; } - mysqli_query($mysql,"UPDATE `Wiki_Pages` SET `EditTime`='$Time',`Title`='$PageTitle',`Content`='$PageContent' WHERE `ID`='$PageID'"); + wiki_query("UPDATE `Wiki_Pages` SET `EditTime`='$Time',`Title`='$PageTitle',`Content`='$PageContent' WHERE `ID`='$PageID'"); $SQLError .= mysqli_error($mysql); - mysqli_query($mysql,"INSERT INTO `Wiki_Edits` VALUES ('NULL', '$PageID', '{$_SESSION['ID']}', '$Time', '$Size', '$PageName', 'Reverted to: $PageDescription', '$PageTitle', '$PageContent', '')"); + wiki_query("INSERT INTO `Wiki_Edits` VALUES ('NULL', '$PageID', '{$_SESSION['ID']}', '$Time', '$Size', '$PageName', 'Reverted to: $PageDescription', '$PageTitle', '$PageContent', '')"); $SQLError .= mysqli_error($mysql); - mysqli_query($mysql,"UPDATE `Wiki_Accounts` SET `EditTime`='$Time' WHERE `ID`='{$_SESSION['ID']}'"); + wiki_query("UPDATE `Wiki_Accounts` SET `EditTime`='$Time' WHERE `ID`='{$_SESSION['ID']}'"); $SQLError .= mysqli_error($mysql); if($SQLError) @@ -615,7 +615,7 @@ function PageTitler($Page) if(empty($Form['_Errors'])) { - $Penis = mysqli_query($mysql,"Select `Name` from `Wiki_Accounts` where `Name`='$Name'"); + $Penis = wiki_query("Select `Name` from `Wiki_Accounts` where `Name`='$Name'"); list($OldName) = mysqli_fetch_array($Penis); if($Name == $OldName) diff --git a/wwwroot/popular.php b/wwwroot/popular.php index 4a7e835..cc21a70 100644 --- a/wwwroot/popular.php +++ b/wwwroot/popular.php @@ -4,7 +4,7 @@ require('functions.php'); -$viewsQuery = mysqli_query($mysql,"Select `Path`,`Title`,`Views` +$viewsQuery = wiki_query("Select `Path`,`Title`,`Views` from Wiki_Pages order by `Views` desc limit 40"); @@ -31,7 +31,7 @@ } -$peopleQuery = mysqli_query($mysql,"Select Name,count(*) as n +$peopleQuery = wiki_query("Select Name,count(*) as n from Wiki_Edits where Archived != 1 group by Name @@ -64,7 +64,7 @@ } -$pageQuery = mysqli_query($mysql,"Select PageID,count(*) as n +$pageQuery = wiki_query("Select PageID,count(*) as n from Wiki_Edits where Archived != 1 group by PageID @@ -73,7 +73,7 @@ while(list($pageID, $count) = mysqli_fetch_array($pageQuery)) { - $pageInfo = mysqli_query($mysql,"Select `Path`, `Title` from `Wiki_Pages` where `ID`='$pageID'"); + $pageInfo = wiki_query("Select `Path`, `Title` from `Wiki_Pages` where `ID`='$pageID'"); list($path, $title) = mysqli_fetch_array($pageInfo); $pageCount++; diff --git a/wwwroot/search.php b/wwwroot/search.php index 6dd5786..a8b3825 100644 --- a/wwwroot/search.php +++ b/wwwroot/search.php @@ -15,7 +15,7 @@ where match(`Path`, `Title`, `Content`) against('$Search')"; - $Results = mysqli_num_rows(mysqli_query($mysql,$Query)); + $Results = mysqli_num_rows(wiki_query($Query)); $Time = time(); if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) @@ -47,7 +47,7 @@ echo "
Looks like your search didn't turn up anything.
Your query might be too short, too common, or maybe it's really not here.
"; else { - $TimeQuery = mysqli_query($mysql,"Select `Time` + $TimeQuery = wiki_query("Select `Time` from `Wiki Searches` where `IP`='$userIP' and `Search`='$Search' order by `ID` desc"); @@ -55,7 +55,7 @@ list($OldTime) = mysqli_fetch_array($TimeQuery); if($OldTime + 86400 < $Time) - mysqli_query($mysql,"Insert into `Wiki Searches` values ('', '$Time', '$Results', '$Search', '$userIP')"); + wiki_query("Insert into `Wiki Searches` values ('', '$Time', '$Results', '$Search', '$userIP')"); } echo "
$Links
"; diff --git a/wwwroot/src/actions/archive.php b/wwwroot/src/actions/archive.php index 790f980..9eb7ad5 100644 --- a/wwwroot/src/actions/archive.php +++ b/wwwroot/src/actions/archive.php @@ -17,7 +17,7 @@ function archive($path, $action, $title, $content) { if($_POST['confirmed']) { - mysqli_query($mysql, "Update `Wiki_Edits` set `Archived` = '1' where `ID` = '{$action[1]}'"); + wiki_query( "Update `Wiki_Edits` set `Archived` = '1' where `ID` = '{$action[1]}'"); $content['Body'] = "

Edit archived!

"; } else @@ -40,14 +40,14 @@ function archive($path, $action, $title, $content) if($_POST['confirmed']) { // Get the page ID - $PageQuery = mysqli_query($mysql,"SELECT `ID` FROM `Wiki_Pages` WHERE `Path`='$path'"); + $PageQuery = wiki_query("SELECT `ID` FROM `Wiki_Pages` WHERE `Path`='$path'"); list($pageID) = mysqli_fetch_array($PageQuery); if($pageID) { - mysqli_query($mysql,"Update `Wiki_Edits` set `Archived` = '1' where `PageID` = '{$pageID}'"); - mysqli_query($mysql,"Delete from `Wiki_Tags` where `pageID` = '{$pageID}'"); - mysqli_query($mysql,"Delete from `Wiki_Pages` where `ID` = '{$pageID}'"); + wiki_query("Update `Wiki_Edits` set `Archived` = '1' where `PageID` = '{$pageID}'"); + wiki_query("Delete from `Wiki_Tags` where `pageID` = '{$pageID}'"); + wiki_query("Delete from `Wiki_Pages` where `ID` = '{$pageID}'"); $content['Body'] = "

Page archived!

"; } else diff --git a/wwwroot/src/actions/diff.php b/wwwroot/src/actions/diff.php index f403bf5..5b29443 100644 --- a/wwwroot/src/actions/diff.php +++ b/wwwroot/src/actions/diff.php @@ -11,13 +11,13 @@ function diff($path, $action, $title, $content) if(is_numeric($action[1])) { - $pageQuery = mysqli_query($mysql,"SELECT `PageID`,`AccountID`,`EditTime`,`Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `ID`='$action[1]' and `Archived` = 0"); + $pageQuery = wiki_query("SELECT `PageID`,`AccountID`,`EditTime`,`Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `ID`='$action[1]' and `Archived` = 0"); list($PageID, $AccountID, $PageEditTime, $PageName, $PageDescription, $PageTitle, $pageContent) = mysqli_fetch_array($pageQuery); - $previousQuery = mysqli_query($mysql,"Select `ID`, `Content` from `Wiki_Edits` where `ID` < '$action[1]' and `PageID`='$PageID' and `Archived` = 0 order by `ID` desc limit 1"); + $previousQuery = wiki_query("Select `ID`, `Content` from `Wiki_Edits` where `ID` < '$action[1]' and `PageID`='$PageID' and `Archived` = 0 order by `ID` desc limit 1"); list($previousID, $previousContent) = mysqli_fetch_array($previousQuery); - $nextQuery = mysqli_query($mysql,"Select `ID` from `Wiki_Edits` where `ID` > '$action[1]' and `PageID`='$PageID' and `Archived` = 0 order by `ID` limit 1"); + $nextQuery = wiki_query("Select `ID` from `Wiki_Edits` where `ID` > '$action[1]' and `PageID`='$PageID' and `Archived` = 0 order by `ID` limit 1"); list($nextID) = mysqli_fetch_array($nextQuery); if(!empty($previousID)) diff --git a/wwwroot/src/actions/history.php b/wwwroot/src/actions/history.php index b68dc23..1d3d326 100644 --- a/wwwroot/src/actions/history.php +++ b/wwwroot/src/actions/history.php @@ -6,19 +6,19 @@ function history($path, $action, $title, $content) $Head = ''; $content['PageNav']->Active("Page History"); - $pageQuery = mysqli_query($mysql,"Select `ID` from `Wiki_Pages` where `Path`='$path'"); + $pageQuery = wiki_query("Select `ID` from `Wiki_Pages` where `Path`='$path'"); list($pageID) = mysqli_fetch_array($pageQuery); - $totalQuery = mysqli_query($mysql,"Select `ID` + $totalQuery = wiki_query("Select `ID` from `Wiki_Edits` where `PageID` = '$pageID' and `Archived` = 0"); - $nextQuery = mysqli_query($mysql,"Select `ID`, `Title` + $nextQuery = wiki_query("Select `ID`, `Title` from `Wiki_Edits` where `PageID` = '$pageID' and `Archived` = 0 order by `ID` desc limit 1"); - $previousQuery = mysqli_query($mysql,"Select `ID`, `Title` + $previousQuery = wiki_query("Select `ID`, `Title` from `Wiki_Edits` where `PageID` = '$pageID' and `Archived` = 0 order by `ID` limit 1"); @@ -30,19 +30,19 @@ function history($path, $action, $title, $content) if(is_numeric($action[1])) { - $PreviousQuery = mysqli_query($mysql,"Select `Content` from `Wiki_Edits` where `ID` < '$action[1]' and `Archived` = 0 order by `ID` desc limit 1"); + $PreviousQuery = wiki_query("Select `Content` from `Wiki_Edits` where `ID` < '$action[1]' and `Archived` = 0 order by `ID` desc limit 1"); list($PreviousContent) = mysqli_fetch_array($PreviousQuery); - $PageQuery = mysqli_query($mysql,"SELECT `AccountID`,`EditTime`,`Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `ID`='$action[1]' and `Archived` = 0"); + $PageQuery = wiki_query("SELECT `AccountID`,`EditTime`,`Name`,`Description`,`Title`,`Content` FROM `Wiki_Edits` WHERE `ID`='$action[1]' and `Archived` = 0"); list($AccountID, $PageEditTime, $PageName, $PageDescription, $PageTitle, $PageContent) = mysqli_fetch_array($PageQuery); - $previousQuery = mysqli_query($mysql,"Select `ID`, `Title` + $previousQuery = wiki_query("Select `ID`, `Title` from `Wiki_Edits` where `PageID` = '$pageID' and `ID` > '$action[1]' and `Archived` = 0 order by `ID` limit 1"); - $nextQuery = mysqli_query($mysql,"Select `ID`, `Title` + $nextQuery = wiki_query("Select `ID`, `Title` from `Wiki_Edits` where `PageID` = '$pageID' and `ID` < '$action[1]' and `Archived` = 0 order by `ID` desc limit 1"); @@ -95,7 +95,7 @@ function history($path, $action, $title, $content) $content['Title'] = " Page History "; - $PageQuery = mysqli_query($mysql,"SELECT `ID` FROM `Wiki_Pages` WHERE `Path`='$path'"); + $PageQuery = wiki_query("SELECT `ID` FROM `Wiki_Pages` WHERE `Path`='$path'"); list($PageID) = mysqli_fetch_array($PageQuery); $HistoryQuery = "SELECT `ID`,`AccountID`,`EditTime`,`Size`,`Tags`,`Name`,`Description`,`Title` FROM `Wiki_Edits` WHERE `PageID`='$PageID' and `Archived` = 0 ORDER BY `ID` DESC"; diff --git a/wwwroot/src/actions/random.php b/wwwroot/src/actions/random.php index 71db515..7021713 100644 --- a/wwwroot/src/actions/random.php +++ b/wwwroot/src/actions/random.php @@ -6,7 +6,7 @@ function random($path, $action, $title, $content) $tagLinks = []; if($path) { - $PageQuery = mysqli_query($mysql,"SELECT `ID`,`Title`,`Content`,`Edits`,`Views`,`EditTime` FROM `Wiki_Pages` WHERE `Path` = '$path'"); + $PageQuery = wiki_query("SELECT `ID`,`Title`,`Content`,`Edits`,`Views`,`EditTime` FROM `Wiki_Pages` WHERE `Path` = '$path'"); list($PageID, $PageTitle, $PageContent, $PageEdits, $pageViews, $PageEditTime) = mysqli_fetch_array($PageQuery); @@ -20,7 +20,7 @@ function random($path, $action, $title, $content) $next = $pageNext; - $tagQuery = mysqli_query($mysql,"Select tags.`tag`, stats.`count` + $tagQuery = wiki_query("Select tags.`tag`, stats.`count` from `Wiki_Tags` as tags, `Wiki_Tag_Statistics` as stats @@ -63,7 +63,7 @@ function random($path, $action, $title, $content) else { - mysqli_query($mysql,"Update `Wiki_Pages` set `Views` = `Views` + 1 where `ID`='$PageID'"); + wiki_query("Update `Wiki_Pages` set `Views` = `Views` + 1 where `ID`='$PageID'"); } if($previous['Path']) diff --git a/wwwroot/src/actions/recent.php b/wwwroot/src/actions/recent.php index e1ab540..5abf827 100644 --- a/wwwroot/src/actions/recent.php +++ b/wwwroot/src/actions/recent.php @@ -42,7 +42,7 @@ function recent($path, $action, $title, $content) if(empty($Data[$PageID])) { - $PageQuery = mysqli_query($mysql,"SELECT `Path` FROM `Wiki_Pages` WHERE `ID`='$PageID'"); + $PageQuery = wiki_query("SELECT `Path` FROM `Wiki_Pages` WHERE `ID`='$PageID'"); list($PagePath) = mysqli_fetch_array($PageQuery); $Data[$PageID] = $PagePath; diff --git a/wwwroot/src/actions/rename.php b/wwwroot/src/actions/rename.php index 6ab5605..70e7764 100644 --- a/wwwroot/src/actions/rename.php +++ b/wwwroot/src/actions/rename.php @@ -15,14 +15,14 @@ function action_rename($path, $action, $title, $content) if(!empty($_POST)) { $path = mysqli_real_escape_string($mysql,$path); - $page_query = mysqli_query($mysql,"Select ID from `Wiki_Pages` where Path = '{$path}' limit 1"); + $page_query = wiki_query("Select ID from `Wiki_Pages` where Path = '{$path}' limit 1"); list($page_id) = mysqli_fetch_array($page_query); // We can only change the path of an existing page... if($page_id) { $new = str_replace(" ", "-", $_POST['new']); - mysqli_query($mysql,"Update `Wiki_Pages` set `Path` = '".mysqli_real_escape_string($mysql, $new)."' where ID = '{$page_id}'"); + wiki_query("Update `Wiki_Pages` set `Path` = '".mysqli_real_escape_string($mysql, $new)."' where ID = '{$page_id}'"); $content['Title'] = "Page renamed!"; $content['Body'] = "

The old page {$path} has been renamed to {$_POST['new']}

"; diff --git a/wwwroot/src/actions/replace.php b/wwwroot/src/actions/replace.php index c89f2a9..2e31117 100644 --- a/wwwroot/src/actions/replace.php +++ b/wwwroot/src/actions/replace.php @@ -21,26 +21,26 @@ function replace($path, $action, $title, $content) ); // Loop through all pages - $pageQuery = mysqli_query($mysql,"Select `ID`, `Content` from `Wiki_Pages`"); + $pageQuery = wiki_query("Select `ID`, `Content` from `Wiki_Pages`"); while(list($pageID, $pageContent) = mysqli_fetch_array($pageQuery)) { $pageContent = str_replace($_POST['find'], $_POST['replace'], $pageContent); $pageContent = mysqli_real_escape_string($pageContent); - mysqli_query($mysql,"Update `Wiki_Pages` set `Content` = '{$pageContent}' where `ID` = '{$pageID}'"); + wiki_query("Update `Wiki_Pages` set `Content` = '{$pageContent}' where `ID` = '{$pageID}'"); unset($pageID, $pageContent); $count['pages']++; } // Loop through all edits - $editQuery = mysqli_query($mysql,"Select `ID`, `Content` from `Wiki_Edits`"); + $editQuery = wiki_query("Select `ID`, `Content` from `Wiki_Edits`"); while(list($editID, $editContent) = mysqli_fetch_array($editQuery)) { $editContent = str_replace($_POST['find'], $_POST['replace'], $editContent); $editContent = mysqli_real_escape_string($editContent); - mysqli_query($mysql,"Update `Wiki_Edits` set `Content` = '{$editContent}' where `ID` = '{$editID}'"); + wiki_query("Update `Wiki_Edits` set `Content` = '{$editContent}' where `ID` = '{$editID}'"); unset($editID, $editContent); $count['edits']++; diff --git a/wwwroot/src/actions/source.php b/wwwroot/src/actions/source.php index 74213b3..2e81526 100644 --- a/wwwroot/src/actions/source.php +++ b/wwwroot/src/actions/source.php @@ -12,7 +12,7 @@ function source($path, $action, $title, $content) if(is_numeric($action[1])) { - $PageQuery = mysqli_query($mysql,"SELECT `AccountID`,`EditTime`,`Name`,`Description`,`Title`,`Content`,`TagList` FROM `Wiki_Edits` WHERE `ID`='$action[1]' and `Archived` = 0"); + $PageQuery = wiki_query("SELECT `AccountID`,`EditTime`,`Name`,`Description`,`Title`,`Content`,`TagList` FROM `Wiki_Edits` WHERE `ID`='$action[1]' and `Archived` = 0"); list($AccountID, $PageEditTime, $PageName, $PageDescription, $PageTitle, $PageContent, $tagText) = mysqli_fetch_array($PageQuery); $Form['_Options'] = "action:;"; diff --git a/wwwroot/src/actions/tag.php b/wwwroot/src/actions/tag.php index 7df09a8..5b8142b 100644 --- a/wwwroot/src/actions/tag.php +++ b/wwwroot/src/actions/tag.php @@ -12,18 +12,18 @@ function tag($path, $action, $title, $content) if(isset($action[2])) $path = $action[2]; - $totalQuery = mysqli_query($mysql,"Select stats.`count` + $totalQuery = wiki_query("Select stats.`count` from `Wiki_Tag_Statistics` as stats where stats.`tag` = '$tag'"); - $nextQuery = mysqli_query($mysql,"Select `Path`, `Title` + $nextQuery = wiki_query("Select `Path`, `Title` from `Wiki_Pages`, `Wiki_Tags` as tag where tag.`tag` = '$tag' and tag.`pageID` = `ID` order by tag.`tagID` desc limit 1"); - $previousQuery = mysqli_query($mysql,"Select `Path`, `Title` + $previousQuery = wiki_query("Select `Path`, `Title` from `Wiki_Pages`, `Wiki_Tags` as tag where tag.`tag` = '$tag' and tag.`pageID` = `ID` @@ -36,16 +36,16 @@ function tag($path, $action, $title, $content) // Check if we're actually on the home page if($path or isset($action[2]) or preg_match("{^/home}", $_SERVER['REQUEST_URI'])) { - $PageQuery = mysqli_query($mysql,"SELECT `ID`,`Title`,`Content`,`Edits`,`Views`,`EditTime`,tag.`tagID` FROM `Wiki_Pages`, `Wiki_Tags` as tag WHERE `Path` like '$path' and tag.`tag` = '$tag' and tag.`pageID` = `ID`"); + $PageQuery = wiki_query("SELECT `ID`,`Title`,`Content`,`Edits`,`Views`,`EditTime`,tag.`tagID` FROM `Wiki_Pages`, `Wiki_Tags` as tag WHERE `Path` like '$path' and tag.`tag` = '$tag' and tag.`pageID` = `ID`"); list($PageID, $PageTitle, $PageContent, $PageEdits, $pageViews, $PageEditTime, $tagID) = mysqli_fetch_array($PageQuery); - $previousQuery = mysqli_query($mysql,"Select `Path`, `Title` + $previousQuery = wiki_query("Select `Path`, `Title` from `Wiki_Pages`, `Wiki_Tags` as tag where tag.`tag` = '$tag' and tag.`pageID` = `ID` and tag.`tagID` >'$tagID' order by tag.`tagID` limit 1"); - $nextQuery = mysqli_query($mysql,"Select `Path`, `Title` + $nextQuery = wiki_query("Select `Path`, `Title` from `Wiki_Pages`, `Wiki_Tags` as tag where tag.`tag` = '$tag' and tag.`pageID` = `ID` and tag.`tagID` < '$tagID' @@ -61,7 +61,7 @@ function tag($path, $action, $title, $content) $next = $pageNext; - $tagQuery = mysqli_query($mysql,"Select tags.`tag`, stats.`count` + $tagQuery = wiki_query("Select tags.`tag`, stats.`count` from `Wiki_Tags` as tags, `Wiki_Tag_Statistics` as stats @@ -104,7 +104,7 @@ function tag($path, $action, $title, $content) else { - mysqli_query($mysql,"Update `Wiki_Pages` set `Views` = `Views` + 1 where `ID`='$PageID'"); + wiki_query("Update `Wiki_Pages` set `Views` = `Views` + 1 where `ID`='$PageID'"); } if($_SESSION['admin']) @@ -131,7 +131,7 @@ function tag($path, $action, $title, $content) } else { - mysqli_query($mysql,"Update `Wiki_Tag_Statistics` set `views` = `views` + 1 + wiki_query("Update `Wiki_Tag_Statistics` set `views` = `views` + 1 where `tag` = '$tag'"); if($previous['Path']) @@ -163,7 +163,7 @@ function tag($path, $action, $title, $content) { list($pageID, $pagePath, $pageTitle, $pageContent) = $Result; - $tagQuery = mysqli_query($mysql,"Select tags.`tag`, stats.`count` + $tagQuery = wiki_query("Select tags.`tag`, stats.`count` from `Wiki_Tags` as tags, `Wiki_Tag_Statistics` as stats diff --git a/wwwroot/src/actions/view.php b/wwwroot/src/actions/view.php index 58ffa74..ab8431f 100644 --- a/wwwroot/src/actions/view.php +++ b/wwwroot/src/actions/view.php @@ -6,10 +6,10 @@ function view($path, $action, $title, $content) $content['PageNav']->Active("View Page"); $tagLinks = null; - $PageQuery = mysqli_query($mysql,"SELECT `ID`,`Title`,`Content`,`Edits`,`Views`,`EditTime` FROM `Wiki_Pages` WHERE `Path`='$path'"); + $PageQuery = wiki_query("SELECT `ID`,`Title`,`Content`,`Edits`,`Views`,`EditTime` FROM `Wiki_Pages` WHERE `Path`='$path'"); list($PageID, $PageTitle, $PageContent, $PageEdits, $pageViews, $PageEditTime) = mysqli_fetch_array($PageQuery); - $tagQuery = mysqli_query($mysql,"Select tags.`tag`, stats.`count` + $tagQuery = wiki_query("Select tags.`tag`, stats.`count` from `Wiki_Tags` as tags, `Wiki_Tag_Statistics` as stats @@ -53,7 +53,7 @@ function view($path, $action, $title, $content) else { - mysqli_query($mysql,"Update `Wiki_Pages` set `Views` = `Views` + 1 where `ID`='$PageID'"); + wiki_query("Update `Wiki_Pages` set `Views` = `Views` + 1 where `ID`='$PageID'"); } if(!empty($_SESSION['admin'])) diff --git a/wwwroot/src/markup/edit.php b/wwwroot/src/markup/edit.php index f6c9934..55d04ea 100644 --- a/wwwroot/src/markup/edit.php +++ b/wwwroot/src/markup/edit.php @@ -156,7 +156,7 @@ function edit_replacements($tag, $content) // Make sure the user IP is sanitized $userIP = preg_replace('/[^0-9.]/', '', $userIP); - mysqli_query($mysql,"Insert into `Images` values ('NULL', '$Time', '', '$userIP', '$Link', 'upload/$Filename.$Extension')"); + wiki_query("Insert into `Images` values ('NULL', '$Time', '', '$userIP', '$Link', 'upload/$Filename.$Extension')"); $Text = trim("upload/$Filename.$Extension|$Size|$Position|$Border|$Text", '|'); return array('tag' => strtolower($tag), 'content' => $Text); @@ -238,7 +238,7 @@ function edit_replacements($tag, $content) // Make sure the user IP is sanitized $userIP = preg_replace('/[^0-9.]/', '', $userIP); - mysqli_query($mysql,"Insert into `Images` values ('NULL', '$time', '', '$userIP', '$link', 'upload/$Filename.$Extension')"); + wiki_query("Insert into `Images` values ('NULL', '$time', '', '$userIP', '$link', 'upload/$Filename.$Extension')"); $text = trim("upload/$Filename.$Extension|$autoplay|$loop", '|'); return array('tag' => strtolower($tag), 'content' => $text); diff --git a/wwwroot/src/markup/view.php b/wwwroot/src/markup/view.php index dcb1800..24148d0 100644 --- a/wwwroot/src/markup/view.php +++ b/wwwroot/src/markup/view.php @@ -49,7 +49,7 @@ function view_replacements($tag, $content) switch(strtolower($content)) { case "pages": - $pageTotal = mysqli_query($mysql,"Select `ID` from `Wiki_Pages`"); + $pageTotal = wiki_query("Select `ID` from `Wiki_Pages`"); $totalPages = mysqli_num_rows($pageTotal); return number_format($totalPages); @@ -652,7 +652,7 @@ function replace_links($matches, $mode) // Check if the page exists $escaped_page = mysqli_real_escape_string($mysql, $page); - $page_query = mysqli_query($mysql, "Select ID from `Wiki_Pages` where `Path`='{$escaped_page}'"); + $page_query = wiki_query( "Select ID from `Wiki_Pages` where `Path`='{$escaped_page}'"); list($page_exists) = mysqli_fetch_array($page_query); if(empty($page_exists)) diff --git a/wwwroot/src/mysql.php b/wwwroot/src/mysql.php index 16d1c13..b0dd1d4 100644 --- a/wwwroot/src/mysql.php +++ b/wwwroot/src/mysql.php @@ -1,6 +1,7 @@ spanBuilder('db.query') + ->setAttribute('db.system', 'mariadb') + ->setAttribute('db.statement', $sql) + ->startSpan(); + $scope = $span->activate(); + + $result = mysqli_query($mysql, $sql); + + if ($result === false) { + $span->setAttribute('db.error', mysqli_error($mysql)); + $span->setStatus(\OpenTelemetry\API\Trace\StatusCode::STATUS_ERROR, mysqli_error($mysql)); + } + + $span->end(); + $scope->detach(); + return $result; +} + ?> diff --git a/wwwroot/src/pages/tag-cloud.php b/wwwroot/src/pages/tag-cloud.php index beacb6b..2e999f6 100644 --- a/wwwroot/src/pages/tag-cloud.php +++ b/wwwroot/src/pages/tag-cloud.php @@ -6,7 +6,7 @@ $popularTags = array(); $recentTags = array(); -$viewedQuery = mysqli_query($mysql,"Select `tag`, `views` +$viewedQuery = wiki_query("Select `tag`, `views` from `Wiki_Tag_Statistics` order by `views` desc limit 50"); @@ -29,7 +29,7 @@ -$popularQuery = mysqli_query($mysql,"Select `tag`, `count`, `modified` +$popularQuery = wiki_query("Select `tag`, `count`, `modified` from `Wiki_Tag_Statistics` order by `count` desc limit 50"); @@ -52,7 +52,7 @@ echo ""; -$recentQuery = mysqli_query($mysql,"Select `tag`, `count`, `modified` +$recentQuery = wiki_query("Select `tag`, `count`, `modified` from `Wiki_Tag_Statistics` order by `modified` desc limit 50"); diff --git a/wwwroot/src/pages/tags.php b/wwwroot/src/pages/tags.php index d60c65c..5b4e9ec 100644 --- a/wwwroot/src/pages/tags.php +++ b/wwwroot/src/pages/tags.php @@ -4,7 +4,7 @@ include('../functions.php'); -$viewedQuery = mysqli_query($mysql,"Select `tag`, `views` +$viewedQuery = wiki_query("Select `tag`, `views` from `Wiki_Tag_Statistics` order by `views` desc limit 35"); @@ -17,7 +17,7 @@ $viewedTable .= "$viewedCount$tagText$views"; } -$popularQuery = mysqli_query($mysql,"Select `tag`, `count`, `modified` +$popularQuery = wiki_query("Select `tag`, `count`, `modified` from `Wiki_Tag_Statistics` order by `count` desc limit 35"); @@ -31,7 +31,7 @@ $popularTable .= "$popularCount$tagText$count$popularDate"; } -$recentQuery = mysqli_query($mysql,"Select `tag`, `count`, `modified` +$recentQuery = wiki_query("Select `tag`, `count`, `modified` from `Wiki_Tag_Statistics` order by `modified` desc limit 35"); @@ -46,7 +46,7 @@ } /* -$newestQuery = mysqli_query($mysql,"Select `tag`, `count`, `modified` +$newestQuery = wiki_query("Select `tag`, `count`, `modified` from `Wiki_Tag_Statistics` order by `created` desc limit 35"); diff --git a/wwwroot/src/telemetry.php b/wwwroot/src/telemetry.php new file mode 100644 index 0000000..90acbd5 --- /dev/null +++ b/wwwroot/src/telemetry.php @@ -0,0 +1,38 @@ +getTracer('wiki', '1.0.0'); + +$_otelRootSpan = $tracer->spanBuilder('http ' . ($_SERVER['REQUEST_METHOD'] ?? 'GET')) + ->setSpanKind(SpanKind::KIND_SERVER) + ->setAttribute('http.method', $_SERVER['REQUEST_METHOD'] ?? 'GET') + ->setAttribute('http.target', $_SERVER['REQUEST_URI'] ?? '/') + ->setAttribute('http.host', $_SERVER['HTTP_HOST'] ?? '') + ->startSpan(); + +$_otelRootScope = $_otelRootSpan->activate(); + +register_shutdown_function(function() { + global $_otelRootSpan, $_otelRootScope; + if (!isset($_otelRootSpan)) return; + $status = http_response_code() ?: 200; + $_otelRootSpan->setAttribute('http.status_code', $status); + if ($status >= 500) { + $_otelRootSpan->setStatus(StatusCode::STATUS_ERROR); + } + $_otelRootSpan->end(); + $_otelRootScope->detach(); +}); diff --git a/wwwroot/stats/edits.php b/wwwroot/stats/edits.php index 50b2cca..9181d61 100644 --- a/wwwroot/stats/edits.php +++ b/wwwroot/stats/edits.php @@ -23,7 +23,7 @@ } $display = strtotime($display); -$query = mysqli_query($mysql,"Select `EditTime` from `Wiki_Edits` where `EditTime` > {$display} order by `EditTime` asc"); +$query = wiki_query("Select `EditTime` from `Wiki_Edits` where `EditTime` > {$display} order by `EditTime` asc"); while(list($time) = mysqli_fetch_array($query)) { diff --git a/wwwroot/stats/searches.php b/wwwroot/stats/searches.php index a8701bd..5f7e4d9 100644 --- a/wwwroot/stats/searches.php +++ b/wwwroot/stats/searches.php @@ -13,7 +13,7 @@ $LastWeek = $Today - ($Day * 30); -$Query = mysqli_query($mysql,"Select `Time` from `Wiki Searches` where `Time` > $LastWeek"); +$Query = wiki_query("Select `Time` from `Wiki Searches` where `Time` > $LastWeek"); while(list($Time) = mysqli_fetch_array($Query)) { $When = date('d M', $Time); diff --git a/wwwroot/superpopular.php b/wwwroot/superpopular.php index cabc622..572bc86 100644 --- a/wwwroot/superpopular.php +++ b/wwwroot/superpopular.php @@ -2,7 +2,7 @@ require('functions.php'); include('src/connection.php'); -$PeopleQuery = mysqli_query($mysql,"Select AccountID,count(*) as n +$PeopleQuery = wiki_query("Select AccountID,count(*) as n from Wiki_Edits group by AccountID order by n desc @@ -12,7 +12,7 @@ { $AccountCount++; - $AccountQuery = mysqli_query($mysql,"Select `Name`, `EditTime` from `Wiki_Accounts` where `ID`='$AccountID'"); + $AccountQuery = wiki_query("Select `Name`, `EditTime` from `Wiki_Accounts` where `ID`='$AccountID'"); list($AccountName, $EditTime) = mysqli_fetch_array($AccountQuery); $AccountName = gethostbyaddr($AccountName); diff --git a/wwwroot/upload.php b/wwwroot/upload.php index 7dde7fd..5fc4c65 100644 --- a/wwwroot/upload.php +++ b/wwwroot/upload.php @@ -86,7 +86,7 @@ function uuid($prefix = '') // Make sure the user IP is sanitized $userIP = preg_replace('/[^0-9.]/', '', $userIP); - mysqli_query($mysql,"Insert into `Images` values ('NULL', '$Time', '', '$userIP', '{$Image['name']}', 'upload/$Filename.$Extension')"); + wiki_query("Insert into `Images` values ('NULL', '$Time', '', '$userIP', '{$Image['name']}', 'upload/$Filename.$Extension')"); if(!empty($_GET['api'])) { From a7453a38bee5306b7247fd951c6265c9ec68f760 Mon Sep 17 00:00:00 2001 From: cybabun1 Date: Wed, 15 Apr 2026 10:30:11 -0600 Subject: [PATCH 2/4] Fix nodesource repo: upgrade node 14 (EOL) to node 20 LTS --- Dockerfile.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile.php b/Dockerfile.php index c9e3f03..6544c6a 100644 --- a/Dockerfile.php +++ b/Dockerfile.php @@ -20,10 +20,9 @@ apt-transport-https \ curl -# setup nodejs repo +# setup nodejs repo (node 20 LTS) RUN set -exu \ - && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | apt-key add - \ - && echo "deb https://deb.nodesource.com/node_14.x bookworm main" | tee /etc/apt/sources.list.d/nodesource.list + && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - # setup php8.0 repo RUN set -exu \ From f2df7629a7b1f40f28c6847f5fb14a57515c823d Mon Sep 17 00:00:00 2001 From: cybabun1 Date: Wed, 15 Apr 2026 10:31:41 -0600 Subject: [PATCH 3/4] =?UTF-8?q?Remove=20npm=20from=20apt=20install=20?= =?UTF-8?q?=E2=80=94=20bundled=20with=20nodesource=20node=2020?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile.php b/Dockerfile.php index 6544c6a..d937df1 100644 --- a/Dockerfile.php +++ b/Dockerfile.php @@ -40,8 +40,7 @@ php8.0-exif \ php8.0-gd \ php8.0-curl \ - nodejs \ - npm + nodejs # clean apt caches RUN set -exu \ From a0785e86a1d85aab5c9f4ff3f206d9e47087a1cf Mon Sep 17 00:00:00 2001 From: cybabun1 Date: Wed, 15 Apr 2026 10:33:51 -0600 Subject: [PATCH 4/4] Pin gen-otlp-protobuf >=1.2.1 and google/protobuf v4 to fix PHP 8.0 compat --- wwwroot/composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wwwroot/composer.json b/wwwroot/composer.json index 9c9cf99..1be965f 100644 --- a/wwwroot/composer.json +++ b/wwwroot/composer.json @@ -1,7 +1,9 @@ { "require": { "open-telemetry/sdk": "^1.0", - "open-telemetry/exporter-otlp": "^1.0", + "open-telemetry/exporter-otlp": "^1.0.0", + "open-telemetry/gen-otlp-protobuf": "^1.2.1", + "google/protobuf": "^4.0", "php-http/curl-client": "^2.0", "nyholm/psr7": "^1.0" },