http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96816
Revision: 96816
Author: jeroendedauw
Date: 2011-09-11 22:40:47 +0000 (Sun, 11 Sep 2011)
Log Message:
-----------
implemented ratio and expiry settings
Modified Paths:
--------------
trunk/extensions/Survey/Survey.hooks.php
trunk/extensions/Survey/includes/SurveyTag.php
trunk/extensions/Survey/resources/ext.survey.tag.js
Modified: trunk/extensions/Survey/Survey.hooks.php
===================================================================
--- trunk/extensions/Survey/Survey.hooks.php 2011-09-11 22:10:45 UTC (rev
96815)
+++ trunk/extensions/Survey/Survey.hooks.php 2011-09-11 22:40:47 UTC (rev
96816)
@@ -136,7 +136,7 @@
$surveys = Survey::select(
array(
- 'id', 'namespaces'
+ 'id', 'namespaces', 'ratio', 'expiry'
),
array(
'enabled' => 1,
@@ -157,7 +157,9 @@
$GLOBALS['wgOut']->addWikiText( Xml::element(
'survey',
array(
- 'id' => $survey->getId()
+ 'id' => $survey->getId(),
+ 'ratio' => $survey->getField(
'ratio' ),
+ 'expiry' => $survey->getField(
'expiry' ),
)
) );
}
Modified: trunk/extensions/Survey/includes/SurveyTag.php
===================================================================
--- trunk/extensions/Survey/includes/SurveyTag.php 2011-09-11 22:10:45 UTC
(rev 96815)
+++ trunk/extensions/Survey/includes/SurveyTag.php 2011-09-11 22:40:47 UTC
(rev 96816)
@@ -94,6 +94,8 @@
'cookie' => array(),
'title' => array(),
'require-enabled' => array( 'filter' =>
FILTER_VALIDATE_INT, 'options' => array( 'min_range' => 0, 'max_range' => 1 ) ),
+ 'expiry' => array( 'filter' => FILTER_VALIDATE_INT,
'options' => array( 'min_range' => 0 ) ),
+ 'ratio' => array( 'filter' => FILTER_VALIDATE_INT,
'options' => array( 'min_range' => 0, 'max_range' => 100 ) ),
);
}
Modified: trunk/extensions/Survey/resources/ext.survey.tag.js
===================================================================
--- trunk/extensions/Survey/resources/ext.survey.tag.js 2011-09-11 22:10:45 UTC
(rev 96815)
+++ trunk/extensions/Survey/resources/ext.survey.tag.js 2011-09-11 22:40:47 UTC
(rev 96816)
@@ -17,41 +17,53 @@
function shouldShowSurvey( options ) {
var shouldShow = $.cookie( getCookieName( options ) ) != 'done';
survey.log( 'shouldShowSurvey ' + getCookieName( options ) + ':
' + shouldShow.toString() );
- return shouldShow;
+ return options.cookie || shouldShow;
}
- function onSurveyShown( options ) {
- var expirySeconds = ( typeof options.expiry !== 'undefined' ) ?
options.expiry : 60 * 60 * 24 * 30;
- var date = new Date();
- date.setTime( date.getTime() + expirySeconds * 1000 );
- $.cookie( getCookieName( options ), 'done', { 'expires': date,
'path': '/' } );
+ function onSurveyDone( options ) {
+ if ( options.cookie ) {
+ var date = new Date();
+ date.setTime( date.getTime() + options.expiry * 1000 );
+ $.cookie( getCookieName( options ), 'done', {
'expires': date, 'path': '/' } );
+ survey.log( 'wrote done to cookie ' + getCookieName(
options ) );
+ }
}
function initTag( $tag ) {
- var options = {};
+ var ratioAttr = $tag.attr( 'survey-data-ratio' );
+ var expiryAttr = $tag.attr( 'survey-data-expiry' );
+ var options = {
+ 'ratio': typeof ratioAttr === 'undefined' ? 1 :
parseFloat( ratioAttr ) / 100,
+ 'cookie': $tag.attr( 'survey-data-cookie' ) !== 'no',
+ 'expiry': typeof expiryAttr === 'undefined' ? 60 * 60 *
24 * 30 : expiryAttr
+ };
+
if ( $tag.attr( 'survey-data-id' ) ) {
- options['id'] = $tag.attr( 'survey-data-id' );
+ options.id = $tag.attr( 'survey-data-id' );
} else if ( $tag.attr( 'survey-data-name' ) ) {
- options['name'] = $tag.attr( 'survey-data-name' );
+ options.name = $tag.attr( 'survey-data-name' );
}
else {
// TODO
return;
}
- if ( $tag.attr( 'survey-data-cookie' ) === 'no' ) {
- $tag.mwSurvey( options );
- }
- else {
+ var rand = Math.random();
+ survey.log( rand + ' < ' + options.ratio );
+
+ if ( rand < options.ratio ) {
if ( shouldShowSurvey( options ) ) {
options['onShow'] = function( eventArgs ) {
- onSurveyShown( options );
+ onSurveyDone( options );
};
$tag.mwSurvey( options );
}
}
+ else {
+ onSurveyDone( options );
+ }
}
$( document ).ready( function() {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs