diff --git a/repository/wikimedia/lang/en/repository_wikimedia.php b/repository/wikimedia/lang/en/repository_wikimedia.php index d0c152f6eb6..31146839c6f 100644 --- a/repository/wikimedia/lang/en/repository_wikimedia.php +++ b/repository/wikimedia/lang/en/repository_wikimedia.php @@ -23,7 +23,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['keyword'] = 'Full text'; +$string['keyword'] = 'Search for'; $string['pluginname'] = 'Wikimedia'; $string['wikimedia:view'] = 'View wikimedia repository'; $string['configplugin'] = 'Wikimedia repository type configuration'; +$string['maxwidth'] = 'Max image width (px)'; +$string['maxheight'] = 'Max image height (px)'; diff --git a/repository/wikimedia/lib.php b/repository/wikimedia/lib.php index cc4bf2be796..09a00fb924a 100644 --- a/repository/wikimedia/lib.php +++ b/repository/wikimedia/lib.php @@ -55,6 +55,43 @@ class repository_wikimedia extends repository { $SESSION->{$sess_keyword} = $this->keyword; } } + + /** + * Returns maximum width for images + * + * Takes the maximum width for images eithre from search form or from + * user preferences, updates user preferences if needed + * + * @return int + */ + public function get_maxwidth() { + $param = optional_param('wikimedia_maxwidth', 0, PARAM_INT); + $pref = get_user_preferences('repository_wikimedia_maxwidth', WIKIMEDIA_IMAGE_SIDE_LENGTH); + if ($param > 0 && $param != $pref) { + $pref = $param; + set_user_preference('repository_wikimedia_maxwidth', $pref); + } + return $pref; + } + + /** + * Returns maximum height for images + * + * Takes the maximum height for images eithre from search form or from + * user preferences, updates user preferences if needed + * + * @return int + */ + public function get_maxheight() { + $param = optional_param('wikimedia_maxheight', 0, PARAM_INT); + $pref = get_user_preferences('repository_wikimedia_maxheight', WIKIMEDIA_IMAGE_SIDE_LENGTH); + if ($param > 0 && $param != $pref) { + $pref = $param; + set_user_preference('repository_wikimedia_maxheight', $pref); + } + return $pref; + } + public function get_listing($path = '', $page = '') { $client = new wikimedia; $list = array(); @@ -62,7 +99,9 @@ class repository_wikimedia extends repository { if ($list['page'] < 1) { $list['page'] = 1; } - $list['list'] = $client->search_images($this->keyword, $list['page'] - 1); + $list['list'] = $client->search_images($this->keyword, $list['page'] - 1, + array('iiurlwidth' => $this->get_maxwidth(), + 'iiurlheight' => $this->get_maxheight())); $list['nologin'] = true; $list['norefresh'] = true; $list['nosearch'] = true; @@ -88,13 +127,26 @@ class repository_wikimedia extends repository { $keyword->type = 'text'; $keyword->name = 'wikimedia_keyword'; $keyword->value = ''; + $maxwidth = array( + 'label' => get_string('maxwidth', 'repository_wikimedia').': ', + 'type' => 'text', + 'name' => 'wikimedia_maxwidth', + 'value' => get_user_preferences('repository_wikimedia_maxwidth', WIKIMEDIA_IMAGE_SIDE_LENGTH), + ); + $maxheight = array( + 'label' => get_string('maxheight', 'repository_wikimedia').': ', + 'type' => 'text', + 'name' => 'wikimedia_maxheight', + 'value' => get_user_preferences('repository_wikimedia_maxheight', WIKIMEDIA_IMAGE_SIDE_LENGTH), + ); if ($this->options['ajax']) { $form = array(); - $form['login'] = array($keyword); + $form['login'] = array($keyword, (object)$maxwidth, (object)$maxheight); $form['nologin'] = true; $form['norefresh'] = true; $form['nosearch'] = true; - $form['allowcaching'] = true; // indicates that login form can be cached in filepicker.js + $form['allowcaching'] = false; // indicates that login form can NOT + // be cached in filepicker.js (maxwidth and maxheight are dynamic) return $form; } else { echo <<_param['action'] = 'query'; $this->_param['generator'] = 'search'; @@ -151,8 +156,9 @@ class wikimedia { $this->_param['gsroffset'] = $page * WIKIMEDIA_THUMBS_PER_PAGE; $this->_param['prop'] = 'imageinfo'; $this->_param['iiprop'] = 'url|dimensions|mime|timestamp|size|user'; - $this->_param['iiurlwidth'] = WIKIMEDIA_IMAGE_SIDE_LENGTH; - $this->_param['iiurlheight'] = WIKIMEDIA_IMAGE_SIDE_LENGTH; + $this->_param += $params; + $this->_param += array('iiurlwidth' => WIKIMEDIA_IMAGE_SIDE_LENGTH, + 'iiurlheight' => WIKIMEDIA_IMAGE_SIDE_LENGTH); //didn't work with POST $content = $this->_conn->get($this->api, $this->_param); $result = unserialize($content); @@ -173,6 +179,12 @@ class wikimedia { 'image_width' => $page['imageinfo'][0]['thumbwidth'], 'image_height' => $page['imageinfo'][0]['thumbheight'] ); + if ($attrs['image_width'] <= WIKIMEDIA_THUMB_SIZE && $attrs['image_height'] <= WIKIMEDIA_THUMB_SIZE) { + $attrs['realthumbnail'] = $attrs['source']; + } + if ($attrs['image_width'] <= 24 && $attrs['image_height'] <= 24) { + $attrs['realicon'] = $attrs['source']; + } } else { $attrs = array( //upload full size image @@ -183,20 +195,19 @@ class wikimedia { ); } $attrs += array( - 'thumbnail' => $this->get_thumb_url($page['imageinfo'][0]['url'], $page['imageinfo'][0]['width'], $page['imageinfo'][0]['height'], 120), - 'icon' => $this->get_thumb_url($page['imageinfo'][0]['url'], $page['imageinfo'][0]['width'], $page['imageinfo'][0]['height'], 24), + 'realthumbnail' => $this->get_thumb_url($page['imageinfo'][0]['url'], $page['imageinfo'][0]['width'], $page['imageinfo'][0]['height'], WIKIMEDIA_THUMB_SIZE), + 'realicon' => $this->get_thumb_url($page['imageinfo'][0]['url'], $page['imageinfo'][0]['width'], $page['imageinfo'][0]['height'], 24), 'author' => $page['imageinfo'][0]['user'], 'datemodified' => strtotime($page['imageinfo'][0]['timestamp']), ); } else { // other file types - $attrs = array( - $thumbnail = '', - $source = $page['imageinfo'][0]['url']); + $attrs = array('source' => $page['imageinfo'][0]['url']); } $files_array[] = array( 'title'=>substr($title, 5), //chop off 'File:' - 'thumbnail_width'=>120, - 'thumbnail_height'=>120, + 'thumbnail' => $OUTPUT->pix_url(file_extension_icon(substr($title, 5), WIKIMEDIA_THUMB_SIZE))->out(false), + 'thumbnail_width' => WIKIMEDIA_THUMB_SIZE, + 'thumbnail_height' => WIKIMEDIA_THUMB_SIZE, 'license' => 'cc-sa', // the accessible url of the file 'url'=>$page['imageinfo'][0]['descriptionurl']