Skip to content

Commit

Permalink
Include page name in HTML title
Browse files Browse the repository at this point in the history
Resolves #25
  • Loading branch information
BrandonXLF committed Nov 25, 2023
1 parent 8f28162 commit c5838d3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
21 changes: 21 additions & 0 deletions includes/LinkCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ private function counts($table, $prefix, $mode = self::COUNT_MODE_LINK, $hasFrom
];
}

public function getTitle() {
$parts = [];

if (isset($this->error)) {
array_push($parts, 'Error');
} elseif (isset($this->counts)) {
array_push($parts, $this->title->getFullText());
}

array_push($parts, 'Link Count');

return implode(' - ', $parts);
}

public function getHtml() {
if (isset($this->error)) {
return (new OOUI\Tag('div'))->addClasses(['error'])->appendContent($this->error)->toString();
Expand Down Expand Up @@ -212,6 +226,13 @@ public function getHtml() {
return $out . $links;
}

public function getPageUpdateJson() {
return json_encode([
'title' => $this->getTitle(),
'html' => $this->getHtml()
]);
}

public function getJson() {
if (isset($this->error)) {
return json_encode(['error' => $this->error]);
Expand Down
6 changes: 4 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

require 'vendor/autoload.php';

$linkCount = new LinkCount(get('page'), get('project'), get('namespaces'));

?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Link Count</title>
<title><?php echo $linkCount->getTitle(); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="js/" defer></script>
<link rel="stylesheet" href="node_modules/oojs-ui/dist/oojs-ui-wikimediaui.min.css">
Expand All @@ -17,7 +19,7 @@
<main>
<h1>Link Count</h1>
<?php echo (new Form)->getHtml(); ?>
<div id="out"><?php echo (new LinkCount(get('page'), get('project'), get('namespaces')))->getHtml(); ?></div>
<div id="out"><?php echo $linkCount->getHtml(); ?></div>
</main>
<?php echo (new Footer('.'))->getHTML(); ?>
</body>
Expand Down
7 changes: 6 additions & 1 deletion output/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

require '../vendor/autoload.php';

echo (new LinkCount(get('page'), get('project'), get('namespaces')))->getHtml();
$linkCount = new LinkCount(get('page'), get('project'), get('namespaces'));

header('Content-Type: application/json');
echo $linkCount->getPageUpdateJson();

?>
3 changes: 2 additions & 1 deletion static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function submitForm(pushState) {
request = $.get('output/?' + query);

request.then(function(res) {
out.html(res);
document.title = res.title;
out.html(res.html);
}, function(req) {
if (req.wasReplaced) return;

Expand Down

0 comments on commit c5838d3

Please sign in to comment.