Merge "Migrate redirectToFragment() from wikibits.js to own module"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 7 Jan 2014 21:16:14 +0000 (21:16 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 7 Jan 2014 21:16:14 +0000 (21:16 +0000)
includes/Article.php
resources/Resources.php
resources/mediawiki.action/mediawiki.action.view.redirectToFragment.js [new file with mode: 0644]
skins/common/wikibits.js

index c82b39f..42ed58f 100644 (file)
@@ -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
index 4489ddb..01d4a3f 100644 (file)
@@ -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 (file)
index 0000000..1e2d624
--- /dev/null
@@ -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 ) );
index d28ca0a..35fc9f2 100644 (file)
@@ -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.