r79895 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79894‎ | r79895 | r79896 >
Date:13:05, 9 January 2011
Author:catrope
Status:ok
Tags:
Comment:
ResourceLoader-ify the Collection extension. This is not a complete cleanup and there's still some nasty things in there, but this was needed to get it to work properly without including jQuery and jQuery UI itself. Collection's copies of jQuery and JUI were ancient and can be removed, but I left them alone for now.
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)
  • /trunk/extensions/Collection/Collection.hooks.php (modified) (history)
  • /trunk/extensions/Collection/Collection.php (modified) (history)
  • /trunk/extensions/Collection/Collection.suggest.php (modified) (history)
  • /trunk/extensions/Collection/Collection.templates.php (modified) (history)
  • /trunk/extensions/Collection/js/bookcreator.css (added) (history)
  • /trunk/extensions/Collection/js/collection.js (modified) (history)
  • /trunk/extensions/Collection/js/suggest.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/Collection.php
@@ -154,10 +154,43 @@
155155 $wgHooks['SkinBuildSidebar'][] = 'CollectionHooks::buildSidebar';
156156 $wgHooks['SiteNoticeAfter'][] = 'CollectionHooks::siteNoticeAfter';
157157 $wgHooks['OutputPageCheckLastModified'][] = 'CollectionHooks::checkLastModified';
 158+$wgHooks['ResourceLoaderGetConfigVars'][] = 'CollectionHooks::resourceLoaderGetConfigVars';
158159
159160 $wgAvailableRights[] = 'collectionsaveasuserpage';
160161 $wgAvailableRights[] = 'collectionsaveascommunitypage';
161162
 163+$collResourceTemplate = array(
 164+ 'localBasePath' => "$dir/js",
 165+ 'remoteExtPath' => 'Collection/js'
 166+);
 167+
 168+$wgResourceModules += array(
 169+ 'ext.collection.jquery.json' => $collResourceTemplate + array(
 170+ 'scripts' => 'jquery.json.js'
 171+ ),
 172+ 'ext.collection.jquery.jstorage' => $collResourceTemplate + array(
 173+ 'scripts' => 'jstorage.js',
 174+ 'dependencies' => 'ext.collection.jquery.json'
 175+ ),
 176+ 'ext.collection.suggest' => $collResourceTemplate + array(
 177+ 'scripts' => 'suggest.js',
 178+ 'dependencies' => 'ext.collection.bookcreator'
 179+ ),
 180+ 'ext.collection' => $collResourceTemplate + array(
 181+ 'scripts' => 'collection.js',
 182+ 'dependencies' => array( 'ext.collection.bookcreator', 'jquery.ui.sortable' ),
 183+ ),
 184+ 'ext.collection.bookcreator' => $collResourceTemplate + array(
 185+ 'scripts' => 'bookcreator.js',
 186+ 'styles' => 'bookcreator.css',
 187+ 'dependencies' => 'ext.collection.jquery.jstorage'
 188+ ),
 189+ 'ext.collection.checkLoadFromLocalStorage' => $collResourceTemplate + array(
 190+ 'scripts' => 'check_load_from_localstorage.js',
 191+ 'dependencies' => 'ext.collection.jquery.jstorage'
 192+ )
 193+);
 194+
162195 # register global Ajax functions:
163196
164197 function wfAjaxGetCollection() {
Index: trunk/extensions/Collection/Collection.suggest.php
@@ -66,6 +66,7 @@
6767
6868 $template = self::getCollectionSuggestTemplate( $mode, $param );
6969 $wgOut->setPageTitle( wfMsg( 'coll-suggest_title' ) );
 70+ $wgOut->addModules( 'ext.collection.suggest' );
7071 $wgOut->addTemplate( $template );
7172 }
7273
Index: trunk/extensions/Collection/Collection.hooks.php
@@ -252,56 +252,11 @@
253253 }
254254 }
255255
256 - $html = Xml::element( 'script',
257 - array(
258 - 'type' => $wgJsMimeType,
259 - 'src' => "$jsPath/jquery.js?$wgCollectionStyleVersion",
260 - ),
261 - '', false
262 - );
263 -
264 - $html .= Xml::element( 'script',
265 - array(
266 - 'type' => $wgJsMimeType,
267 - 'src' => "$jsPath/jquery.json.js?$wgCollectionStyleVersion",
268 - ),
269 - '', false
270 - );
271 -
272 - $html .= Xml::element( 'script',
273 - array(
274 - 'type' => $wgJsMimeType,
275 - 'src' => "$jsPath/jstorage.js?$wgCollectionStyleVersion",
276 - ),
277 - '', false
278 - );
279 -
280 - $html .= Xml::element( 'script',
281 - array(
282 - 'type' => $wgJsMimeType,
283 - 'src' => "$jsPath/bookcreator.js?$wgCollectionStyleVersion",
284 - ),
285 - '', false
286 - );
287 - $html .= Xml::element( 'style',
288 - array( 'type' => 'text/css' ),
289 - <<<EOS
290 -#collectionpopup {
291 - position: absolute;
292 - padding: 4px;
293 - border: 1px solid #000;
294 - background-color: #fea;
295 - z-index: 9999;
296 - display: inline;
297 - font-size: 10pt;
298 -}
299 -EOS
300 - , false
301 - );
 256+ $wgOut->addModules( 'ext.collection.bookcreator' );
