http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89583
Revision: 89583
Author: kaldari
Date: 2011-06-06 17:09:37 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
fundraising specific code - mostly for automatic link construction and tracking
Modified Paths:
--------------
trunk/extensions/CentralNotice/CentralNotice.db.php
trunk/extensions/CentralNotice/CentralNotice.i18n.php
trunk/extensions/CentralNotice/CentralNotice.php
trunk/extensions/CentralNotice/SpecialBannerController.php
trunk/extensions/CentralNotice/SpecialBannerLoader.php
trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
trunk/extensions/CentralNotice/centralnotice.css
trunk/extensions/CentralNotice/centralnotice.js
Added Paths:
-----------
trunk/extensions/CentralNotice/patches/patch-template_fundraising.sql
Modified: trunk/extensions/CentralNotice/CentralNotice.db.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNotice.db.php 2011-06-06 17:02:56 UTC
(rev 89582)
+++ trunk/extensions/CentralNotice/CentralNotice.db.php 2011-06-06 17:09:37 UTC
(rev 89583)
@@ -143,7 +143,9 @@
'tmp_name',
'tmp_weight',
'tmp_display_anon',
- 'tmp_display_account'
+ 'tmp_display_account',
+ 'tmp_fundraising',
+ 'tmp_landing_pages'
),
array(
'cn_notices.not_id' =>
$campaignId,
@@ -159,7 +161,9 @@
'weight' => intval(
$row->tmp_weight ),
'display_anon' => intval(
$row->tmp_display_anon ),
'display_account' => intval(
$row->tmp_display_account ),
- 'campaign' =>
CentralNotice::getNoticeName( $campaignId ),
+ 'fundraising' => intval(
$row->tmp_fundraising ),
+ 'landing_pages' =>
$row->tmp_landing_pages,
+ 'campaign' =>
CentralNotice::getNoticeName( $campaignId )
);
}
}
Modified: trunk/extensions/CentralNotice/CentralNotice.i18n.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNotice.i18n.php 2011-06-06
17:02:56 UTC (rev 89582)
+++ trunk/extensions/CentralNotice/CentralNotice.i18n.php 2011-06-06
17:09:37 UTC (rev 89583)
@@ -127,6 +127,9 @@
'centralnotice-banner-type' => 'Banner type:',
'centralnotice-banner-hidable' => 'Static/Hidable',
'centralnotice-banner-collapsible' => 'Collapsible',
+ 'centralnotice-banner-fundraising' => 'This is a fundraising banner',
+ 'centralnotice-banner-fundraising-help' => 'Create an anchor tag in the
banner body with id="cn_fundraising_link" and enter one or more landing pages
below, for example, "JimmyAppeal01". The href of the link will be constructed
automatically.',
+ 'centralnotice-banner-landing-pages' => 'Landing pages
(comma-separated):',
'centralnotice-geotargeted' => 'Geotargeted',
'centralnotice-countries' => 'Countries',
'centralnotice-allocation' => 'Allocation',
Modified: trunk/extensions/CentralNotice/CentralNotice.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNotice.php 2011-06-06 17:02:56 UTC
(rev 89582)
+++ trunk/extensions/CentralNotice/CentralNotice.php 2011-06-06 17:09:37 UTC
(rev 89583)
@@ -39,6 +39,12 @@
// for cached content
$wgCentralNoticeLoader = true;
+// Flag for turning on fundraising specific features
+$wgNoticeEnableFundraising = true;
+
+// Base URL for default fundraiser landing page (without query string)
+$wgNoticeFundraisingUrl =
'http://wikimediafoundation.org/wiki/Special:LandingCheck';
+
// Source for live counter information
$wgNoticeCounterSource =
'http://wikimediafoundation.org/wiki/Special:ContributionTotal?action=raw';
@@ -122,6 +128,8 @@
$base . '/patches/patch-notice_languages.sql' );
$wgExtNewFields[] = array( 'cn_templates',
'tmp_display_anon',
$base . '/patches/patch-template_settings.sql'
);
+ $wgExtNewFields[] = array( 'cn_templates',
'tmp_fundraising',
+ $base .
'/patches/patch-template_fundraising.sql' );
$wgExtNewTables[] = array( 'cn_notice_countries',
$base . '/patches/patch-notice_countries.sql' );
$wgExtNewTables[] = array( 'cn_notice_projects',
@@ -137,6 +145,8 @@
$base . '/patches/patch-notice_languages.sql',
true ) );
$updater->addExtensionUpdate( array( 'addField',
'cn_templates', 'tmp_display_anon',
$base . '/patches/patch-template_settings.sql',
true ) );
+ $updater->addExtensionUpdate( array( 'addField',
'cn_templates', 'tmp_fundraising',
+ $base .
'/patches/patch-template_fundraising.sql', true ) );
$updater->addExtensionUpdate( array( 'addTable',
'cn_notice_countries',
$base . '/patches/patch-notice_countries.sql',
true ) );
$updater->addExtensionUpdate( array( 'addTable',
'cn_notice_projects',
Modified: trunk/extensions/CentralNotice/SpecialBannerController.php
===================================================================
--- trunk/extensions/CentralNotice/SpecialBannerController.php 2011-06-06
17:02:56 UTC (rev 89582)
+++ trunk/extensions/CentralNotice/SpecialBannerController.php 2011-06-06
17:09:37 UTC (rev 89583)
@@ -43,7 +43,7 @@
* In order to circumvent the normal squid cache override we add
'/cn.js' to the bannerlist URL.
*/
function getOutput() {
- global $wgCentralPagePath, $wgContLang;
+ global $wgCentralPagePath, $wgNoticeFundraisingUrl, $wgContLang;
$js = $this->getScriptFunctions() . $this->getToggleScripts();
$js .= <<<JAVASCRIPT
@@ -54,11 +54,13 @@
'getVars': {}
},
'fn': {
- 'loadBanner': function( bannerName ) {
+ 'loadBanner': function( bannerName, fundraising,
landingPages, campaign ) {
// Get the requested banner
var bannerPageQuery = $.param( {
- 'banner': bannerName, 'userlang':
wgUserLanguage,
- 'db': wgDBname, 'sitename': wgSiteName,
'country': Geo.country } );
+ 'banner': bannerName, 'campaign':
campaign, 'userlang': wgUserLanguage,
+ 'db': wgDBname, 'sitename': wgSiteName,
'country': Geo.country,
+ 'fundraising': fundraising,
'landingpages': landingPages
+ } );
var bannerPage = '?title=Special:BannerLoader&'
+ bannerPageQuery;
JAVASCRIPT;
$js .= "\n\t\t\t\tvar bannerScript = '<script
type=\"text/javascript\" src=\"" .
@@ -111,11 +113,15 @@
// Return if there's nothing left after the
grooming
if( groomedBannerList.length == 0 ) return
false;
+ // Choose a random key
+ var pointer = Math.floor( Math.random() *
groomedBannerList.length );
+
// Load a random banner from our groomed list
$.centralNotice.fn.loadBanner(
- groomedBannerList[
- Math.floor( Math.random() *
groomedBannerList.length )
- ].name
+ groomedBannerList[pointer].name,
+ groomedBannerList[pointer].fundraising,
+
groomedBannerList[pointer].landing_pages,
+ groomedBannerList[pointer].campaign
);
},
'getQueryStringVariables': function() {
@@ -151,9 +157,29 @@
}
function getScriptFunctions() {
+ global $wgNoticeFundraisingUrl;
$script = <<<JAVASCRIPT
function insertBanner(bannerJson) {
- jQuery('div#centralNotice').prepend( bannerJson.banner );
+ jQuery( 'div#centralNotice' ).prepend( bannerJson.bannerHtml );
+ if ( bannerJson.fundraising ) {
+JAVASCRIPT;
+ $script .= "\n\t\tvar url = '" .
+ Xml::escapeJsString( $wgNoticeFundraisingUrl ) . "';";
+ $script .= <<<JAVASCRIPT
+ console.debug(bannerJson.landingPages.length);
+ if ( bannerJson.landingPages.length ) {
+ targets = String( bannerJson.landingPages ).split(',');
+ url += "?" + jQuery.param( {
+ 'landing_page': targets[Math.floor(
Math.random() * targets.length )].replace( /^\s+|\s+$/, '' )
+ } );
+ url += "&" + jQuery.param( {
+ 'utm_medium': 'sitenotice', 'utm_campaign':
bannerJson.campaign,
+ 'utm_source': bannerJson.bannerName,
'language': wgUserLanguage,
+ 'country': Geo.country
+ } );
+ jQuery( '#cn_fundraising_link' ).attr( 'href', url );
+ }
+ }
}
function toggleNotice() {
var notice = document.getElementById('centralNotice');
Modified: trunk/extensions/CentralNotice/SpecialBannerLoader.php
===================================================================
--- trunk/extensions/CentralNotice/SpecialBannerLoader.php 2011-06-06
17:02:56 UTC (rev 89582)
+++ trunk/extensions/CentralNotice/SpecialBannerLoader.php 2011-06-06
17:09:37 UTC (rev 89583)
@@ -20,11 +20,12 @@
$wgOut->disable();
$this->sendHeaders();
- // Get user language from the query string
+ // Get values from the query string
$this->language = $wgRequest->getText( 'userlang', 'en' );
-
- // Get site name from the query string
$this->siteName = $wgRequest->getText( 'sitename', 'Wikipedia'
);
+ $this->campaign = $wgRequest->getText( 'campaign', 'unknown' );
+ $this->fundraising = $wgRequest->getBool( 'fundraising', false
);
+ $this->landingPages = $wgRequest->getText( 'landingpages' );
if ( $wgRequest->getText( 'banner' ) ) {
$bannerName = $wgRequest->getText( 'banner' );
@@ -71,7 +72,13 @@
array( $this, 'getNoticeField' ),
$this->getNoticeTemplate()
);
- $bannerArray = array( 'banner' => $bannerHtml );
+ $bannerArray = array(
+ 'bannerName' => $bannerName,
+ 'bannerHtml' => $bannerHtml,
+ 'campaign' => $this->campaign,
+ 'fundraising' => $this->fundraising,
+ 'landingPages' => $this->landingPages
+ );
$bannerJs = 'insertBanner('.FormatJson::encode(
$bannerArray ).');';
return $bannerJs;
}
Modified: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
===================================================================
--- trunk/extensions/CentralNotice/SpecialNoticeTemplate.php 2011-06-06
17:02:56 UTC (rev 89582)
+++ trunk/extensions/CentralNotice/SpecialNoticeTemplate.php 2011-06-06
17:09:37 UTC (rev 89583)
@@ -88,7 +88,9 @@
$newTemplateName,
$newTemplateBody,
$wgRequest->getBool(
'displayAnon' ),
- $wgRequest->getBool(
'displayAccount' )
+ $wgRequest->getBool(
'displayAccount' ),
+ $wgRequest->getBool(
'fundraising' ),
+ $wgRequest->getVal(
'landingPages' )
);
$sub = 'view';
} else {
@@ -102,7 +104,9 @@
$wgRequest->getText( 'template'
),
$wgRequest->getText(
'templateBody' ),
$wgRequest->getBool(
'displayAnon' ),
- $wgRequest->getBool(
'displayAccount' )
+ $wgRequest->getBool(
'displayAccount' ),
+ $wgRequest->getBool(
'fundraising' ),
+ $wgRequest->getVal(
'landingPages' )
);
$sub = 'view';
}
@@ -226,36 +230,58 @@
array( 'method' => 'post', 'onsubmit' => 'return
validateBannerForm(this)' ) );
$htmlOut .= Xml::element( 'h2', null, wfMsg(
'centralnotice-add-template' ) );
$htmlOut .= Html::hidden( 'wpMethod', 'addTemplate' );
+
+ // If there was an error, we'll need to restore the state of
the form
+ if ( $wgRequest->wasPosted() ) {
+ $templateName = $wgRequest->getVal( 'templateName' );
+ $displayAnon = $wgRequest->getCheck( 'displayAnon' );
+ $displayAccount = $wgRequest->getCheck(
'displayAccount' );
+ $fundraising = $wgRequest->getCheck( 'fundraising' );
+ $landingPages = $wgRequest->getVal( 'landingPages' );
+ $body = $wgRequest->getVal( 'templateBody' );
+ } else { // Use default values
+ $templateName = '';
+ $displayAnon = true;
+ $displayAccount = true;
+ $fundraising = false;
+ $landingPages = '';
+ $body = '';
+ }
+
$htmlOut .= Xml::tags( 'p', null,
Xml::inputLabel(
wfMsg( 'centralnotice-banner-name' ),
- 'templateName', 'templateName', 25,
$wgRequest->getVal( 'templateName' )
+ 'templateName', 'templateName', 25,
$templateName
)
);
+ // Display settings
$htmlOut .= Xml::openElement( 'p', null );
$htmlOut .= wfMsg( 'centralnotice-banner-display' );
- if ( $wgRequest->wasPosted() ) {
- // Restore checkbox state in event of error
- $displayAnon = $wgRequest->getCheck( 'displayAnon' );
- } else {
- // Default is checked
- $displayAnon = true;
- }
$htmlOut .= Xml::check( 'displayAnon', $displayAnon, array(
'id' => 'displayAnon' ) );
$htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-anonymous'
), 'displayAnon' );
- if ( $wgRequest->wasPosted() ) {
- // Restore checkbox state in event of error
- $displayAccount = $wgRequest->getCheck(
'displayAccount' );
- } else {
- // Default is checked
- $displayAccount = true;
- }
$htmlOut .= Xml::check( 'displayAccount', $displayAccount,
array( 'id' => 'displayAccount' ) );
$htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-logged-in'
), 'displayAccount' );
$htmlOut .= Xml::closeElement( 'p' );
+ // Fundraising settings
+ $htmlOut .= Xml::openElement( 'p', null );
+ $htmlOut .= Xml::check( 'fundraising', $fundraising, array(
'id' => 'fundraising' ) );
+ $htmlOut .= Xml::label( wfMsg(
'centralnotice-banner-fundraising' ), 'fundraising' );
+ $htmlOut .= Xml::closeElement( 'p' );
+ $htmlOut .= Xml::openElement( 'div', array( 'id' =>
'fundraisingInterface', 'style' => 'display: none;' ) );
+ $htmlOut .= Xml::tags( 'p', array(), wfMsg(
'centralnotice-banner-fundraising-help' ) );
+ $htmlOut .= Xml::tags( 'p', array(),
+ Xml::inputLabel(
+ wfMsg( 'centralnotice-banner-landing-pages' ),
+ 'landingPages', 'landingPages', 40,
$landingPages,
+ array( 'maxlength' => 255 )
+ )
+ );
+ $htmlOut .= Xml::closeElement( 'div' );
+
+ // Begin banner body section
$htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-banner' ) );
$htmlOut .= wfMsg( 'centralnotice-edit-template-summary' );
$buttons = array();
@@ -267,9 +293,6 @@
wfMsg( 'centralnotice-insert',
$wgLang->commaList( $buttons ) )
);
- // Restore banner body state in the event of an error on form
submit
- $body = $wgRequest->getVal( 'templateBody', '' );
-
$htmlOut .= Xml::textarea( 'templateBody', $body, 60, 20 );
$htmlOut .= Xml::closeElement( 'fieldset' );
$htmlOut .= Html::hidden( 'authtoken', $wgUser->editToken() );
@@ -315,7 +338,9 @@
$row = $dbr->selectRow( 'cn_templates',
array(
'tmp_display_anon',
- 'tmp_display_account'
+ 'tmp_display_account',
+ 'tmp_fundraising',
+ 'tmp_landing_pages'
),
array( 'tmp_name' => $currentTemplate ),
__METHOD__
@@ -526,10 +551,15 @@
if ( $wgRequest->wasPosted() && $wgRequest->getVal(
'mainform' ) ) {
$displayAnon = $wgRequest->getCheck(
'displayAnon' );
$displayAccount = $wgRequest->getCheck(
'displayAccount' );
+ $fundraising = $wgRequest->getCheck(
'fundraising' );
+ $landingPages = $wgRequest->getVal(
'landingPages' );
$body = $wgRequest->getVal( 'templateBody',
$body );
- } else { // Defaults
+ } else { // Use previously stored values
$displayAnon = ( $row->tmp_display_anon == 1 );
$displayAccount = ( $row->tmp_display_account
== 1 );
+ $fundraising = ( $row->tmp_fundraising == 1 );
+ $landingPages = $row->tmp_landing_pages;
+ // $body default is defined prior to message
interface code
}
// Show banner settings
@@ -543,6 +573,29 @@
wfArrayMerge( $disabled, array( 'id' =>
'displayAccount' ) ) );
$htmlOut .= Xml::label( wfMsg(
'centralnotice-banner-logged-in' ), 'displayAccount' );
$htmlOut .= Xml::closeElement( 'p' );
+
+ // Fundraising settings
+ $htmlOut .= Xml::openElement( 'p', null );
+ $htmlOut .= Xml::check( 'fundraising', $fundraising,
+ wfArrayMerge( $disabled, array( 'id' =>
'fundraising' ) ) );
+ $htmlOut .= Xml::label( wfMsg(
'centralnotice-banner-fundraising' ), 'fundraising' );
+ $htmlOut .= Xml::closeElement( 'p' );
+ if ( $fundraising ) {
+ $htmlOut .= Xml::openElement( 'div', array(
'id'=>'fundraisingInterface' ) );
+ } else {
+ $htmlOut .= Xml::openElement( 'div', array(
'id'=>'fundraisingInterface', 'style'=>'display:none;' ) );
+ }
+ $htmlOut .= Xml::tags( 'p', array(), wfMsg(
'centralnotice-banner-fundraising-help' ) );
+ $htmlOut .= Xml::tags( 'p', array(),
+ Xml::inputLabel(
+ wfMsg(
'centralnotice-banner-landing-pages' ),
+ 'landingPages', 'landingPages', 40,
$landingPages,
+ array( 'maxlength' => 255 )
+ )
+ );
+ $htmlOut .= Xml::closeElement( 'div' );
+
+ // Begin banner body section
$htmlOut .= Xml::closeElement( 'fieldset' );
if ( $this->editable ) {
$htmlOut .= Xml::fieldset( wfMsg(
'centralnotice-edit-template' ) );
@@ -708,7 +761,7 @@
/**
* Create a new banner
*/
- private function addTemplate( $name, $body, $displayAnon,
$displayAccount ) {
+ private function addTemplate( $name, $body, $displayAnon,
$displayAccount, $fundraising, $landingPages ) {
if ( $body == '' || $name == '' ) {
$this->showError( 'centralnotice-null-string' );
return;
@@ -734,12 +787,14 @@
array(
'tmp_name' => $name,
'tmp_display_anon' => $displayAnon,
- 'tmp_display_account' => $displayAccount
+ 'tmp_display_account' =>
$displayAccount,
+ 'tmp_fundraising' => $fundraising,
+ 'tmp_landing_pages' => $landingPages
),
__METHOD__
);
- // Perhaps these should move into the db as blob
+ // Perhaps these should move into the db as blobs
instead of being stored as articles
$article = new Article(
Title::newFromText(
"centralnotice-template-{$name}", NS_MEDIAWIKI )
);
@@ -751,7 +806,7 @@
/**
* Update a banner
*/
- private function editTemplate( $name, $body, $displayAnon,
$displayAccount ) {
+ private function editTemplate( $name, $body, $displayAnon,
$displayAccount, $fundraising, $landingPages ) {
if ( $body == '' || $name == '' ) {
$this->showError( 'centralnotice-null-string' );
return;
@@ -768,7 +823,9 @@
$res = $dbw->update( 'cn_templates',
array(
'tmp_display_anon' => $displayAnon,
- 'tmp_display_account' => $displayAccount
+ 'tmp_display_account' =>
$displayAccount,
+ 'tmp_fundraising' => $fundraising,
+ 'tmp_landing_pages' => $landingPages
),
array( 'tmp_name' => $name )
);
@@ -801,20 +858,24 @@
$row = $dbr->selectRow( 'cn_templates',
array(
'tmp_display_anon',
- 'tmp_display_account'
+ 'tmp_display_account',
+ 'tmp_fundraising',
+ 'tmp_landing_pages'
),
array( 'tmp_name' => $source ),
__METHOD__
);
$displayAnon = $row->tmp_display_anon;
$displayAccount = $row->tmp_display_account;
+ $fundraising = $row->tmp_fundraising;
+ $landingPages = $row->tmp_landing_pages;
// Pull banner text and respect any inc: markup
$bodyPage = Title::newFromText(
"Centralnotice-template-{$source}", NS_MEDIAWIKI );
$template_body = Revision::newFromTitle( $bodyPage )->getText();
// Create new banner
- if ( $this->addTemplate( $dest, $template_body, $displayAnon,
$displayAccount ) ) {
+ if ( $this->addTemplate( $dest, $template_body, $displayAnon,
$displayAccount, $fundraising, $landingPages ) ) {
// Populate the fields
foreach ( $langs as $lang => $fields ) {
Modified: trunk/extensions/CentralNotice/centralnotice.css
===================================================================
--- trunk/extensions/CentralNotice/centralnotice.css 2011-06-06 17:02:56 UTC
(rev 89582)
+++ trunk/extensions/CentralNotice/centralnotice.css 2011-06-06 17:09:37 UTC
(rev 89583)
@@ -53,6 +53,10 @@
border-style: solid;
border-width: 1px;
}
+#preferences div#fundraisingInterface {
+ margin-left:1.6em;
+ margin-right:1.6em;
+}
/* Vector-specific definitions */
body.skin-vector #preferences fieldset.prefsection {
Modified: trunk/extensions/CentralNotice/centralnotice.js
===================================================================
--- trunk/extensions/CentralNotice/centralnotice.js 2011-06-06 17:02:56 UTC
(rev 89582)
+++ trunk/extensions/CentralNotice/centralnotice.js 2011-06-06 17:09:37 UTC
(rev 89583)
@@ -69,5 +69,12 @@
$("#geoMultiSelector").fadeOut('fast');
}
});
+ $("#fundraising").click(function () {
+ if ($('#fundraising:checked').val() !== undefined) {
+ $("#fundraisingInterface").fadeIn('fast');
+ } else {
+ $("#fundraisingInterface").fadeOut('fast');
+ }
+ });
});
})(jQuery);
Added: trunk/extensions/CentralNotice/patches/patch-template_fundraising.sql
===================================================================
--- trunk/extensions/CentralNotice/patches/patch-template_fundraising.sql
(rev 0)
+++ trunk/extensions/CentralNotice/patches/patch-template_fundraising.sql
2011-06-06 17:09:37 UTC (rev 89583)
@@ -0,0 +1,6 @@
+-- Update to support fundraiser-specific functions for banners
+
+-- Store a flag indicating whether or not this is a fundraising banner
+ALTER TABLE /*$wgDBprefix*/cn_templates ADD `tmp_fundraising` bool NOT NULL
DEFAULT 0;
+-- Store a list of one or more landing pages
+ALTER TABLE /*$wgDBprefix*/cn_templates ADD `tmp_landing_pages` VARCHAR( 255 )
NULL DEFAULT NULL;
\ No newline at end of file
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs