Fundraising 2011/Styleguide/Foundation wiki landing pages

From Meta, a Wikimedia project coordination wiki

This is the 2011FR code for landing pages on wikimediafoundation.org. Although we mainly use donate wiki now, these templates are still around if needed.


Landing pages[edit]

In summary the new setup means that we can copy & paste the exact same code for every language/country combination, and it will automatically pick the correct currency and translations (if they exist). Plus it automatically fills in the landing-page and language parameters for the template. It does all this by using looking at the title of the page it's used on, particularly the parts after the slashes (This means one small restriction: we can't ever use landing page base names that have a slash in them.)

Tip: A really useful page to test landing page code is wmf:Special:ExpandTemplates. You can paste code in here, and then see what it looks like with different page titles.

<div class="{{Donate-direction}}"> ---------------------------------------  Text direction
{{2011FR/lp-layout -------------------------------------------------------  Overall page layout (lp)
| donate-now-title      = -----------{{FRLocalize|2011FR/core-form-title}}  Rightside form title (core)
| masthead              = ------------------------------------------------  Not in use
| appeal-title          = ---------{{FRLocalize|2011FR/core-appeal-title}}  Leftside appeal title (core)
| appeal-text           = -------{{FRLocalize|2011FR/appeal-jimmy-letter}}  Main appeal text (appeal)
| donate-now-content    =
{{2011FR/lp-form-countryspecific ----------------------------------------   Donation Form (lp)
| masthead              = --------------------------------------------none  Not in use
| form-name             = -------------------------TwoStepTwoColumnLetter2  Not in use
| text-template         = -------------------------------2010/JimmyLetterK  Not in use
| gift-amount-text      = ----{{FRLocalize|2011FR/core-form-selectamount}}  Text above ask string (core)
| creditcard-label      = ---------{{FRLocalize|2011FR/core-form-cclabel}}  Credit card button label (core)
| paypal-label          = ---------{{FRLocalize|2011FR/core-form-pplabel}}  Paypal button label (core)
| banktransfer-label    = ------------------------------------------------  Not in use
| monthlydonation-text  = -----{{FRLocalize|2011FR/core-form-monthlylink}}  Do you want to donate monthly text (core)
| other-ways-link       = -------{{FRLocalize|2011FR/core-form-otherways}}  Other ways to give text(core)
| privacy-policy-text   = ------{{FRLocalize|2011FR/core-form-policylink}}  Privacy policy text(core)
| email-option          = -----{{FRLocalize|2011FR/core-form-emailoption}}  Want to be contacted by email text(core)
| amount-type           = ----------------------------------------USDbased  Name of string array (currency)
| donate-currency-codes = -----{{FRLocalize-Country|2011FR/CurrencyCodes}}  Currency codes (currency)
| donate-amount-0       =     1 ------------------------------------------  Ask string value (currency)
| donate-amount-1       =     1 ------------------------------------------  See last link
| donate-amount-2       =     1 ------------------------------------------  See last link
| donate-amount-3       =     1 ------------------------------------------  See last link
| donate-amount-4       =     1 ------------------------------------------  See last link
| donate-amount-5       =     0 ------------------------------------------  See last link
| donate-amount-6       =     0 ------------------------------------------  See last link
| donate-amount-7       =     0 ------------------------------------------  See last link
| donate-amount-8       =     0 ------------------------------------------  See last link
| donate-amount-9       =     0 ------------------------------------------  See last link
| donate-amount-other   = -----{{FRLocalize|2011FR/core-form-otheramount}}  Other option text (core)
| language              = ---------{{lc:{{#titleparts:{{PAGENAME}}|1|2}}}}  Do not change
| landing-page          = {{{alternate-landing|{{urlencode:{{#titleparts:{{PAGENAME}}|1}}|WIKI}} }}} Do not change
| validation-error      = ----------{{FRLocalize|2011FR/validation-error}}  General error message (core)
| validation-error-minimum = -{{FRLocalize|2011FR/core-form-minimumerror}}  Enter more than $xx (core)
}}
}}
</div>

List of landing page layout templates[edit]

This landing page layouts control the colour and font schemes and the page's structure and design and is done with a combination of html elements and css. It is these pages which allow for a wide variety of LP designs.

This template is the standard landing page template and contains the css and the base two column layout for the landing page.
This template is similar to the above except that the donation box floats free of the appeal in a fixed position

List of landing page form templates[edit]

These forms are what actually collect the donations on the landing page and contains significant amounts of html, javascript and jquery functions. Take EXTREME caution when editting these templates directly, major changes should occur in a new template.

This template contains the vast majority of the "donation payment" box. This template has a currency select dropdown.
This template contains the vast majority of the "donation payment" box. This template automatically displays the country currency with no option to change.

Text direction[edit]

Template:2011FR/lp-layout takes the language part of the page name, and returns "rtl" for languages written right-to-left or "ltr" otherwise. This is used in a wrapper div for the whole page, and also passed to the Donate-appeal template for any tweaks needed there.

It is also possible to pass a language code directly, e.g. {{Donate-direction|ar}} returns "rtl".

Appeal templates[edit]

The appeal templates consist of bodies of text typically from an individual asking any potential donor to support the projects. These follow the same localisation structure as the core messages

Complete list of appeal templates

  • Template:2011FR/appeal-jimmy-xxxx/fr/FR

List of donation ask strings[edit]

These templates store the donation ask strings indexed by country code.

Accepted currencies[edit]

This template is the master list for enabled currencies. The "all" is tacked on by wmf:Template:FRLocalize-Country. If a template that has the country code exists that template will be used.

List of constant JavaScript array templates[edit]

These templates, ideally, never change and should not be changed unless you really know what you are doing. They essentially make the code in wmf:Template:2011FR/lp-form-countryspecific and all derivative templates easier to read. Therefore making a bad edit will break those templates.

This template stores the elements of the array "country2currency" from the template wmf:Template:2011FR/lp-form-countryspecific. The purpose of this array is to take the ISO 3166 country code as an index and return the ISO 4217 currency code for that countries official currency.
This template stores the elements of the array "currency2country" from the template wmf:Template:2011FR/lp-form-countryspecific. The purpose of this array is to take the ISO 4217 currency code as an index and return the ISO 3166 country code for the country that uses this currency as its official currency EXCEPT for "USD" and "EUR". For these two currencies the array returns "USD" and "EUR". The reason for this behavior is to have a general, non-country specific behavior for "USD" and "EUR".
This template stores the elements of the array "currencySymbols" from the template wmf:Template:2011FR/lp-form-countryspecific. The purpose of this array is to take the ISO 4217 currency code as an index and return the symbol for that currency.
This template stores the elements of the array "currencyMinimums" from the template wmf:Template:2011FR/lp-form-countryspecific. The purpose of this array is to take the ISO 4217 currency code as an index and return the minimum donation for that currency.
This template stores the elements of the array "currencyPositions" from the template wmf:Template:2011FR/lp-form-countryspecific. The purpose of this array is to take the ISO 4217 currency code as an index and return whether the currency symbol comes before or after the numerical amount EXCEPT FOR the Euro which depends on language. This requires the next template.
This template stores the elements of the array "euroPositions" from the template wmf:Template:2011FR/lp-form-countryspecific. The purpose of this array is to take the ISO 639 language code as an index and return whether the Euro symbol comes before or after the numerical amount.

Social media template[edit]

This template adds some extra hidden content to a page, to be picked up when it's shared on Facebook. Note that this template must be the first thing to appear on a page for it to work, and the "title" parameter will only work on wikis with Manual:$wgRestrictDisplayTitle set to false (wikimediafoundation.org is one of these). Facebook's debugger can be used to test, and force an update of their cache.

{{2011FR/lp-social-media
|title = Title for sharing. Default is "Keep Wikipedia Free".
|description = Description of the link. For some reason this has to be above a certain (undetermined) length or it won't be picked up. Test with the debugger.
|image = Relative URL of image to display, default is "//upload.wikimedia.org/wikipedia/foundation/9/9a/Wikimediafoundation-logo.png"
}}

Python script for building Foundation wiki pages[edit]

Peter C wrote a quick Python script to help set up EN tests, by making all the localised landing pages. You'll need Python and the pywikipedia framework if you don't have them already.

Setup[edit]

  • First install Python 2.7 [1] (Note that Python 3 won't work!)
  • Next get the latest version of the pywikipedia framework from http://tools.wikimedia.de/~valhallasw/pywiki (or if you prefer, you can checkout using svn: http://svn.wikimedia.org/svnroot/pywikipedia/trunk/pywikipedia/)
  • Place the pywikipedia folder in your Python installation's "site-packages" folder. On my setup that's C:\Python27\Lib\site-packages.
  • Place the file "pywikipedia.pth" (source below) in the site-packages folder also (if not using Windows you may need to edit this file to use forward slashes for the path).
  • Place the file "wmfwiki_family.py" in the pywikipedia\families folder (since the default pywikipedia setup doesn't know about wikimediafoundation.org)
  • Create a file "user-config.py" in the main pywikipedia folder.

Use[edit]

You need to edit the script each time, it should be fairly self-explanatory when you look at it. There are 4 variables to change:

  • basetitle: the root title of the landing page e.g. 'L11_JimmyTest/en'. At the moment this includes the language code, until we get the uselang thing sorted properly.
  • editsummary: the edit summary when creating/editing the page.
  • source: the source of the page, the important thing to note is that "$$$" will be replaced with the donate-amounts
  • countries: a list of country codes, each with an array of amounts. Amounts provided are USD conversions. You can edit the list but make sure any extra currencies are actually supported, and watch the commas! You can also comment out countries by putting # at the start of the line.
  • overwrite, which can be set to False if you don't want to overwrite pages that already exist (thanks to Peter G for this suggestion)

Make sure you are bot/flood flagged on wikimediafoundation.org (https://wikimediafoundation.org/wiki/Special:UserRights/Yourusername) and then double click the script to run it.

Sources[edit]

pywikipedia.pth

.\\pywikipedia

wmfwiki_family.py
import family

class Family(family.Family):
    def __init__(self):
        family.Family.__init__(self)
        self.name = 'wmfwiki'
        self.langs = {
            'en': u'wikimediafoundation.org',
        }

        self.namespaces[4] = self.namespaces.get(4, {})
        self.namespaces[4]['en'] = ['Wikimedia']
        self.namespaces[5] = self.namespaces.get(5, {})
        self.namespaces[5]['en'] = ['Wikimedia talk']


    def scriptpath(self, code):
        return {
            'en': u'/w',
        }[code]

    def version(self, code):
        return {
            'en': u'1.18wmf1',
        }[code]
user-config.py
# -*- coding: utf-8  -*-
family = 'wmfwiki'
mylang = 'en'
usernames['wmfwiki']['en'] = u'Pcoombe'
put_throttle = 1

(replace Pcoombe with your username on wikimediafoundation.org)

Script
# -*- coding: utf-8  -*-
import wikipedia
wiki = wikipedia
site = wiki.getSite('en', 'wmfwiki')

basetitle   = 'L11_Example/en'
editsummary = 'Localised landing page for test'
overwrite   = False   # overwrite a page if it already exists? True/False (must be capitalised)

source = """{{2011FR/lp-layout
| donate-now-title      =     {{FRLocalize|2011FR/core-form-title}}
| masthead              =
| appeal-title          =     From Wikipedia researcher Achal Prabhala
| appeal-text           =     {{FRLocalize|2011FR/appeal-achal-2C}}
| donate-now-content    =
{{2011FR/lp-form-EN7amounts
| masthead              =     none
| gift-amount-text      =     {{FRLocalize|2011FR/core-form-selectamount}}
| creditcard-label      =     {{FRLocalize|2011FR/core-form-cclabel}}
| paypal-label          =     {{FRLocalize|2011FR/core-form-pplabel}}
| monthlydonation-text  =
| other-ways-link       =     {{FRLocalize|2011FR/core-form-otherways}}
| privacy-policy-text   =     {{FRLocalize|2011FR/core-form-policylink}}
| email-option          =     {{FRLocalize|2011FR/core-form-emailoption}}
| form-name             =     TwoStepTwoColumnLetter2
| text-template         =     2010/JimmyQuote
| donate-currency          =  {{Donate-currency}}
| donate-currency-symbol   =  {{Donate-currency-symbol|{{Donate-currency}} }}
| currency-pos             =  {{Currency-pos|{{Donate-currency}} }}
| donate-currency-codes =     {{FRLocalize-Country|2011FR/CurrencyCodes}}
$$$
| donate-amount-other   =     {{FRLocalize|2011FR/core-form-otheramount}}
| language              =     {{lc:{{#titleparts:{{PAGENAME}}|1|2}}}}
| landing-page          =     {{{alternate-landing|{{urlencode:{{#titleparts:{{PAGENAME}}|1}}|WIKI}} }}}
| validation-error      =     {{FRLocalize|2011FR/validation-error}}
| validation-error-minimum =  {{FRLocalize|2011FR/core-form-minimumerror}}
}}
}}
"""

## list of countries and amounts. Watch the commas!
countries = {
''    : [5,10,20,35,50,100,250],
##'/US' : [5,10,20,35,50,100,250],
'/CA' : [5,10,20,35,50,100,250],
'/CZ' : [95,185,365,640,910,1850,4550],
'/DK' : [30,55,110,195,275,545,1400],
'/HK' : [40,80,160,275,390,780,1950],
'/HU' : [1100,2200,4350,7550,11000,22000,54000],
'/IL' : [20,40,75,130,185,370,925],
'/JP' : [385,770,1550,2700,3850,7700,19500],
'/NO' : [30,60,115,200,285,570,1450],
'/NZ' : [10,15,30,45,65,130,320],
'/PL' : [20,35,65,115,160,315,790],
'/SE' : [35,70,135,235,335,670,1700],
'/SG' : [10,15,30,50,65,130,325],
'/AT' : [5,10,15,25,40,75,185],
'/BE' : [5,10,15,25,40,75,185],
'/CY' : [5,10,15,25,40,75,185],
'/EE' : [5,10,15,25,40,75,185],
'/ES' : [5,10,15,25,40,75,185],
'/FI' : [5,10,15,25,40,75,185],
'/GR' : [5,10,15,25,40,75,185],
'/IE' : [5,10,15,25,40,75,185],
'/IT' : [5,10,15,25,40,75,185],
'/LU' : [5,10,15,25,40,75,185],
'/MT' : [5,10,15,25,40,75,185],
'/NL' : [5,10,15,25,40,75,185],
'/PT' : [5,10,15,25,40,75,185],
'/SK' : [5,10,15,25,40,75,185],
'/SI' : [5,10,15,25,40,75,185],
'/TR' : [5,10,15,25,40,75,185]
}

def main():
    if source.find("donate-amount-0") != -1:
        wiki.output("Found one or more 'donate-amount' values specified in your source.")
        wiki.output("You should probably use the special string '$$$' instead, and I will insert them automatically")
        ans = wiki.input("If you're sure what you're doing type 'i' to ignore, or anything else to quit.")
        if ans != 'i':
            return
    
    for country, amounts in countries.iteritems():
        newpage = wiki.Page(site, basetitle + country)
        if overwrite == True or newpage.exists() == False:
            amountcontent = ''
            for i, x in enumerate(amounts):
                amountcontent = amountcontent + '| donate-amount-' + str(i) + ' = ' + str(x) + '\n'
            newcontent = source.replace('$$$', amountcontent)
            newpage.put(newcontent, editsummary)
        else:
            wiki.output("Skipped " + newpage.aslink() + ", already exists")

if __name__ == '__main__':
    try:
        main()
    finally:
        wikipedia.stopme()