diff --git a/inc/confutils.php b/inc/confutils.php index 06c70acdeaafdbd460091fd660c066bd16d0f9c6..75d56d4974487737585786c025a5cce7259b7943 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -120,21 +120,48 @@ function getInterwiki() { } /** - * Returns the jquery script versions defined in lib/scripts/jquery/versions + * Returns the jquery script URLs for the versions defined in lib/scripts/jquery/versions * + * @trigger CONFUTIL_CDN_SELECT * @return array */ -function getJqueryVersions() { +function getCdnUrls() { + global $conf; + + // load version info $versions = array(); $lines = file(DOKU_INC . 'lib/scripts/jquery/versions'); - foreach($lines as $line ) { + foreach($lines as $line) { $line = preg_replace('/#.*$/', '', $line); list($key, $val) = explode('=', $line, 2); $key = trim($key); $val = trim($val); $versions[$key] = $val; } - return $versions; + + $src = array(); + $data = array( + 'versions' => $versions, + 'src' => &$src + ); + $event = new Doku_Event('CONFUTIL_CDN_SELECT', $data); + if($event->advise_before()) { + if(!$conf['jquerycdn']) { + $jqmod = md5(join('-', $versions)); + $src[] = DOKU_BASE . 'lib/exe/jquery.php' . '?tseed=' . $jqmod; + } elseif($conf['jquerycdn'] == 'jquery') { + $src[] = sprintf('https://code.jquery.com/jquery-%s.min.js', $versions['JQ_VERSION']); + $src[] = sprintf('https://code.jquery.com/jquery-migrate-%s.min.js', $versions['JQM_VERSION']); + $src[] = sprintf('https://code.jquery.com/ui/%s/jquery-ui.min.js', $versions['JQUI_VERSION']); + } elseif($conf['jquerycdn'] == 'cdnjs') { + $src[] = sprintf('https://cdnjs.cloudflare.com/ajax/libs/jquery/%s/jquery.min.js', $versions['JQ_VERSION']); + $src[] = sprintf('https://cdnjs.cloudflare.com/ajax/libs/jquery-migrate/%s/jquery-migrate.min.js', $versions['JQM_VERSION']); + $src[] = sprintf('https://cdnjs.cloudflare.com/ajax/libs/jqueryui/%s/jquery-ui.min.js', $versions['JQUI_VERSION']); + } + } + $event->advise_after(); + + return $src; } /** diff --git a/inc/template.php b/inc/template.php index c7089abfb11ec57b3b2bdf42d202b43c4e52b782..f806a4a6e9a650151b039a199d4f2521d67c401c 100644 --- a/inc/template.php +++ b/inc/template.php @@ -410,25 +410,10 @@ function tpl_metaheaders($alt = true) { $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); // load jquery - $jqver = getJqueryVersions(); - if($conf['jquerycdn']) { + $jquery = getCdnUrls(); + foreach($jquery as $src) { $head['script'][] = array( - 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', - 'src' => sprintf('https://code.jquery.com/jquery-%s.min.js', $jqver['JQ_VERSION']) - ); - $head['script'][] = array( - 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', - 'src' => sprintf('https://code.jquery.com/jquery-migrate-%s.min.js', $jqver['JQM_VERSION']) - ); - $head['script'][] = array( - 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', - 'src' => sprintf('https://code.jquery.com/ui/%s/jquery-ui.min.js', $jqver['JQUI_VERSION']) - ); - } else { - $jqmod = md5(join('-', $jqver)); - $head['script'][] = array( - 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', - 'src' => DOKU_BASE . 'lib/exe/jquery.php' . '?tseed=' . $jqmod + 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src ); } diff --git a/lib/plugins/config/lang/en/lang.php b/lib/plugins/config/lang/en/lang.php index 8a53a6b038945c4849ebba67fa9387c94bf9c17f..e4c81ce110eeac5582a9c249b770f983eba60c84 100644 --- a/lib/plugins/config/lang/en/lang.php +++ b/lib/plugins/config/lang/en/lang.php @@ -175,7 +175,12 @@ $lang['renderer__plugin'] = '%s (plugin)'; /* Network Options */ $lang['dnslookups'] = 'DokuWiki will lookup hostnames for remote IP addresses of users editing pages. If you have a slow or non working DNS server or don\'t want this feature, disable this option'; -$lang['jquerycdn'] = 'Should the jQuery and jQuery UI script files be loaded from the code.jquery.com CDN? This adds additional HTTP requests, but users may already have the files cached.'; +$lang['jquerycdn'] = 'Should the jQuery and jQuery UI script files be loaded from a CDN? This adds additional HTTP requests, but files may load faster and users may have them cached already.'; + +/* jQuery CDN options */ +$lang['jquerycdn_o_0'] = 'No CDN, local delivery only'; +$lang['jquerycdn_o_jquery'] = 'CDN at code.jquery.com'; +$lang['jquerycdn_o_cdnjs'] = 'CDN at cdnjs.com'; /* Proxy Options */ $lang['proxy____host'] = 'Proxy servername'; diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php index 51a73c7aec51f350c5770e53123eab4f997d6382..495c44eb4b5d57ffb60c7c8218fc41ea7b690aba 100644 --- a/lib/plugins/config/settings/config.metadata.php +++ b/lib/plugins/config/settings/config.metadata.php @@ -221,7 +221,7 @@ $meta['readdircache'] = array('numeric'); $meta['_network'] = array('fieldset'); $meta['dnslookups'] = array('onoff'); -$meta['jquerycdn'] = array('onoff'); +$meta['jquerycdn'] = array('multichoice', '_choices' => array(0,'jquery', 'cdnjs')); $meta['proxy____host'] = array('string','_pattern' => '#^(|[a-z0-9\-\.+]+)$#i'); $meta['proxy____port'] = array('numericopt'); $meta['proxy____user'] = array('string');