diff --git a/wcfsetup/install/files/lib/page/AbstractGridViewPage.class.php b/wcfsetup/install/files/lib/page/AbstractGridViewPage.class.php index baa20941e42..04d75943ef3 100644 --- a/wcfsetup/install/files/lib/page/AbstractGridViewPage.class.php +++ b/wcfsetup/install/files/lib/page/AbstractGridViewPage.class.php @@ -6,6 +6,7 @@ use wcf\system\request\LinkHandler; use wcf\system\gridView\AbstractGridView; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Abstract implementation of a page that is rendering a grid view. @@ -49,6 +50,8 @@ public function readParameters() if (isset($_REQUEST['filters']) && \is_array($_REQUEST['filters'])) { $this->filters = $_REQUEST['filters']; } + + $this->canonicalURL = $this->getCanonicalUrl(); } #[\Override] @@ -66,6 +69,7 @@ public function assignVariables() WCF::getTPL()->assign([ 'gridView' => $this->gridView, + 'headContent' => $this->getHeadContent(), ]); } @@ -88,7 +92,65 @@ protected function initGridView(): void if ($this->pageNo != 1) { $this->gridView->setPageNo($this->pageNo); } - $this->gridView->setBaseUrl(LinkHandler::getInstance()->getControllerLink(static::class)); + $this->gridView->setBaseUrl( + LinkHandler::getInstance()->getControllerLink(static::class, $this->getBaseUrlParameters()) + ); + } + + /** + * @return array + */ + protected function getBaseUrlParameters(): array + { + return []; + } + + protected function getHeadContent(): string + { + $linkTags = []; + if ($this->gridView->getPageNo() < $this->gridView->countPages()) { + $linkTags[] = \sprintf( + '', + StringUtil::encodeHTML( + LinkHandler::getInstance()->getControllerLink(static::class, \array_merge( + $this->getBaseUrlParameters(), + [ + 'pageNo' => $this->gridView->getPageNo() + 1, + 'sortField' => $this->sortField ?: null, + 'sortOrder' => $this->sortOrder ?: null, + ] + )) + ) + ); + } + + if ($this->gridView->getPageNo() > 1) { + $linkTags[] = \sprintf( + '', + StringUtil::encodeHTML( + LinkHandler::getInstance()->getControllerLink(static::class, \array_merge( + $this->getBaseUrlParameters(), + [ + 'pageNo' => $this->gridView->getPageNo() !== 2 ? $this->gridView->getPageNo() - 1 : null, + 'sortField' => $this->sortField ?: null, + 'sortOrder' => $this->sortOrder ?: null, + ] + )) + ) + ); + } + + return \implode("\n", $linkTags); + } + + protected function getCanonicalUrl(): string + { + return LinkHandler::getInstance()->getControllerLink(static::class, \array_merge( + $this->getBaseUrlParameters(), + [ + 'pageNo' => $this->pageNo !== 1 ? $this->pageNo : null, + ] + )); } /** diff --git a/wcfsetup/install/files/lib/page/AbstractListViewPage.class.php b/wcfsetup/install/files/lib/page/AbstractListViewPage.class.php index 028f7ea60aa..6e557ba8205 100644 --- a/wcfsetup/install/files/lib/page/AbstractListViewPage.class.php +++ b/wcfsetup/install/files/lib/page/AbstractListViewPage.class.php @@ -51,6 +51,8 @@ public function readParameters() if (isset($_REQUEST['filters']) && \is_array($_REQUEST['filters'])) { $this->filters = $_REQUEST['filters']; } + + $this->canonicalURL = $this->getCanonicalUrl(); } #[\Override] @@ -139,21 +141,19 @@ protected function getHeadContent(): string ); } - $linkTags[] = \sprintf( - '', - StringUtil::encodeHTML( - LinkHandler::getInstance()->getControllerLink(static::class, \array_merge( - $this->getBaseUrlParameters(), - [ - 'pageNo' => $this->listView->getPageNo() !== 1 ? $this->listView->getPageNo() : null, - ] - )) - ) - ); - return \implode("\n", $linkTags); } + protected function getCanonicalUrl(): string + { + return LinkHandler::getInstance()->getControllerLink(static::class, \array_merge( + $this->getBaseUrlParameters(), + [ + 'pageNo' => $this->pageNo !== 1 ? $this->pageNo : null, + ] + )); + } + /** * Returns the list view instance for the rendering of this page. *