diff --git a/Dockerfile.php b/Dockerfile.php
index 3ea07b3..d937df1 100644
--- a/Dockerfile.php
+++ b/Dockerfile.php
@@ -20,17 +20,16 @@
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 \
&& 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,8 +39,8 @@
php8.0-mysql \
php8.0-exif \
php8.0-gd \
- nodejs \
- npm
+ php8.0-curl \
+ nodejs
# clean apt caches
RUN set -exu \
@@ -64,15 +63,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 6824c01..8a0fb3d 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -23,6 +23,8 @@ services:
- "com.centurylinklabs.watchtower.enable=true"
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..1be965f
--- /dev/null
+++ b/wwwroot/composer.json
@@ -0,0 +1,13 @@
+{
+ "require": {
+ "open-telemetry/sdk": "^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"
+ },
+ "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
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 .= "