2 * In general, MediaWiki does not ask browsers to resolve wiki page
3 * redirects client-side over HTTP. Instead, wiki page redirects are
4 * resolved server-side and rendered directly in response to a
7 * This script is responsible for:
9 * - Update the address bar to reflect the rendered destination.
11 * Given [[Foo]] redirecting to [[Bar]], when viewing [[Foo]]
12 * the server renders Bar content, with "Bar" as doc title
13 * and with "Bar" in the address bar.
15 * - For internal redirect destination that specify a fragment, if
16 * the navigation does not set its own fragment, scroll to the
19 * Given [[Foo]] redirecting to [[Bar#Foo]], the browser should
20 * scroll to "Foo", and render address bar Bar#Foo (not Foo, Bar,
23 * Given [[Foo]] redirecting to [[Bar#Foo]], when navigating to
24 * [[Foo#Quux]], the address bar should reflect Bar#Quux, and
25 * let the native scroll happen, don't override scroll to #Foo.
30 let canonical = mw.config.get( 'wgInternalRedirectTargetUrl' );
36 if ( location.hash ) {
37 // Ignore redirect's own fragment and preserve fragment override in address
38 canonical = canonical.replace( /#.*$/, '' ) + location.hash;
40 const index = canonical.indexOf( '#' );
41 fragment = ( index !== -1 ) ? canonical.slice( index ) : null;
44 // Update address bar, including browser history.
45 // Preserve correct "Back"-button behaviour by using replaceState instead of
46 // pushState (or location.hash assignment)
47 history.replaceState( history.state, '', canonical );
50 // Specification for history.replaceState() doesn't require browser to scroll,
51 // so scroll to be sure (see also T110501).
52 const node = document.getElementById( fragment.slice( 1 ) );
54 node.scrollIntoView();