r89583 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89582‎ | r89583 | r89584 >
Date:17:09, 6 June 2011
Author:kaldari
Status:resolved (Comments)
Tags:
Comment:
fundraising specific code - mostly for automatic link construction and tracking
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.db.php (modified) (history)
  • /trunk/extensions/CentralNotice/CentralNotice.i18n.php (modified) (history)
  • /trunk/extensions/CentralNotice/CentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialBannerController.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialBannerLoader.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeTemplate.php (modified) (history)
  • /trunk/extensions/CentralNotice/centralnotice.css (modified) (history)
  • /trunk/extensions/CentralNotice/centralnotice.js (modified) (history)
  • /trunk/extensions/CentralNotice/patches/patch-template_fundraising.sql (added) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.php
@@ -39,6 +39,12 @@
4040 // for cached content
4141 $wgCentralNoticeLoader = true;
4242
 43+// Flag for turning on fundraising specific features
 44+$wgNoticeEnableFundraising = true;
 45+
 46+// Base URL for default fundraiser landing page (without query string)
 47+$wgNoticeFundraisingUrl = 'http://wikimediafoundation.org/wiki/Special:LandingCheck';
 48+
4349 // Source for live counter information
4450 $wgNoticeCounterSource = 'http://wikimediafoundation.org/wiki/Special:ContributionTotal?action=raw';
4551
@@ -122,6 +128,8 @@
123129 $base . '/patches/patch-notice_languages.sql' );
124130 $wgExtNewFields[] = array( 'cn_templates', 'tmp_display_anon',
125131 $base . '/patches/patch-template_settings.sql' );
 132+ $wgExtNewFields[] = array( 'cn_templates', 'tmp_fundraising',
 133+ $base . '/patches/patch-template_fundraising.sql' );
126134 $wgExtNewTables[] = array( 'cn_notice_countries',
127135 $base . '/patches/patch-notice_countries.sql' );
128136 $wgExtNewTables[] = array( 'cn_notice_projects',
@@ -137,6 +145,8 @@
138146 $base . '/patches/patch-notice_languages.sql', true ) );
139147 $updater->addExtensionUpdate( array( 'addField', 'cn_templates', 'tmp_display_anon',
140148 $base . '/patches/patch-template_settings.sql', true ) );
 149+ $updater->addExtensionUpdate( array( 'addField', 'cn_templates', 'tmp_fundraising',
 150+ $base . '/patches/patch-template_fundraising.sql', true ) );
141151 $updater->addExtensionUpdate( array( 'addTable', 'cn_notice_countries',
142152 $base . '/patches/patch-notice_countries.sql', true ) );
143153 $updater->addExtensionUpdate( array( 'addTable', 'cn_notice_projects',
Index: trunk/extensions/CentralNotice/centralnotice.css
@@ -53,6 +53,10 @@
5454 border-style: solid;
5555 border-width: 1px;
5656 }
 57+#preferences div#fundraisingInterface {
 58+ margin-left:1.6em;
 59+ margin-right:1.6em;
 60+}
5761
5862 /* Vector-specific definitions */
5963 body.skin-vector #preferences fieldset.prefsection {
Index: trunk/extensions/CentralNotice/SpecialBannerLoader.php
@@ -20,11 +20,12 @@
2121 $wgOut->disable();
2222 $this->sendHeaders();
2323
24 - // Get user language from the query string
 24+ // Get values from the query string
2525 $this->language = $wgRequest->getText( 'userlang', 'en' );
26 -
27 - // Get site name from the query string
2826 $this->siteName = $wgRequest->getText( 'sitename', 'Wikipedia' );
 27+ $this->campaign = $wgRequest->getText( 'campaign', 'unknown' );
 28+ $this->fundraising = $wgRequest->getBool( 'fundraising', false );
 29+ $this->landingPages = $wgRequest->getText( 'landingpages' );
