Index: trunk/extensions/AddThis/AddThis.body.php |
— | — | @@ -9,16 +9,28 @@ |
10 | 10 | class AddThis { |
11 | 11 | |
12 | 12 | /** |
| 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 | + /** |
13 | 24 | * Parser hook for the <addthis /> tag extension. |
14 | 25 | * |
15 | 26 | * @param $parser |
16 | 27 | * @return string |
17 | 28 | */ |
18 | | - public static function parserHook( $parser ) { |
19 | | - global $wgAddThispubid, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder; |
| 29 | + static function parserHook( $parser ) { |
| 30 | + global $wgAddThis, $wgAddThispubid, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder; |
20 | 31 | |
21 | 32 | # Localisation for "Share" |
22 | | - $share = wfMsg( 'addthis' ); |
| 33 | + $share = wfMsgExt( 'addthis', escape ); |
| 34 | + |
23 | 35 | # Output AddThis widget |
24 | 36 | $output ='<!-- AddThis Button BEGIN --> |
25 | 37 | <div class="addthis_toolbox addthis_default_style" id="addthistoolbar" style="background:'.$wgAddThisBackground.'; border-color:'.$wgAddThisBorder.';"> |
— | — | @@ -26,9 +38,14 @@ |
27 | 39 | |
28 | 40 | $output .= self::makeLinks( $wgAddThisHServ ); |
29 | 41 | $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 | + } |
32 | 48 | |
| 49 | + |
33 | 50 | return $output; |
34 | 51 | } |
35 | 52 | |
— | — | @@ -38,41 +55,38 @@ |
39 | 56 | * @param $article Article |
40 | 57 | * @param $outputDone |
41 | 58 | * @param $pcache |
42 | | - * @return bool |
| 59 | + * @return bool|bool |
43 | 60 | */ |
44 | 61 | public static function AddThisHeader( &$article, &$outputDone, &$pcache ) { |
45 | | - global $wgOut, $wgAddThispubid, $wgAddThisHeader, $wgAddThisMain, |
| 62 | + global $wgOut, $wgAddThispubid, $wgAddThis, $wgAddThisHeader, $wgAddThisMain, |
46 | 63 | $wgRequest, $wgAddThisHServ, $wgAddThisBackground, $wgAddThisBorder; |
47 | 64 | |
| 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 | + |
48 | 73 | # 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 ); |
61 | 75 | |
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&pubid='.$wgAddThispubid.'" class="addthis_button_compact"> ' . $share . '</a><span class="addthis_separator"> </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&pubid='.$wgAddThispubid.'" class="addthis_button_compact"> ' . $share . '</a><span class="addthis_separator"> </span>'); |
68 | 80 | |
69 | | - $wgOut->addHTML( self::makeLinks( $wgAddThisHServ ) ); |
| 81 | + $wgOut->addHTML( self::makeLinks( $wgAddThisHServ ) ); |
70 | 82 | |
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>'); |
76 | 85 | |
| 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 | + |
77 | 91 | return true; |
78 | 92 | } |
79 | 93 | |
— | — | @@ -81,28 +95,33 @@ |
82 | 96 | * |
83 | 97 | * @param $skin |
84 | 98 | * @param $bar |
85 | | - * @return array|bool|string |
| 99 | + * @return bool|array|bool |
86 | 100 | */ |
87 | 101 | public static function AddThisSidebar( $skin, &$bar ) { |
88 | | - global $wgOut, $wgAddThispubid, $wgAddThisSidebar, $wgAddThisSBServ; |
| 102 | + global $wgOut, $wgAddThis, $wgAddThispubid, $wgAddThisSidebar, $wgAddThisSBServ; |
89 | 103 | |
90 | 104 | # Load css stylesheet |
91 | 105 | $wgOut->addModuleStyles( 'ext.addThis' ); |
| 106 | + |
92 | 107 | # 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 | + } |
97 | 111 | |
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">'; |
99 | 115 | |
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 ); |
103 | 117 | |
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>'; |
106 | 124 | } |
| 125 | + |
107 | 126 | return true; |
108 | 127 | } |
109 | 128 | |
— | — | @@ -122,4 +141,4 @@ |
123 | 142 | |
124 | 143 | return $html; |
125 | 144 | } |
126 | | -} |
\ No newline at end of file |
| 145 | +} |
Index: trunk/extensions/AddThis/AddThis.php |
— | — | @@ -45,6 +45,9 @@ |
46 | 46 | * $wgAddThisMain |
47 | 47 | * - Display AddThis widget on main page |
48 | 48 | * Default is true |
| 49 | + * $wgAddThis['addressbarsharing'] |
| 50 | + * - Enable AddThis widget on main page |
| 51 | + * Default is true |
49 | 52 | * $wgAddThisSBServ[0]['service'] |
50 | 53 | * - Service code for 1st button in sidebar - service codes: http://www.addthis.com/services/list |
51 | 54 | * Default is compact - AddThis icon used to access full AddThis popup menu |
— | — | @@ -122,6 +125,9 @@ |
123 | 126 | $wgAddThisSidebar = true; |
124 | 127 | $wgAddThisHeader = true; |
125 | 128 | $wgAddThisMain = true; |
| 129 | +$wgAddThis = array( |
| 130 | + 'addressbarsharing' => false, |
| 131 | +); |
126 | 132 | |
127 | 133 | # Sidebar settings |
128 | 134 | $wgAddThisSBServ = array( |
— | — | @@ -165,7 +171,7 @@ |
166 | 172 | 'service' => 'stumbleupon', |
167 | 173 | ), |
168 | 174 | array( |
169 | | - 'service' => 'reddit', |
| 175 | + 'service' => 'digg', |
170 | 176 | ), |
171 | 177 | array( |
172 | 178 | 'service' => 'email', |
— | — | @@ -180,7 +186,7 @@ |
181 | 187 | $wgExtensionCredits['other'][] = array( |
182 | 188 | 'path' => __FILE__, |
183 | 189 | 'name' => 'AddThis', |
184 | | - 'version' => '1.0', |
| 190 | + 'version' => '1.0.1', |
185 | 191 | 'author' => '[https://www.mediawiki.org/wiki/User:Varnent Gregory Varnum] (Contributions by [https://www.mediawiki.org/wiki/User:Johnduhart John Du Hart])', |
186 | 192 | 'description' => 'Adds [http://www.addthis.com AddThis button] to the sidebar and page header', |
187 | 193 | 'descriptionmsg' => 'addthis-desc', |
— | — | @@ -206,16 +212,5 @@ |
207 | 213 | * |
208 | 214 | */ |
209 | 215 | $wgHooks['ArticleViewHeader'][] = 'AddThis::AddThisHeader'; |
210 | | -$wgHooks['ParserFirstCallInit'][] = 'efAddThisHeaderTag'; |
| 216 | +$wgHooks['ParserFirstCallInit'][] = 'AddThis::AddThisHeaderTag'; |
211 | 217 | $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 |