ÿØÿà JFIF    ÿÛ „  ( %!1"%)+...383-7(-.+  -%%--------+------------/----------------------------ÿÀ  ¶" ÿÄ     ÿÄ @    !1AQaq‘¡"±ÁÑð2’BRráS‚ñ3b¢CT²Ò #cÿÄ    ÿÄ '   1!AQ2a"‘±#ÿÚ   ? ò(/p‘—–¢·,M|¯G»R£üešT. ôŸEoCFñ‡ 4ÔkåóxR|µÁ¨ÓDà!Ç´µ˜‡p ÍQ‹§!þž^õWsŒy  åÁ§$á«%ºq˜™JyyË0y«^Ϗ -3ÃÏËÈ£Æ\P’ä„s&•‹Üs üô'àWt¹pñCp$bÚF`·7.^)¾!)ÒÙ˜–ÅÏš^h¾ø³·ìe±ŒaeÖ—Í,e=B}Jéߦ$$½—šÙÜCC¯¶è8β–Åkèwx LÉngT±æ¹£Ócœ¿Í/©Éÿ ‰ÚCÒ­mq;Tt¶–}0"zÖPcd1š­¤tˆ„ÐÓâqú[™öUCŠ2޿د­É(¸ßúçšmW,Ò ºf‹Ån™ÄLêÁ8üÁkÁ€L¥ÍuJ1œôrÂSŒÓöt!7EUíïb)AËi¬â-ÙHk8òÁiXYwÅ)O^"ÇØriÛô{»wRUKÙÏÚlÓ¬€‚’שT ] ªb—ÊîKC^×M“xùäñz¬zJ× {4[¹M'IÆeH1LCWÕ]œûº WDæà°OÅ‚¹c²ÞuA–rL`HšpCez‡V’— Ž‚Ë„–ñ­'µR0ÕÖ=À:±G»C\nÆÉ5*¢ †3šhQ4ýÒi$Õ1"Ü]¢p-q3zcQ$ªö¨¥æf›‘»´ÝÚHá„e²JÇ–iÊ:·à¬Øc5Åk»Laª*wi [0Ówk ¦a¦0Õ²ÅÅ‚T¸’³q:Æ<¹ú Ò˜Æ}2VE•Ѐp¡Ô3Úº …h³^LJºçì¥Ánó|˜ÖˆÎˆ+« ¦dø‘Mº–d\ªDðÛ„Ì×LÝ——Ð9Ç|•FèçVm™¨€™3õS–9Äå¢<̉Ìm¢±`·º˜&Z²ž Ë®D«¶»6™‰©­HÈ Àá«h­i³04æ’hxœi3ï¨(ÓL·†‹¶ËpŒ ƒÜÒ? :õdsÀ –3æÓ·Üjâ¬9—]8n¼&]I F£¼…ì–—Œ0v°LǐÅfÛ2TÖ’aµ˜N@ÖBSÏ^à´4-±°b×nÈÈœÆD=KdŒø…ÄÈK,›ÖR§fjü$^ÔÎ!„6^ s:Üun\ôkCÞò÷<—Lúl Í›G¹ÀPá¼Nc¡šÒ…ÙWͳœ±vÊáЄ×9‹P‰cEØ‘™›µŸP<×g1 º©Ø¬wiÁ^l5× I/';Ë+´Z‡ÓÄFÕp[Èð’ HÄ ó 9¬Dl4“é±Ï”V=^Hð;žLädÉa‚°Ë,#/Ž~²BÔÛ QãñQtIeórVB,ÏÂf‹4#Μc‹É3ZIÖ Œ¢¥·üxa‡Ãçè„jŠ[5 Ä!U?,3žÎ×…ðdÓ÷háŠA‰ìÄ4÷ÃÜZÃE{‰®+W\ZÍE[‰»µk»MÝ­`¢©†˜ÃV‹-f¢¡†¢a«eŠ%«Y¨©q%jâd,Ôq`) ¤¦…šˆ ¦E>0Ùb²t–Ÿ  ÷jsςҒKÈcø(é›;k(’#ôŒQ ™C> õ³M9óºÆµ¤çâ;uÀ)5>RÔ¸fÓ~Ȧ—’-$fe«"FâUˆÊwµPÏu w+"åÉó¨6s™Û9(À¨ù©hE°½†n`m~“@©›p!Vkhµ Á1šbEqqÊ@ºèl›2 –Yã%‘‚hÛ{a¶‡ÅÞM²¬çL34®Çl]®‹ŽØŒm'RÜe35æöˆ­Á­ cP9šeÁköo´L³Ì=p8]”‡B¶,šº|ɏdzXˆØk*ÇÚ{#ñ‰pã(€¶‡9ý'šÜ³½¯kƒ†Â’ëSOƒ•Å®H6+a¢µˆ‹Y¨b˜b+XˆÖ!°u!¢"µˆˆn2ˆ Å0Ä`Å Ô®c(ÓÜGº•Ä»Œ âWî%q.áÐÄ÷î%umÍ£+ÜQ,Vn¦-GphU¸¢X­&,Gt ·K¢ÅÅ·¥RÄÊÉbKn N­R2g$VµÕó Qr#–ÓZUÏð0ÎtÙÀœz ëöo“Îk¯n„T°"SÞ+³/…€½"ižãO%Í%&Δâ‘ËØ´IˆÓ°Ë‰ÞM3.™yçÁzit›`4C`k¢¼á!álÄï sÂ[×!¤l¾æo"ƒIÔ'@ªu)3›ô®“@Z à¾] üœ'‡4¸PÞkÁ-qÄH‰ÓÍBd´ÿ —¹°ÄA&ÊUC„öz‚‚RæŠtf¬>˜ÑidšEçÑL÷áý¡V±h§­c¿¥¨ƒ@g¼…Ýö^ÞËc.ž„æ“I[ ª+·zÐÒÚ,½Ð»¶€C›7jk$๖€Ž¾ÅÙpp¶ÍþéΤ ½ØÎŒq ñpæžÅ¥#Øâ49ÃÂK^MYV“,¶Éz_òæ:…;Õ«¦I3âJ£¤û5$7Èxün\â]Êe¯(Ÿ&Ž‹¶2<6Ćf× æ¢ƱqWı[(ÙÂŽç‚T7¨@ÈÉÍß‚ïÙ"&3TYlGށ†)†#5ŠA©^T2ÆÁ†)©†©†¤yGXÁ†©"†)©¼ÅV WS†#©]R–r‹q5ÕbâWþBh¯u+ªÅÄ×ü„nÑ^êkªÁj‰jeœWˆÕÕ`µDµ2Ì+Ä µDµµ5Ô{¤Þ0RF’H÷AÛ<ÊÁ§ ƈæ0Ñ£ê4 öÚµ[¬/1²€â<-¬šö²r×0o×w ´xÐÒË„ g01¬„åEM蛇Ã\6µE›‘fÙO k÷CºnÓ1`iîÒ² áÂ!ÑLÄÿ ³¬\õ*:M=Ç»c‹2[‰ØsÕLò\ŒK L^™üÄN\¶#» Ç\……ßïIœÉ$¸ÎñÍ®ÔHÇ Ûí/´>Li”„†g^$ 7NÍÑÑ2M2ªNg=k½Ð}Ÿl6‡ —JWˆ”ÞéT·+µ¦üÂFè¢Vs6ýÆ4»2+2IÝ9ô9®ÇGÙÇ1+Ä8;*Õ§ž½D*îÑWÚçá3Ma¤·ˆ¥t}š²Ü…Q+Æüµ8HíS”üxGéÁˆ¦Ël„éÈ 5 µÄƒ6äÜ(kIš¯S†fÖ&¸®×v|Äyˆ*禌Éù@7-®Ä[]ÎÖ¿ê`º…=:…žJVnݳvðÖKE¼‚ »mà ÷f®:Ë ™–4rð¡4` ܹçž~‹C=œ…¾Ïj|VDtK.ƒ"9 Ï ­–éXá³6WÒïIL-Ї Ç db/install.php000064400000002452152266403450007322 0ustar00. /** * Installation file for the wikimedia repository * * @package repository_wikimedia * @category repository * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * Create a default instance of the wikimedia repository * * @return bool A status indicating success or failure */ function xmldb_repository_wikimedia_install() { global $CFG; $result = true; require_once($CFG->dirroot.'/repository/lib.php'); $wikimediaplugin = new repository_type('wikimedia', array(), true); if(!$id = $wikimediaplugin->create(true)) { $result = false; } return $result; } db/access.php000064400000002231152266403450007110 0ustar00. /** * Plugin capabilities. * * @package repository_wikimedia * @copyright 2009 Dongsheng Cai * @author Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); $capabilities = array( 'repository/wikimedia:view' => array( 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, 'archetypes' => array( 'user' => CAP_ALLOW ) ) ); lang/en/repository_wikimedia.php000064400000003461152266403450013055 0ustar00. /** * Strings for component 'repository_wikimedia', language 'en', branch 'MOODLE_20_STABLE' * * @package repository_wikimedia * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $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)'; $string['privacy:metadata:repository_wikimedia'] = 'The Wikimedia repository plugin does store user preferences, and transmits user data from Moodle to the remote system.'; $string['privacy:metadata:repository_wikimedia:search_text'] = 'The Wikimedia repository user search text query.'; $string['privacy:metadata:repository_wikimedia:preference:maxwidth'] = 'The user preference max width configured for the Wikimedia repository'; $string['privacy:metadata:repository_wikimedia:preference:maxheight'] = 'The user preference Max Height configured for the Wikimedia repository.'; pix/icon.png000064400000001670152266403450007015 0ustar00PNG  IHDR(-SPLTE==;uuuކ444|||ދYYY˶jjj텅111̊浵nnnɓxxxﭭȀޣ~~~*9^tRNS  !$&'*+-/38ORegksuw5yIDATxV.Qo{ٮvFZUvٶN߇Y \U9!h w{l`Γ,Ud/Cl\D\%(b3pʓͬ]82naxk t1|7԰X(tC$VÇq )E@u }<- 0:0]uDQCIdJз>VSv JU޼@9Mޝ{@F\'g?[~IENDB`lib.php000064400000016045152266403450006040 0ustar00. /** * This plugin is used to access wikimedia files * * @since Moodle 2.0 * @package repository_wikimedia * @copyright 2010 Dongsheng Cai {@link http://dongsheng.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once($CFG->dirroot . '/repository/lib.php'); require_once(__DIR__ . '/wikimedia.php'); /** * repository_wikimedia class * This is a class used to browse images from wikimedia * * @since Moodle 2.0 * @package repository_wikimedia * @copyright 2009 Dongsheng Cai {@link http://dongsheng.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class repository_wikimedia extends repository { /** @var string keyword search. */ protected $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(); $list['page'] = (int)$page; if ($list['page'] < 1) { $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; if (!empty($list['list'])) { $list['pages'] = -1; // means we don't know exactly how many pages there are but we can always jump to the next page } else if ($list['page'] > 1) { $list['pages'] = $list['page']; // no images available on this page, this is the last page } else { $list['pages'] = 0; // no paging } return $list; } // login public function check_login() { global $SESSION; $this->keyword = optional_param('wikimedia_keyword', '', PARAM_RAW); if (empty($this->keyword)) { $this->keyword = optional_param('s', '', PARAM_RAW); } $sess_keyword = 'wikimedia_'.$this->id.'_keyword'; if (empty($this->keyword) && optional_param('page', '', PARAM_RAW)) { // This is the request of another page for the last search, retrieve the cached keyword. if (isset($SESSION->{$sess_keyword})) { $this->keyword = $SESSION->{$sess_keyword}; } } else if (!empty($this->keyword)) { // Save the search keyword in the session so we can retrieve it later. $SESSION->{$sess_keyword} = $this->keyword; } return !empty($this->keyword); } // if check_login returns false, // this function will be called to print a login form. public function print_login() { $keyword = new stdClass(); $keyword->label = get_string('keyword', 'repository_wikimedia').': '; $keyword->id = 'input_text_keyword'; $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, (object)$maxwidth, (object)$maxheight); $form['nologin'] = true; $form['norefresh'] = true; $form['nosearch'] = true; $form['allowcaching'] = false; // indicates that login form can NOT // be cached in filepicker.js (maxwidth and maxheight are dynamic) return $form; } else { echo << {$keyword->label} EOD; } } //search // if this plugin support global search, if this function return // true, search function will be called when global searching working public function global_search() { return false; } public function search($search_text, $page = 0) { $client = new wikimedia; $search_result = array(); $search_result['list'] = $client->search_images($search_text); return $search_result; } // when logout button on file picker is clicked, this function will be // called. public function logout() { return $this->print_login(); } public function supported_returntypes() { return (FILE_INTERNAL | FILE_EXTERNAL); } /** * Return the source information * * @param stdClass $url * @return string|null */ public function get_file_source_info($url) { return $url; } /** * Is this repository accessing private data? * * @return bool */ public function contains_private_data() { return false; } } version.php000064400000002312152266403450006747 0ustar00. /** * Version details * * @package repository * @subpackage wikimedia * @copyright 2009 Dongsheng Cai * @author Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); $plugin->version = 2025041400; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2025040800; // Requires this Moodle version. $plugin->component = 'repository_wikimedia'; // Full name of the plugin (used for diagnostics) classes/privacy/provider.php000064400000012744152266403450012240 0ustar00. /** * Privacy Subsystem implementation for repository_wikimedia. * * @package repository_wikimedia * @copyright 2018 Zig Tan * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace repository_wikimedia\privacy; use core_privacy\local\metadata\collection; use core_privacy\local\request\approved_contextlist; use core_privacy\local\request\approved_userlist; use core_privacy\local\request\context; use core_privacy\local\request\contextlist; use core_privacy\local\request\userlist; use core_privacy\local\request\writer; defined('MOODLE_INTERNAL') || die(); /** * Privacy Subsystem for repository_wikimedia implementing metadata and plugin providers. * * @copyright 2018 Zig Tan * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\core_userlist_provider, \core_privacy\local\request\plugin\provider, \core_privacy\local\request\user_preference_provider { /** * Returns meta data about this system. * * @param collection $collection The initialised collection to add items to. * @return collection A listing of user data stored through this system. */ public static function get_metadata(collection $collection): collection { $collection->add_external_location_link( 'wikimedia.org', [ 'search_text' => 'privacy:metadata:repository_wikimedia:search_text' ], 'privacy:metadata:repository_wikimedia' ); $collection->add_user_preference( 'repository_wikimedia_maxwidth', 'privacy:metadata:repository_wikimedia:preference:maxwidth' ); $collection->add_user_preference( 'repository_wikimedia_maxheight', 'privacy:metadata:repository_wikimedia:preference:maxheight' ); return $collection; } /** * Get the list of contexts that contain user information for the specified user. * * @param int $userid The user to search. * @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin. */ public static function get_contexts_for_userid(int $userid): contextlist { return new contextlist(); } /** * Get the list of users who have data within a context. * * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ public static function get_users_in_context(userlist $userlist) { } /** * Export all user data for the specified user, in the specified contexts. * * @param approved_contextlist $contextlist The approved contexts to export information for. */ public static function export_user_data(approved_contextlist $contextlist) { } /** * Delete all data for all users in the specified context. * * @param context $context The specific context to delete data for. */ public static function delete_data_for_all_users_in_context(\context $context) { } /** * Delete all user data for the specified user, in the specified contexts. * * @param approved_contextlist $contextlist The approved contexts and user information to delete information for. */ public static function delete_data_for_user(approved_contextlist $contextlist) { } /** * Delete multiple users within a single context. * * @param approved_userlist $userlist The approved context and user information to delete information for. */ public static function delete_data_for_users(approved_userlist $userlist) { } /** * Export all user preferences for the plugin. * * @param int $userid The userid of the user whose data is to be exported. */ public static function export_user_preferences(int $userid) { $maxwidth = get_user_preferences('repository_wikimedia_maxwidth', null, $userid); if ($maxwidth !== null) { writer::export_user_preference( 'repository_wikimedia', 'repository_wikimedia_maxwidth', $maxwidth, get_string('privacy:metadata:repository_wikimedia:preference:maxwidth', 'repository_wikimedia') ); } $maxheight = get_user_preferences('repository_wikimedia_maxheight', null, $userid); if ($maxheight !== null) { writer::export_user_preference( 'repository_wikimedia', 'repository_wikimedia_maxheight', $maxheight, get_string('privacy:metadata:repository_wikimedia:preference:maxheight', 'repository_wikimedia') ); } } } wikimedia.php000064400000024731152266403450007236 0ustar00. /** * wikimedia class * class for communication with Wikimedia Commons API * * @author Dongsheng Cai , Raul Kern * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ define('WIKIMEDIA_THUMBS_PER_PAGE', 24); define('WIKIMEDIA_FILE_NS', 6); define('WIKIMEDIA_IMAGE_SIDE_LENGTH', 1024); define('WIKIMEDIA_THUMB_SIZE', 120); class wikimedia { private $_conn = null; private $_param = array(); /** @var string API URL. */ protected $api; /** @var string user ID. */ protected $userid; /** @var string username. */ protected $username; /** @var string token key. */ protected $token; public function __construct($url = '') { if (empty($url)) { $this->api = 'https://commons.wikimedia.org/w/api.php'; } else { $this->api = $url; } $this->_param['format'] = 'json'; $this->_param['redirects'] = true; $this->_conn = new curl(array('cache'=>true, 'debug'=>false)); } public function login($user, $pass) { $this->_param['action'] = 'login'; $this->_param['lgname'] = $user; $this->_param['lgpassword'] = $pass; $content = $this->_conn->post($this->api, $this->_param); $result = json_decode($content, true); if (!empty($result['result']['sessionid'])) { $this->userid = $result['result']['lguserid']; $this->username = $result['result']['lgusername']; $this->token = $result['result']['lgtoken']; return true; } else { return false; } } public function logout() { $this->_param['action'] = 'logout'; $content = $this->_conn->post($this->api, $this->_param); return; } public function get_image_url($titles) { $image_urls = array(); $this->_param['action'] = 'query'; if (is_array($titles)) { foreach ($titles as $title) { $this->_param['titles'] .= ('|'.urldecode($title)); } } else { $this->_param['titles'] = urldecode($titles); } $this->_param['prop'] = 'imageinfo'; $this->_param['iiprop'] = 'url'; $content = $this->_conn->post($this->api, $this->_param); $result = json_decode($content, true); foreach ($result['query']['pages'] as $page) { if (!empty($page['imageinfo'][0]['url'])) { $image_urls[] = $page['imageinfo'][0]['url']; } } return $image_urls; } public function get_images_by_page($title) { $image_urls = array(); $this->_param['action'] = 'query'; $this->_param['generator'] = 'images'; $this->_param['titles'] = urldecode($title); $this->_param['prop'] = 'images|info|imageinfo'; $this->_param['iiprop'] = 'url'; $content = $this->_conn->post($this->api, $this->_param); $result = json_decode($content, true); if (!empty($result['query']['pages'])) { foreach ($result['query']['pages'] as $page) { $image_urls[$page['title']] = $page['imageinfo'][0]['url']; } } return $image_urls; } /** * Generate thumbnail URL from image URL. * * @param string $image_url * @param int $orig_width * @param int $orig_height * @param int $thumb_width * @param bool $force When true, forces the generation of a thumb URL. * @global object OUTPUT * @return string */ public function get_thumb_url($image_url, $orig_width, $orig_height, $thumb_width = 75, $force = false) { global $OUTPUT; if (!$force && $orig_width <= $thumb_width && $orig_height <= $thumb_width) { return $image_url; } else { $thumb_url = ''; $commons_main_dir = 'https://upload.wikimedia.org/wikipedia/commons/'; if ($image_url) { $short_path = str_replace($commons_main_dir, '', $image_url); $extension = strtolower(pathinfo($short_path, PATHINFO_EXTENSION)); if (strcmp($extension, 'gif') == 0) { //no thumb for gifs return $OUTPUT->image_url(file_extension_icon('.gif'))->out(false); } $dir_parts = explode('/', $short_path); $file_name = end($dir_parts); if ($orig_height > $orig_width) { $thumb_width = round($thumb_width * $orig_width/$orig_height); } $thumb_url = $commons_main_dir . 'thumb/' . implode('/', $dir_parts) . '/'. $thumb_width .'px-' . $file_name; if (strcmp($extension, 'svg') == 0) { //png thumb for svg-s $thumb_url .= '.png'; } } return $thumb_url; } } /** * Search for images and return photos array. * * @param string $keyword * @param int $page * @param array $params additional query params * @return array */ public function search_images($keyword, $page = 0, $params = array()) { global $OUTPUT; $files_array = array(); $this->_param['action'] = 'query'; $this->_param['generator'] = 'search'; $this->_param['gsrsearch'] = $keyword; $this->_param['gsrnamespace'] = WIKIMEDIA_FILE_NS; $this->_param['gsrlimit'] = WIKIMEDIA_THUMBS_PER_PAGE; $this->_param['gsroffset'] = $page * WIKIMEDIA_THUMBS_PER_PAGE; $this->_param['prop'] = 'imageinfo'; $this->_param['iiprop'] = 'url|dimensions|mime|timestamp|size|user'; $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 = json_decode($content, true); if (!empty($result['query']['pages'])) { foreach ($result['query']['pages'] as $page) { $title = $page['title']; $file_type = $page['imageinfo'][0]['mime']; $image_types = array('image/jpeg', 'image/png', 'image/gif', 'image/svg+xml'); if (in_array($file_type, $image_types)) { //is image $extension = pathinfo($title, PATHINFO_EXTENSION); $issvg = strcmp($extension, 'svg') == 0; // Get PNG equivalent to SVG files. if ($issvg) { $title .= '.png'; } // The thumbnail (max size requested) is smaller than the original size, we will use the thumbnail. if ($page['imageinfo'][0]['thumbwidth'] < $page['imageinfo'][0]['width']) { $attrs = array( //upload scaled down image 'source' => $page['imageinfo'][0]['thumburl'], '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']; } // We use the original file. } else { $attrs = array( //upload full size image 'image_width' => $page['imageinfo'][0]['width'], 'image_height' => $page['imageinfo'][0]['height'], 'size' => $page['imageinfo'][0]['size'] ); // We cannot use the source when the file is SVG. if ($issvg) { // So we generate a PNG thumbnail of the file at its original size. $attrs['source'] = $this->get_thumb_url($page['imageinfo'][0]['url'], $page['imageinfo'][0]['width'], $page['imageinfo'][0]['height'], $page['imageinfo'][0]['width'], true); } else { $attrs['source'] = $page['imageinfo'][0]['url']; } } $attrs += array( '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('source' => $page['imageinfo'][0]['url']); } $files_array[] = array( 'title'=>substr($title, 5), //chop off 'File:' 'thumbnail' => $OUTPUT->image_url(file_extension_icon(substr($title, 5)))->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'] ) + $attrs; } } return $files_array; } } tests/generator/lib.php000064400000002271152266403450011164 0ustar00. /** * Wikimedia repository data generator * * @package repository_wikimedia * @category test * @copyright 2013 Frédéric Massart * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * Wikimedia repository data generator class * * @package repository_wikimedia * @category test * @copyright 2013 Frédéric Massart * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class repository_wikimedia_generator extends testing_repository_generator { } tests/behat/add_files.feature000064400000001726152266403450012275 0ustar00@repository @repository_wikimedia @javascript Feature: Wikimedia repository In order to update my profile picture As an admin I need to choose a picture from Wikimedia Scenario: Users can add profile picture using wikimedia Given I log in as "admin" And I open my profile in edit mode And I click on "Add..." "button" in the "New picture" "form_row" # Upload a new user picture using Wikimedia repository. And I follow "Wikimedia" And I set the field "Search for:" to "cat" And I click on "Submit" "button" # Click on the link of the first search result. And I click on "a.fp-file" "css_element" And I click on "Select this file" "button" When I click on "Update profile" "button" # New profile picture. Then "//img[contains(@class, 'userpicture')]" "xpath_element" should exist # Default profile picture should not exist any more. And "//img[contains(@class, 'defaultuserpic')]" "xpath_element" should not exist