aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--includes/Article.php5
-rw-r--r--resources/Resources.php7
-rw-r--r--resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js35
-rw-r--r--skins/common/wikibits.js11
4 files changed, 53 insertions, 5 deletions
diff --git a/includes/Article.php b/includes/Article.php
index c82b39fe4173..42ed58fbb2d9 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 <link rel="canonical"> tag
diff --git a/resources/Resources.php b/resources/Resources.php
index 4489ddbf4018..01d4a3f13609 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -894,6 +894,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 000000000000..1e2d624a3a1d
--- /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 <https://bugzilla.mozilla.org/show_bug.cgi?id=516293>.
+ // 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 d28ca0a3da05..35fc9f2e482d 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.