r108868 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108867‎ | r108868 | r108869 >
Date:22:48, 13 January 2012
Author:rmoen
Status:ok (Comments)
Tags:interfaceconcurrency 
Comment:
added js resources for checking in / out resources via concurrency api. loaded the hooks class
Modified paths:
  • /trunk/extensions/InterfaceConcurrency/InterfaceConcurrency.hooks.php (modified) (history)
  • /trunk/extensions/InterfaceConcurrency/InterfaceConcurrency.php (modified) (history)
  • /trunk/extensions/InterfaceConcurrency/modules (added) (history)
  • /trunk/extensions/InterfaceConcurrency/modules/jquery.interfaceConcurrency (added) (history)
  • /trunk/extensions/InterfaceConcurrency/modules/jquery.interfaceConcurrency/jquery.interfaceConcurrency.js (added) (history)

Diff [purge]

Index: trunk/extensions/InterfaceConcurrency/InterfaceConcurrency.php
@@ -49,8 +49,24 @@
5050 $wgAPIModules['concurrency'] = 'ApiConcurrency';
5151
5252 // Hooks
 53+$wgAutoloadClasses['InterfaceConcurrencyHooks'] = $dir . 'InterfaceConcurrency.hooks.php';
 54+$wgHooks['BeforePageDisplay'][] = 'InterfaceConcurrencyHooks::beforePageDisplay';
5355 $wgHooks['LoadExtensionSchemaUpdates'][] = 'InterfaceConcurrencyHooks::onLoadExtensionSchemaUpdates';
5456
 57+// Resources
 58+$icResourceTemplate = array(
 59+ 'localBasePath' => $dir . 'modules',
 60+ 'remoteExtPath' => 'InterfaceConcurrency/modules'
 61+);
 62+
 63+$wgResourceModules['jquery.interfaceConcurrency'] = $icResourceTemplate + array(
 64+ 'scripts' => 'jquery.interfaceConcurrency/jquery.interfaceConcurrency.js',
 65+ 'dependencies' => array(
 66+ 'mediawiki.util',
 67+ 'mediawiki.user',
 68+ ),
 69+);
 70+
5571 // Configuration
5672 $wgConcurrency = array(
5773 'ExpirationDefault' => 60 * 15, // Default checkout duration. 15 minutes.
Index: trunk/extensions/InterfaceConcurrency/InterfaceConcurrency.hooks.php
@@ -2,6 +2,17 @@
33
44 class InterfaceConcurrencyHooks {
55 /**
 6+ * Adds Interface Concurrency JS to the output
 7+ *
 8+ * @param $output OutputPage
 9+ * @param $skin Skin
 10+ */
 11+ public static function beforePageDisplay( &$output, &$skin ) {
 12+ $output->addModules( array( 'jquery.interfaceConcurrency' ) );
 13+ return true;
 14+ }
 15+
 16+ /**
617 * Runs InterfaceConcurrency schema updates#
718 *
819 * @param $updater DatabaseUpdater
Index: trunk/extensions/InterfaceConcurrency/modules/jquery.interfaceConcurrency/jquery.interfaceConcurrency.js
@@ -0,0 +1,55 @@
 2+/**
 3+ * Base jQuery plugin for Concurrency
 4+ *
 5+ * @author Rob Moen
 6+ *
 7+ * Checkout Example:
 8+
 9+ $.concurrency.check( {
 10+ ccaction: 'checkout',
 11+ resourcetype: 'application-specific-string',
 12+ record: 123
 13+ }, function( result ){
 14+ if( result == 'failure' ) {
 15+ //checkout failed because item is already checked out. do something useful here.
 16+ } else if (result == 'success') {
 17+ //successfully checked out item. do something useful here.
 18+ }
 19+ } );
 20+ */
 21+
 22+(function ( $ ) {
 23+ $.concurrency = {
 24+ /*
 25+ * Checkin our checkout an object via API
 26+ * @param Object = {
 27+ ccaction: (string) 'checkout' or 'checkin'
 28+ resourcetype: (string) 'application-specific-string'
 29+ record: (int) resource id
 30+ callback: (function) handle results
 31+ }
 32+ */
 33+ check: function( params, callback ) {
 34+ params = $.extend({
 35+ action: 'concurrency',
 36+ token: mw.user.tokens.get( 'editToken' ),
 37+ format: 'json'
 38+ }, params);
 39+
 40+ return $.ajax( {
 41+ type: 'POST',
 42+ url: mw.util.wikiScript( 'api' ),
 43+ data: params,
 44+ success: function( data ){
 45+ if ( typeof callback === 'function' ){
 46+ if ( data && data.concurrency.result ) {
 47+ callback( data.concurrency.result );
 48+ }
 49+ }
 50+ },
 51+ dataType: 'json'
 52+ } );
 53+ }
 54+ };
 55+
 56+})( jQuery );
\ No newline at end of file
Property changes on: trunk/extensions/InterfaceConcurrency/modules/jquery.interfaceConcurrency/jquery.interfaceConcurrency.js
___________________________________________________________________
Added: svn:eol-style
157 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r109649remove BeforePageDisplay hook, interfaceConcurrency module shoudld be loaded ...rmoen21:39, 20 January 2012
r109878[InterfaceConcurrency] whitespace + missing dependency...krinkle00:20, 24 January 2012

Comments

#Comment by Raindrift (talk | contribs)   00:04, 24 January 2012

The jQuery plugin probably makes sense if we plan to build a new backend that exists outside the Mediawiki API, but you can probably still use mw.Api for the actual call.

#Comment by Krinkle (talk | contribs)   00:23, 24 January 2012
+	'dependencies' => array(
+		'mediawiki.util',
+		'mediawiki.user',
[..]
+				token: mw.user.tokens.get( 'editToken' ),

The dependency should be on user.tokens instead of mediawiki.user. mediawiki.user is a base module and the various user.* modules extend it with Maps for options, tokens and perhaps more in the future.

Fixed in r109878

Status & tagging log