2930
3031 if ( $wgRequest->getText( 'banner' ) ) {
3132 $bannerName = $wgRequest->getText( 'banner' );
@@ -71,7 +72,13 @@
7273 array( $this, 'getNoticeField' ),
7374 $this->getNoticeTemplate()
7475 );
75 - $bannerArray = array( 'banner' => $bannerHtml );
 76+ $bannerArray = array(
 77+ 'bannerName' => $bannerName,
 78+ 'bannerHtml' => $bannerHtml,
 79+ 'campaign' => $this->campaign,
 80+ 'fundraising' => $this->fundraising,
 81+ 'landingPages' => $this->landingPages
 82+ );
7683 $bannerJs = 'insertBanner('.FormatJson::encode( $bannerArray ).');';
7784 return $bannerJs;
7885 }
Index: trunk/extensions/CentralNotice/patches/patch-template_fundraising.sql
@@ -0,0 +1,6 @@
 2+-- Update to support fundraiser-specific functions for banners
 3+
 4+-- Store a flag indicating whether or not this is a fundraising banner
 5+ALTER TABLE /*$wgDBprefix*/cn_templates ADD `tmp_fundraising` bool NOT NULL DEFAULT 0;
 6+-- Store a list of one or more landing pages
 7+ALTER TABLE /*$wgDBprefix*/cn_templates ADD `tmp_landing_pages` VARCHAR( 255 ) NULL DEFAULT NULL;
\ No newline at end of file
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php
@@ -127,6 +127,9 @@
128128 'centralnotice-banner-type' => 'Banner type:',
129129 'centralnotice-banner-hidable' => 'Static/Hidable',
130130 'centralnotice-banner-collapsible' => 'Collapsible',
 131+ 'centralnotice-banner-fundraising' => 'This is a fundraising banner',
 132+ '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.',
 133+ 'centralnotice-banner-landing-pages' => 'Landing pages (comma-separated):',
