From 521bb9432e2c7028db9e7a60763b848899d60a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Sun, 8 Mar 2026 17:00:44 +0100 Subject: [PATCH 1/2] fix: Deprecate OC_App::getCurrentApp and remove its only use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/TemplateLayout.php | 10 +++++----- lib/private/legacy/OC_App.php | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index f3109ba8cb5db..bce2422be0abc 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -58,6 +58,7 @@ public function __construct( private INavigationManager $navigationManager, private ITemplateManager $templateManager, private ServerVersion $serverVersion, + private IRequest $request, ) { } @@ -72,7 +73,8 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate { switch ($renderAs) { case TemplateResponse::RENDER_AS_USER: $page = $this->templateManager->getTemplate('core', 'layout.user'); - if (in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { + $pathInfo = $this->request->getPathInfo(); + if ($pathInfo !== false && str_starts_with($pathInfo, '/settings/')) { $page->assign('bodyid', 'body-settings'); } else { $page->assign('bodyid', 'body-user'); @@ -254,10 +256,8 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate { $page->append('jsfiles', $web . '/' . $file . $this->getVersionHashSuffix()); } - $request = Server::get(IRequest::class); - try { - $pathInfo = $request->getPathInfo(); + $pathInfo = $this->request->getPathInfo(); } catch (\Exception $e) { $pathInfo = ''; } @@ -298,7 +298,7 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate { } } - if ($request->isUserAgent([Request::USER_AGENT_CLIENT_IOS, Request::USER_AGENT_SAFARI, Request::USER_AGENT_SAFARI_MOBILE])) { + if ($this->request->isUserAgent([Request::USER_AGENT_CLIENT_IOS, Request::USER_AGENT_SAFARI, Request::USER_AGENT_SAFARI_MOBILE])) { // Prevent auto zoom with iOS but still allow user zoom // On chrome (and others) this does not work (will also disable user zoom) $page->assign('viewport_maximum_scale', '1.0'); diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 5dd7bfe3b7dcb..76e5fda71fb11 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -261,6 +261,7 @@ public static function getAppVersionByPath(string $path): string { /** * get the id of loaded app + * @deprecated 34.0.0 Don’t do that */ public static function getCurrentApp(): string { if (\OC::$CLI) { From b87867856277be9731466557607ba184735e20f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Sun, 8 Mar 2026 17:21:23 +0100 Subject: [PATCH 2/2] chore: Adapt tests to TemplateLayout constructor changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- tests/lib/TemplateLayoutTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/lib/TemplateLayoutTest.php b/tests/lib/TemplateLayoutTest.php index 918c06bebb746..5d988182324f3 100644 --- a/tests/lib/TemplateLayoutTest.php +++ b/tests/lib/TemplateLayoutTest.php @@ -16,6 +16,7 @@ use OCP\IAppConfig; use OCP\IConfig; use OCP\INavigationManager; +use OCP\IRequest; use OCP\ServerVersion; use OCP\Template\ITemplateManager; use PHPUnit\Framework\MockObject\MockObject; @@ -28,6 +29,7 @@ class TemplateLayoutTest extends \Test\TestCase { private INavigationManager&MockObject $navigationManager; private ITemplateManager&MockObject $templateManager; private ServerVersion&MockObject $serverVersion; + private IRequest&MockObject $request; private TemplateLayout $templateLayout; @@ -41,6 +43,7 @@ protected function setUp(): void { $this->navigationManager = $this->createMock(INavigationManager::class); $this->templateManager = $this->createMock(ITemplateManager::class); $this->serverVersion = $this->createMock(ServerVersion::class); + $this->request = $this->createMock(IRequest::class); } #[\PHPUnit\Framework\Attributes\DataProvider('dataVersionHash')] @@ -73,6 +76,9 @@ public function testVersionHash( ->with('theming', 'cachebuster', '0') ->willReturn('42'); + $this->request->method('getPathInfo') + ->willReturn('/' . $path); + $this->templateLayout = $this->getMockBuilder(TemplateLayout::class) ->onlyMethods(['getAppNamefromPath']) ->setConstructorArgs([ @@ -83,6 +89,7 @@ public function testVersionHash( $this->navigationManager, $this->templateManager, $this->serverVersion, + $this->request, ]) ->getMock();