diff --git a/includes/LinkCount.php b/includes/LinkCount.php index 05de5a4..b509810 100644 --- a/includes/LinkCount.php +++ b/includes/LinkCount.php @@ -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(); @@ -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]); diff --git a/index.php b/index.php index d2a1810..74fd73b 100644 --- a/index.php +++ b/index.php @@ -2,11 +2,13 @@ require 'vendor/autoload.php'; +$linkCount = new LinkCount(get('page'), get('project'), get('namespaces')); + ?> - Link Count + <?php echo $linkCount->getTitle(); ?> @@ -17,7 +19,7 @@

Link Count

getHtml(); ?> -
getHtml(); ?>
+
getHtml(); ?>
getHTML(); ?> diff --git a/output/index.php b/output/index.php index 2f300b7..18b02af 100644 --- a/output/index.php +++ b/output/index.php @@ -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(); + +?> diff --git a/static/index.js b/static/index.js index df542b8..1039e04 100644 --- a/static/index.js +++ b/static/index.js @@ -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;