131134 'centralnotice-geotargeted' => 'Geotargeted',
132135 'centralnotice-countries' => 'Countries',
133136 'centralnotice-allocation' => 'Allocation',
Index: trunk/extensions/CentralNotice/SpecialBannerController.php
@@ -43,7 +43,7 @@
4444 * In order to circumvent the normal squid cache override we add '/cn.js' to the bannerlist URL.
4545 */
4646 function getOutput() {
47 - global $wgCentralPagePath, $wgContLang;
 47+ global $wgCentralPagePath, $wgNoticeFundraisingUrl, $wgContLang;
4848
4949 $js = $this->getScriptFunctions() . $this->getToggleScripts();
5050 $js .= <<<JAVASCRIPT
@@ -54,11 +54,13 @@
5555 'getVars': {}
5656 },
5757 'fn': {
58 - 'loadBanner': function( bannerName ) {
 58+ 'loadBanner': function( bannerName, fundraising, landingPages, campaign ) {
5959 // Get the requested banner
6060 var bannerPageQuery = $.param( {
61 - 'banner': bannerName, 'userlang': wgUserLanguage,
62 - 'db': wgDBname, 'sitename': wgSiteName, 'country': Geo.country } );
 61+ 'banner': bannerName, 'campaign': campaign, 'userlang': wgUserLanguage,
 62+ 'db': wgDBname, 'sitename': wgSiteName, 'country': Geo.country,
 63+ 'fundraising': fundraising, 'landingpages': landingPages
 64+ } );
6365 var bannerPage = '?title=Special:BannerLoader&' + bannerPageQuery;
6466 JAVASCRIPT;
6567 $js .= "\n\t\t\t\tvar bannerScript = '<script type=\"text/javascript\" src=\"" .
@@ -111,11 +113,15 @@
112114 // Return if there's nothing left after the grooming
113115 if( groomedBannerList.length == 0 ) return false;
114116
 117+ // Choose a random key
 118+ var pointer = Math.floor( Math.random() * groomedBannerList.length );
 119+
115120 // Load a random banner from our groomed list
116121 $.centralNotice.fn.loadBanner(
117 - groomedBannerList[
118 - Math.floor( Math.random() * groomedBannerList.length )
119 - ].name
 122+ groomedBannerList[pointer].name,
 123+ groomedBannerList[pointer].fundraising,
 124+ groomedBannerList[pointer].landing_pages,
 125+ groomedBannerList[pointer].campaign
120126 );
121127 },
122128 'getQueryStringVariables': function() {
@@ -151,9 +157,29 @@
152158 }
153159
154160 function getScriptFunctions() {
 161+ global $wgNoticeFundraisingUrl;
155162 $script = <<<JAVASCRIPT
156163 function insertBanner(bannerJson) {
157 - jQuery('div#centralNotice').prepend( bannerJson.banner );
 164+ jQuery( 'div#centralNotice' ).prepend( bannerJson.bannerHtml );
 165+ if ( bannerJson.fundraising ) {
 166+JAVASCRIPT;
 167+ $script .= "\n\t\tvar url = '" .
 168+ Xml::escapeJsString( $wgNoticeFundraisingUrl ) . "';";
 169+ $script .= <<<JAVASCRIPT
 170+ console.debug(bannerJson.landingPages.length);
 171+ if ( bannerJson.landingPages.length ) {
 172+ targets = String( bannerJson.landingPages ).split(',');
 173+ url += "?" + jQuery.param( {
 174+ 'landing_page': targets[Math.floor( Math.random() * targets.length )].replace( /^\s+|\s+$/, '' )
 175+ } );
 176+ url += "&" + jQuery.param( {
 177+ 'utm_medium': 'sitenotice', 'utm_campaign': bannerJson.campaign,
 178+ 'utm_source': bannerJson.bannerName, 'language': wgUserLanguage,
 179+ 'country': Geo.country
 180+ } );
 181+ jQuery( '#cn_fundraising_link' ).attr( 'href', url );
 182+ }
 183+ }
158184 }
159185 function toggleNotice() {
160186 var notice = document.getElementById('centralNotice');
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
@@ -88,7 +88,9 @@
8989 $newTemplateName,
9090 $newTemplateBody,
9191 $wgRequest->getBool( 'displayAnon' ),
92 - $wgRequest->getBool( 'displayAccount' )
 92+ $wgRequest->getBool( 'displayAccount' ),
 93+ $wgRequest->getBool( 'fundraising' ),
 94+ $wgRequest->getVal( 'landingPages' )
9395 );
9496 $sub = 'view';
9597 } else {
@@ -102,7 +104,9 @@
103105 $wgRequest->getText( 'template' ),
104106 $wgRequest->getText( 'templateBody' ),
105107 $wgRequest->getBool( 'displayAnon' ),
106 - $wgRequest->getBool( 'displayAccount' )
 108+ $wgRequest->getBool( 'displayAccount' ),
 109+ $wgRequest->getBool( 'fundraising' ),
 110+ $wgRequest->getVal( 'landingPages' )
107111 );
108112 $sub = 'view';
109113 }
@@ -226,36 +230,58 @@
227231 array( 'method' => 'post', 'onsubmit' => 'return validateBannerForm(this)' ) );
228232 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-add-template' ) );
229233 $htmlOut .= Html::hidden( 'wpMethod', 'addTemplate' );
 234+
 235+ // If there was an error, we'll need to restore the state of the form
 236+ if ( $wgRequest->wasPosted() ) {
 237+ $templateName = $wgRequest->getVal( 'templateName' );
 238+ $displayAnon = $wgRequest->getCheck( 'displayAnon' );
 239+ $displayAccount = $wgRequest->getCheck( 'displayAccount' );
 240+ $fundraising = $wgRequest->getCheck( 'fundraising' );
 241+ $landingPages = $wgRequest->getVal( 'landingPages' );
 242+ $body = $wgRequest->getVal( 'templateBody' );
 243+ } else { // Use default values
 244+ $templateName = '';
 245+ $displayAnon = true;
 246+ $displayAccount = true;
 247+ $fundraising = false;
 248+ $landingPages = '';
 249+ $body = '';
 250+ }
 251+
