Index: branches/RL2/extensions/Gadgets/Gadgets_body.php |
— | — | @@ -1,196 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Gadgets extension - lets users select custom javascript gadgets |
5 | | - * |
6 | | - * |
7 | | - * For more info see http://mediawiki.org/wiki/Extension:Gadgets |
8 | | - * |
9 | | - * @file |
10 | | - * @ingroup Extensions |
11 | | - * @author Daniel Kinzler, brightbyte.de |
12 | | - * @copyright © 2007 Daniel Kinzler |
13 | | - * @license GNU General Public Licence 2.0 or later |
14 | | - */ |
15 | | - |
16 | | -class GadgetHooks { |
17 | | - |
18 | | - /** |
19 | | - * ArticleSaveComplete hook handler. |
20 | | - * |
21 | | - * @param $article Article |
22 | | - * @param $user User |
23 | | - * @param $text String: New page text |
24 | | - */ |
25 | | - public static function articleSaveComplete( $article, $user, $text ) { |
26 | | - //update cache if MediaWiki:Gadgets-definition was edited |
27 | | - $title = $article->mTitle; |
28 | | - if( $title->getNamespace() == NS_MEDIAWIKI && $title->getText() == 'Gadgets-definition' ) { |
29 | | - Gadget::loadStructuredList( $text ); |
30 | | - } |
31 | | - return true; |
32 | | - } |
33 | | - |
34 | | - /** |
35 | | - * GetPreferences hook handler. |
36 | | - * @param $user User |
37 | | - * @param $preferences Array: Preference descriptions |
38 | | - */ |
39 | | - public static function getPreferences( $user, &$preferences ) { |
40 | | - $gadgets = Gadget::loadStructuredList(); |
41 | | - if (!$gadgets) return true; |
42 | | - |
43 | | - $options = array(); |
44 | | - $default = array(); |
45 | | - foreach( $gadgets as $section => $thisSection ) { |
46 | | - $available = array(); |
47 | | - foreach( $thisSection as $gadget ) { |
48 | | - if ( $gadget->isAllowed( $user ) ) { |
49 | | - $gname = $gadget->getName(); |
50 | | - $available[$gadget->getDescription()] = $gname; |
51 | | - if ( $gadget->isEnabled( $user ) ) { |
52 | | - $default[] = $gname; |
53 | | - } |
54 | | - } |
55 | | - } |
56 | | - if ( $section !== '' ) { |
57 | | - $section = wfMsgExt( "gadget-section-$section", 'parseinline' ); |
58 | | - if ( count ( $available ) ) { |
59 | | - $options[$section] = $available; |
60 | | - } |
61 | | - } else { |
62 | | - $options = array_merge( $options, $available ); |
63 | | - } |
64 | | - } |
65 | | - |
66 | | - $preferences['gadgets-intro'] = |
67 | | - array( |
68 | | - 'type' => 'info', |
69 | | - 'label' => ' ', |
70 | | - 'default' => Xml::tags( 'tr', array(), |
71 | | - Xml::tags( 'td', array( 'colspan' => 2 ), |
72 | | - wfMsgExt( 'gadgets-prefstext', 'parse' ) ) ), |
73 | | - 'section' => 'gadgets', |
74 | | - 'raw' => 1, |
75 | | - 'rawrow' => 1, |
76 | | - ); |
77 | | - |
78 | | - $preferences['gadgets'] = |
79 | | - array( |
80 | | - 'type' => 'multiselect', |
81 | | - 'options' => $options, |
82 | | - 'section' => 'gadgets', |
83 | | - 'label' => ' ', |
84 | | - 'prefix' => 'gadget-', |
85 | | - 'default' => $default, |
86 | | - ); |
87 | | - |
88 | | - return true; |
89 | | - } |
90 | | - |
91 | | - /** |
92 | | - * ResourceLoaderRegisterModules hook handler. |
93 | | - * @param $resourceLoader ResourceLoader |
94 | | - */ |
95 | | - public static function registerModules( &$resourceLoader ) { |
96 | | - $gadgets = Gadget::loadList(); |
97 | | - if ( !$gadgets ) { |
98 | | - return true; |
99 | | - } |
100 | | - foreach ( $gadgets as $g ) { |
101 | | - $module = $g->getModule(); |
102 | | - if ( $module ) { |
103 | | - $resourceLoader->register( $g->getModuleName(), $module ); |
104 | | - } |
105 | | - } |
106 | | - return true; |
107 | | - } |
108 | | - |
109 | | - /** |
110 | | - * BeforePageDisplay hook handler. |
111 | | - * @param $out OutputPage |
112 | | - */ |
113 | | - public static function beforePageDisplay( $out ) { |
114 | | - global $wgUser; |
115 | | - |
116 | | - wfProfileIn( __METHOD__ ); |
117 | | - |
118 | | - $gadgets = Gadget::loadList(); |
119 | | - if ( !$gadgets ) { |
120 | | - wfProfileOut( __METHOD__ ); |
121 | | - return true; |
122 | | - } |
123 | | - |
124 | | - $lb = new LinkBatch(); |
125 | | - $lb->setCaller( __METHOD__ ); |
126 | | - $pages = array(); |
127 | | - |
128 | | - foreach ( $gadgets as $gadget ) { |
129 | | - if ( $gadget->isEnabled( $wgUser ) && $gadget->isAllowed( $wgUser ) ) { |
130 | | - if ( $gadget->hasModule() ) { |
131 | | - $out->addModules( $gadget->getModuleName() ); |
132 | | - } |
133 | | - foreach ( $gadget->getLegacyScripts() as $page ) { |
134 | | - $lb->add( NS_MEDIAWIKI, $page ); |
135 | | - $pages[] = $page; |
136 | | - } |
137 | | - } |
138 | | - } |
139 | | - |
140 | | - $lb->execute( __METHOD__ ); |
141 | | - |
142 | | - $done = array(); |
143 | | - foreach ( $pages as $page ) { |
144 | | - if ( isset( $done[$page] ) ) continue; |
145 | | - $done[$page] = true; |
146 | | - self::applyScript( $page, $out ); |
147 | | - } |
148 | | - wfProfileOut( __METHOD__ ); |
149 | | - |
150 | | - return true; |
151 | | - } |
152 | | - |
153 | | - /** |
154 | | - * Adds one legacy script to output. |
155 | | - * |
156 | | - * @param $page String: Unprefixed page title |
157 | | - * @param $out OutputPage |
158 | | - */ |
159 | | - private static function applyScript( $page, $out ) { |
160 | | - global $wgJsMimeType; |
161 | | - |
162 | | - # bug 22929: disable gadgets on sensitive pages. Scripts loaded through the |
163 | | - # ResourceLoader handle this in OutputPage::getModules() |
164 | | - # TODO: make this extension load everything via RL, then we don't need to worry |
165 | | - # about any of this. |
166 | | - if( $out->getAllowedModules( ResourceLoaderModule::TYPE_SCRIPTS ) < ResourceLoaderModule::ORIGIN_USER_SITEWIDE ){ |
167 | | - return; |
168 | | - } |
169 | | - |
170 | | - $t = Title::makeTitleSafe( NS_MEDIAWIKI, $page ); |
171 | | - if ( !$t ) return; |
172 | | - |
173 | | - $u = $t->getLocalURL( 'action=raw&ctype=' . $wgJsMimeType ); |
174 | | - $out->addScriptFile( $u, $t->getLatestRevID() ); |
175 | | - } |
176 | | - |
177 | | - /** |
178 | | - * UnitTestsList hook handler |
179 | | - * @param $files Array: List of extension test files |
180 | | - */ |
181 | | - public static function unitTestsList( $files ) { |
182 | | - $files[] = dirname( __FILE__ ) . '/Gadgets_tests.php'; |
183 | | - return true; |
184 | | - } |
185 | | - |
186 | | - public static function loadExtensionSchemaUpdates( $updater ) { |
187 | | - $dir = dirname( __FILE__ ); |
188 | | - $updater->addExtensionUpdate( array( 'addtable', 'gadgets', "$dir/sql/gadgets.sql", true ) ); |
189 | | - return true; |
190 | | - } |
191 | | - |
192 | | - public static function canonicalNamespaces( &$list ) { |
193 | | - $list[NS_GADGET] = 'Gadget'; |
194 | | - $list[NS_GADGET_TALK] = 'Gadget_talk'; |
195 | | - return true; |
196 | | - } |
197 | | -} |
Index: branches/RL2/extensions/Gadgets/Gadgets.php |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | |
58 | 58 | $wgAutoloadClasses['ApiQueryGadgetCategories'] = $dir . 'ApiQueryGadgetCategories.php'; |
59 | 59 | $wgAutoloadClasses['ApiQueryGadgets'] = $dir . 'ApiQueryGadgets.php'; |
60 | | -$wgAutoloadClasses['GadgetHooks'] = $dir . 'Gadgets_body.php'; |
| 60 | +$wgAutoloadClasses['GadgetHooks'] = $dir . 'GadgetHooks.php'; |
61 | 61 | $wgAutoloadClasses['SpecialGadgets'] = $dir . 'SpecialGadgets.php'; |
62 | 62 | |
63 | 63 | $wgSpecialPages['Gadgets'] = 'SpecialGadgets'; |
Index: branches/RL2/extensions/Gadgets/GadgetHooks.php |
— | — | @@ -0,0 +1,196 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Gadgets extension - lets users select custom javascript gadgets |
| 5 | + * |
| 6 | + * |
| 7 | + * For more info see http://mediawiki.org/wiki/Extension:Gadgets |
| 8 | + * |
| 9 | + * @file |
| 10 | + * @ingroup Extensions |
| 11 | + * @author Daniel Kinzler, brightbyte.de |
| 12 | + * @copyright © 2007 Daniel Kinzler |
| 13 | + * @license GNU General Public Licence 2.0 or later |
| 14 | + */ |
| 15 | + |
| 16 | +class GadgetHooks { |
| 17 | + |
| 18 | + /** |
| 19 | + * ArticleSaveComplete hook handler. |
| 20 | + * |
| 21 | + * @param $article Article |
| 22 | + * @param $user User |
| 23 | + * @param $text String: New page text |
| 24 | + */ |
| 25 | + public static function articleSaveComplete( $article, $user, $text ) { |
| 26 | + //update cache if MediaWiki:Gadgets-definition was edited |
| 27 | + $title = $article->mTitle; |
| 28 | + if( $title->getNamespace() == NS_MEDIAWIKI && $title->getText() == 'Gadgets-definition' ) { |
| 29 | + Gadget::loadStructuredList( $text ); |
| 30 | + } |
| 31 | + return true; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * GetPreferences hook handler. |
| 36 | + * @param $user User |
| 37 | + * @param $preferences Array: Preference descriptions |
| 38 | + */ |
| 39 | + public static function getPreferences( $user, &$preferences ) { |
| 40 | + $gadgets = Gadget::loadStructuredList(); |
| 41 | + if (!$gadgets) return true; |
| 42 | + |
| 43 | + $options = array(); |
| 44 | + $default = array(); |
| 45 | + foreach( $gadgets as $section => $thisSection ) { |
| 46 | + $available = array(); |
| 47 | + foreach( $thisSection as $gadget ) { |
| 48 | + if ( $gadget->isAllowed( $user ) ) { |
| 49 | + $gname = $gadget->getName(); |
| 50 | + $available[$gadget->getDescription()] = $gname; |
| 51 | + if ( $gadget->isEnabled( $user ) ) { |
| 52 | + $default[] = $gname; |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + if ( $section !== '' ) { |
| 57 | + $section = wfMsgExt( "gadget-section-$section", 'parseinline' ); |
| 58 | + if ( count ( $available ) ) { |
| 59 | + $options[$section] = $available; |
| 60 | + } |
| 61 | + } else { |
| 62 | + $options = array_merge( $options, $available ); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + $preferences['gadgets-intro'] = |
| 67 | + array( |
| 68 | + 'type' => 'info', |
| 69 | + 'label' => ' ', |
| 70 | + 'default' => Xml::tags( 'tr', array(), |
| 71 | + Xml::tags( 'td', array( 'colspan' => 2 ), |
| 72 | + wfMsgExt( 'gadgets-prefstext', 'parse' ) ) ), |
| 73 | + 'section' => 'gadgets', |
| 74 | + 'raw' => 1, |
| 75 | + 'rawrow' => 1, |
| 76 | + ); |
| 77 | + |
| 78 | + $preferences['gadgets'] = |
| 79 | + array( |
| 80 | + 'type' => 'multiselect', |
| 81 | + 'options' => $options, |
| 82 | + 'section' => 'gadgets', |
| 83 | + 'label' => ' ', |
| 84 | + 'prefix' => 'gadget-', |
| 85 | + 'default' => $default, |
| 86 | + ); |
| 87 | + |
| 88 | + return true; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * ResourceLoaderRegisterModules hook handler. |
| 93 | + * @param $resourceLoader ResourceLoader |
| 94 | + */ |
| 95 | + public static function registerModules( &$resourceLoader ) { |
| 96 | + $gadgets = Gadget::loadList(); |
| 97 | + if ( !$gadgets ) { |
| 98 | + return true; |
| 99 | + } |
| 100 | + foreach ( $gadgets as $g ) { |
| 101 | + $module = $g->getModule(); |
| 102 | + if ( $module ) { |
| 103 | + $resourceLoader->register( $g->getModuleName(), $module ); |
| 104 | + } |
| 105 | + } |
| 106 | + return true; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * BeforePageDisplay hook handler. |
| 111 | + * @param $out OutputPage |
| 112 | + */ |
| 113 | + public static function beforePageDisplay( $out ) { |
| 114 | + global $wgUser; |
| 115 | + |
| 116 | + wfProfileIn( __METHOD__ ); |
| 117 | + |
| 118 | + $gadgets = Gadget::loadList(); |
| 119 | + if ( !$gadgets ) { |
| 120 | + wfProfileOut( __METHOD__ ); |
| 121 | + return true; |
| 122 | + } |
| 123 | + |
| 124 | + $lb = new LinkBatch(); |
| 125 | + $lb->setCaller( __METHOD__ ); |
| 126 | + $pages = array(); |
| 127 | + |
| 128 | + foreach ( $gadgets as $gadget ) { |
| 129 | + if ( $gadget->isEnabled( $wgUser ) && $gadget->isAllowed( $wgUser ) ) { |
| 130 | + if ( $gadget->hasModule() ) { |
| 131 | + $out->addModules( $gadget->getModuleName() ); |
| 132 | + } |
| 133 | + foreach ( $gadget->getLegacyScripts() as $page ) { |
| 134 | + $lb->add( NS_MEDIAWIKI, $page ); |
| 135 | + $pages[] = $page; |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + $lb->execute( __METHOD__ ); |
| 141 | + |
| 142 | + $done = array(); |
| 143 | + foreach ( $pages as $page ) { |
| 144 | + if ( isset( $done[$page] ) ) continue; |
| 145 | + $done[$page] = true; |
| 146 | + self::applyScript( $page, $out ); |
| 147 | + } |
| 148 | + wfProfileOut( __METHOD__ ); |
| 149 | + |
| 150 | + return true; |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Adds one legacy script to output. |
| 155 | + * |
| 156 | + * @param $page String: Unprefixed page title |
| 157 | + * @param $out OutputPage |
| 158 | + */ |
| 159 | + private static function applyScript( $page, $out ) { |
| 160 | + global $wgJsMimeType; |
| 161 | + |
| 162 | + # bug 22929: disable gadgets on sensitive pages. Scripts loaded through the |
| 163 | + # ResourceLoader handle this in OutputPage::getModules() |
| 164 | + # TODO: make this extension load everything via RL, then we don't need to worry |
| 165 | + # about any of this. |
| 166 | + if( $out->getAllowedModules( ResourceLoaderModule::TYPE_SCRIPTS ) < ResourceLoaderModule::ORIGIN_USER_SITEWIDE ){ |
| 167 | + return; |
| 168 | + } |
| 169 | + |
| 170 | + $t = Title::makeTitleSafe( NS_MEDIAWIKI, $page ); |
| 171 | + if ( !$t ) return; |
| 172 | + |
| 173 | + $u = $t->getLocalURL( 'action=raw&ctype=' . $wgJsMimeType ); |
| 174 | + $out->addScriptFile( $u, $t->getLatestRevID() ); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * UnitTestsList hook handler |
| 179 | + * @param $files Array: List of extension test files |
| 180 | + */ |
| 181 | + public static function unitTestsList( $files ) { |
| 182 | + $files[] = dirname( __FILE__ ) . '/Gadgets_tests.php'; |
| 183 | + return true; |
| 184 | + } |
| 185 | + |
| 186 | + public static function loadExtensionSchemaUpdates( $updater ) { |
| 187 | + $dir = dirname( __FILE__ ); |
| 188 | + $updater->addExtensionUpdate( array( 'addtable', 'gadgets', "$dir/sql/gadgets.sql", true ) ); |
| 189 | + return true; |
| 190 | + } |
| 191 | + |
| 192 | + public static function canonicalNamespaces( &$list ) { |
| 193 | + $list[NS_GADGET] = 'Gadget'; |
| 194 | + $list[NS_GADGET_TALK] = 'Gadget_talk'; |
| 195 | + return true; |
| 196 | + } |
| 197 | +} |
Property changes on: branches/RL2/extensions/Gadgets/GadgetHooks.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
1 | 198 | Merged /branches/Gadgets-work/Gadgets_body.php:r73145-76526 |
2 | 199 | Merged /branches/wmf/1.17wmf1/extensions/Gadgets/Gadgets_body.php:r81884 |
Added: svn:eol-style |
3 | 200 | + native |
Added: svn:keywords |
4 | 201 | + LastChangedDate LastChangedRevision |