From d77b5db55f2430cee7288eddd186ebb4500e16c7 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Wed, 18 Jul 2018 16:38:24 +0800 Subject: [PATCH] MDL-56712 media: Remove 3.2 deprecated functions and classes --- lib/medialib.php | 152 ------------------------------------ lib/outputrenderers.php | 127 ------------------------------ lib/tests/medialib_test.php | 18 ++--- lib/upgrade.txt | 6 +- lib/upgradelib.php | 1 + media/classes/player.php | 22 +----- media/upgrade.txt | 6 ++ 7 files changed, 23 insertions(+), 309 deletions(-) delete mode 100644 lib/medialib.php diff --git a/lib/medialib.php b/lib/medialib.php deleted file mode 100644 index 3c51122c76515..0000000000000 --- a/lib/medialib.php +++ /dev/null @@ -1,152 +0,0 @@ -. - -/** - * Deprecated classes and constants. - * - * DO NOT INCLUDE THIS FILE - * - * use $CFG->media_default_width instead of CORE_MEDIA_VIDEO_WIDTH, - * $CFG->media_default_height instead of CORE_MEDIA_VIDEO_HEIGHT, - * core_media_manager::instance() instead of static methods in core_media, - * core_media_manager::OPTION_zzz instead of core_media::OPTION_zzz - * - * New syntax to include media files: - * - * $mediamanager = core_media_manager::instance(); - * echo $mediamanager->embed_url(new moodle_url('http://example.org/a.mp3')); - * - * @package core_media - * @copyright 2012 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -if (!defined('CORE_MEDIA_VIDEO_WIDTH')) { - // Default video width if no width is specified; some players may do something - // more intelligent such as use real video width. - // May be defined in config.php if required. - define('CORE_MEDIA_VIDEO_WIDTH', 400); -} -if (!defined('CORE_MEDIA_VIDEO_HEIGHT')) { - // Default video height. May be defined in config.php if required. - define('CORE_MEDIA_VIDEO_HEIGHT', 300); -} -if (!defined('CORE_MEDIA_AUDIO_WIDTH')) { - // Default audio width if no width is specified. - // May be defined in config.php if required. - define('CORE_MEDIA_AUDIO_WIDTH', 300); -} - -debugging('Do not include lib/medialib.php, use $CFG->media_default_width instead of CORE_MEDIA_VIDEO_WIDTH, ' . - '$CFG->media_default_height instead of CORE_MEDIA_VIDEO_HEIGHT, ' . - 'core_media_manager::instance() instead of static methods in core_media, ' . - 'core_media_manager::OPTION_zzz instead of core_media::OPTION_zzz', - DEBUG_DEVELOPER); - -/** - * Constants and static utility functions for use with core_media_renderer. - * - * @deprecated since Moodle 3.2 - * - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -abstract class core_media { - /** - * Option: Disable text link fallback. - * - * Use this option if you are going to print a visible link anyway so it is - * pointless to have one as fallback. - * - * To enable, set value to true. - */ - const OPTION_NO_LINK = 'nolink'; - - /** - * Option: When embedding, if there is no matching embed, do not use the - * default link fallback player; instead return blank. - * - * This is different from OPTION_NO_LINK because this option still uses the - * fallback link if there is some kind of embedding. Use this option if you - * are going to check if the return value is blank and handle it specially. - * - * To enable, set value to true. - */ - const OPTION_FALLBACK_TO_BLANK = 'embedorblank'; - - /** - * Option: Enable players which are only suitable for use when we trust the - * user who embedded the content. - * - * At present, this option enables the SWF player. - * - * To enable, set value to true. - */ - const OPTION_TRUSTED = 'trusted'; - - /** - * Option: Put a div around the output (if not blank) so that it displays - * as a block using the 'resourcecontent' CSS class. - * - * To enable, set value to true. - */ - const OPTION_BLOCK = 'block'; - - /** - * Given a string containing multiple URLs separated by #, this will split - * it into an array of moodle_url objects suitable for using when calling - * embed_alternatives. - * - * Note that the input string should NOT be html-escaped (i.e. if it comes - * from html, call html_entity_decode first). - * - * @param string $combinedurl String of 1 or more alternatives separated by # - * @param int $width Output variable: width (will be set to 0 if not specified) - * @param int $height Output variable: height (0 if not specified) - * @return array Array of 1 or more moodle_url objects - */ - public static function split_alternatives($combinedurl, &$width, &$height) { - return core_media_manager::instance()->split_alternatives($combinedurl, $width, $height); - } - - /** - * Returns the file extension for a URL. - * @param moodle_url $url URL - */ - public static function get_extension(moodle_url $url) { - return core_media_manager::instance()->get_extension($url); - } - - /** - * Obtains the filename from the moodle_url. - * @param moodle_url $url URL - * @return string Filename only (not escaped) - */ - public static function get_filename(moodle_url $url) { - return core_media_manager::instance()->get_filename($url); - } - - /** - * Guesses MIME type for a moodle_url based on file extension. - * @param moodle_url $url URL - * @return string MIME type - */ - public static function get_mimetype(moodle_url $url) { - return core_media_manager::instance()->get_mimetype($url); - } -} diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 1223ef64a8d1e..9fbbaa0f478d0 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -4739,133 +4739,6 @@ public function heading($text, $level = 2, $classes = 'main', $id = null) {} } -/** - * Renderer for media files. - * - * Used in file resources, media filter, and any other places that need to - * output embedded media. - * - * @deprecated since Moodle 3.2 - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class core_media_renderer extends plugin_renderer_base { - /** @var array Array of available 'player' objects */ - private $players; - /** @var string Regex pattern for links which may contain embeddable content */ - private $embeddablemarkers; - - /** - * Constructor - * - * This is needed in the constructor (not later) so that you can use the - * constants and static functions that are defined in core_media class - * before you call renderer functions. - */ - public function __construct() { - debugging('Class core_media_renderer is deprecated, please use core_media_manager::instance()', DEBUG_DEVELOPER); - } - - /** - * Renders a media file (audio or video) using suitable embedded player. - * - * See embed_alternatives function for full description of parameters. - * This function calls through to that one. - * - * When using this function you can also specify width and height in the - * URL by including ?d=100x100 at the end. If specified in the URL, this - * will override the $width and $height parameters. - * - * @param moodle_url $url Full URL of media file - * @param string $name Optional user-readable name to display in download link - * @param int $width Width in pixels (optional) - * @param int $height Height in pixels (optional) - * @param array $options Array of key/value pairs - * @return string HTML content of embed - */ - public function embed_url(moodle_url $url, $name = '', $width = 0, $height = 0, - $options = array()) { - return core_media_manager::instance()->embed_url($url, $name, $width, $height, $options); - } - - /** - * Renders media files (audio or video) using suitable embedded player. - * The list of URLs should be alternative versions of the same content in - * multiple formats. If there is only one format it should have a single - * entry. - * - * If the media files are not in a supported format, this will give students - * a download link to each format. The download link uses the filename - * unless you supply the optional name parameter. - * - * Width and height are optional. If specified, these are suggested sizes - * and should be the exact values supplied by the user, if they come from - * user input. These will be treated as relating to the size of the video - * content, not including any player control bar. - * - * For audio files, height will be ignored. For video files, a few formats - * work if you specify only width, but in general if you specify width - * you must specify height as well. - * - * The $options array is passed through to the core_media_player classes - * that render the object tag. The keys can contain values from - * core_media::OPTION_xx. - * - * @param array $alternatives Array of moodle_url to media files - * @param string $name Optional user-readable name to display in download link - * @param int $width Width in pixels (optional) - * @param int $height Height in pixels (optional) - * @param array $options Array of key/value pairs - * @return string HTML content of embed - */ - public function embed_alternatives($alternatives, $name = '', $width = 0, $height = 0, - $options = array()) { - return core_media_manager::instance()->embed_alternatives($alternatives, $name, $width, $height, $options); - } - - /** - * Checks whether a file can be embedded. If this returns true you will get - * an embedded player; if this returns false, you will just get a download - * link. - * - * This is a wrapper for can_embed_urls. - * - * @param moodle_url $url URL of media file - * @param array $options Options (same as when embedding) - * @return bool True if file can be embedded - */ - public function can_embed_url(moodle_url $url, $options = array()) { - return core_media_manager::instance()->can_embed_url($url, $options); - } - - /** - * Checks whether a file can be embedded. If this returns true you will get - * an embedded player; if this returns false, you will just get a download - * link. - * - * @param array $urls URL of media file and any alternatives (moodle_url) - * @param array $options Options (same as when embedding) - * @return bool True if file can be embedded - */ - public function can_embed_urls(array $urls, $options = array()) { - return core_media_manager::instance()->can_embed_urls($urls, $options); - } - - /** - * Obtains a list of markers that can be used in a regular expression when - * searching for URLs that can be embedded by any player type. - * - * This string is used to improve peformance of regex matching by ensuring - * that the (presumably C) regex code can do a quick keyword check on the - * URL part of a link to see if it matches one of these, rather than having - * to go into PHP code for every single link to see if it can be embedded. - * - * @return string String suitable for use in regex such as '(\.mp4|\.flv)' - */ - public function get_embeddable_markers() { - return core_media_manager::instance()->get_embeddable_markers(); - } -} /** * The maintenance renderer. diff --git a/lib/tests/medialib_test.php b/lib/tests/medialib_test.php index 20e5d6d734ef9..194cc1958d507 100644 --- a/lib/tests/medialib_test.php +++ b/lib/tests/medialib_test.php @@ -129,7 +129,7 @@ public function test_list_supported_urls() { } /** - * Test for core_media_renderer get_players + * Test for get_players */ public function test_get_players() { // All players are initially disabled (except link, which you can't). @@ -158,7 +158,7 @@ public function test_get_players() { } /** - * Test for core_media_renderer can_embed_url + * Test for can_embed_url */ public function test_can_embed_url() { // All players are initially disabled, so mp4 cannot be rendered. @@ -188,7 +188,7 @@ public function test_can_embed_url() { } /** - * Test for core_media_renderer embed_url. + * Test for embed_url. * Checks multiple format/fallback support. */ public function test_embed_url_fallbacks() { @@ -264,7 +264,7 @@ public function test_embed_url_fallbacks() { } /** - * Test for core_media_renderer embed_url. + * Test for embed_url. * Check SWF works including the special option required to enable it */ public function test_embed_url_swf() { @@ -302,7 +302,7 @@ public function test_slash_arguments() { } /** - * Test for core_media_renderer embed_url. + * Test for embed_url. * Checks the EMBED_OR_BLANK option. */ public function test_embed_or_blank() { @@ -325,7 +325,7 @@ public function test_embed_or_blank() { } /** - * Test for core_media_renderer embed_url. + * Test for embed_url. * Checks that size is passed through correctly to player objects and tests * size support in html5video output. */ @@ -358,7 +358,7 @@ public function test_embed_url_size() { } /** - * Test for core_media_renderer embed_url. + * Test for embed_url. * Checks that name is passed through correctly to player objects and tests * name support in html5video output. */ @@ -379,7 +379,7 @@ public function test_embed_url_name() { } /** - * Test for core_media_renderer split_alternatives. + * Test for split_alternatives. */ public function test_split_alternatives() { $mediamanager = core_media_manager::instance(); @@ -416,7 +416,7 @@ public function test_split_alternatives() { } /** - * Test for core_media_renderer embed_alternatives (with multiple urls) + * Test for embed_alternatives (with multiple urls) */ public function test_embed_alternatives() { // Most aspects of this are same as single player so let's just try diff --git a/lib/upgrade.txt b/lib/upgrade.txt index f2e8d0b524347..99f7f96f06a7c 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -6,8 +6,10 @@ information provided here is intended especially for developers. * Custom AJAX handlers for the form autocomplete fields can now optionally return string in their processResults() callback. If a string is returned, it is displayed instead of the list if suggested items. This can be used, for example, to inform the user that there are too many items matching the current search criteria. -* The following functions have been finally deprecated and can not be used any more: - - external_function_info() +* The following functions have been finally deprecated and can not be used anymore: + - external_function_info() + - class core_media_renderer + - class core_media * Following api's have been removed in behat_config_manager, please use behat_config_util instead. - get_features_with_tags() - get_components_steps_definitions() diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 8dc6d316569ac..500dbbb806f07 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -431,6 +431,7 @@ function upgrade_stale_php_files_present() { $someexamplesofremovedfiles = array( // Removed in 3.6. + '/lib/medialib.php', '/lib/password_compat/lib/password.php', // Removed in 3.5. '/lib/dml/mssql_native_moodle_database.php', diff --git a/media/classes/player.php b/media/classes/player.php index 7171c05762fe0..407aabd79e91a 100644 --- a/media/classes/player.php +++ b/media/classes/player.php @@ -154,21 +154,10 @@ public function supports($usedextensions = []) { public abstract function get_rank(); /** - * Returns if the current player is enabled. - * * @deprecated since Moodle 3.2 - * @return bool True if player is enabled */ public function is_enabled() { - debugging('Function core_media_player::is_enabled() is deprecated without replacement', DEBUG_DEVELOPER); - - $enabled = \core\plugininfo\media::get_enabled_plugins(); - - if ($enabled && preg_match('/^media_(.*)_plugin$/', get_class($this), $matches)) { - return array_key_exists($matches[1], $enabled); - } - - return false; + throw new coding_exception('core_media_player::is_enabled() can not be used anymore.'); } /** @@ -217,15 +206,10 @@ protected function get_name($name, $urls) { } /** - * Compares by rank order, highest first. Used for sort functions. * @deprecated since Moodle 3.2 - * @param core_media_player $a Player A - * @param core_media_player $b Player B - * @return int Negative if A should go before B, positive for vice versa */ - public static function compare_by_rank(core_media_player $a, core_media_player $b) { - debugging('Function core_media_player::compare_by_rank() is deprecated without replacement', DEBUG_DEVELOPER); - return $b->get_rank() - $a->get_rank(); + public static function compare_by_rank() { + throw new coding_exception('core_media_player::compare_by_rank() can not be used anymore.'); } /** diff --git a/media/upgrade.txt b/media/upgrade.txt index 2deef55c3c5f5..8e1594cf438cd 100644 --- a/media/upgrade.txt +++ b/media/upgrade.txt @@ -1,6 +1,12 @@ This files describes API changes in /media/ plugins, information provided here is intended especially for developers. +=== 3.6 === + +* The following functions have been finally deprecated and can not be used anymore: + * core_media_player::is_enabled() + * core_media_player::compare_by_rank() + === 3.3 === * core_media_manager setup() is now deprecated as it is now called when initialising core_media_manager::instance(). * core_media_manager is now final. Do not extend core_media_manager, instead create a media plugin.