diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2025-04-08 21:47:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-08 21:47:31 +0200 |
commit | dd32639fa9f330df8b198b42599468b09b78e87c (patch) | |
tree | 3f6fcf1601a108c00aaf0de2bdc505c4947f4c88 | |
parent | 90a3928cdb2f390f2018e819b26c62255322be4d (diff) | |
parent | 6efd9b751128777f927b4b0c0a1b7d08c183f1d1 (diff) | |
download | nextcloud-server-dd32639fa9f330df8b198b42599468b09b78e87c.tar.gz nextcloud-server-dd32639fa9f330df8b198b42599468b09b78e87c.zip |
Merge pull request #51838 from nextcloud/feat/cleanup-oc-util-methods
Mark all methods of OC_Util as deprecated
-rw-r--r-- | apps/settings/templates/help.php | 2 | ||||
-rw-r--r-- | build/psalm-baseline.xml | 5 | ||||
-rw-r--r-- | core/Listener/BeforeTemplateRenderedListener.php | 2 | ||||
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 2 | ||||
-rw-r--r-- | cypress/e2e/settings/users.cy.ts | 5 | ||||
-rw-r--r-- | lib/base.php | 2 | ||||
-rw-r--r-- | lib/private/Image.php | 2 | ||||
-rw-r--r-- | lib/private/Setup.php | 86 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 9 | ||||
-rw-r--r-- | lib/private/Share20/ShareDisableChecker.php | 7 | ||||
-rw-r--r-- | lib/private/Template/JSConfigHelper.php | 7 | ||||
-rw-r--r-- | lib/private/Template/functions.php | 5 | ||||
-rw-r--r-- | lib/private/legacy/OC_Util.php | 161 | ||||
-rw-r--r-- | lib/public/Share/IManager.php | 4 | ||||
-rw-r--r-- | lib/public/Util.php | 23 | ||||
-rw-r--r-- | tests/lib/UtilTest.php | 20 |
16 files changed, 164 insertions, 178 deletions
diff --git a/apps/settings/templates/help.php b/apps/settings/templates/help.php index 14883996791..17356e6ccdf 100644 --- a/apps/settings/templates/help.php +++ b/apps/settings/templates/help.php @@ -3,7 +3,7 @@ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -\OC_Util::addStyle('settings', 'help'); +\OCP\Util::addStyle('settings', 'help'); ?> <?php if ($_['knowledgebaseEmbedded'] === true) : ?> <div id="app-navigation" role="navigation" tabindex="0"> diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 1a94fd88a17..a8db3332dc9 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -2607,11 +2607,6 @@ <code><![CDATA[\Test\Util\User\Dummy]]></code> </UndefinedClass> </file> - <file src="lib/private/legacy/OC_Util.php"> - <InvalidReturnType> - <code><![CDATA[void]]></code> - </InvalidReturnType> - </file> <file src="lib/public/AppFramework/ApiController.php"> <NoInterfaceProperties> <code><![CDATA[$this->request->server]]></code> diff --git a/core/Listener/BeforeTemplateRenderedListener.php b/core/Listener/BeforeTemplateRenderedListener.php index 4ce892664e9..cc1dee91cfe 100644 --- a/core/Listener/BeforeTemplateRenderedListener.php +++ b/core/Listener/BeforeTemplateRenderedListener.php @@ -37,7 +37,7 @@ class BeforeTemplateRenderedListener implements IEventListener { Util::addScript('core', 'public'); } - \OC_Util::addStyle('server', null, true); + Util::addStyle('server', null, true); if ($event instanceof BeforeLoginTemplateRenderedEvent) { // todo: make login work without these diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index a36d8320227..195b6dca99a 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -359,7 +359,7 @@ describe('Core base tests', function() { // to make sure they run. var cit = window.isPhantom?xit:it; - // must provide the same results as \OC_Util::naturalSortCompare + // must provide the same results as \OCP\Util::naturalSortCompare it('sorts alphabetically', function() { var a = [ 'def', diff --git a/cypress/e2e/settings/users.cy.ts b/cypress/e2e/settings/users.cy.ts index 417191b26f8..5b8726e92ca 100644 --- a/cypress/e2e/settings/users.cy.ts +++ b/cypress/e2e/settings/users.cy.ts @@ -115,12 +115,13 @@ describe('Settings: Create and delete accounts', function() { // The "Delete account" action in the actions menu is shown and clicked cy.get('.action-item__popper .action').contains('Delete account').should('exist').click({ force: true }) - // And confirmation dialog accepted - cy.get('.nc-generic-dialog button').contains(`Delete ${testUser.userId}`).click({ force: true }) // Make sure no confirmation modal is shown handlePasswordConfirmation(admin.password) + // And confirmation dialog accepted + cy.get('.nc-generic-dialog button').contains(`Delete ${testUser.userId}`).click({ force: true }) + // deleted clicked the user is not shown anymore getUserListRow(testUser.userId).should('not.exist') }) diff --git a/lib/base.php b/lib/base.php index bda6b6e01a1..c1182e47d61 100644 --- a/lib/base.php +++ b/lib/base.php @@ -704,7 +704,7 @@ class OC { if (count($errors) > 0) { if (!self::$CLI) { http_response_code(503); - OC_Util::addStyle('guest'); + Util::addStyle('guest'); try { Server::get(ITemplateManager::class)->printGuestPage('', 'error', ['errors' => $errors]); exit; diff --git a/lib/private/Image.php b/lib/private/Image.php index 3dd0bc49662..96699a0046b 100644 --- a/lib/private/Image.php +++ b/lib/private/Image.php @@ -56,7 +56,7 @@ class Image implements IImage { $this->appConfig = $appConfig ?? Server::get(IAppConfig::class); $this->config = $config ?? Server::get(IConfig::class); - if (\OC_Util::fileInfoLoaded()) { + if (class_exists(finfo::class)) { $this->fileInfo = new finfo(FILEINFO_MIME_TYPE); } } diff --git a/lib/private/Setup.php b/lib/private/Setup.php index f2b8a4c66a2..6d3021aff71 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -21,12 +21,14 @@ use OC\User\BackgroundJobs\CleanupDeletedUsers; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\Defaults; +use OCP\Http\Client\IClientService; use OCP\IAppConfig; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; use OCP\IL10N; use OCP\IRequest; +use OCP\IURLGenerator; use OCP\IUserManager; use OCP\IUserSession; use OCP\L10N\IFactory as IL10NFactory; @@ -170,8 +172,7 @@ class Setup { self::protectDataDirectory(); try { - $util = new \OC_Util(); - $htAccessWorking = $util->isHtaccessWorking(Server::get(IConfig::class)); + $htAccessWorking = $this->isHtaccessWorking($dataDir); } catch (\OCP\HintException $e) { $errors[] = [ 'error' => $e->getMessage(), @@ -212,6 +213,87 @@ class Setup { ]; } + public function createHtaccessTestFile(string $dataDir): string|false { + // php dev server does not support htaccess + if (php_sapi_name() === 'cli-server') { + return false; + } + + // testdata + $fileName = '/htaccesstest.txt'; + $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; + + // creating a test file + $testFile = $dataDir . '/' . $fileName; + + if (file_exists($testFile)) {// already running this test, possible recursive call + return false; + } + + $fp = @fopen($testFile, 'w'); + if (!$fp) { + throw new \OCP\HintException('Can\'t create test file to check for working .htaccess file.', + 'Make sure it is possible for the web server to write to ' . $testFile); + } + fwrite($fp, $testContent); + fclose($fp); + + return $testContent; + } + + /** + * Check if the .htaccess file is working + * + * @param \OCP\IConfig $config + * @return bool + * @throws Exception + * @throws \OCP\HintException If the test file can't get written. + */ + public function isHtaccessWorking(string $dataDir) { + $config = Server::get(IConfig::class); + + if (\OC::$CLI || !$config->getSystemValueBool('check_for_working_htaccess', true)) { + return true; + } + + $testContent = $this->createHtaccessTestFile($dataDir); + if ($testContent === false) { + return false; + } + + $fileName = '/htaccesstest.txt'; + $testFile = $dataDir . '/' . $fileName; + + // accessing the file via http + $url = Server::get(IURLGenerator::class)->getAbsoluteURL(\OC::$WEBROOT . '/data' . $fileName); + try { + $content = Server::get(IClientService::class)->newClient()->get($url)->getBody(); + } catch (\Exception $e) { + $content = false; + } + + if (str_starts_with($url, 'https:')) { + $url = 'http:' . substr($url, 6); + } else { + $url = 'https:' . substr($url, 5); + } + + try { + $fallbackContent = Server::get(IClientService::class)->newClient()->get($url)->getBody(); + } catch (\Exception $e) { + $fallbackContent = false; + } + + // cleanup + @unlink($testFile); + + /* + * If the content is not equal to test content our .htaccess + * is working as required + */ + return $content !== $testContent && $fallbackContent !== $testContent; + } + /** * @return array<string|array> errors */ diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 037105428f5..431f19582d0 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1970,14 +1970,9 @@ class Manager implements IManager { } /** - * Copied from \OC_Util::isSharingDisabledForUser - * - * TODO: Deprecate function from OC_Util - * - * @param string $userId - * @return bool + * Check if sharing is disabled for the current user */ - public function sharingDisabledForUser($userId) { + public function sharingDisabledForUser(?string $userId): bool { return $this->shareDisableChecker->sharingDisabledForUser($userId); } diff --git a/lib/private/Share20/ShareDisableChecker.php b/lib/private/Share20/ShareDisableChecker.php index 9b8bc01558c..8cf523b8b31 100644 --- a/lib/private/Share20/ShareDisableChecker.php +++ b/lib/private/Share20/ShareDisableChecker.php @@ -25,12 +25,7 @@ class ShareDisableChecker { $this->sharingDisabledForUsersCache = new CappedMemoryCache(); } - - /** - * @param ?string $userId - * @return bool - */ - public function sharingDisabledForUser(?string $userId) { + public function sharingDisabledForUser(?string $userId): bool { if ($userId === null) { return false; } diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php index 5743d2965d2..93f5d7a5866 100644 --- a/lib/private/Template/JSConfigHelper.php +++ b/lib/private/Template/JSConfigHelper.php @@ -30,6 +30,7 @@ use OCP\ILogger; use OCP\ISession; use OCP\IURLGenerator; use OCP\IUser; +use OCP\Server; use OCP\ServerVersion; use OCP\Session\Exceptions\SessionNotAvailableException; use OCP\Share\IManager as IShareManager; @@ -161,6 +162,8 @@ class JSConfigHelper { 'enable_non-accessible_features' => $this->config->getSystemValueBool('enable_non-accessible_features', true), ]; + $shareManager = Server::get(IShareManager::class); + $array = [ '_oc_debug' => $this->config->getSystemValue('debug', false) ? 'true' : 'false', '_oc_isadmin' => $uid !== null && $this->groupManager->isAdmin($uid) ? 'true' : 'false', @@ -235,11 +238,11 @@ class JSConfigHelper { 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, 'enforcePasswordForPublicLink' => Util::isPublicLinkPasswordRequired(), 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, - 'sharingDisabledForUser' => Util::isSharingDisabledForUser(), + 'sharingDisabledForUser' => $shareManager->sharingDisabledForUser($uid), 'resharingAllowed' => Share::isResharingAllowed(), 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), - 'allowGroupSharing' => \OC::$server->get(IShareManager::class)->allowGroupSharing(), + 'allowGroupSharing' => $shareManager->allowGroupSharing(), 'defaultInternalExpireDateEnabled' => $defaultInternalExpireDateEnabled, 'defaultInternalExpireDate' => $defaultInternalExpireDate, 'defaultInternalExpireDateEnforced' => $defaultInternalExpireDateEnforced, diff --git a/lib/private/Template/functions.php b/lib/private/Template/functions.php index 77a1e831008..402a7491e03 100644 --- a/lib/private/Template/functions.php +++ b/lib/private/Template/functions.php @@ -131,10 +131,10 @@ function script($app, $file = null): void { function style($app, $file = null): void { if (is_array($file)) { foreach ($file as $f) { - OC_Util::addStyle($app, $f); + Util::addStyle($app, $f); } } else { - OC_Util::addStyle($app, $file); + Util::addStyle($app, $file); } } @@ -143,6 +143,7 @@ function style($app, $file = null): void { * @param string $app the appname * @param string|string[] $file the filename, * if an array is given it will add all styles + * @deprecated 32.0.0 */ function vendor_style($app, $file = null): void { if (is_array($file)) { diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index b2950275e41..580fec7b5b3 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -9,7 +9,6 @@ use bantu\IniGetWrapper\IniGetWrapper; use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager; use OC\Files\SetupManager; use OCP\Files\Template\ITemplateManager; -use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\IGroupManager; use OCP\IURLGenerator; @@ -19,17 +18,13 @@ use OCP\Security\ISecureRandom; use OCP\Share\IManager; use Psr\Log\LoggerInterface; +/** + * @deprecated 32.0.0 Use \OCP\Util or any appropriate official API instead + */ class OC_Util { public static $styles = []; public static $headers = []; - /** @var array Local cache of version.php */ - private static $versionCache = null; - - protected static function getAppManager() { - return \OC::$server->getAppManager(); - } - /** * Setup the file system * @@ -62,8 +57,8 @@ class OC_Util { * Check if a password is required for each public link * * @param bool $checkGroupMembership Check group membership exclusion - * @return boolean - * @suppress PhanDeprecatedFunction + * @return bool + * @deprecated 32.0.0 use OCP\Share\IManager's shareApiLinkEnforcePassword directly */ public static function isPublicLinkPasswordRequired(bool $checkGroupMembership = true) { /** @var IManager $shareManager */ @@ -77,6 +72,7 @@ class OC_Util { * @param IGroupManager $groupManager * @param IUser|null $user * @return bool + * @deprecated 32.0.0 use OCP\Share\IManager's sharingDisabledForUser directly */ public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { /** @var IManager $shareManager */ @@ -89,7 +85,7 @@ class OC_Util { * check if share API enforces a default expire date * * @return bool - * @suppress PhanDeprecatedFunction + * @deprecated 32.0.0 use OCP\Share\IManager's shareApiLinkDefaultExpireDateEnforced directly */ public static function isDefaultExpireDateEnforced() { /** @var IManager $shareManager */ @@ -205,12 +201,10 @@ class OC_Util { } /** - * @return void - * @suppress PhanUndeclaredMethod + * @deprecated 32.0.0 Call tearDown directly on SetupManager */ - public static function tearDownFS() { - /** @var SetupManager $setupManager */ - $setupManager = \OC::$server->get(SetupManager::class); + public static function tearDownFS(): void { + $setupManager = \OCP\Server::get(SetupManager::class); $setupManager->tearDown(); } @@ -219,10 +213,9 @@ class OC_Util { * * @param string $application application to get the files from * @param string $directory directory within this application (css, js, vendor, etc) - * @param string $file the file inside of the above folder - * @return string the path + * @param ?string $file the file inside of the above folder */ - private static function generatePath($application, $directory, $file) { + private static function generatePath($application, $directory, $file): string { if (is_null($file)) { $file = $application; $application = ''; @@ -240,9 +233,9 @@ class OC_Util { * @param string $application application id * @param string|null $file filename * @param bool $prepend prepend the Style to the beginning of the list - * @return void + * @deprecated 32.0.0 Use \OCP\Util::addStyle */ - public static function addStyle($application, $file = null, $prepend = false) { + public static function addStyle($application, $file = null, $prepend = false): void { $path = OC_Util::generatePath($application, 'css', $file); self::addExternalResource($application, $prepend, $path, 'style'); } @@ -253,9 +246,9 @@ class OC_Util { * @param string $application application id * @param string|null $file filename * @param bool $prepend prepend the Style to the beginning of the list - * @return void + * @deprecated 32.0.0 */ - public static function addVendorStyle($application, $file = null, $prepend = false) { + public static function addVendorStyle($application, $file = null, $prepend = false): void { $path = OC_Util::generatePath($application, 'vendor', $file); self::addExternalResource($application, $prepend, $path, 'style'); } @@ -267,9 +260,8 @@ class OC_Util { * @param bool $prepend prepend the file to the beginning of the list * @param string $path * @param string $type (script or style) - * @return void */ - private static function addExternalResource($application, $prepend, $path, $type = 'script') { + private static function addExternalResource($application, $prepend, $path, $type = 'script'): void { if ($type === 'style') { if (!in_array($path, self::$styles)) { if ($prepend === true) { @@ -289,8 +281,9 @@ class OC_Util { * @param array $attributes array of attributes for the element * @param string $text the text content for the element * @param bool $prepend prepend the header to the beginning of the list + * @deprecated 32.0.0 Use \OCP\Util::addHeader instead */ - public static function addHeader($tag, $attributes, $text = null, $prepend = false) { + public static function addHeader($tag, $attributes, $text = null, $prepend = false): void { $header = [ 'tag' => $tag, 'attributes' => $attributes, @@ -306,7 +299,6 @@ class OC_Util { /** * check if the current server configuration is suitable for ownCloud * - * @param \OC\SystemConfig $config * @return array arrays with error messages and hints */ public static function checkServer(\OC\SystemConfig $config) { @@ -529,6 +521,7 @@ class OC_Util { * * @param string $dataDirectory * @return array arrays with error messages and hints + * @internal */ public static function checkDataDirectoryPermissions($dataDirectory) { if (!\OC::$server->getConfig()->getSystemValueBool('check_data_directory_permissions', true)) { @@ -557,6 +550,7 @@ class OC_Util { * * @param string $dataDirectory data directory path * @return array errors found + * @internal */ public static function checkDataDirectoryValidity($dataDirectory) { $l = \OC::$server->getL10N('lib'); @@ -581,9 +575,9 @@ class OC_Util { * Check if the user is logged in, redirects to home if not. With * redirect URL parameter to the request URI. * - * @return void + * @deprecated 32.0.0 */ - public static function checkLoggedIn() { + public static function checkLoggedIn(): void { // Check if we are a user if (!\OC::$server->getUserSession()->isLoggedIn()) { header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( @@ -605,10 +599,10 @@ class OC_Util { /** * Check if the user is a admin, redirects to home if not * - * @return void + * @deprecated 32.0.0 */ - public static function checkAdminUser() { - OC_Util::checkLoggedIn(); + public static function checkAdminUser(): void { + self::checkLoggedIn(); if (!OC_User::isAdminUser(OC_User::getUser())) { header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); exit(); @@ -621,7 +615,7 @@ class OC_Util { * the apps visible for the current user * * @return string URL - * @suppress PhanDeprecatedFunction + * @deprecated 32.0.0 use IURLGenerator's linkToDefaultPageUrl directly */ public static function getDefaultPageUrl() { /** @var IURLGenerator $urlGenerator */ @@ -632,9 +626,9 @@ class OC_Util { /** * Redirect to the user default page * - * @return void + * @deprecated 32.0.0 */ - public static function redirectToDefaultPage() { + public static function redirectToDefaultPage(): void { $location = self::getDefaultPageUrl(); header('Location: ' . $location); exit(); @@ -645,7 +639,7 @@ class OC_Util { * * @return string */ - public static function getInstanceId() { + public static function getInstanceId(): string { $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); if (is_null($id)) { // We need to guarantee at least one letter in instanceid so it can be used as the session_name @@ -663,6 +657,7 @@ class OC_Util { * * @param string|string[] $value * @return ($value is array ? string[] : string) + * @deprecated 32.0.0 use \OCP\Util::sanitizeHTML instead */ public static function sanitizeHTML($value) { if (is_array($value)) { @@ -685,6 +680,7 @@ class OC_Util { * * @param string $component part of URI to encode * @return string + * @deprecated 32.0.0 use \OCP\Util::encodePath instead */ public static function encodePath($component) { $encoded = rawurlencode($component); @@ -692,86 +688,6 @@ class OC_Util { return $encoded; } - - public function createHtaccessTestFile(\OCP\IConfig $config) { - // php dev server does not support htaccess - if (php_sapi_name() === 'cli-server') { - return false; - } - - // testdata - $fileName = '/htaccesstest.txt'; - $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; - - // creating a test file - $testFile = $config->getSystemValueString('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; - - if (file_exists($testFile)) {// already running this test, possible recursive call - return false; - } - - $fp = @fopen($testFile, 'w'); - if (!$fp) { - throw new \OCP\HintException('Can\'t create test file to check for working .htaccess file.', - 'Make sure it is possible for the web server to write to ' . $testFile); - } - fwrite($fp, $testContent); - fclose($fp); - - return $testContent; - } - - /** - * Check if the .htaccess file is working - * - * @param \OCP\IConfig $config - * @return bool - * @throws Exception - * @throws \OCP\HintException If the test file can't get written. - */ - public function isHtaccessWorking(\OCP\IConfig $config) { - if (\OC::$CLI || !$config->getSystemValueBool('check_for_working_htaccess', true)) { - return true; - } - - $testContent = $this->createHtaccessTestFile($config); - if ($testContent === false) { - return false; - } - - $fileName = '/htaccesstest.txt'; - $testFile = $config->getSystemValueString('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; - - // accessing the file via http - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); - try { - $content = \OC::$server->get(IClientService::class)->newClient()->get($url)->getBody(); - } catch (\Exception $e) { - $content = false; - } - - if (str_starts_with($url, 'https:')) { - $url = 'http:' . substr($url, 6); - } else { - $url = 'https:' . substr($url, 5); - } - - try { - $fallbackContent = \OC::$server->get(IClientService::class)->newClient()->get($url)->getBody(); - } catch (\Exception $e) { - $fallbackContent = false; - } - - // cleanup - @unlink($testFile); - - /* - * If the content is not equal to test content our .htaccess - * is working as required - */ - return $content !== $testContent && $fallbackContent !== $testContent; - } - /** * Check if current locale is non-UTF8 * @@ -791,9 +707,9 @@ class OC_Util { * Check if the setlocale call does not work. This can happen if the right * local packages are not available on the server. * - * @return bool + * @internal */ - public static function isSetLocaleWorking() { + public static function isSetLocaleWorking(): bool { if (self::isNonUTF8Locale()) { // Borrowed from \Patchwork\Utf8\Bootup::initLocale setlocale(LC_ALL, 'C.UTF-8', 'C'); @@ -811,9 +727,9 @@ class OC_Util { /** * Check if it's possible to get the inline annotations * - * @return bool + * @internal */ - public static function isAnnotationsWorking() { + public static function isAnnotationsWorking(): bool { if (PHP_VERSION_ID >= 80300) { /** @psalm-suppress UndefinedMethod */ $reflection = \ReflectionMethod::createFromMethodName(__METHOD__); @@ -828,9 +744,9 @@ class OC_Util { /** * Check if the PHP module fileinfo is loaded. * - * @return bool + * @internal */ - public static function fileInfoLoaded() { + public static function fileInfoLoaded(): bool { return function_exists('finfo_open'); } @@ -900,6 +816,7 @@ class OC_Util { * @param \OC\SystemConfig $config * @return bool whether the core or any app needs an upgrade * @throws \OCP\HintException When the upgrade from the given version is not allowed + * @deprecated 32.0.0 Use \OCP\Util::needUpgrade instead */ public static function needUpgrade(\OC\SystemConfig $config) { if ($config->getValue('installed', false)) { diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index 23713f2e462..89d6f5e4a87 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -485,11 +485,9 @@ interface IManager { /** * Check if sharing is disabled for the given user * - * @param string $userId - * @return bool * @since 9.0.0 */ - public function sharingDisabledForUser($userId); + public function sharingDisabledForUser(?string $userId): bool; /** * Check if outgoing server2server shares are allowed diff --git a/lib/public/Util.php b/lib/public/Util.php index 65776bd15a7..14663abd62f 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -78,19 +78,16 @@ class Util { * * @return boolean * @since 7.0.0 - * @deprecated 9.1.0 Use \OC::$server->get(\OCP\Share\IManager::class)->sharingDisabledForUser + * @deprecated 9.1.0 Use Server::get(\OCP\Share\IManager::class)->sharingDisabledForUser */ public static function isSharingDisabledForUser() { if (self::$shareManager === null) { - self::$shareManager = \OC::$server->get(IManager::class); + self::$shareManager = Server::get(IManager::class); } - $user = \OC::$server->getUserSession()->getUser(); - if ($user !== null) { - $user = $user->getUID(); - } + $user = Server::get(\OCP\IUserSession::class)->getUser(); - return self::$shareManager->sharingDisabledForUser($user); + return self::$shareManager->sharingDisabledForUser($user?->getUID()); } /** @@ -102,13 +99,15 @@ class Util { } /** - * add a css file - * @param string $application - * @param string $file + * Add a css file + * + * @param string $application application id + * @param ?string $file filename + * @param bool $prepend prepend the style to the beginning of the list * @since 4.0.0 */ - public static function addStyle($application, $file = null): void { - \OC_Util::addStyle($application, $file); + public static function addStyle(string $application, ?string $file = null, bool $prepend = false): void { + \OC_Util::addStyle($application, $file, $prepend); } /** diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php index fcb77332fcc..0063a991e48 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -42,25 +42,25 @@ class UtilTest extends \Test\TestCase { 'And It Even May <strong>Nest</strong>' ], ]; - $result = OC_Util::sanitizeHTML($badArray); + $result = Util::sanitizeHTML($badArray); $this->assertEquals($goodArray, $result); $badString = '<img onload="alert(1)" />'; - $result = OC_Util::sanitizeHTML($badString); + $result = Util::sanitizeHTML($badString); $this->assertEquals('<img onload="alert(1)" />', $result); $badString = "<script>alert('Hacked!');</script>"; - $result = OC_Util::sanitizeHTML($badString); + $result = Util::sanitizeHTML($badString); $this->assertEquals('<script>alert('Hacked!');</script>', $result); $goodString = 'This is a good string without HTML.'; - $result = OC_Util::sanitizeHTML($goodString); + $result = Util::sanitizeHTML($goodString); $this->assertEquals('This is a good string without HTML.', $result); } public function testEncodePath(): void { $component = '/§#@test%&^ä/-child'; - $result = OC_Util::encodePath($component); + $result = Util::encodePath($component); $this->assertEquals('/%C2%A7%23%40test%25%26%5E%C3%A4/-child', $result); } @@ -295,12 +295,12 @@ class UtilTest extends \Test\TestCase { } public function testAddStyle(): void { - \OC_Util::addStyle('core', 'myFancyCSSFile1'); - \OC_Util::addStyle('myApp', 'myFancyCSSFile2'); - \OC_Util::addStyle('core', 'myFancyCSSFile0', true); - \OC_Util::addStyle('core', 'myFancyCSSFile10', true); + Util::addStyle('core', 'myFancyCSSFile1'); + Util::addStyle('myApp', 'myFancyCSSFile2'); + Util::addStyle('core', 'myFancyCSSFile0', true); + Util::addStyle('core', 'myFancyCSSFile10', true); // add duplicate - \OC_Util::addStyle('core', 'myFancyCSSFile1'); + Util::addStyle('core', 'myFancyCSSFile1'); $this->assertEquals([], Util::getScripts()); $this->assertEquals([ |