From 675417a75c3c0d93838397b4670e2d26d53eb2fe Mon Sep 17 00:00:00 2001
From: Morris Jobke <hey@morrisjobke.de>
Date: Thu, 26 Nov 2015 10:48:08 +0100
Subject: [PATCH] Untangle the linkToDocs method in OC_Helper

* now uses the proper URLGenerator interface
* add comment about DI problems
---
 lib/base.php                       |  7 +++++--
 lib/private/config.php             |  4 +++-
 lib/private/helper.php             |  9 ---------
 lib/private/template/functions.php |  2 +-
 lib/private/util.php               | 11 +++++++----
 5 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/lib/base.php b/lib/base.php
index feaf46e83f1..6a1841fa93b 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -246,18 +246,21 @@ class OC {
 		$configFileWritable = is_writable($configFilePath);
 		if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled()
 			|| !$configFileWritable && self::checkUpgrade(false)) {
+
+			$urlGenerator = \OC::$server->getURLGenerator();
+
 			if (self::$CLI) {
 				echo $l->t('Cannot write into "config" directory!')."\n";
 				echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n";
 				echo "\n";
-				echo $l->t('See %s', array(\OC_Helper::linkToDocs('admin-dir_permissions')))."\n";
+				echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n";
 				exit;
 			} else {
 				OC_Template::printErrorPage(
 					$l->t('Cannot write into "config" directory!'),
 					$l->t('This can usually be fixed by '
 					. '%sgiving the webserver write access to the config directory%s.',
-					 array('<a href="'.\OC_Helper::linkToDocs('admin-dir_permissions').'" target="_blank">', '</a>'))
+					 array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank">', '</a>'))
 				);
 			}
 		}
diff --git a/lib/private/config.php b/lib/private/config.php
index 3ad800a00be..94b4fd56daa 100644
--- a/lib/private/config.php
+++ b/lib/private/config.php
@@ -234,7 +234,9 @@ class Config {
 
 		// File does not exist, this can happen when doing a fresh install
 		if(!is_resource ($filePointer)) {
-			$url = \OC_Helper::linkToDocs('admin-dir_permissions');
+			// TODO fix this via DI once it is very clear that this doesn't cause side effects due to initialization order
+			// currently this breaks app routes but also could have other side effects especially during setup and exception handling
+			$url = \OC::$server->getURLGenerator()->linkToDocs('admin-dir_permissions');
 			throw new HintException(
 				"Can't write into config directory!",
 				'This can usually be fixed by '
diff --git a/lib/private/helper.php b/lib/private/helper.php
index fc7653baf6f..fb8e38cc26e 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -81,15 +81,6 @@ class OC_Helper {
 		return OC::$server->getURLGenerator()->linkTo($app, $file, $args);
 	}
 
-	/**
-	 * @param string $key
-	 * @return string url to the online documentation
-	 * @deprecated Use \OC::$server->getURLGenerator()->linkToDocs($key)
-	 */
-	public static function linkToDocs($key) {
-		return OC::$server->getURLGenerator()->linkToDocs($key);
-	}
-
 	/**
 	 * Creates an absolute url
 	 * @param string $app app
diff --git a/lib/private/template/functions.php b/lib/private/template/functions.php
index cea5860cec6..79d18632d2f 100644
--- a/lib/private/template/functions.php
+++ b/lib/private/template/functions.php
@@ -154,7 +154,7 @@ function link_to( $app, $file, $args = array() ) {
  * @return string url to the online documentation
  */
 function link_to_docs($key) {
-	return OC_Helper::linkToDocs($key);
+	return \OC::$server->getURLGenerator()->linkToDocs($key);
 }
 
 /**
diff --git a/lib/private/util.php b/lib/private/util.php
index 69f01c22be9..84a8c49c383 100644
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -621,6 +621,9 @@ class OC_Util {
 		$webServerRestart = false;
 		$setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'),
 			new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom());
+
+		$urlGenerator = \OC::$server->getURLGenerator();
+
 		$availableDatabases = $setup->getSupportedDatabases();
 		if (empty($availableDatabases)) {
 			$errors[] = array(
@@ -649,7 +652,7 @@ class OC_Util {
 				'error' => $l->t('Cannot write into "config" directory'),
 				'hint' => $l->t('This can usually be fixed by '
 					. '%sgiving the webserver write access to the config directory%s.',
-					array('<a href="' . \OC_Helper::linkToDocs('admin-dir_permissions') . '" target="_blank">', '</a>'))
+					array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank">', '</a>'))
 			);
 		}
 
@@ -664,7 +667,7 @@ class OC_Util {
 					'hint' => $l->t('This can usually be fixed by '
 						. '%sgiving the webserver write access to the apps directory%s'
 						. ' or disabling the appstore in the config file.',
-						array('<a href="' . \OC_Helper::linkToDocs('admin-dir_permissions') . '" target="_blank">', '</a>'))
+						array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank">', '</a>'))
 				);
 			}
 		}
@@ -679,14 +682,14 @@ class OC_Util {
 						'error' => $l->t('Cannot create "data" directory (%s)', array($CONFIG_DATADIRECTORY)),
 						'hint' => $l->t('This can usually be fixed by '
 							. '<a href="%s" target="_blank">giving the webserver write access to the root directory</a>.',
-							array(OC_Helper::linkToDocs('admin-dir_permissions')))
+							array($urlGenerator->linkToDocs('admin-dir_permissions')))
 					);
 				}
 			} else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) {
 				//common hint for all file permissions error messages
 				$permissionsHint = $l->t('Permissions can usually be fixed by '
 					. '%sgiving the webserver write access to the root directory%s.',
-					array('<a href="' . \OC_Helper::linkToDocs('admin-dir_permissions') . '" target="_blank">', '</a>'));
+					array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank">', '</a>'));
 				$errors[] = array(
 					'error' => 'Data directory (' . $CONFIG_DATADIRECTORY . ') not writable by ownCloud',
 					'hint' => $permissionsHint
-- 
GitLab