302257
303258 $addRemoveState = $mode;
304259
305 - $html .= Xml::element( 'div',
 260+ $html = Xml::element( 'div',
306261 array( 'style' => wfMsg( 'coll-book_creator_box_style' ) ),
307262 null
308263 );
@@ -563,5 +518,13 @@
564519 }
565520 return true;
566521 }
 522+
 523+ /**
 524+ * ResourceLoaderGetConfigVars hook
 525+ */
 526+ static function resourceLoaderGetConfigVars( &$vars ) {
 527+ $vars['wgCollectionVersion'] = $GLOBALS['wgCollectionVersion'];
 528+ return true;
 529+ }
567530 }
568531
Index: trunk/extensions/Collection/js/bookcreator.css
@@ -0,0 +1,40 @@
 2+#collectionpopup {
 3+ position: absolute;
 4+ padding: 4px;
 5+ border: 1px solid #000;
 6+ background-color: #fea;
 7+ z-index: 9999;
 8+ display: inline;
 9+ font-size: 10pt;
 10+}
 11+
 12+.collection-button {
 13+ float: left;
 14+ padding: 0 10px;
 15+ border: 1px solid #777;
 16+ -webkit-border-radius: 8px;
 17+ -moz-border-radius: 8px;
 18+}
 19+
 20+.collection-button.ok {
 21+ /* @embed */
 22+ background: url(../images/green-button-back.png) center no-repeat;
 23+ margin-right: 10px;
 24+}
 25+
 26+.collection-button.cancel {
 27+ /* @embed */
 28+ background: url(../images/red-button-back.png) center no-repeat;
 29+}
 30+
 31+.collection-button a {
 32+ display: block;
 33+ color: #fff;
 34+ font-size: 1.1em;
 35+ font-weight: bold;
 36+ line-height: 1.8em;
 37+}
 38+
 39+.collection-button a:hover {
 40+ text-decoration: none;
 41+}
Property changes on: trunk/extensions/Collection/js/bookcreator.css
___________________________________________________________________
Added: svn:eol-style
142 + native
Index: trunk/extensions/Collection/js/collection.js
@@ -234,4 +234,4 @@
235235 }
236236 });
237237
238 -})(collection_jQuery);
 238+})(jQuery);
Index: trunk/extensions/Collection/js/suggest.js
@@ -39,5 +39,5 @@
4040
4141 window.collectionSuggestCall = collectionSuggestCall;
4242
43 -})(collection_jQuery);
 43+})(jQuery);
4444
Index: trunk/extensions/Collection/Collection.body.php
@@ -321,14 +321,7 @@
322322 $imagepath = "$wgScriptPath/extensions/Collection/images";
323323 $jspath = "$wgScriptPath/extensions/Collection/js";
324324
325 - $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$jspath/jquery.js?" .
326 - "$wgCollectionStyleVersion\"></script>" );
327 - $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$jspath/jquery.json.js?" .
328 - "$wgCollectionStyleVersion\"></script>" );
329 - $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$jspath/jstorage.js?" .
330 - "$wgCollectionStyleVersion\"></script>" );
331 - $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$jspath/check_load_from_localstorage.js?" .
332 - "$wgCollectionStyleVersion\"></script>" );
 325+ $wgOut->addModules( 'ext.collection.checkLoadFromLocalStorage' );
