r91032 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91031‎ | r91032 | r91033 >
Date:00:20, 29 June 2011
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
adding functionality for custom image use logging
Modified paths:
  • /trunk/extensions/WikiLove/WikiLove.php (modified) (history)
  • /trunk/extensions/WikiLove/WikiLoveImageLog.api.php (added) (history)
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/WikiLove.php
@@ -55,6 +55,7 @@
5656
5757 // add autoload classes
5858 $wgAutoloadClasses['WikiLoveApi'] = $dir . 'WikiLove.api.php';
 59+$wgAutoloadClasses['WikiLoveImageLogApi'] = $dir . 'WikiLoveImageLog.api.php';
5960 $wgAutoloadClasses['WikiLoveHooks'] = $dir . 'WikiLove.hooks.php';
6061 $wgAutoloadClasses['WikiLoveLocal'] = $dir . 'WikiLove.local.php';
6162
@@ -71,6 +72,7 @@
7273
7374 // api modules
7475 $wgAPIModules['wikilove'] = 'WikiLoveApi';
 76+$wgAPIModules['wikiloveimagelog'] = 'WikiLoveImageLogApi';
7577
7678 $extWikiLoveTpl = array(
7779 'localBasePath' => dirname( __FILE__ ) . '/modules/ext.wikiLove',
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
@@ -369,13 +369,16 @@
370370 },
371371 dataType: 'json',
372372 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
375380 $.wikiLove.showAddDetailsError( 'wikilove-err-image-bad' );
 381+ $.wikiLove.logCustomImageUse( imageTitle, 0 );
376382 $( '#mw-wikilove-preview-spinner' ).fadeOut( 200 );
377 - } else {
378 - // Image exists. Proceed with preview.
379 - $.wikiLove.submitPreview();
380383 }
381384 },
382385 error: function() {
@@ -460,6 +463,22 @@
461464 },
462465
463466 /*
 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+ /*
464483 * Fires AJAX request for previewing wikitext.
465484 */
466485 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+}

Sign-offs

UserFlagDate
Krinkleinspected18:25, 29 June 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r91093Rename WikiLove API classes and filenames per convention...krinkle18:24, 29 June 2011

Comments

#Comment by Krinkle (talk | contribs)   18:25, 29 June 2011

Inspected JS. Leaving API to Roan.

Status & tagging log