Index: trunk/extensions/InterfaceConcurrency/InterfaceConcurrency.php |
— | — | @@ -49,8 +49,24 @@ |
50 | 50 | $wgAPIModules['concurrency'] = 'ApiConcurrency'; |
51 | 51 | |
52 | 52 | // Hooks |
| 53 | +$wgAutoloadClasses['InterfaceConcurrencyHooks'] = $dir . 'InterfaceConcurrency.hooks.php'; |
| 54 | +$wgHooks['BeforePageDisplay'][] = 'InterfaceConcurrencyHooks::beforePageDisplay'; |
53 | 55 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'InterfaceConcurrencyHooks::onLoadExtensionSchemaUpdates'; |
54 | 56 | |
| 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 | + |
55 | 71 | // Configuration |
56 | 72 | $wgConcurrency = array( |
57 | 73 | 'ExpirationDefault' => 60 * 15, // Default checkout duration. 15 minutes. |
Index: trunk/extensions/InterfaceConcurrency/InterfaceConcurrency.hooks.php |
— | — | @@ -2,6 +2,17 @@ |
3 | 3 | |
4 | 4 | class InterfaceConcurrencyHooks { |
5 | 5 | /** |
| 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 | + /** |
6 | 17 | * Runs InterfaceConcurrency schema updates# |
7 | 18 | * |
8 | 19 | * @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 |
1 | 57 | + native |