diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php
index 0fd5a1c7f6e..fd30e8239e0 100644
--- a/admin/settings/plugins.php
+++ b/admin/settings/plugins.php
@@ -206,6 +206,7 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext))
$temp->add(new admin_setting_heading('managerepositoriescommonheading', get_string('commonsettings', 'admin'), ''));
$temp->add(new admin_setting_configtext('repositorycacheexpire', get_string('cacheexpire', 'repository'), get_string('configcacheexpire', 'repository'), 120));
$temp->add(new admin_setting_configcheckbox('repositoryuseexternallink', get_string('useexternallink', 'repository'), get_string('configuseexternallink', 'repository'), 0));
+ $temp->add(new admin_setting_configcheckbox('repositoryusepickerbutton', get_string('usepickerbutton', 'repository'), '', 1));
$ADMIN->add('repositorysettings', $temp);
$ADMIN->add('repositorysettings', new admin_externalpage('repositorynew',
get_string('addplugin', 'repository'), $url, 'moodle/site:config', true),
diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php
index 586236c07db..486a5f6187e 100644
--- a/lang/en_utf8/repository.php
+++ b/lang/en_utf8/repository.php
@@ -121,6 +121,7 @@ $string['uploading'] = 'Uploading...';
$string['uploadsucc'] = 'The file has been uploaded successfully';
$string['useexternallink'] = 'Use external link instead downloading files';
$string['configuseexternallink'] = 'Will return the external link to file picker instead downloading external files';
+$string['usepickerbutton'] = 'Use file picker button beside text element';
$string['wrongcontext'] = 'You cannot access to this context';
$string['xhtmlerror'] = 'You are probably using XHTML strict header, some YUI Component doesn\'t work in this mode, please turn it off in moodle';
$string['ziped'] = 'Compress folder successfully';
diff --git a/lib/form/url.js b/lib/form/url.js
new file mode 100644
index 00000000000..b5aecf390c8
--- /dev/null
+++ b/lib/form/url.js
@@ -0,0 +1,19 @@
+function url_callback(params) {
+}
+function url_launch_filepicker(id, client_id, itemid) {
+ var picker = document.createElement('DIV');
+ picker.id = 'file-picker-'+client_id;
+ picker.className = 'file-picker';
+ document.body.appendChild(picker);
+ var el=document.getElementById(id);
+ var params = {};
+ params.env = 'texturl';
+ params.itemid = itemid;
+ params.maxbytes = -1;
+ params.maxfiles = -1;
+ params.savepath = '/';
+ params.target = el;
+ params.callback = url_callback;
+ var fp = open_filepicker(client_id, params);
+ return false;
+}
diff --git a/lib/form/url.php b/lib/form/url.php
new file mode 100755
index 00000000000..a167e365bae
--- /dev/null
+++ b/lib/form/url.php
@@ -0,0 +1,131 @@
+dirroot/repository/lib.php");
+ $options = (array)$options;
+ foreach ($options as $name=>$value) {
+ $this->_options[$name] = $value;
+ }
+ parent::HTML_QuickForm_text($elementName, $elementLabel, $attributes);
+ repository_head_setup();
+ }
+
+ function setHiddenLabel($hiddenLabel){
+ $this->_hiddenLabel = $hiddenLabel;
+ }
+ function toHtml(){
+ global $CFG, $COURSE, $USER, $PAGE;
+
+ $id = $this->_attributes['id'];
+ $elname = $this->_attributes['name'];
+
+ if ($this->_hiddenLabel) {
+ $this->_generateId();
+ $str = ''.parent::toHtml();
+ } else {
+ $str = parent::toHtml();
+ }
+ if (!$CFG->repositoryusepickerbutton) {
+ return $str;
+ }
+ $strsaved = get_string('filesaved', 'repository');
+ $straddlink = get_string('choosealink', 'repository');
+ if ($COURSE->id == SITEID) {
+ $context = get_context_instance(CONTEXT_SYSTEM);
+ } else {
+ $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
+ }
+ $client_id = uniqid();
+
+ $repojs = repository_get_client($context, $client_id, '*', 'link');
+
+ $PAGE->requires->js('lib/form/url.js');
+ $str .= $repojs;
+ $str .= <<$straddlink
+EOD;
+ // hide the button if javascript is not enabled
+ $str .= $PAGE->requires->js_function_call('show_item', array("filepicker-btn-{$client_id}"))->asap();
+ return $str;
+ }
+ /**
+ * Automatically generates and assigns an 'id' attribute for the element.
+ *
+ * Currently used to ensure that labels work on radio buttons and
+ * checkboxes. Per idea of Alexander Radivanovich.
+ * Overriden in moodleforms to remove qf_ prefix.
+ *
+ * @access private
+ * @return void
+ */
+ function _generateId()
+ {
+ static $idx = 1;
+
+ if (!$this->getAttribute('id')) {
+ $this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++), 0, 6)));
+ }
+ } // end func _generateId
+ /**
+ * set html for help button
+ *
+ * @access public
+ * @param array $help array of arguments to make a help button
+ * @param string $function function name to call to get html
+ */
+ function setHelpButton($helpbuttonargs, $function='helpbutton'){
+ if (!is_array($helpbuttonargs)){
+ $helpbuttonargs=array($helpbuttonargs);
+ }else{
+ $helpbuttonargs=$helpbuttonargs;
+ }
+ //we do this to to return html instead of printing it
+ //without having to specify it in every call to make a button.
+ if ('helpbutton' == $function){
+ $defaultargs=array('', '', 'moodle', true, false, '', true);
+ $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+ }
+ $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
+ }
+ /**
+ * get html for help button
+ *
+ * @access public
+ * @return string html for help button
+ */
+ function getHelpButton(){
+ return $this->_helpbutton;
+ }
+ /**
+ * Slightly different container template when frozen. Don't want to use a label tag
+ * with a for attribute in that case for the element label but instead use a div.
+ * Templates are defined in renderer constructor.
+ *
+ * @return string
+ */
+ function getElementTemplateType(){
+ if ($this->_flagFrozen){
+ return 'static';
+ } else {
+ return 'default';
+ }
+ }
+}
diff --git a/lib/formslib.php b/lib/formslib.php
index 757ee789cc3..e13d49630d4 100644
--- a/lib/formslib.php
+++ b/lib/formslib.php
@@ -2240,6 +2240,6 @@ MoodleQuickForm::registerElementType('submitlink', "$CFG->libdir/form/submitlink
MoodleQuickForm::registerElementType('tags', "$CFG->libdir/form/tags.php", 'MoodleQuickForm_tags');
MoodleQuickForm::registerElementType('text', "$CFG->libdir/form/text.php", 'MoodleQuickForm_text');
MoodleQuickForm::registerElementType('textarea', "$CFG->libdir/form/textarea.php", 'MoodleQuickForm_textarea');
-MoodleQuickForm::registerElementType('texturl', "$CFG->libdir/form/texturl.php", 'MoodleQuickForm_texturl');
+MoodleQuickForm::registerElementType('url', "$CFG->libdir/form/url.php", 'MoodleQuickForm_url');
MoodleQuickForm::registerElementType('warning', "$CFG->libdir/form/warning.php", 'MoodleQuickForm_warning');
?>
diff --git a/mod/url/mod_form.php b/mod/url/mod_form.php
index 58f6ca29d0d..ce9b3db9b5b 100644
--- a/mod/url/mod_form.php
+++ b/mod/url/mod_form.php
@@ -46,7 +46,7 @@ class mod_url_mod_form extends moodleform_mod {
//-------------------------------------------------------
$mform->addElement('header', 'content', get_string('contentheader', 'url'));
- $mform->addElement('texturl', 'externalurl', get_string('externalurl', 'url'), array('size'=>'60'), null);
+ $mform->addElement('url', 'externalurl', get_string('externalurl', 'url'), array('size'=>'60'), null);
//-------------------------------------------------------
$mform->addElement('header', 'optionssection', get_string('optionsheader', 'url'));