r95740 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95739‎ | r95740 | r95741 >
Date:08:38, 30 August 2011
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
RL2: Convert the BeforePageDisplay hook code to the new backend
Modified paths:
  • /branches/RL2/extensions/Gadgets/GadgetHooks.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/Gadgets.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/Gadgets.php
@@ -78,7 +78,7 @@
7979 ) );
8080
8181 $wgHooks['ArticleSaveComplete'][] = 'GadgetHooks::articleSaveComplete';
82 -//$wgHooks['BeforePageDisplay'][] = 'GadgetHooks::beforePageDisplay'; // FIXME: broken
 82+$wgHooks['BeforePageDisplay'][] = 'GadgetHooks::beforePageDisplay';
8383 $wgHooks['CanonicalNamespaces'][] = 'GadgetHooks::canonicalNamespaces';
8484 $wgHooks['GetPreferences'][] = 'GadgetHooks::getPreferences';
8585 $wgHooks['LoadExtensionSchemaUpdates'][] = 'GadgetHooks::loadExtensionSchemaUpdates';
Index: branches/RL2/extensions/Gadgets/GadgetHooks.php
@@ -36,6 +36,8 @@
3737 * @param $preferences Array: Preference descriptions
3838 */
3939 public static function getPreferences( $user, &$preferences ) {
 40+ // TODO convert
 41+ return true;
4042 $gadgets = Gadget::loadStructuredList();
4143 if (!$gadgets) return true;
4244
@@ -112,70 +114,29 @@
113115 * @param $out OutputPage
114116 */
115117 public static function beforePageDisplay( $out ) {
116 - global $wgUser;
 118+ global $wgUser, $wgGadgetRepositories;
117119
118120 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 ) ) {
133131 $out->addModules( $gadget->getModuleName() );
134132 }
135 - foreach ( $gadget->getLegacyScripts() as $page ) {
136 - $lb->add( NS_MEDIAWIKI, $page );
137 - $pages[] = $page;
138 - }
139133 }
140134 }
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+
150136 wfProfileOut( __METHOD__ );
151 -
152137 return true;
153138 }
154139
155140 /**
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 - /**
180141 * UnitTestsList hook handler
181142 * @param $files Array: List of extension test files
182143 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r95747RL2: Convert preferences code to use the new backendcatrope09:49, 30 August 2011

Comments

#Comment by Krinkle (talk | contribs)   20:08, 30 August 2011
+				if ( $gadget->isEnabledForUser( $wgUser ) && $gadget->isAllowed( $wgUser ) ) {

Also needs an isHidden check.

#Comment by Krinkle (talk | contribs)   20:08, 30 August 2011

... which you fixed in r95747.

Status & tagging log