333326
334327 $coll = CollectionSession::getCollection();
335328 $dialogtxt = wfMsg( 'coll-load_local_book' );
@@ -338,40 +331,6 @@
339332 "var collection_dialogtxt = " . Xml::encodeJsVar( $dialogtxt ) . ";\n" .
340333 "</script>" );
341334
342 - $wgOut->mScripts .= <<<EOS
343 -<style type="text/css">
344 -.collection-button {
345 - float: left;
346 - padding: 0 10px;
347 - border: 1px solid #777;
348 - -webkit-border-radius: 8px;
349 - -moz-border-radius: 8px;
350 -}
351 -
352 -.collection-button.ok {
353 - background: url($imagepath/green-button-back.png) center no-repeat;
354 - margin-right: 10px;
355 -}
356 -
357 -.collection-button.cancel {
358 - background: url($imagepath/red-button-back.png) center no-repeat;
359 -}
360 -
361 -.collection-button a {
362 - display: block;
363 - color: #fff;
364 - font-size: 1.1em;
365 - font-weight: bold;
366 - line-height: 1.8em;
367 -}
368 -
369 -.collection-button a:hover {
370 - text-decoration: none;
371 -}
372 -</style>
373 -EOS
374 - ;
375 -
376335 $title = Title::newFromText( $referer );
377336 if ( is_null( $title ) || $title->equals( $wgTitle ) ) {
378337 $title = Title::newMainPage();
@@ -522,11 +481,7 @@
523482
524483 $this->setHeaders();
525484 $wgOut->setPageTitle( wfMsg( 'coll-manage_your_book' ) );
526 - $wgOut->addInlineScript( "var wgCollectionVersion = \"$wgCollectionVersion\";" );
527 - $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$jspath/jquery.js?$wgCollectionStyleVersion\"></script>" );
528 - $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$jspath/jquery.ui.js?$wgCollectionStyleVersion\"></script>" );
529 - $wgOut->addInlineScript( "var collection_jQuery = jQuery.noConflict();" );
530 - $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$jspath/collection.js?$wgCollectionStyleVersion\"></script>" );
 485+ $wgOut->addModules( 'ext.collection' );
531486
532487 $template = new CollectionPageTemplate();
533488 $template->set( 'collection', CollectionSession::getCollection() );
@@ -1101,10 +1056,7 @@
11021057 $wgOut->addInlineScript( 'var collection_id = "' . urlencode( $response['collection_id'] ) . '";' );
11031058 $wgOut->addInlineScript( 'var writer = "' . urlencode( $response['writer'] ) . '";' );
11041059 $wgOut->addInlineScript( 'var collection_rendering = true;' );
1105 - $wgOut->addInlineScript( "var wgCollectionVersion = \"$wgCollectionVersion\";" );
1106 - $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$wgScriptPath/extensions/Collection/js/jquery.js?$wgCollectionStyleVersion\"></script>" );
1107 - $wgOut->addInlineScript( "var collection_jQuery = jQuery.noConflict();" );
1108 - $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$wgScriptPath/extensions/Collection/js/collection.js?$wgCollectionStyleVersion\"></script>" );
 1060+ $wgOut->addModules( 'ext.collection' );
11091061 $wgOut->setPageTitle( wfMsg( 'coll-rendering_title' ) );
11101062
11111063 if ( isset( $response['status']['status'] ) && $response['status']['status'] ) {
Index: trunk/extensions/Collection/Collection.templates.php
@@ -446,13 +446,6 @@
447447 class CollectionSuggestTemplate extends QuickTemplate {
448448 function execute () {
449449 ?>
450 -<script src="<?php echo htmlspecialchars( $GLOBALS['wgScriptPath'] . "/extensions/Collection/js/jquery.js?" . $GLOBALS['wgCollectionStyleVersion'] ) ?>" type="<?php echo $GLOBALS['wgJsMimeType']; ?>"></script>
451 -<script type="<?php echo $GLOBALS['wgJsMimeType']; ?>">
452 -/*<![CDATA[*/
453 -var collection_jQuery = jQuery.noConflict();
454 -/*]]>*/
455 -</script>
456 -<script src="<?php echo $GLOBALS['wgScriptPath'] . "/extensions/Collection/js/suggest.js?" . $GLOBALS['wgCollectionStyleVersion'] ?>" type="<?php echo $GLOBALS['wgJsMimeType']; ?>"></script>
457450 <div>
458451 <?php $this->msg( 'coll-suggest_intro_text' ) ?>
459452 <div id="collectionSuggestStatus" style="text-align: center; margin: 5px auto 10px auto; padding: 0 4px; border: 1px solid #ed9; background-color: #fea; visibility: hidden;">&#160;</div>

Follow-up revisions

RevisionCommit summaryAuthorDate
r79902* Removed usage of $wgArticle, replaced by $wgRequest->getVal( 'oldid' ) and ...ialex16:47, 9 January 2011
r810091.17: MFT r79839, r79862, r79863, r79895, r80003, r80005, r80164, r80692catrope00:20, 26 January 2011

Status & tagging log