r102113 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102112‎ | r102113 | r102114 >
Date:20:13, 5 November 2011
Author:ialex
Status:deferred
Tags:
Comment:
* Use BaseTemplateToolbox to add the link in the toolbox
* Check presence of 'whatlinkshere' item to know whether this one should be displayed or not (i.e. not a special page in former versions, article related flag in current)
* Put the link directly after 'recentchangeslinked' or 'whatlinkshere' for consistency instead of at the bottom
Modified paths:
  • /trunk/extensions/Watchers/Watchers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Watchers/Watchers.php
@@ -32,7 +32,7 @@
3333
3434 $wgSpecialPages['Watchers'] = 'SpecialWatchers';
3535
36 -$wgHooks['SkinTemplateToolboxEnd'][] = 'wfWatchersExtensionAfterToolbox';
 36+$wgHooks['BaseTemplateToolbox'][] = 'wfWatchersExtensionAfterToolbox';
3737
3838 /**
3939 * Set this to a number to anonymize results ("X or more" / "Less that X" people watching this page)
@@ -43,30 +43,22 @@
4444 /**
4545 * Display link in toolbox
4646 */
47 -function wfWatchersExtensionAfterToolbox( &$tpl ) { # Checked for HTML and MySQL insertion attacks
48 - if ( method_exists( $tpl, 'getSkin' ) ) {
49 - $title = $tpl->getSkin()->getTitle();
50 - } else {
51 - global $wgTitle;
52 - $title = $wgTitle;
53 - }
54 -
55 - if( $title->isTalkPage() ) {
56 - # No talk pages please
 47+function wfWatchersExtensionAfterToolbox( $tpl, $toolbox ) { # Checked for HTML and MySQL insertion attacks
 48+ # Only when displaying non-talk pages
 49+ if( !isset( $toolbox['whatlinkshere'] ) || $toolbox['whatlinkshere'] === false ) {
5750 return true;
5851 }
5952
60 - if( $title->getNamespace() < 0 ) {
61 - # No special pages please
62 - return true;
63 - }
64 -
65 - echo '<li id="t-watchers"><a href="' ;
 53+ $title = $tpl->getSkin()->getTitle();
6654 $nt = SpecialPage::getTitleFor( 'Watchers' );
67 - echo $nt->escapeLocalURL( 'page=' . $title->getPrefixedDBkey() );
68 - echo '">';
69 - echo wfMsgHtml( 'watchers_link_title' );
70 - echo "</a></li>\n";
 55+ $res['watchers'] = array(
 56+ 'href' => $nt->getLocalURL( 'page=' . $title->getPrefixedDBkey() ),
 57+ 'msg' => 'watchers_link_title',
 58+ 'id' => 't-watchers',
 59+ );
7160
 61+ $after = isset( $toolbox['recentchangeslinked'] ) ? 'recentchangeslinked' : 'whatlinkshere';
 62+ $toolbox = wfArrayInsertAfter( $toolbox, $res, $after );
 63+
7264 return true;
7365 }

Status & tagging log