From: umherirrender Date: Tue, 17 Dec 2013 18:41:33 +0000 (+0100) Subject: Migrate redirectToFragment() from wikibits.js to own module X-Git-Tag: 1.31.0-rc.0~17348^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=7bca293dfd66cc6eca919d5d3d98940388745c1b;p=lhc%2Fweb%2Fwiklou.git Migrate redirectToFragment() from wikibits.js to own module This patch creates the new top module 'mediawiki.action.view.redirectToFragment'. This module contains the same code, but was migrated to use jQuery.profile to detect the layout of the browser. Other changes as written on bug 35858 can be done in seperate patch set(s). This is to have a start. The old code has to stay a version, because the cache can contain inline script calls to this function, which should not break. Bug: 35858 Change-Id: Ic10c060c3a2cbab455348e57740fc8abdc66ff9a --- diff --git a/includes/Article.php b/includes/Article.php index 821c32ea69..e7a1188ba4 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -989,9 +989,8 @@ class Article implements Page { // Set the fragment if one was specified in the redirect if ( strval( $this->getTitle()->getFragment() ) != '' ) { - $outputPage->addInlineScript( Xml::encodeJsCall( - 'redirectToFragment', array( $this->getTitle()->getFragmentForURL() ) - ) ); + $outputPage->addJsConfigVars( 'wgRedirectToFragment', $this->getTitle()->getFragmentForURL() ); + $outputPage->addModules( 'mediawiki.action.view.redirectToFragment' ); } // Add a tag diff --git a/resources/Resources.php b/resources/Resources.php index d2a06b782e..b389fefc7d 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -835,6 +835,13 @@ return array( 'postedit-confirmation', ), ), + 'mediawiki.action.view.redirectToFragment' => array( + 'scripts' => 'resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js', + 'dependencies' => array( + 'jquery.client', + ), + 'position' => 'top', + ), 'mediawiki.action.view.rightClickEdit' => array( 'scripts' => 'resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js', ), diff --git a/resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js b/resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js new file mode 100644 index 0000000000..1e2d624a3a --- /dev/null +++ b/resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js @@ -0,0 +1,35 @@ +/** + * JavaScript to scroll the page to an id, when a redirect with fragment is viewed. + */ +( function ( mw, $ ) { + var profile = $.client.profile(), + fragment = mw.config.get( 'wgRedirectToFragment' ); + + if ( fragment === null ) { + // nothing to do + return; + } + + if ( profile.layout === 'webkit' && profile.layoutVersion < 420 ) { + // Released Safari w/ WebKit 418.9.1 messes up horribly + // Nightlies of 420+ are ok + return; + } + if ( !window.location.hash ) { + window.location.hash = fragment; + + // Mozilla needs to wait until after load, otherwise the window doesn't + // scroll. See . + // There's no obvious way to detect this programmatically, so we use + // version-testing. If Firefox fixes the bug, they'll jump twice, but + // better twice than not at all, so make the fix hit future versions as + // well. + if ( profile.layout === 'gecko' ) { + $( function () { + if ( window.location.hash === fragment ) { + window.location.hash = fragment; + } + } ); + } + } +}( mediaWiki, jQuery ) ); diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index d28ca0a3da..35fc9f2e48 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -18,7 +18,14 @@ if ( mw.config.get( 'wgBreakFrames' ) ) { } } -win.redirectToFragment = function ( fragment ) { +/** + * Legacy function to scroll to an id while viewing the page over a redirect. + * Superseeded by module 'mediawiki.action.view.redirectToFragment' in version 1.23. + * Kepted because cache can contain still inline script calls to this function. + * Should be removed in version 1.24. + * @deprecated since 1.23 Use mediawiki.action.view.redirectToFragment instead + */ +mw.log.deprecate( win, 'redirectToFragment', function ( fragment ) { var webKitVersion, match = navigator.userAgent.match( /AppleWebKit\/(\d+)/ ); if ( match ) { @@ -46,7 +53,7 @@ win.redirectToFragment = function ( fragment ) { } ); } } -}; +}, 'Use the module mediawiki.action.view.redirectToFragment instead.' ); /** * User-agent sniffing.