Don't load legacy gadget scripts

The time has come to stop supporting legacy gadgets that haven't
migrated to ResourceLoader yet.

For many Gadgets, migrating to ResourceLoader will be as easy
as adding "[ResourceLoader]" to its definition on MediaWiki:Gadgets-definition.

However for older gadgets, they may need more maintenance. Though
similarly they may've already been malfunctioning silently.

The most common techniques used by legacy scripts, and what their
equivalents are in modern JavaScript, see:
<https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_(users)>

Ref T107399.

Change-Id: Ia5f7323a40a28541515ef3a3f5079f1cc940f392
This commit is contained in:
Timo Tijhof 2015-08-06 17:05:29 -07:00 committed by Krinkle
parent ee17259501
commit 29e7a9193d
4 changed files with 25 additions and 41 deletions

View file

@ -20,6 +20,7 @@
*
* @file
*/
use WrappedString\WrappedString;
class GadgetHooks {
/**
@ -172,7 +173,7 @@ class GadgetHooks {
$lb = new LinkBatch();
$lb->setCaller( __METHOD__ );
$pages = array();
$enabledLegacyGadgets = array();
/**
* @var $gadget Gadget
@ -186,56 +187,30 @@ class GadgetHooks {
$out->addModules( $gadget->getModuleName() );
}
foreach ( $gadget->getLegacyScripts() as $page ) {
$lb->add( NS_MEDIAWIKI, $page );
$pages[] = $page;
if ( $gadget->getLegacyScripts() ) {
$enabledLegacyGadgets[] = $id;
}
}
}
// Allow other extensions, e.g. MobileFrontend, to disallow legacy gadgets
if ( Hooks::run( 'Gadgets::allowLegacy', array( $out->getContext() ) ) ) {
$lb->execute();
$done = array();
foreach ( $pages as $page ) {
if ( isset( $done[$page] ) ) {
continue;
}
$done[$page] = true;
self::applyScript( $page, $out );
}
$strings = array();
foreach ( $enabledLegacyGadgets as $id ) {
$strings[] = self::makeLegacyWarning( $id );
}
$out->addHTML( WrappedString::join( "\n", $strings ) );
return true;
}
/**
* Adds one legacy script to output.
*
* @param string $page Unprefixed page title
* @param OutputPage $out
*/
private static function applyScript( $page, $out ) {
global $wgJsMimeType;
private static function makeLegacyWarning( $id ) {
$special = SpecialPage::getTitleFor( 'Gadgets' );
# bug 22929: disable gadgets on sensitive pages. Scripts loaded through the
# ResourceLoader handle this in OutputPage::getModules()
# TODO: make this extension load everything via RL, then we don't need to worry
# about any of this.
if ( $out->getAllowedModules( ResourceLoaderModule::TYPE_SCRIPTS ) < ResourceLoaderModule::ORIGIN_USER_SITEWIDE ) {
return;
}
$t = Title::makeTitleSafe( NS_MEDIAWIKI, $page );
if ( !$t ) {
return;
}
$u = $t->getLocalURL( 'action=raw&ctype=' . $wgJsMimeType );
$out->addScriptFile( $u, $t->getLatestRevID() );
return ResourceLoader::makeInlineScript(
Xml::encodeJsCall( 'mw.log.warn', array(
"Gadget \"$id\" was not loaded. Please migrate it to use ResourceLoader. " .
' See <' . $special->getCanonicalURL() . '>.'
) )
);
}
/**

View file

@ -122,6 +122,13 @@ class SpecialGadgets extends SpecialPage {
$lnk[] = Linker::link( $t, htmlspecialchars( $t->getText() ) );
}
$output->addHTML( $lang->commaList( $lnk ) );
if ( $gadget->getLegacyScripts() ) {
$output->addHTML( '<br />' . Html::rawElement(
'span',
array( 'class' => 'mw-gadget-legacy errorbox' ),
$this->msg( 'gadgets-legacy' )->parse()
) );
}
$rights = array();
foreach ( $gadget->getRequiredRights() as $right ) {

View file

@ -15,6 +15,7 @@
"gadgets-required-rights": "Requires the following {{PLURAL:$2|right|rights}}:\n\n$1",
"gadgets-required-skins": "Available on the {{PLURAL:$2|$1 skin|following skins: $1}}.",
"gadgets-default": "Enabled for everyone by default.",
"gadgets-legacy": "Gadget is not loaded. Please migrate to ResourceLoader. ([https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_(users) Learn more])",
"gadgets-export": "Export",
"gadgets-export-title": "Gadget export",
"gadgets-not-found": "Gadget \"$1\" not found.",

View file

@ -26,6 +26,7 @@
"gadgets-required-rights": "Parameters:\n* $1 - a list in wikitext.\n* $2 - the number of items in list $1 for PLURAL use.",
"gadgets-required-skins": "Parameters:\n* $1 - a comma separated list.\n* $2 - the number of items in list $1 for PLURAL use.",
"gadgets-default": "Used in [[Special:Gadgets]], if the extension is enabled for everyone by the Wiki's default settings.",
"gadgets-legacy": "Used on [[Special:Gadgets]], if the extension contains legacy scripts and doesn't use ResourceLoader yet.",
"gadgets-export": "Used on [[Special:Gadgets]]. This is a verb, not noun.\n{{Identical|Export}}",
"gadgets-export-title": "Used as page title. Example: [[Special:Gadgets/export/editbuttons]]",
"gadgets-not-found": "Used as error message. Parameters:\n* $1 - gadget name",