r108205 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108204‎ | r108205 | r108206 >
Date:09:17, 6 January 2012
Author:varnent
Status:deferred
Tags:
Comment:
v1.0.1 - support for addthis address bar sharing - lots of code cleanup
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
@@ -9,16 +9,28 @@
1010 class AddThis {
1111
1212 /**
 13+ * Register parser hook
 14+ *
 15+ * @param $parser Parser
 16+ * @return bool
 17+ */
 18+ public static function AddThisHeaderTag( &$parser ) {
 19+ $parser->setHook( 'addthis', __CLASS__.'::parserHook' );
 20+ return true;
 21+ }
 22+
 23+ /**
1324 * Parser hook for the <addthis /> tag extension.
1425 *
1526 * @param $parser
1627 * @return string
1728 */
18 - public static function parserHook( $parser ) {
19 - global $wgAddThispubid, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder;
 29+ static function parserHook( $parser ) {
 30+ global $wgAddThis, $wgAddThispubid, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder;
2031
2132 # Localisation for "Share"
22 - $share = wfMsg( 'addthis' );
 33+ $share = wfMsgExt( 'addthis', escape );
 34+
2335 # Output AddThis widget
2436 $output ='<!-- AddThis Button BEGIN -->
2537 <div class="addthis_toolbox addthis_default_style" id="addthistoolbar" style="background:'.$wgAddThisBackground.'; border-color:'.$wgAddThisBorder.';">
@@ -26,9 +38,14 @@
2739
2840 $output .= self::makeLinks( $wgAddThisHServ );
2941 $output .='</div>
30 - <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid='.$wgAddThispubid.'"></script>
31 - <!-- AddThis Button END -->';
 42+ <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid='.$wgAddThispubid.'"></script>';
 43+
 44+ # Output AddThis Address Bar Sharing script, if enabled
 45+ if ( $wgAddThis['addressbarsharing'] ) {
 46+ $output .='<script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>';
 47+ }
3248
 49+
3350 return $output;
3451 }
3552
@@ -38,41 +55,38 @@
3956 * @param $article Article
4057 * @param $outputDone
4158 * @param $pcache
42 - * @return bool
 59+ * @return bool|bool
4360 */
4461 public static function AddThisHeader( &$article, &$outputDone, &$pcache ) {
45 - global $wgOut, $wgAddThispubid, $wgAddThisHeader, $wgAddThisMain,
 62+ global $wgOut, $wgAddThispubid, $wgAddThis, $wgAddThisHeader, $wgAddThisMain,
4663 $wgRequest, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder;
4764
 65+ # Check if page is in content namespace and the setting to enable/disable article header tooblar either on the main page or at all
 66+ if ( !MWNamespace::isContent( $article->getTitle()->getNamespace() )
 67+ || !$wgAddThisHeader
 68+ || ( $article->getTitle()->isMainPage() && !$wgAddThisMain )
 69+ ) {
 70+ return true;
 71+ }
 72+
4873 # Localisation for "Share"
49 - $share = wfMsg( 'addthis' );
50 - # Check if page is in main namespace
51 - $title = $article->getTitle();
52 - # Check setting to enable/disable article header tooblar
53 - if ( $wgAddThisHeader ) {
54 - # Check if article is mainpage set by [[MediaWiki:Mainpage]]
55 - if ( $wgRequest->getText( 'title' ) == str_replace( ' ', '_', wfMsg( 'mainpage' ) ) ) {
56 - # Check setting to enable/disable article header toolbar on mainpage
57 - if( !$wgAddThisMain ) {
58 - return true;
59 - }
60 - }
 74+ $share = wfMsgExt( 'addthis', escape );
6175
62 - # Check if page is in content namespace
63 - if ( MWNamespace::isContent( $title->getNamespace() ) ) {
64 - # Output AddThis widget
65 - $wgOut->addHTML('<!-- AddThis Button BEGIN -->
66 - <div class="addthis_toolbox addthis_default_style" id="addthistoolbar" style="background:'.$wgAddThisBackground.'; border-color:'.$wgAddThisBorder.';">
67 - <a href="http://www.addthis.com/bookmark.php?v=250&amp;pubid='.$wgAddThispubid.'" class="addthis_button_compact">&nbsp;' . $share . '</a><span class="addthis_separator">&nbsp;</span>');
 76+ # Output AddThis widget
 77+ $wgOut->addHTML('<!-- AddThis Button BEGIN -->
 78+ <div class="addthis_toolbox addthis_default_style" id="addthistoolbar" style="background:'.$wgAddThisBackground.'; border-color:'.$wgAddThisBorder.';">
 79+ <a href="http://www.addthis.com/bookmark.php?v=250&amp;pubid='.$wgAddThispubid.'" class="addthis_button_compact">&nbsp;' . $share . '</a><span class="addthis_separator">&nbsp;</span>');
6880
69 - $wgOut->addHTML( self::makeLinks( $wgAddThisHServ ) );
 81+ $wgOut->addHTML( self::makeLinks( $wgAddThisHServ ) );
7082
71 - $wgOut->addHTML('</div>
72 - <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid='.$wgAddThispubid.'"></script>
73 - <!-- AddThis Button END -->');
74 - }
75 - }
 83+ $wgOut->addHTML('</div>
 84+ <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid='.$wgAddThispubid.'"></script>');
7685
 86+ # Output AddThis Address Bar Sharing script, if enabled
 87+ if ( $wgAddThis['addressbarsharing'] ) {
 88+ $wgOut->addHTML('<script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>');
 89+ }
 90+
7791 return true;
7892 }
7993
@@ -81,28 +95,33 @@
8296 *
8397 * @param $skin
8498 * @param $bar
85 - * @return array|bool|string
 99+ * @return bool|array|bool
86100 */
87101 public static function AddThisSidebar( $skin, &$bar ) {
88 - global $wgOut, $wgAddThispubid, $wgAddThisSidebar, $wgAddThisSBServ;
 102+ global $wgOut, $wgAddThis, $wgAddThispubid, $wgAddThisSidebar, $wgAddThisSBServ;
89103
90104 # Load css stylesheet
91105 $wgOut->addModuleStyles( 'ext.addThis' );
 106+
92107 # Check setting to enable/disable sidebar portlet
93 - if ( $wgAddThisSidebar ) {
94 - # Output AddThis widget
95 - $bar['addthis'] = '<!-- AddThis Button BEGIN -->
96 - <div class="addthis_toolbox addthis_default_style" id="addthissidebar">';
 108+ if ( !$wgAddThisSidebar ) {
 109+ return true;
 110+ }
97111
98 - $bar['addthis'] .= self::makeLinks( $wgAddThisSBServ );
 112+ # Output AddThis widget
 113+ $bar['addthis'] = '<!-- AddThis Button BEGIN -->
 114+ <div class="addthis_toolbox addthis_default_style" id="addthissidebar">';
99115
100 - $bar['addthis'] .= '</div>
101 - <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid='.$wgAddThispubid.'"></script>
102 - <!-- AddThis Button END -->';
 116+ $bar['addthis'] .= self::makeLinks( $wgAddThisSBServ );
103117
104 - // FIXME: This is a hook, should we really be returning a string here?
105 - return $bar;
 118+ $bar['addthis'] .= '</div>
 119+ <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid='.$wgAddThispubid.'"></script>';
 120+
 121+ # Output AddThis Address Bar Sharing script, if enabled
 122+ if ( $wgAddThis['addressbarsharing'] ) {
 123+ $bar['addthis'] .='<script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>';
106124 }
 125+
107126 return true;
108127 }
109128
@@ -122,4 +141,4 @@
123142
124143 return $html;
125144 }
126 -}
\ No newline at end of file
 145+}
Index: trunk/extensions/AddThis/AddThis.php
@@ -45,6 +45,9 @@
4646 * $wgAddThisMain
4747 * - Display AddThis widget on main page
4848 * Default is true
 49+ * $wgAddThis['addressbarsharing']
 50+ * - Enable AddThis widget on main page
 51+ * Default is true
4952 * $wgAddThisSBServ[0]['service']
5053 * - Service code for 1st button in sidebar - service codes: http://www.addthis.com/services/list
5154 * Default is compact - AddThis icon used to access full AddThis popup menu
@@ -122,6 +125,9 @@
123126 $wgAddThisSidebar = true;
124127 $wgAddThisHeader = true;
125128 $wgAddThisMain = true;
 129+$wgAddThis = array(
 130+ 'addressbarsharing' => false,
 131+);
126132
127133 # Sidebar settings
128134 $wgAddThisSBServ = array(
@@ -165,7 +171,7 @@
166172 'service' => 'stumbleupon',
167173 ),
168174 array(
169 - 'service' => 'reddit',
 175+ 'service' => 'digg',
170176 ),
171177 array(
172178 'service' => 'email',
@@ -180,7 +186,7 @@
181187 $wgExtensionCredits['other'][] = array(
182188 'path' => __FILE__,
183189 'name' => 'AddThis',
184 - 'version' => '1.0',
 190+ 'version' => '1.0.1',
185191 'author' => '[https://www.mediawiki.org/wiki/User:Varnent Gregory Varnum] (Contributions by [https://www.mediawiki.org/wiki/User:Johnduhart John Du Hart])',
186192 'description' => 'Adds [http://www.addthis.com AddThis button] to the sidebar and page header',
187193 'descriptionmsg' => 'addthis-desc',
@@ -206,16 +212,5 @@
207213 *
208214 */
209215 $wgHooks['ArticleViewHeader'][] = 'AddThis::AddThisHeader';
210 -$wgHooks['ParserFirstCallInit'][] = 'efAddThisHeaderTag';
 216+$wgHooks['ParserFirstCallInit'][] = 'AddThis::AddThisHeaderTag';
211217 $wgHooks['SkinBuildSidebar'][] = 'AddThis::AddThisSidebar';
212 -
213 -/**
214 - * Register parser hook
215 - *
216 - * @param $parser Parser
217 - * @return bool
218 - */
219 -function efAddThisHeaderTag( &$parser ) {
220 - $parser->setHook( 'addthis', 'AddThis::parserHook' );
221 - return true;
222 -}
\ No newline at end of file