230252 $htmlOut .= Xml::tags( 'p', null,
231253 Xml::inputLabel(
232254 wfMsg( 'centralnotice-banner-name' ),
233 - 'templateName', 'templateName', 25, $wgRequest->getVal( 'templateName' )
 255+ 'templateName', 'templateName', 25, $templateName
234256 )
235257 );
236258
 259+ // Display settings
237260 $htmlOut .= Xml::openElement( 'p', null );
238261 $htmlOut .= wfMsg( 'centralnotice-banner-display' );
239 - if ( $wgRequest->wasPosted() ) {
240 - // Restore checkbox state in event of error
241 - $displayAnon = $wgRequest->getCheck( 'displayAnon' );
242 - } else {
243 - // Default is checked
244 - $displayAnon = true;
245 - }
246262 $htmlOut .= Xml::check( 'displayAnon', $displayAnon, array( 'id' => 'displayAnon' ) );
247263 $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-anonymous' ), 'displayAnon' );
248 - if ( $wgRequest->wasPosted() ) {
249 - // Restore checkbox state in event of error
250 - $displayAccount = $wgRequest->getCheck( 'displayAccount' );
251 - } else {
252 - // Default is checked
253 - $displayAccount = true;
254 - }
255264 $htmlOut .= Xml::check( 'displayAccount', $displayAccount,
256265 array( 'id' => 'displayAccount' ) );
257266 $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-logged-in' ), 'displayAccount' );
258267 $htmlOut .= Xml::closeElement( 'p' );
259268
 269+ // Fundraising settings
 270+ $htmlOut .= Xml::openElement( 'p', null );
 271+ $htmlOut .= Xml::check( 'fundraising', $fundraising, array( 'id' => 'fundraising' ) );
 272+ $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-fundraising' ), 'fundraising' );
 273+ $htmlOut .= Xml::closeElement( 'p' );
 274+ $htmlOut .= Xml::openElement( 'div', array( 'id' => 'fundraisingInterface', 'style' => 'display: none;' ) );
 275+ $htmlOut .= Xml::tags( 'p', array(), wfMsg( 'centralnotice-banner-fundraising-help' ) );
 276+ $htmlOut .= Xml::tags( 'p', array(),
 277+ Xml::inputLabel(
 278+ wfMsg( 'centralnotice-banner-landing-pages' ),
 279+ 'landingPages', 'landingPages', 40, $landingPages,
 280+ array( 'maxlength' => 255 )
 281+ )
 282+ );
 283+ $htmlOut .= Xml::closeElement( 'div' );
 284+
 285+ // Begin banner body section
