Index: branches/RL2/extensions/Gadgets/Gadgets.php |
— | — | @@ -78,7 +78,7 @@ |
79 | 79 | ) ); |
80 | 80 | |
81 | 81 | $wgHooks['ArticleSaveComplete'][] = 'GadgetHooks::articleSaveComplete'; |
82 | | -//$wgHooks['BeforePageDisplay'][] = 'GadgetHooks::beforePageDisplay'; // FIXME: broken |
| 82 | +$wgHooks['BeforePageDisplay'][] = 'GadgetHooks::beforePageDisplay'; |
83 | 83 | $wgHooks['CanonicalNamespaces'][] = 'GadgetHooks::canonicalNamespaces'; |
84 | 84 | $wgHooks['GetPreferences'][] = 'GadgetHooks::getPreferences'; |
85 | 85 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'GadgetHooks::loadExtensionSchemaUpdates'; |
Index: branches/RL2/extensions/Gadgets/GadgetHooks.php |
— | — | @@ -36,6 +36,8 @@ |
37 | 37 | * @param $preferences Array: Preference descriptions |
38 | 38 | */ |
39 | 39 | public static function getPreferences( $user, &$preferences ) { |
| 40 | + // TODO convert |
| 41 | + return true; |
40 | 42 | $gadgets = Gadget::loadStructuredList(); |
41 | 43 | if (!$gadgets) return true; |
42 | 44 | |
— | — | @@ -112,70 +114,29 @@ |
113 | 115 | * @param $out OutputPage |
114 | 116 | */ |
115 | 117 | public static function beforePageDisplay( $out ) { |
116 | | - global $wgUser; |
| 118 | + global $wgUser, $wgGadgetRepositories; |
117 | 119 | |
118 | 120 | wfProfileIn( __METHOD__ ); |
119 | | - |
120 | | - $gadgets = Gadget::loadList(); |
121 | | - if ( !$gadgets ) { |
122 | | - wfProfileOut( __METHOD__ ); |
123 | | - return true; |
124 | | - } |
125 | | - |
126 | | - $lb = new LinkBatch(); |
127 | | - $lb->setCaller( __METHOD__ ); |
128 | | - $pages = array(); |
129 | | - |
130 | | - foreach ( $gadgets as $gadget ) { |
131 | | - if ( $gadget->isEnabled( $wgUser ) && $gadget->isAllowed( $wgUser ) ) { |
132 | | - if ( $gadget->hasModule() ) { |
| 121 | + |
| 122 | + foreach ( $wgGadgetRepositories as $params ) { |
| 123 | + $repoClass = $params['class']; |
| 124 | + unset( $params['class'] ); |
| 125 | + $repo = new $repoClass( $params ); |
| 126 | + |
| 127 | + $gadgets = $repo->getGadgetNames(); |
| 128 | + foreach ( $gadgets as $name ) { |
| 129 | + $gadget = $repo->getGadget( $name ); |
| 130 | + if ( $gadget->isEnabledForUser( $wgUser ) && $gadget->isAllowed( $wgUser ) ) { |
133 | 131 | $out->addModules( $gadget->getModuleName() ); |
134 | 132 | } |
135 | | - foreach ( $gadget->getLegacyScripts() as $page ) { |
136 | | - $lb->add( NS_MEDIAWIKI, $page ); |
137 | | - $pages[] = $page; |
138 | | - } |
139 | 133 | } |
140 | 134 | } |
141 | | - |
142 | | - $lb->execute( __METHOD__ ); |
143 | | - |
144 | | - $done = array(); |
145 | | - foreach ( $pages as $page ) { |
146 | | - if ( isset( $done[$page] ) ) continue; |
147 | | - $done[$page] = true; |
148 | | - self::applyScript( $page, $out ); |
149 | | - } |
| 135 | + |
150 | 136 | wfProfileOut( __METHOD__ ); |
151 | | - |
152 | 137 | return true; |
153 | 138 | } |
154 | 139 | |
155 | 140 | /** |
156 | | - * Adds one legacy script to output. |
157 | | - * |
158 | | - * @param $page String: Unprefixed page title |
159 | | - * @param $out OutputPage |
160 | | - */ |
161 | | - private static function applyScript( $page, $out ) { |
162 | | - global $wgJsMimeType; |
163 | | - |
164 | | - # bug 22929: disable gadgets on sensitive pages. Scripts loaded through the |
165 | | - # ResourceLoader handle this in OutputPage::getModules() |
166 | | - # TODO: make this extension load everything via RL, then we don't need to worry |
167 | | - # about any of this. |
168 | | - if( $out->getAllowedModules( ResourceLoaderModule::TYPE_SCRIPTS ) < ResourceLoaderModule::ORIGIN_USER_SITEWIDE ){ |
169 | | - return; |
170 | | - } |
171 | | - |
172 | | - $t = Title::makeTitleSafe( NS_MEDIAWIKI, $page ); |
173 | | - if ( !$t ) return; |
174 | | - |
175 | | - $u = $t->getLocalURL( 'action=raw&ctype=' . $wgJsMimeType ); |
176 | | - $out->addScriptFile( $u, $t->getLatestRevID() ); |
177 | | - } |
178 | | - |
179 | | - /** |
180 | 141 | * UnitTestsList hook handler |
181 | 142 | * @param $files Array: List of extension test files |
182 | 143 | */ |