Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion wcfsetup/install/files/lib/page/AbstractGridViewPage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -49,6 +50,8 @@ public function readParameters()
if (isset($_REQUEST['filters']) && \is_array($_REQUEST['filters'])) {
$this->filters = $_REQUEST['filters'];
}

$this->canonicalURL = $this->getCanonicalUrl();
}

#[\Override]
Expand All @@ -66,6 +69,7 @@ public function assignVariables()

WCF::getTPL()->assign([
'gridView' => $this->gridView,
'headContent' => $this->getHeadContent(),
]);
}

Expand All @@ -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<string, mixed>
*/
protected function getBaseUrlParameters(): array
{
return [];
}

protected function getHeadContent(): string
{
$linkTags = [];
if ($this->gridView->getPageNo() < $this->gridView->countPages()) {
$linkTags[] = \sprintf(
'<link rel="next" href="%s">',
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(
'<link rel="prev" href="%s">',
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,
]
));
}

/**
Expand Down
24 changes: 12 additions & 12 deletions wcfsetup/install/files/lib/page/AbstractListViewPage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function readParameters()
if (isset($_REQUEST['filters']) && \is_array($_REQUEST['filters'])) {
$this->filters = $_REQUEST['filters'];
}

$this->canonicalURL = $this->getCanonicalUrl();
}

#[\Override]
Expand Down Expand Up @@ -139,21 +141,19 @@ protected function getHeadContent(): string
);
}

$linkTags[] = \sprintf(
'<link rel="canonical" href="%s">',
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.
*
Expand Down
Loading