Skip to content

Commit 88c06f5

Browse files
committed
Include page name in HTML title
Resolves BrandonXLF#25
1 parent 85a59e0 commit 88c06f5

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

includes/LinkCount.php

+21
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@ private function counts($table, $prefix, $mode = self::COUNT_MODE_LINK, $singleN
178178
];
179179
}
180180

181+
public function getTitle() {
182+
$parts = [];
183+
184+
if (isset($this->error)) {
185+
array_push($parts, 'Error');
186+
} elseif (isset($this->counts)) {
187+
array_push($parts, $this->title->getFullText());
188+
}
189+
190+
array_push($parts, 'Link Count');
191+
192+
return implode(' - ', $parts);
193+
}
194+
181195
public function getHtml() {
182196
if (isset($this->error)) {
183197
return (new OOUI\Tag('div'))->addClasses(['error'])->appendContent($this->error)->toString();
@@ -232,6 +246,13 @@ public function getHtml() {
232246
return $out . $links;
233247
}
234248

249+
public function getPageUpdateJson() {
250+
return json_encode([
251+
'title' => $this->getTitle(),
252+
'html' => $this->getHtml()
253+
]);
254+
}
255+
235256
public function getJson() {
236257
if (isset($this->error)) {
237258
return json_encode(['error' => $this->error]);

index.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
require 'vendor/autoload.php';
44

5+
$linkCount = new LinkCount(get('page'), get('project'), get('namespaces'));
6+
57
?>
68
<!DOCTYPE html>
79
<html lang="en">
810
<head>
9-
<title>Link Count</title>
11+
<title><?php echo $linkCount->getTitle(); ?></title>
1012
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1113
<script src="js/" defer></script>
1214
<link rel="stylesheet" href="node_modules/oojs-ui/dist/oojs-ui-wikimediaui.min.css">
@@ -17,7 +19,7 @@
1719
<main>
1820
<h1>Link Count</h1>
1921
<?php echo (new Form)->getHtml(); ?>
20-
<div id="out"><?php echo (new LinkCount(get('page'), get('project'), get('namespaces')))->getHtml(); ?></div>
22+
<div id="out"><?php echo $linkCount->getHtml(); ?></div>
2123
</main>
2224
<?php echo (new Footer('.'))->getHTML(); ?>
2325
</body>

output/index.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22

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

5-
echo (new LinkCount(get('page'), get('project'), get('namespaces')))->getHtml();
5+
$linkCount = new LinkCount(get('page'), get('project'), get('namespaces'));
6+
7+
header('Content-Type: application/json');
8+
echo $linkCount->getPageUpdateJson();
9+
10+
?>

static/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ function submitForm(pushState) {
4444
request = $.get('output/?' + query);
4545

4646
request.then(function(res) {
47-
out.html(res);
47+
document.title = res.title;
48+
out.html(res.html);
4849
}, function(req) {
4950
if (req.wasReplaced) return;
5051

0 commit comments

Comments
 (0)