Index: trunk/extensions/WikiLove/WikiLove.php |
— | — | @@ -55,6 +55,7 @@ |
56 | 56 | |
57 | 57 | // add autoload classes |
58 | 58 | $wgAutoloadClasses['WikiLoveApi'] = $dir . 'WikiLove.api.php'; |
| 59 | +$wgAutoloadClasses['WikiLoveImageLogApi'] = $dir . 'WikiLoveImageLog.api.php'; |
59 | 60 | $wgAutoloadClasses['WikiLoveHooks'] = $dir . 'WikiLove.hooks.php'; |
60 | 61 | $wgAutoloadClasses['WikiLoveLocal'] = $dir . 'WikiLove.local.php'; |
61 | 62 | |
— | — | @@ -71,6 +72,7 @@ |
72 | 73 | |
73 | 74 | // api modules |
74 | 75 | $wgAPIModules['wikilove'] = 'WikiLoveApi'; |
| 76 | +$wgAPIModules['wikiloveimagelog'] = 'WikiLoveImageLogApi'; |
75 | 77 | |
76 | 78 | $extWikiLoveTpl = array( |
77 | 79 | 'localBasePath' => dirname( __FILE__ ) . '/modules/ext.wikiLove', |
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js |
— | — | @@ -369,13 +369,16 @@ |
370 | 370 | }, |
371 | 371 | dataType: 'json', |
372 | 372 | success: function( data ) { |
373 | | - if ( !data.query.pages[-1].imageinfo ) { |
374 | | - // Image does not exist |
| 373 | + // See if image exists locally or through InstantCommons |
| 374 | + if ( !data.query.pages[-1] || data.query.pages[-1].imageinfo) { |
| 375 | + // Image exists |
| 376 | + $.wikiLove.submitPreview(); |
| 377 | + $.wikiLove.logCustomImageUse( imageTitle, 1 ); |
| 378 | + } else { |
| 379 | + // Image does not exist |
375 | 380 | $.wikiLove.showAddDetailsError( 'wikilove-err-image-bad' ); |
| 381 | + $.wikiLove.logCustomImageUse( imageTitle, 0 ); |
376 | 382 | $( '#mw-wikilove-preview-spinner' ).fadeOut( 200 ); |
377 | | - } else { |
378 | | - // Image exists. Proceed with preview. |
379 | | - $.wikiLove.submitPreview(); |
380 | 383 | } |
381 | 384 | }, |
382 | 385 | error: function() { |
— | — | @@ -460,6 +463,22 @@ |
461 | 464 | }, |
462 | 465 | |
463 | 466 | /* |
| 467 | + * Log each time a user attempts to use a custom image via the Make your own feature. |
| 468 | + */ |
| 469 | + logCustomImageUse: function( imageTitle, success ) { |
| 470 | + $.ajax( { |
| 471 | + url: mw.util.wikiScript( 'api' ), |
| 472 | + data: { |
| 473 | + 'action': 'wikiloveimagelog', |
| 474 | + 'image': imageTitle, |
| 475 | + 'success': success, |
| 476 | + 'format': 'json' |
| 477 | + }, |
| 478 | + dataType: 'json' |
| 479 | + } ); |
| 480 | + }, |
| 481 | + |
| 482 | + /* |
464 | 483 | * Fires AJAX request for previewing wikitext. |
465 | 484 | */ |
466 | 485 | doPreview: function( wikitext ) { |
Index: trunk/extensions/WikiLove/WikiLoveImageLog.api.php |
— | — | @@ -0,0 +1,64 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * This API is for logging each time a user attempts to use a custom image via the Make your own |
| 6 | + * feature. This is basically just to see if users can grok the concept. Once usage analysis is |
| 7 | + * complete, this API can be deleted. |
| 8 | + */ |
| 9 | +class WikiLoveImageLogApi extends ApiBase { |
| 10 | + public function execute() { |
| 11 | + global $wgRequest, $wgWikiLoveLogging, $wgParser; |
| 12 | + |
| 13 | + $params = $this->extractRequestParams(); |
| 14 | + |
| 15 | + if ( $wgWikiLoveLogging ) { |
| 16 | + $this->saveInDb( $params['image'], $params['success'] ); |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * @param $user User ID |
| 22 | + * @param $image string |
| 23 | + * @param $success integer |
| 24 | + */ |
| 25 | + private function saveInDb( $image, $success ) { |
| 26 | + global $wgUser; |
| 27 | + $dbw = wfGetDB( DB_MASTER ); |
| 28 | + |
| 29 | + $values = array( |
| 30 | + 'wlil_timestamp' => $dbw->timestamp(), |
| 31 | + 'wlil_user_id' => $wgUser->getId(), |
| 32 | + 'wlil_image' => $image, |
| 33 | + 'wlil_success' => $success, |
| 34 | + ); |
| 35 | + |
| 36 | + try{ |
| 37 | + $dbw->insert( 'wikilove_image_log', $values, __METHOD__ ); |
| 38 | + } catch( DBQueryError $dbqe ) { |
| 39 | + $this->setWarning( 'Action was not logged' ); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + public function getDescription() { |
| 44 | + return array( |
| 45 | + 'This API is for logging each time a user attempts to use a custom image via WikiLove.', |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + public function getAllowedParams() { |
| 50 | + return array( |
| 51 | + 'image' => array( |
| 52 | + ApiBase::PARAM_TYPE => 'string', |
| 53 | + ApiBase::PARAM_REQUIRED => true, |
| 54 | + ), |
| 55 | + 'success' => array( |
| 56 | + ApiBase::PARAM_TYPE => 'integer', |
| 57 | + ApiBase::PARAM_REQUIRED => true, |
| 58 | + ) |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + public function getVersion() { |
| 63 | + return __CLASS__ . ': $Id: WikiLoveImageLog.api.php XXXXX 2011-06-28 15:32:13Z kaldari $'; |
| 64 | + } |
| 65 | +} |