Index: trunk/extensions/ShortUrl/ShortUrl.functions.php |
— | — | @@ -69,3 +69,11 @@ |
70 | 70 | } |
71 | 71 | return Title::makeTitle( $entry['su_namespace'], $entry['su_title'] ); |
72 | 72 | } |
| 73 | + |
| 74 | +/** |
| 75 | + * @param $title Title |
| 76 | + * @return True if a shorturl needs to be displayed |
| 77 | + */ |
| 78 | +function needsShortUrl( $title ) { |
| 79 | + return $title->exists() && ! $title->equals( Title::newMainPage() ); |
| 80 | +} |
Index: trunk/extensions/ShortUrl/ShortUrl.php |
— | — | @@ -34,8 +34,9 @@ |
35 | 35 | |
36 | 36 | $wgHooks['SkinTemplateToolboxEnd'][] = 'ShortUrlHooks::AddToolboxLink'; |
37 | 37 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'ShortUrlHooks::SetupSchema'; |
| 38 | +$wgHooks['OutputPageBeforeHTML'][] = 'ShortUrlHooks::OutputPageBeforeHTML'; |
38 | 39 | |
39 | | -$wgResourceModules['ext.ShortUrl'] = array( |
| 40 | +$wgResourceModules['ext.shortUrl'] = array( |
40 | 41 | 'scripts' => 'js/ext.shortUrl.js', |
41 | 42 | 'styles' => 'css/ext.shortUrl.css', |
42 | 43 | 'dependencies' => array( 'jquery' ), |
Index: trunk/extensions/ShortUrl/css/ext.shortUrl.css |
— | — | @@ -1,4 +1,4 @@ |
2 | | -.title-shorturl { |
| 2 | +.title-shortlink { |
3 | 3 | font-size: small; |
4 | 4 | font-family: monospace; |
5 | 5 | } |
Index: trunk/extensions/ShortUrl/ShortUrl.hooks.php |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | public static function AddToolboxLink( &$tpl ) { |
25 | 25 | global $wgOut, $wgShortUrlPrefix; |
26 | 26 | $title = $wgOut->getTitle(); |
27 | | - if ( $title->exists() && ! $title->equals( Title::newMainPage() ) ) { |
| 27 | + if ( needsShortUrl( $title ) ) { |
28 | 28 | $shortId = shorturlEncode( $title ); |
29 | 29 | $shortURL = $wgShortUrlPrefix . $shortId; |
30 | 30 | $html = Html::rawElement( 'li', array( 'id' => 't-shorturl' ), |
— | — | @@ -35,12 +35,25 @@ |
36 | 36 | ); |
37 | 37 | |
38 | 38 | echo $html; |
39 | | - $wgOut->addModules( 'ext.ShortUrl' ); |
| 39 | + // echo '<script type="text/javascript">mediaWiki.loader.load( "ext.shortUrl" );</script>'; |
40 | 40 | } |
41 | 41 | return true; |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
| 45 | + * @param $out OutputPage |
| 46 | + * @param $text the HTML text to be added |
| 47 | + */ |
| 48 | + public static function OutputPageBeforeHTML( &$out, &$text ) { |
| 49 | + global $wgOut; |
| 50 | + $title = $wgOut->getTitle(); |
| 51 | + if ( needsShortUrl( $title ) ) { |
| 52 | + $wgOut->addModules( 'ext.shortUrl' ); |
| 53 | + } |
| 54 | + return true; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
45 | 58 | * @param $du DatabaseUpdater |
46 | 59 | * @return bool |
47 | 60 | */ |