diff --git a/lib/weblib.php b/lib/weblib.php
index 05630890ea2..c5555f945c2 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -6968,7 +6968,12 @@ function doc_link($path='', $text='', $iconpath='') {
$lang = str_replace('_utf8', '', current_language());
- $str = '';
+ //derive branch from the first three letters of version.php's $release with the period taken out.($CFG->release isn't populated yet during upgrade)
+ include($CFG->dirroot.'/version.php');
+ preg_match('/^(.)\.(.)/', $release, $matches);
+ $branch = $matches[1].$matches[2];
+
+ $str = '';
if (empty($iconpath)) {
$iconpath = $CFG->httpswwwroot . '/pix/docs.gif';