r104397 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104396‎ | r104397 | r104398 >
Date:05:52, 28 November 2011
Author:johnduhart
Status:deferred (Comments)
Tags:
Comment:
Cleanup the AddThis extension to conform to MediaWiki standards
Modified paths:
  • /trunk/extensions/AddThis/AddThis.body.php (modified) (history)
  • /trunk/extensions/AddThis/AddThis.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AddThis/AddThis.body.php
@@ -8,101 +8,119 @@
99 */
1010 class AddThis {
1111
12 -/**
13 - * Parser hook for the <addthis /> tag extension.
14 - *
15 - */
 12+ /**
 13+ * Parser hook for the <addthis /> tag extension.
 14+ *
 15+ * @param $parser
 16+ * @return string
 17+ */
1618 public static function parserHook( $parser ) {
17 - global $wgAddThispubid, $wgAddThisHeader, $wgAddThisMain, $wgAddThisMainpage, $wgRequest, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder;
18 - # Localisation for "Share"
 19+ global $wgAddThispubid, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder;
 20+
 21+ # Localisation for "Share"
1922 $share = wfMsg( 'addthis' );
20 - # Output AddThis widget
21 - $output .='<!-- AddThis Button BEGIN -->
 23+ # Output AddThis widget
 24+ $output ='<!-- AddThis Button BEGIN -->
2225 <div class="addthis_toolbox addthis_default_style" id="addthistoolbar" style="background:'.$wgAddThisBackground.'; border-color:'.$wgAddThisBorder.';">
2326 <a href="http://www.addthis.com/bookmark.php?v=250&amp;pubid=ra-4eb75def4ec6488b" class="addthis_button_compact">&nbsp;' . $share . '</a><span class="addthis_separator">&nbsp;</span>';
 27+
2428 foreach ( $wgAddThisHServ as $n => $a ) {
25 - if (true === isset($wgAddThisHServ[$n]["attribs"])) {
 29+ if ( isset( $wgAddThisHServ[$n]["attribs"] ) ) {
2630 $output .= '<a class="addthis_button_'.$wgAddThisHServ[$n]["service"].'" '.$wgAddThisHServ[$n]["attribs"].'></a>';
27 - }
28 - else {
29 - $output .= '<a class="addthis_button_'.$wgAddThisHServ[$n]["service"].'"></a>';
30 - }
 31+ } else {
 32+ $output .= '<a class="addthis_button_'.$wgAddThisHServ[$n]["service"].'"></a>';
 33+ }
3134 }
3235 $output .='</div>
3336 <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid='.$wgAddThispubid.'"></script>
3437 <!-- AddThis Button END -->';
 38+
3539 return $output;
36 - }
 40+ }