260286 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-banner' ) );
261287 $htmlOut .= wfMsg( 'centralnotice-edit-template-summary' );
262288 $buttons = array();
@@ -267,9 +293,6 @@
268294 wfMsg( 'centralnotice-insert', $wgLang->commaList( $buttons ) )
269295 );
270296
271 - // Restore banner body state in the event of an error on form submit
272 - $body = $wgRequest->getVal( 'templateBody', '' );
273 -
274297 $htmlOut .= Xml::textarea( 'templateBody', $body, 60, 20 );
275298 $htmlOut .= Xml::closeElement( 'fieldset' );
276299 $htmlOut .= Html::hidden( 'authtoken', $wgUser->editToken() );
@@ -315,7 +338,9 @@
316339 $row = $dbr->selectRow( 'cn_templates',
317340 array(
318341 'tmp_display_anon',
319 - 'tmp_display_account'
 342+ 'tmp_display_account',
 343+ 'tmp_fundraising',
 344+ 'tmp_landing_pages'
320345 ),
321346 array( 'tmp_name' => $currentTemplate ),
322347 __METHOD__
@@ -526,10 +551,15 @@
527552 if ( $wgRequest->wasPosted() && $wgRequest->getVal( 'mainform' ) ) {
528553 $displayAnon = $wgRequest->getCheck( 'displayAnon' );
529554 $displayAccount = $wgRequest->getCheck( 'displayAccount' );
 555+ $fundraising = $wgRequest->getCheck( 'fundraising' );
 556+ $landingPages = $wgRequest->getVal( 'landingPages' );
530557 $body = $wgRequest->getVal( 'templateBody', $body );
531 - } else { // Defaults
 558+ } else { // Use previously stored values
532559 $displayAnon = ( $row->tmp_display_anon == 1 );
533560 $displayAccount = ( $row->tmp_display_account == 1 );
 561+ $fundraising = ( $row->tmp_fundraising == 1 );
 562+ $landingPages = $row->tmp_landing_pages;
 563+ // $body default is defined prior to message interface code
534564 }
535565
536566 // Show banner settings
@@ -543,6 +573,29 @@
544574 wfArrayMerge( $disabled, array( 'id' => 'displayAccount' ) ) );
545575 $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-logged-in' ), 'displayAccount' );
546576 $htmlOut .= Xml::closeElement( 'p' );
 577+
 578+ // Fundraising settings
 579+ $htmlOut .= Xml::openElement( 'p', null );
 580+ $htmlOut .= Xml::check( 'fundraising', $fundraising,
 581+ wfArrayMerge( $disabled, array( 'id' => 'fundraising' ) ) );
 582+ $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-fundraising' ), 'fundraising' );
 583+ $htmlOut .= Xml::closeElement( 'p' );
 584+ if ( $fundraising ) {
 585+ $htmlOut .= Xml::openElement( 'div', array( 'id'=>'fundraisingInterface' ) );
 586+ } else {
 587+ $htmlOut .= Xml::openElement( 'div', array( 'id'=>'fundraisingInterface', 'style'=>'display:none;' ) );
 588+ }
 589+ $htmlOut .= Xml::tags( 'p', array(), wfMsg( 'centralnotice-banner-fundraising-help' ) );
 590+ $htmlOut .= Xml::tags( 'p', array(),
 591+ Xml::inputLabel(
 592+ wfMsg( 'centralnotice-banner-landing-pages' ),
 593+ 'landingPages', 'landingPages', 40, $landingPages,
 594+ array( 'maxlength' => 255 )
 595+ )
 596+ );
 597+ $htmlOut .= Xml::closeElement( 'div' );
 598+
 599+ // Begin banner body section
