diff --git a/admin/tool/filetypes/renderer.php b/admin/tool/filetypes/renderer.php index f283af177f0..f920a1a54a6 100644 --- a/admin/tool/filetypes/renderer.php +++ b/admin/tool/filetypes/renderer.php @@ -82,7 +82,9 @@ class tool_filetypes_renderer extends plugin_renderer_base { // First cell has icon and extension. $icon = $this->pix_icon('f/' . $filetype['icon'], ''); - $row->cells[] = new html_table_cell($icon . ' ' . html_writer::span(s($extension))); + $iconcell = new html_table_cell($icon . ' ' . html_writer::span(s($extension))); + $iconcell->attributes['class'] = 'icon-size-5'; + $row->cells[] = $iconcell; // Reset URL and button if needed. $reverturl = new \moodle_url('/admin/tool/filetypes/revert.php', diff --git a/admin/tool/filetypes/tests/tool_filetypes_test.php b/admin/tool/filetypes/tests/tool_filetypes_test.php index 6d536835d4e..1e22a01d4f9 100644 --- a/admin/tool/filetypes/tests/tool_filetypes_test.php +++ b/admin/tool/filetypes/tests/tool_filetypes_test.php @@ -14,16 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the custom file types. - * - * @package tool_filetypes - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - use tool_filetypes\utils; /** @@ -32,10 +22,13 @@ use tool_filetypes\utils; * @package tool_filetypes * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @coversDefaultClass \tool_filetypes\utils */ class tool_filetypes_test extends advanced_testcase { /** * Tests is_extension_invalid() function. + * + * @covers ::is_extension_invalid */ public function test_is_extension_invalid() { // The pdf file extension already exists in default moodle minetypes. @@ -56,6 +49,8 @@ class tool_filetypes_test extends advanced_testcase { /** * Tests is_defaulticon_allowed() function. + * + * @covers ::is_defaulticon_allowed */ public function test_is_defaulticon_allowed() { // You ARE allowed to set a default icon for a MIME type that hasn't @@ -73,6 +68,8 @@ class tool_filetypes_test extends advanced_testcase { /** * Tests get_icons_from_path() function. + * + * @covers ::get_icons_from_path */ public function test_get_icons_from_path() { // Get icons from the fixtures folder. @@ -83,4 +80,14 @@ class tool_filetypes_test extends advanced_testcase { // returned and only one of it. $this->assertEquals(array('frog' => 'frog', 'zombie' => 'zombie'), $icons); } + + /** + * Test get_file_icons() function to confirm no file icons are removed/added by mistake. + * + * @covers ::get_file_icons + */ + public function test_get_file_icons() { + $icons = utils::get_file_icons(); + $this->assertCount(30, $icons); + } } diff --git a/course/renderer.php b/course/renderer.php index 27c6f992f05..f86e24d1c9f 100644 --- a/course/renderer.php +++ b/course/renderer.php @@ -979,7 +979,7 @@ class core_course_renderer extends plugin_renderer_base { html_writer::empty_tag('img', ['src' => $url, 'alt' => '']), ['class' => 'courseimage']); } else { - $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle'); + $image = $this->output->pix_icon(file_file_icon($file), $file->get_filename(), 'moodle'); $filename = html_writer::tag('span', $image, ['class' => 'fp-icon']). html_writer::tag('span', $file->get_filename(), ['class' => 'fp-filename']); $contentfiles .= html_writer::tag('span', diff --git a/files/classes/external/stored_file_exporter.php b/files/classes/external/stored_file_exporter.php index 4a664d10516..c491170e971 100644 --- a/files/classes/external/stored_file_exporter.php +++ b/files/classes/external/stored_file_exporter.php @@ -147,7 +147,7 @@ class stored_file_exporter extends \core\external\exporter { $filenameshort .= substr($filename, -4); } - $icon = $this->file->is_directory() ? file_folder_icon(128) : file_file_icon($this->file, 128); + $icon = $this->file->is_directory() ? file_folder_icon() : file_file_icon($this->file); $url = moodle_url::make_pluginfile_url( $this->file->get_contextid(), diff --git a/files/renderer.php b/files/renderer.php index 0795e9574c9..de35b24bc78 100644 --- a/files/renderer.php +++ b/files/renderer.php @@ -70,10 +70,10 @@ class core_files_renderer extends plugin_renderer_base { if ($file['filesize']) { $filesize = display_size($file['filesize']); } - $fileicon = file_file_icon($file, 24); + $fileicon = file_file_icon($file); $filetype = get_mimetype_description($file); } else { - $fileicon = file_folder_icon(24); + $fileicon = file_folder_icon(); } $table->data[] = array( html_writer::link($file['url'], $this->output->pix_icon($fileicon, get_string('icon')) . ' ' . $file['filename']), diff --git a/lib/classes/filetypes.php b/lib/classes/filetypes.php index f4d09c6bd15..2a41e23b0b0 100644 --- a/lib/classes/filetypes.php +++ b/lib/classes/filetypes.php @@ -47,12 +47,12 @@ abstract class core_filetypes { protected static function get_default_types() { return array( 'xxx' => array('type' => 'document/unknown', 'icon' => 'unknown'), - '3gp' => array('type' => 'video/quicktime', 'icon' => 'quicktime', 'groups' => array('video'), 'string' => 'video'), + '3gp' => array('type' => 'video/quicktime', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'), '7z' => array('type' => 'application/x-7z-compressed', 'icon' => 'archive', 'groups' => array('archive'), 'string' => 'archive'), 'aac' => array('type' => 'audio/aac', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'), 'string' => 'audio'), - 'accdb' => array('type' => 'application/msaccess', 'icon' => 'base'), + 'accdb' => array('type' => 'application/msaccess', 'icon' => 'database'), 'ai' => array('type' => 'application/postscript', 'icon' => 'eps', 'groups' => array('image'), 'string' => 'image'), 'aif' => array('type' => 'audio/x-aiff', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'), 'aiff' => array('type' => 'audio/x-aiff', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'), @@ -61,16 +61,16 @@ abstract class core_filetypes { 'asc' => array('type' => 'text/plain', 'icon' => 'sourcecode'), 'asm' => array('type' => 'text/plain', 'icon' => 'sourcecode'), 'au' => array('type' => 'audio/au', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'), - 'avi' => array('type' => 'video/x-ms-wm', 'icon' => 'avi', + 'avi' => array('type' => 'video/x-ms-wm', 'icon' => 'video', 'groups' => array('video', 'web_video'), 'string' => 'video'), - 'bmp' => array('type' => 'image/bmp', 'icon' => 'bmp', 'groups' => array('image'), 'string' => 'image'), + 'bmp' => array('type' => 'image/bmp', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'), 'c' => array('type' => 'text/plain', 'icon' => 'sourcecode'), 'cct' => array('type' => 'shockwave/director', 'icon' => 'flash'), 'cpp' => array('type' => 'text/plain', 'icon' => 'sourcecode'), 'cs' => array('type' => 'application/x-csh', 'icon' => 'sourcecode'), 'css' => array('type' => 'text/css', 'icon' => 'text', 'groups' => array('web_file')), 'csv' => array('type' => 'text/csv', 'icon' => 'spreadsheet', 'groups' => array('spreadsheet')), - 'dv' => array('type' => 'video/x-dv', 'icon' => 'quicktime', 'groups' => array('video'), 'string' => 'video'), + 'dv' => array('type' => 'video/x-dv', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'), 'dmg' => array('type' => 'application/octet-stream', 'icon' => 'unknown'), 'doc' => array('type' => 'application/msword', 'icon' => 'document', 'groups' => array('document')), @@ -85,7 +85,7 @@ abstract class core_filetypes { 'dotm' => array('type' => 'application/vnd.ms-word.template.macroEnabled.12', 'icon' => 'document'), 'dcr' => array('type' => 'application/x-director', 'icon' => 'flash'), - 'dif' => array('type' => 'video/x-dv', 'icon' => 'quicktime', 'groups' => array('video'), 'string' => 'video'), + 'dif' => array('type' => 'video/x-dv', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'), 'dir' => array('type' => 'application/x-director', 'icon' => 'flash'), 'dxr' => array('type' => 'application/x-director', 'icon' => 'flash'), 'eps' => array('type' => 'application/postscript', 'icon' => 'eps'), @@ -96,7 +96,7 @@ abstract class core_filetypes { 'flv' => array('type' => 'video/x-flv', 'icon' => 'flash', 'groups' => array('video', 'web_video'), 'string' => 'video'), 'f4v' => array('type' => 'video/mp4', 'icon' => 'flash', 'groups' => array('video', 'web_video'), 'string' => 'video'), - 'fmp4' => array('type' => 'video/mp4', 'icon' => 'mpeg', 'groups' => array('html_video', 'video', 'web_video'), + 'fmp4' => array('type' => 'video/mp4', 'icon' => 'video', 'groups' => array('html_video', 'video', 'web_video'), 'string' => 'video'), 'gallery' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'), 'galleryitem' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'), @@ -121,9 +121,9 @@ abstract class core_filetypes { 'hqx' => array('type' => 'application/mac-binhex40', 'icon' => 'archive', 'groups' => array('archive'), 'string' => 'archive'), 'htc' => array('type' => 'text/x-component', 'icon' => 'markup'), - 'html' => array('type' => 'text/html', 'icon' => 'html', 'groups' => array('web_file')), - 'xhtml' => array('type' => 'application/xhtml+xml', 'icon' => 'html', 'groups' => array('web_file')), - 'htm' => array('type' => 'text/html', 'icon' => 'html', 'groups' => array('web_file')), + 'html' => array('type' => 'text/html', 'icon' => 'markup', 'groups' => array('web_file')), + 'xhtml' => array('type' => 'application/xhtml+xml', 'icon' => 'markup', 'groups' => array('web_file')), + 'htm' => array('type' => 'text/html', 'icon' => 'markup', 'groups' => array('web_file')), 'ico' => array('type' => 'image/vnd.microsoft.icon', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'), 'ics' => array('type' => 'text/calendar', 'icon' => 'text'), @@ -137,11 +137,11 @@ abstract class core_filetypes { 'jmt' => array('type' => 'text/xml', 'icon' => 'markup'), 'jmx' => array('type' => 'text/xml', 'icon' => 'markup'), 'jnlp' => array('type' => 'application/x-java-jnlp-file', 'icon' => 'markup'), - 'jpe' => array('type' => 'image/jpeg', 'icon' => 'jpeg', 'groups' => array('image', 'web_image', 'optimised_image'), + 'jpe' => array('type' => 'image/jpeg', 'icon' => 'image', 'groups' => array('image', 'web_image', 'optimised_image'), 'string' => 'image'), - 'jpeg' => array('type' => 'image/jpeg', 'icon' => 'jpeg', 'groups' => array('image', 'web_image', 'optimised_image'), + 'jpeg' => array('type' => 'image/jpeg', 'icon' => 'image', 'groups' => array('image', 'web_image', 'optimised_image'), 'string' => 'image'), - 'jpg' => array('type' => 'image/jpeg', 'icon' => 'jpeg', 'groups' => array('image', 'web_image', 'optimised_image'), + 'jpg' => array('type' => 'image/jpeg', 'icon' => 'image', 'groups' => array('image', 'web_image', 'optimised_image'), 'string' => 'image'), 'jqz' => array('type' => 'text/xml', 'icon' => 'markup'), 'js' => array('type' => 'application/x-javascript', 'icon' => 'text', 'groups' => array('web_file')), @@ -149,30 +149,30 @@ abstract class core_filetypes { 'latex' => array('type' => 'application/x-latex', 'icon' => 'text'), 'm' => array('type' => 'text/plain', 'icon' => 'sourcecode'), 'mbz' => array('type' => 'application/vnd.moodle.backup', 'icon' => 'moodle'), - 'mdb' => array('type' => 'application/x-msaccess', 'icon' => 'base'), + 'mdb' => array('type' => 'application/x-msaccess', 'icon' => 'database'), 'mht' => array('type' => 'message/rfc822', 'icon' => 'archive'), 'mhtml' => array('type' => 'message/rfc822', 'icon' => 'archive'), - 'mov' => array('type' => 'video/quicktime', 'icon' => 'quicktime', + 'mov' => array('type' => 'video/quicktime', 'icon' => 'video', 'groups' => array('video', 'web_video', 'html_video'), 'string' => 'video'), - 'movie' => array('type' => 'video/x-sgi-movie', 'icon' => 'quicktime', 'groups' => array('video'), 'string' => 'video'), + 'movie' => array('type' => 'video/x-sgi-movie', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'), 'mw' => array('type' => 'application/maple', 'icon' => 'math'), 'mws' => array('type' => 'application/maple', 'icon' => 'math'), - 'm3u' => array('type' => 'audio/x-mpegurl', 'icon' => 'mp3', 'groups' => array('audio'), 'string' => 'audio'), - 'm3u8' => array('type' => 'application/x-mpegURL', 'icon' => 'mpeg', 'groups' => array('media_source')), - 'mp3' => array('type' => 'audio/mp3', 'icon' => 'mp3', 'groups' => array('audio', 'html_audio', 'web_audio'), + 'm3u' => array('type' => 'audio/x-mpegurl', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'), + 'm3u8' => array('type' => 'application/x-mpegURL', 'icon' => 'video', 'groups' => array('media_source')), + 'mp3' => array('type' => 'audio/mp3', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'), 'string' => 'audio'), - 'mp4' => array('type' => 'video/mp4', 'icon' => 'mpeg', 'groups' => array('html_video', 'video', 'web_video'), + 'mp4' => array('type' => 'video/mp4', 'icon' => 'video', 'groups' => array('html_video', 'video', 'web_video'), 'string' => 'video'), - 'm4v' => array('type' => 'video/mp4', 'icon' => 'mpeg', 'groups' => array('html_video', 'video', 'web_video'), + 'm4v' => array('type' => 'video/mp4', 'icon' => 'video', 'groups' => array('html_video', 'video', 'web_video'), 'string' => 'video'), - 'm4a' => array('type' => 'audio/mp4', 'icon' => 'mp3', 'groups' => array('audio', 'html_audio', 'web_audio'), + 'm4a' => array('type' => 'audio/mp4', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'), 'string' => 'audio'), - 'mpeg' => array('type' => 'video/mpeg', 'icon' => 'mpeg', 'groups' => array('video', 'web_video'), + 'mpeg' => array('type' => 'video/mpeg', 'icon' => 'video', 'groups' => array('video', 'web_video'), 'string' => 'video'), - 'mpd' => array('type' => 'application/dash+xml', 'icon' => 'mpeg', 'groups' => array('media_source')), - 'mpe' => array('type' => 'video/mpeg', 'icon' => 'mpeg', 'groups' => array('video', 'web_video'), + 'mpd' => array('type' => 'application/dash+xml', 'icon' => 'video', 'groups' => array('media_source')), + 'mpe' => array('type' => 'video/mpeg', 'icon' => 'video', 'groups' => array('video', 'web_video'), 'string' => 'video'), - 'mpg' => array('type' => 'video/mpeg', 'icon' => 'mpeg', 'groups' => array('video', 'web_video'), + 'mpg' => array('type' => 'video/mpeg', 'icon' => 'video', 'groups' => array('video', 'web_video'), 'string' => 'video'), 'mpr' => array('type' => 'application/vnd.moodle.profiling', 'icon' => 'moodle'), @@ -196,7 +196,7 @@ abstract class core_filetypes { 'icon' => 'calc', 'groups' => array('spreadsheet')), 'odc' => array('type' => 'application/vnd.oasis.opendocument.chart', 'icon' => 'chart'), 'odf' => array('type' => 'application/vnd.oasis.opendocument.formula', 'icon' => 'math'), - 'odb' => array('type' => 'application/vnd.oasis.opendocument.database', 'icon' => 'base'), + 'odb' => array('type' => 'application/vnd.oasis.opendocument.database', 'icon' => 'database'), 'odi' => array('type' => 'application/vnd.oasis.opendocument.image', 'icon' => 'draw'), 'oga' => array('type' => 'audio/ogg', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'), 'string' => 'audio'), @@ -210,7 +210,7 @@ abstract class core_filetypes { 'php' => array('type' => 'text/plain', 'icon' => 'sourcecode'), 'pic' => array('type' => 'image/pict', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'), 'pict' => array('type' => 'image/pict', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'), - 'png' => array('type' => 'image/png', 'icon' => 'png', 'groups' => array('image', 'web_image', 'optimised_image'), + 'png' => array('type' => 'image/png', 'icon' => 'image', 'groups' => array('image', 'web_image', 'optimised_image'), 'string' => 'image'), 'pps' => array('type' => 'application/vnd.ms-powerpoint', 'icon' => 'powerpoint', 'groups' => array('presentation')), 'ppt' => array('type' => 'application/vnd.ms-powerpoint', 'icon' => 'powerpoint', 'groups' => array('presentation')), @@ -231,7 +231,7 @@ abstract class core_filetypes { 'ps' => array('type' => 'application/postscript', 'icon' => 'pdf'), 'pub' => array('type' => 'application/x-mspublisher', 'icon' => 'publisher', 'groups' => array('presentation')), - 'qt' => array('type' => 'video/quicktime', 'icon' => 'quicktime', + 'qt' => array('type' => 'video/quicktime', 'icon' => 'video', 'groups' => array('video', 'web_video'), 'string' => 'video'), 'ra' => array('type' => 'audio/x-realaudio-plugin', 'icon' => 'audio', 'groups' => array('audio', 'web_audio'), 'string' => 'audio'), @@ -276,22 +276,22 @@ abstract class core_filetypes { 'sxm' => array('type' => 'application/vnd.sun.xml.math', 'icon' => 'math'), 'tar' => array('type' => 'application/x-tar', 'icon' => 'archive', 'groups' => array('archive'), 'string' => 'archive'), - 'tif' => array('type' => 'image/tiff', 'icon' => 'tiff', 'groups' => array('image'), 'string' => 'image'), - 'tiff' => array('type' => 'image/tiff', 'icon' => 'tiff', 'groups' => array('image'), 'string' => 'image'), + 'tif' => array('type' => 'image/tiff', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'), + 'tiff' => array('type' => 'image/tiff', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'), 'tex' => array('type' => 'application/x-tex', 'icon' => 'text'), 'texi' => array('type' => 'application/x-texinfo', 'icon' => 'text'), 'texinfo' => array('type' => 'application/x-texinfo', 'icon' => 'text'), - 'ts' => array('type' => 'video/MP2T', 'icon' => 'mpeg', 'groups' => array('video', 'web_video'), + 'ts' => array('type' => 'video/MP2T', 'icon' => 'video', 'groups' => array('video', 'web_video'), 'string' => 'video'), 'tsv' => array('type' => 'text/tab-separated-values', 'icon' => 'text'), 'txt' => array('type' => 'text/plain', 'icon' => 'text', 'defaulticon' => true), 'vtt' => array('type' => 'text/vtt', 'icon' => 'text', 'groups' => array('html_track')), - 'wav' => array('type' => 'audio/wav', 'icon' => 'wav', 'groups' => array('audio', 'html_audio', 'web_audio'), + 'wav' => array('type' => 'audio/wav', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'), 'string' => 'audio'), 'webm' => array('type' => 'video/webm', 'icon' => 'video', 'groups' => array('html_video', 'video', 'web_video'), 'string' => 'video'), - 'wmv' => array('type' => 'video/x-ms-wmv', 'icon' => 'wmv', 'groups' => array('video'), 'string' => 'video'), - 'asf' => array('type' => 'video/x-ms-asf', 'icon' => 'wmv', 'groups' => array('video'), 'string' => 'video'), + 'wmv' => array('type' => 'video/x-ms-wmv', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'), + 'asf' => array('type' => 'video/x-ms-asf', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'), 'wma' => array('type' => 'audio/x-ms-wma', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'), 'xbk' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'), diff --git a/lib/classes/oauth2/discovery/imsbadgeconnect.php b/lib/classes/oauth2/discovery/imsbadgeconnect.php index 0c8489b9ec9..27788408bc7 100644 --- a/lib/classes/oauth2/discovery/imsbadgeconnect.php +++ b/lib/classes/oauth2/discovery/imsbadgeconnect.php @@ -134,7 +134,7 @@ class imsbadgeconnect extends base_definition { $request = [ 'client_name' => $SITE->fullname, 'client_uri' => $hosturl, - 'logo_uri' => $hosturl . 'pix/f/moodle-256.png', + 'logo_uri' => $hosturl . 'pix/moodlelogo.png', 'tos_uri' => $hosturl, 'policy_uri' => $hosturl, 'software_id' => 'moodle', diff --git a/lib/classes/oauth2/service/moodlenet.php b/lib/classes/oauth2/service/moodlenet.php index 24921a36b3e..4ceee2de547 100644 --- a/lib/classes/oauth2/service/moodlenet.php +++ b/lib/classes/oauth2/service/moodlenet.php @@ -135,7 +135,7 @@ class moodlenet implements issuer_interface { $request = [ 'client_name' => $SITE->fullname, 'client_uri' => $hosturl, - 'logo_uri' => $hosturl . '/pix/f/moodle-256.png', + 'logo_uri' => $hosturl . '/pix/moodlelogo.png', 'tos_uri' => $hosturl, 'policy_uri' => $hosturl, 'software_id' => 'moodle', diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index b09d8c85aa2..ffc4baecee5 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3383,5 +3383,93 @@ privatefiles,moodle|/user/files.php'; upgrade_main_savepoint(true, 2023081800.01); } + if ($oldversion < 2023082200.01) { + // Some MIME icons have been removed and replaced with existing icons. They need to be upgraded for custom MIME types. + $replacedicons = [ + 'avi' => 'video', + 'base' => 'database', + 'bmp' => 'image', + 'html' => 'markup', + 'jpeg' => 'image', + 'mov' => 'video', + 'mp3' => 'audio', + 'mpeg' => 'video', + 'png' => 'image', + 'quicktime' => 'video', + 'tiff' => 'image', + 'wav' => 'audio', + 'wmv' => 'video', + ]; + + $custom = []; + if (!empty($CFG->customfiletypes)) { + if (array_key_exists('customfiletypes', $CFG->config_php_settings)) { + // It's set in config.php, so the MIME icons can't be upgraded automatically. + echo("\nYou need to manually check customfiletypes in config.php because some MIME icons have been removed!\n"); + } else { + // It's a JSON string in the config table. + $custom = json_decode($CFG->customfiletypes); + } + } + + $changed = false; + foreach ($custom as $customentry) { + if (!empty($customentry->icon) && array_key_exists($customentry->icon, $replacedicons)) { + $customentry->icon = $replacedicons[$customentry->icon]; + $changed = true; + } + } + + if ($changed) { + // Save the new customfiletypes. + set_config('customfiletypes', json_encode($custom)); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2023082200.01); + } + + if ($oldversion < 2023082200.02) { + // Some MIME icons have been removed. They need to be replaced to 'unknown' for custom MIME types. + $removedicons = array_flip([ + 'clip-353', + 'edit', + 'env', + 'explore', + 'folder-open', + 'help', + 'move', + 'parent', + ]); + + $custom = []; + if (!empty($CFG->customfiletypes)) { + if (array_key_exists('customfiletypes', $CFG->config_php_settings)) { + // It's set in config.php, so the MIME icons can't be upgraded automatically. + echo("\nYou need to manually check customfiletypes in config.php because some MIME icons have been removed!\n"); + } else { + // It's a JSON string in the config table. + $custom = json_decode($CFG->customfiletypes); + } + } + + $changed = false; + foreach ($custom as $customentry) { + if (!empty($customentry->icon) && array_key_exists($customentry->icon, $removedicons)) { + // The icon has been removed, so set it to unknown. + $customentry->icon = 'unknown'; + $changed = true; + } + } + + if ($changed) { + // Save the new customfiletypes. + set_config('customfiletypes', json_encode($custom)); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2023082200.02); + } + return true; } diff --git a/lib/filelib.php b/lib/filelib.php index 7c50999b30e..c112f9ae343 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -798,11 +798,11 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') { if ($file->is_directory()) { $item->filesize = 0; - $item->icon = $OUTPUT->image_url(file_folder_icon(24))->out(false); + $item->icon = $OUTPUT->image_url(file_folder_icon())->out(false); $item->type = 'folder'; $foldername = explode('/', trim($item->filepath, '/')); $item->fullname = trim(array_pop($foldername), '/'); - $item->thumbnail = $OUTPUT->image_url(file_folder_icon(90))->out(false); + $item->thumbnail = $OUTPUT->image_url(file_folder_icon())->out(false); } else { // do NOT use file browser here! $item->mimetype = get_mimetype_description($file); @@ -813,8 +813,8 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') { } $itemurl = moodle_url::make_draftfile_url($draftitemid, $item->filepath, $item->filename); $item->url = $itemurl->out(); - $item->icon = $OUTPUT->image_url(file_file_icon($file, 24))->out(false); - $item->thumbnail = $OUTPUT->image_url(file_file_icon($file, 90))->out(false); + $item->icon = $OUTPUT->image_url(file_file_icon($file))->out(false); + $item->thumbnail = $OUTPUT->image_url(file_file_icon($file))->out(false); // The call to $file->get_imageinfo() fails with an exception if the file can't be read on the file system. // We still want to add such files to the list, so the owner can view and delete them if needed. So, we only call @@ -1811,7 +1811,7 @@ function mimeinfo($element, $filename) { * the other way around. * * @category files - * @param string $element Desired information ('extension', 'icon', 'icon-24', etc.) + * @param string $element Desired information ('extension', 'icon', etc.) * @param string $mimetype MIME type we're looking up * @return string Requested piece of information from array */ @@ -1860,10 +1860,14 @@ function mimeinfo_from_type($element, $mimetype) { * * @param stored_file|file_info|stdClass|array $file (in case of object attributes $file->filename * and $file->mimetype are expected) - * @param int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256 + * @param null $unused This parameter has been deprecated since 4.3 and should not be used anymore. * @return string */ -function file_file_icon($file, $size = null) { +function file_file_icon($file, $unused = null) { + if ($unused !== null) { + debugging('Deprecated argument passed to ' . __FUNCTION__, DEBUG_DEVELOPER); + } + if (!is_object($file)) { $file = (object)$file; } @@ -1888,14 +1892,14 @@ function file_file_icon($file, $size = null) { $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if ($extension && !empty($mimetypes[$extension])) { // if file name has known extension, return icon for this extension - return file_extension_icon($filename, $size); + return file_extension_icon($filename); } } - return file_mimetype_icon($mimetype, $size); + return file_mimetype_icon($mimetype); } /** - * Return the relative icon path for a folder image + * Return the relative icon path for a folder image. * * Usage: * @@ -1904,28 +1908,20 @@ function file_file_icon($file, $size = null) { * * or * - * echo $OUTPUT->pix_icon(file_folder_icon(32), ''); + * echo $OUTPUT->pix_icon(file_folder_icon(), ''); * * - * @param int $iconsize The size of the icon. Defaults to 16 can also be 24, 32, 48, 64, 72, 80, 96, 128, 256 + * @param null $unused This parameter has been deprecated since 4.3 and should not be used anymore. * @return string */ -function file_folder_icon($iconsize = null) { +function file_folder_icon($unused = null) { global $CFG; - static $iconpostfixes = array(256=>'-256', 128=>'-128', 96=>'-96', 80=>'-80', 72=>'-72', 64=>'-64', 48=>'-48', 32=>'-32', 24=>'-24', 16=>''); - static $cached = array(); - $iconsize = max(array(16, (int)$iconsize)); - if (!array_key_exists($iconsize, $cached)) { - foreach ($iconpostfixes as $size => $postfix) { - $fullname = $CFG->dirroot.'/pix/f/folder'.$postfix; - if ($iconsize >= $size && - (file_exists($fullname.'.svg') || file_exists($fullname.'.png') || file_exists($fullname.'.gif'))) { - $cached[$iconsize] = 'f/folder'.$postfix; - break; - } - } + + if ($unused !== null) { + debugging('Deprecated argument passed to ' . __FUNCTION__, DEBUG_DEVELOPER); } - return $cached[$iconsize]; + + return 'f/folder'; } /** @@ -1944,11 +1940,11 @@ function file_folder_icon($iconsize = null) { * @todo MDL-31074 When an $OUTPUT->icon method is available this function should be altered * to conform with that. * @param string $mimetype The mimetype to fetch an icon for - * @param int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256 + * @param null $unused This parameter has been deprecated since 4.3 and should not be used anymore. * @return string The relative path to the icon */ -function file_mimetype_icon($mimetype, $size = NULL) { - return 'f/'.mimeinfo_from_type('icon'.$size, $mimetype); +function file_mimetype_icon($mimetype, $unused = null) { + return 'f/'.mimeinfo_from_type('icon', $mimetype); } /** @@ -1968,11 +1964,14 @@ function file_mimetype_icon($mimetype, $size = NULL) { * @todo MDL-31074 Implement $size * @category files * @param string $filename The filename to get the icon for - * @param int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256 + * @param null $unused This parameter has been deprecated since 4.3 and should not be used anymore. * @return string */ -function file_extension_icon($filename, $size = NULL) { - return 'f/'.mimeinfo('icon'.$size, $filename); +function file_extension_icon($filename, $unused = null) { + if ($unused !== null) { + debugging('Deprecated argument passed to ' . __FUNCTION__, DEBUG_DEVELOPER); + } + return 'f/'.mimeinfo('icon', $filename); } /** @@ -2675,14 +2674,14 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring * Note: it's up to the consumer to set it properly i.e. when serving a "versioned" URL. * * @category files - * @param stored_file $stored_file local file object + * @param stored_file $storedfile local file object * @param int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime) * @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin * @param array $options additional options affecting the file serving * @return null script execution stopped unless $options['dontdie'] is true */ -function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownload=false, array $options=array()) { +function send_stored_file($storedfile, $lifetime=null, $filter=0, $forcedownload=false, array $options=array()) { global $CFG, $COURSE; static $recursion = 0; @@ -2706,22 +2705,15 @@ function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownloa if (!empty($options['preview'])) { // replace the file with its preview $fs = get_file_storage(); - $preview_file = $fs->get_file_preview($stored_file, $options['preview']); - if (!$preview_file) { - // unable to create a preview of the file, send its default mime icon instead - if ($options['preview'] === 'tinyicon') { - $size = 24; - } else if ($options['preview'] === 'thumb') { - $size = 90; - } else { - $size = 256; - } - $fileicon = file_file_icon($stored_file, $size); - send_file($CFG->dirroot.'/pix/'.$fileicon.'.png', basename($fileicon).'.png'); + $previewfile = $fs->get_file_preview($storedfile, $options['preview']); + if (!$previewfile) { + // Unable to create a preview of the file, send its default mime icon instead. + $fileicon = file_file_icon($storedfile); + send_file($CFG->dirroot.'/pix/'.$fileicon.'.svg', basename($fileicon).'.svg'); } else { // preview images have fixed cache lifetime and they ignore forced download // (they are generated by GD and therefore they are considered reasonably safe). - $stored_file = $preview_file; + $storedfile = $previewfile; $lifetime = DAYSECS; $filter = 0; $forcedownload = false; @@ -2729,7 +2721,7 @@ function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownloa } // handle external resource - if ($stored_file && $stored_file->is_external_file() && !isset($options['sendcachedexternalfile'])) { + if ($storedfile && $storedfile->is_external_file() && !isset($options['sendcachedexternalfile'])) { // Have we been here before? $recursion++; @@ -2737,22 +2729,22 @@ function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownloa throw new coding_exception('Recursive file serving detected'); } - $stored_file->send_file($lifetime, $filter, $forcedownload, $options); + $storedfile->send_file($lifetime, $filter, $forcedownload, $options); die; } - if (!$stored_file or $stored_file->is_directory()) { - // nothing to serve + if (!$storedfile || $storedfile->is_directory()) { + // Nothing to serve. if ($dontdie) { return; } die; } - $filename = is_null($filename) ? $stored_file->get_filename() : $filename; + $filename = is_null($filename) ? $storedfile->get_filename() : $filename; // Use given MIME type if specified. - $mimetype = $stored_file->get_mimetype(); + $mimetype = $storedfile->get_mimetype(); // Allow cross-origin requests only for Web Services. // This allow to receive requests done by Web Workers or webapps in different domains. @@ -2760,7 +2752,7 @@ function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownloa header('Access-Control-Allow-Origin: *'); } - send_file($stored_file, $filename, $lifetime, $filter, false, $forcedownload, $mimetype, $dontdie, $options); + send_file($storedfile, $filename, $lifetime, $filter, false, $forcedownload, $mimetype, $dontdie, $options); } /** diff --git a/lib/googleapi.php b/lib/googleapi.php index 9d03ccf6a21..b6b04725830 100644 --- a/lib/googleapi.php +++ b/lib/googleapi.php @@ -131,7 +131,7 @@ class google_docs { 'url' => "{$gdoc->link[0]->attributes()->href}", 'source' => $source, 'date' => strtotime($gdoc->updated), - 'thumbnail' => (string) $OUTPUT->image_url(file_extension_icon($title, 32)) + 'thumbnail' => (string) $OUTPUT->image_url(file_extension_icon($title)) ); } core_date::set_default_server_timezone(); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index d1c97007233..5c9457d84eb 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -87,6 +87,38 @@ information provided here is intended especially for developers. to ensure in some test that the block drawer is closed. This helps with random failures due to the block drawer being forced open in all behat tests. * The core_useragent::get_device_type_list() function has been deprecated. Use core_useragent::devicetypes instead as a replacement. +* The parameter $size of the following functions has been deprecated and is not used any more: + - file_extension_icon + - file_file_icon + - file_folder_icon + - file_mimetype_icon + - mimeinfo_from_type + - url_guess_icon +* The xxxxxxx-yyy.png MIME icons placed in pix/f have been removed and replaced with new SVG files. + In order to reduce the number of icons for the MIME types, a few MIME icons have been removed and + replaced with their generic from the existing ones: + - avi -> video + - base -> database + - bmp -> image + - html -> markup + - jpeg -> image + - mov -> video + - mp3 -> audio + - mpeg -> video + - png -> image + - quicktime -> video + - tiff -> image + - wav -> audio + - wmv -> video + Apart from that, the following MIME icons have been completely removed: + - clip-353 --> It was added in MDL-75362 by mistake. + - edit + - env + - explore + - folder-open + - help + - move + - parent === 4.2 === diff --git a/mod/bigbluebuttonbn/classes/local/helpers/files.php b/mod/bigbluebuttonbn/classes/local/helpers/files.php index d223f2c64dd..dddce8d1b52 100644 --- a/mod/bigbluebuttonbn/classes/local/helpers/files.php +++ b/mod/bigbluebuttonbn/classes/local/helpers/files.php @@ -205,7 +205,7 @@ class files { ); return [ 'icondesc' => get_mimetype_description($file), - 'iconname' => file_file_icon($file, 24), + 'iconname' => file_file_icon($file), 'name' => $file->get_filename(), 'url' => $url->out(false), ]; diff --git a/mod/book/tool/importhtml/locallib.php b/mod/book/tool/importhtml/locallib.php index 5af6f4acadb..3f6714258f7 100644 --- a/mod/book/tool/importhtml/locallib.php +++ b/mod/book/tool/importhtml/locallib.php @@ -282,7 +282,7 @@ function toolbook_importhtml_get_chapter_files($package, $type) { } else { $mime = mimeinfo('icon', $file->pathname); - if ($mime !== 'html') { + if ($mime !== 'markup') { continue; } $level = substr_count($file->pathname, '/'); diff --git a/mod/folder/lib.php b/mod/folder/lib.php index 2534d0393c1..6e618485609 100644 --- a/mod/folder/lib.php +++ b/mod/folder/lib.php @@ -625,7 +625,7 @@ function folder_get_recent_mod_activity(&$activities, &$index, $timestart, $cour $image = $url->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified())); $image = html_writer::empty_tag('img', array('src' => $image)); } else { - $image = $OUTPUT->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle'); + $image = $OUTPUT->pix_icon(file_file_icon($file), $file->get_filename(), 'moodle'); } $tmpactivity->content = (object) [ diff --git a/mod/folder/renderer.php b/mod/folder/renderer.php index d9a2bc5fd52..e6153bf8169 100644 --- a/mod/folder/renderer.php +++ b/mod/folder/renderer.php @@ -121,7 +121,7 @@ class mod_folder_renderer extends plugin_renderer_base { } $result = '