3741
 42+ /**
 43+ * Function for sidebar portlet
 44+ *
 45+ * @param $skin
 46+ * @param $bar
 47+ * @return array|bool|string
 48+ */
 49+ public static function AddThisSidebar( $skin, &$bar ) {
 50+ global $wgOut, $wgAddThispubid, $wgAddThisSidebar, $wgAddThisSBServ;
3851
39 -/**
40 - * Function for sidebar portlet
41 - *
42 - */
43 - static function AddThisSidebar( $skin, &$bar ) {
44 - global $wgOut, $wgAddThispubid, $wgAddThisSidebar, $wgAddThisSBServ;
45 - # Load css stylesheet
46 - $wgOut->addModuleStyles( 'ext.addThis' );
47 - # Check setting to enable/disable sidebar portlet
48 - if(strtolower($wgAddThisSidebar) == 'true') {
49 - # Output AddThis widget
 52+ # Load css stylesheet
 53+ $wgOut->addModuleStyles( 'ext.addThis' );
 54+ # Check setting to enable/disable sidebar portlet
 55+ if ( $wgAddThisSidebar ) {
 56+ # Output AddThis widget
5057 $bar['addthis'] = '<!-- AddThis Button BEGIN -->
5158 <div class="addthis_toolbox addthis_default_style" id="addthissidebar">';
 59+
5260 foreach ( $wgAddThisSBServ as $n => $a ) {
53 - if (true === isset($wgAddThisSBServ[$n]["attribs"])) {
 61+ if ( isset( $wgAddThisSBServ[$n]["attribs"] ) ) {
5462 $bar['addthis'] .= '<a class="addthis_button_'.$wgAddThisSBServ[$n]["service"].'" '.$wgAddThisSBServ[$n]["attribs"].'></a>';
55 - }
56 - else {
57 - $bar['addthis'] .= '<a class="addthis_button_'.$wgAddThisSBServ[$n]["service"].'"></a>';
58 - }
 63+ } else {
 64+ $bar['addthis'] .= '<a class="addthis_button_'.$wgAddThisSBServ[$n]["service"].'"></a>';
5965 }
 66+ }
 67+
6068 $bar['addthis'] .= '</div>
6169 <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid='.$wgAddThispubid.'"></script>
6270 <!-- AddThis Button END -->';
 71+
 72+ // FIXME: This is a hook, should we really be returning a string here?
6373 return $bar;
6474 }
6575 return true;
6676 }
6777
 78+ /**
 79+ * Function for article header toolbar
 80+ *
 81+ * @param $article
 82+ * @param $outputDone
 83+ * @param $pcache
 84+ * @return bool
 85+ */
 86+ public static function AddThisHeader( &$article, &$outputDone, &$pcache ) {
 87+ global $wgOut, $wgAddThispubid, $wgAddThisHeader, $wgAddThisMain,
 88+ $wgRequest, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder;
6889
69 -/**
70 - * Function for article header toolbar
71 - *
72 - */
73 - public static function AddThisHeader( &$article, &$outputDone, &$pcache ) {
74 - global $wgOut, $wgAddThispubid, $wgAddThisHeader, $wgAddThisMain, $wgAddThisMainpage, $wgRequest, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder;
75 - # Localisation for "Share"
76 - $share = wfMsg( 'addthis' );
77 - # Check if page is in main namespace
78 - $title = $article->getTitle();
79 - # Check setting to enable/disable article header tooblar
80 - if(strtolower($wgAddThisHeader) == 'true') {
81 - # Check if article is mainpage set by [[MediaWiki:Mainpage]]
82 - if ($wgRequest->getText( 'title' )==str_replace( ' ', '_', wfMsg( 'mainpage' ) ) ) {
83 - # Check setting to enable/disable article header toolbar on mainpage
84 - if(strtolower($wgAddThisMain) == 'false') {
 90+ # Localisation for "Share"
 91+ $share = wfMsg( 'addthis' );
 92+ # Check if page is in main namespace
 93+ $title = $article->getTitle();
 94+ # Check setting to enable/disable article header tooblar
 95+ if ( $wgAddThisHeader ) {
 96+ # Check if article is mainpage set by [[MediaWiki:Mainpage]]
 97+ if ( $wgRequest->getText( 'title' )==str_replace( ' ', '_', wfMsg( 'mainpage' ) ) ) {
 98+ # Check setting to enable/disable article header toolbar on mainpage
 99+ if( !$wgAddThisMain ) {
85100 return true;
86 - }
87101 }
88 - # Check if page is in content namespace
 102+ }
 103+
 104+ # Check if page is in content namespace
89105 if ( MWNamespace::isContent( $title->getNamespace() ) ) {
90 - # Output AddThis widget
 106+ # Output AddThis widget
91107 $wgOut->addHTML('<!-- AddThis Button BEGIN -->
92108 <div class="addthis_toolbox addthis_default_style" id="addthistoolbar" style="background:'.$wgAddThisBackground.'; border-color:'.$wgAddThisBorder.';">
93109 <a href="http://www.addthis.com/bookmark.php?v=250&amp;pubid=ra-4eb75def4ec6488b" class="addthis_button_compact">&nbsp;' . $share . '</a><span class="addthis_separator">&nbsp;</span>');
 110+
94111 foreach ( $wgAddThisHServ as $n => $a ) {
95112 if (true === isset($wgAddThisHServ[$n]["attribs"])) {
96113 $wgOut->addHTML('<a class="addthis_button_'.$wgAddThisHServ[$n]["service"].'" '.$wgAddThisHServ[$n]["attribs"].'></a>');
97 - }
98 - else {
99 - $wgOut->addHTML('<a class="addthis_button_'.$wgAddThisHServ[$n]["service"].'"></a>');
100 - }
 114+ } else {
 115+ $wgOut->addHTML('<a class="addthis_button_'.$wgAddThisHServ[$n]["service"].'"></a>');
 116+ }
101117 }
 118+
102119 $wgOut->addHTML('</div>
103120 <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid='.$wgAddThispubid.'"></script>
104121 <!-- AddThis Button END -->');
105122 }
106123 }
107 - return true;
 124+
 125+ return true;
108126 }
109127 }
\ No newline at end of file
Index: trunk/extensions/AddThis/AddThis.php
@@ -117,9 +117,9 @@
118118 # Default values for most options
119119 $wgAddThisBackground = '#f6f6f6';
120120 $wgAddThisBorder = '#a7d7f9';
121 -$wgAddThisSidebar = 'true';
122 -$wgAddThisHeader = 'true';
123 -$wgAddThisMain = 'true';
 121+$wgAddThisSidebar = true;
 122+$wgAddThisHeader = true;
 123+$wgAddThisMain = true;
124124
125125 # Sidebar settings
126126 $wgAddThisSBServ = array(
@@ -184,7 +184,6 @@
185185 'url' => 'http://www.mediawiki.org/wiki/Extension:AddThis',
186186 );
187187
188 -
189188 /**
190189 * Register class and localisations
191190 *
@@ -193,29 +192,27 @@
194193 $wgAutoloadClasses['AddThis'] = $dir . 'AddThis.body.php';
195194 $wgExtensionMessagesFiles['AddThis'] = $dir . 'AddThis.i18n.php';
196195
197 -
198196 $wgResourceModules['ext.addThis'] = array(
199197 'styles' => 'addThis.css',
200198 'localBasePath' => dirname( __FILE__ ),
201199 'remoteExtPath' => 'AddThis',
202200 );
203201
204 -
205202 /**
206203 * Hooks
207204 *
208205 */
209206 $wgHooks['ArticleViewHeader'][] = 'AddThis::AddThisHeader';
210 -$wgHooks['ParserFirstCallInit'][] = 'addThisHeaderTag';
 207+$wgHooks['ParserFirstCallInit'][] = 'efAddThisHeaderTag';
211208 $wgHooks['SkinBuildSidebar'][] = 'AddThis::AddThisSidebar';
212209
213 -
214210 /**
215211 * Register parser hook
216212 *
217213 * @param $parser Parser
 214+ * @return bool
218215 */
219 -function addThisHeaderTag( &$parser ) {
 216+function efAddThisHeaderTag( &$parser ) {
220217 $parser->setHook( 'addthis', 'AddThis::parserHook' );
221218 return true;
222219 }
\ No newline at end of file

Comments

#Comment by Nikerabbit (talk | contribs)   09:10, 29 November 2011

There must be a better way to check if Title is main page.

Status & tagging log