first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,154 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for repository_wikimedia.
*
* @package repository_wikimedia
* @copyright 2018 Zig Tan <zig@moodle.com>
* @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 <zig@moodle.com>
* @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')
);
}
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Plugin capabilities.
*
* @package repository_wikimedia
* @copyright 2009 Dongsheng Cai
* @author Dongsheng Cai <dongsheng@moodle.com>
* @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
)
)
);
+39
View File
@@ -0,0 +1,39 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
}
@@ -0,0 +1,35 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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.';
+201
View File
@@ -0,0 +1,201 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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 <<<EOD
<table>
<tr>
<td>{$keyword->label}</td><td><input name="{$keyword->name}" type="text" /></td>
</tr>
</table>
<input type="submit" />
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;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

@@ -0,0 +1,22 @@
@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
@@ -0,0 +1,35 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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 {
}
+31
View File
@@ -0,0 +1,31 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version details
*
* @package repository
* @subpackage wikimedia
* @copyright 2009 Dongsheng Cai
* @author Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'repository_wikimedia'; // Full name of the plugin (used for diagnostics)
+248
View File
@@ -0,0 +1,248 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* wikimedia class
* class for communication with Wikimedia Commons API
*
* @author Dongsheng Cai <dongsheng@moodle.com>, Raul Kern <raunator@gmail.com>
* @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'] = 'php';
$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 = unserialize($content);
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 = unserialize($content);
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 = unserialize($content);
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 = unserialize($content);
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;
}
}