547600 $htmlOut .= Xml::closeElement( 'fieldset' );
548601 if ( $this->editable ) {
549602 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-edit-template' ) );
@@ -708,7 +761,7 @@
709762 /**
710763 * Create a new banner
711764 */
712 - private function addTemplate( $name, $body, $displayAnon, $displayAccount ) {
 765+ private function addTemplate( $name, $body, $displayAnon, $displayAccount, $fundraising, $landingPages ) {
713766 if ( $body == '' || $name == '' ) {
714767 $this->showError( 'centralnotice-null-string' );
715768 return;
@@ -734,12 +787,14 @@
735788 array(
736789 'tmp_name' => $name,
737790 'tmp_display_anon' => $displayAnon,
738 - 'tmp_display_account' => $displayAccount
 791+ 'tmp_display_account' => $displayAccount,
 792+ 'tmp_fundraising' => $fundraising,
 793+ 'tmp_landing_pages' => $landingPages
739794 ),
740795 __METHOD__
741796 );
742797
743 - // Perhaps these should move into the db as blob
 798+ // Perhaps these should move into the db as blobs instead of being stored as articles
744799 $article = new Article(
745800 Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI )
746801 );
@@ -751,7 +806,7 @@
752807 /**
753808 * Update a banner
754809 */
755 - private function editTemplate( $name, $body, $displayAnon, $displayAccount ) {
 810+ private function editTemplate( $name, $body, $displayAnon, $displayAccount, $fundraising, $landingPages ) {
756811 if ( $body == '' || $name == '' ) {
757812 $this->showError( 'centralnotice-null-string' );
758813 return;
@@ -768,7 +823,9 @@
769824 $res = $dbw->update( 'cn_templates',
770825 array(
771826 'tmp_display_anon' => $displayAnon,
772 - 'tmp_display_account' => $displayAccount
 827+ 'tmp_display_account' => $displayAccount,
 828+ 'tmp_fundraising' => $fundraising,
 829+ 'tmp_landing_pages' => $landingPages
773830 ),
774831 array( 'tmp_name' => $name )
775832 );
@@ -801,20 +858,24 @@
802859 $row = $dbr->selectRow( 'cn_templates',
803860 array(
804861 'tmp_display_anon',
805 - 'tmp_display_account'
 862+ 'tmp_display_account',
 863+ 'tmp_fundraising',
 864+ 'tmp_landing_pages'
806865 ),
807866 array( 'tmp_name' => $source ),
808867 __METHOD__
809868 );
810869 $displayAnon = $row->tmp_display_anon;
811870 $displayAccount = $row->tmp_display_account;
 871+ $fundraising = $row->tmp_fundraising;
 872+ $landingPages = $row->tmp_landing_pages;
812873
813874 // Pull banner text and respect any inc: markup
814875 $bodyPage = Title::newFromText( "Centralnotice-template-{$source}", NS_MEDIAWIKI );
815876 $template_body = Revision::newFromTitle( $bodyPage )->getText();
816877
817878 // Create new banner
818 - if ( $this->addTemplate( $dest, $template_body, $displayAnon, $displayAccount ) ) {
 879+ if ( $this->addTemplate( $dest, $template_body, $displayAnon, $displayAccount, $fundraising, $landingPages ) ) {
819880
820881 // Populate the fields
821882 foreach ( $langs as $lang => $fields ) {
Index: trunk/extensions/CentralNotice/CentralNotice.db.php
@@ -143,7 +143,9 @@
144144 'tmp_name',
145145 'tmp_weight',
146146 'tmp_display_anon',
147 - 'tmp_display_account'
 147+ 'tmp_display_account',
 148+ 'tmp_fundraising',
 149+ 'tmp_landing_pages'
148150 ),
149151 array(
150152 'cn_notices.not_id' => $campaignId,
@@ -159,7 +161,9 @@
160162 'weight' => intval( $row->tmp_weight ),
161163 'display_anon' => intval( $row->tmp_display_anon ),
162164 'display_account' => intval( $row->tmp_display_account ),
163 - 'campaign' => CentralNotice::getNoticeName( $campaignId ),
 165+ 'fundraising' => intval( $row->tmp_fundraising ),
 166+ 'landing_pages' => $row->tmp_landing_pages,
 167+ 'campaign' => CentralNotice::getNoticeName( $campaignId )
164168 );
165169 }
166170 }
Index: trunk/extensions/CentralNotice/centralnotice.js
@@ -69,5 +69,12 @@
7070 $("#geoMultiSelector").fadeOut('fast');
7171 }
7272 });
 73+ $("#fundraising").click(function () {
 74+ if ($('#fundraising:checked').val() !== undefined) {
 75+ $("#fundraisingInterface").fadeIn('fast');
 76+ } else {
 77+ $("#fundraisingInterface").fadeOut('fast');
 78+ }
 79+ });
7380 });
7481 })(jQuery);

Follow-up revisions

RevisionCommit summaryAuthorDate
r90680making fundraising interface dependant on wgNoticeEnableFundraising global varkaldari22:18, 23 June 2011
r90892removing debugging call, follow-up to r89583kaldari17:44, 27 June 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   17:47, 27 June 2011

Only problem that stood out on the PHP/JS interface was the stray console.debug; has been removed in r90892. Renamed component of banner JSON data looks like it should be fine as long as code & data go out together.

Status & tagging log