r110826 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110825‎ | r110826 | r110827 >
Date:08:48, 7 February 2012
Author:bawolff
Status:resolved (Comments)
Tags:miscextensions 
Comment:
(bug 33551) - Make ShortUrl work properly with protocol relative urls.
Modified paths:
  • /trunk/extensions/ShortUrl/ShortUrl.php (modified) (history)
  • /trunk/extensions/ShortUrl/js/ext.shortUrl.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ShortUrl/ShortUrl.php
@@ -18,9 +18,11 @@
1919 /**
2020 * Configuration variables
2121 * Prefix to use for the shortened URL. mod_rewrite (or equivalent) needs to be setup
22 - * to produce a shorter URL
 22+ * to produce a shorter URL. See example redirect.htaccess file.
2323 * Default is false which just uses the (not so short) URL that all Special Pages get
2424 * Eg: http://en.wikipedia.org/wiki/Special:ShortUrl/5234
 25+ * An example value for this variable might be:
 26+ * $wgShortUrlPrefix = '//en.wikipedia.org/r/';
2527 */
2628 $wgShortUrlPrefix = false;
2729
@@ -53,5 +55,6 @@
5456 'scripts' => 'js/ext.shortUrl.js',
5557 'styles' => 'css/ext.shortUrl.css',
5658 'localBasePath' => dirname( __FILE__ ),
57 - 'remoteExtPath' => 'ShortUrl'
 59+ 'remoteExtPath' => 'ShortUrl',
 60+ 'dependencies' => array( 'mediawiki.Uri' ),
5861 );
Index: trunk/extensions/ShortUrl/js/ext.shortUrl.js
@@ -1,6 +1,15 @@
22 jQuery( function( $ ) {
33 if( $( '#t-shorturl' ).length ) {
44 var url = $( '#t-shorturl a' ).attr( 'href' );
5 - $( '#firstHeading' ).append( $( '<div class="title-shortlink-container"></div>').append( $( '<a>' ).addClass( 'title-shortlink' ).attr( 'href', url ).text( url ) ) );
 5+ /* Add protocol for proto-relative urls */
 6+ var protoNonRelative = ( new mw.Uri( url ) ).toString();
 7+ $( '#firstHeading' ).append(
 8+ $( '<div class="title-shortlink-container"></div>')
 9+ .append( $( '<a>' )
 10+ .addClass( 'title-shortlink' )
 11+ .attr( 'href', url )
 12+ .text( protoNonRelative )
 13+ )
 14+ );
615 }
716 });

Follow-up revisions

RevisionCommit summaryAuthorDate
r110841MFT r110824, r110826reedy12:41, 7 February 2012
r110842(follow-up r110826) Switch getCanonicalUrl to getFullUrl in the default value...bawolff12:57, 7 February 2012

Comments

#Comment by Reedy (talk | contribs)   12:46, 7 February 2012
#Comment by Bawolff (talk | contribs)   12:51, 7 February 2012

Oh, I only made it work if someone explicitly set a url-relative $wgShortUrlPrefix. I guess i should make it default to a url relative thing to...

#Comment by Bawolff (talk | contribs)   12:57, 7 February 2012

Should be fixed in r110842

#Comment by Reedy (talk | contribs)   13:31, 7 February 2012

Looks good, had to purge the page for some reason, but it looks to work now. Thanks :)

Status & tagging log