Extension:CentralNotice

The CentralNotice extension delivers announcements (usually in the form of banners) to Wikimedia wikis. It is used heavily by the Fundraising team to solicit donations, and for announcements of interest to Wikimedia communities and users. CentralNotice can target announcements by country, language, project, device and logged-in status.

This page has information for CentralNotice developers and wiki administrators who want to install CentralNotice on their own sites. To learn how to create and configure CentralNotice campaigns, please see Help:CentralNotice on Meta-Wiki. For information about the CentralNotice setup on the Wikimedia Foundation's cluster, see CentralNotice on Wikitech.

CentralNotice allows central distribution of announcements to many wikis (called subscribing wikis) from a central wiki (the infrastructure wiki). If you only need to post messages to a single wiki, consider using Sitenotice instead.

Installation
Note: CentralNotice is developed, tested, and known to be deployed only on wikis that do not use table prefixing. If your setup uses table prefixing there is no guarantee this extension will work. Please report any bugs to Phabricator.

For all wikis

 * 1) 1>Special:ExtensionDistributor/CentralNotice</>|Download the latest snapshot and extract it to your extensions directory.
 * 2) Add to <tvar|2></> the following: <tvar|3> </>
 * 3) By default, GeoIP lookup is disabled. If the <tvar|4> </> cookie is pre-populated, however, its value will be used. For local development, you can enable a client-side implementation that uses <tvar|url>https://freegeoip.net</> as follows. For more information, see <tvar|geoip>GeoIP_lookup</>.

The infrastructure wiki

 * 1) From the command line, go to the wiki root and run <tvar|1> </>
 * 2) Edit <tvar|2> </> and set ...
 * 3) <tvar|3> </> to true
 * 4) <tvar|4> </> to be an array of projects that will subscribe to the central wiki. For example <tvar|5> </>
 * 5) By default the <tvar|6> </> group is the only group with the ability to administer CentralNotice. If additional groups are needed, assign them the <tvar|7> </> and <tvar|8> </> permissions.

Subscribing wikis
Edit <tvar|1> </> and set...
 * 1) <tvar|20> </> to <tvar|21> </>;
 * 2) <tvar|30> </> to be an entry in <tvar|31> </>;
 * 3) <tvar|40> </> to the protocol (potentially neutral) and domain of the central wiki. For example <tvar|41> </>;
 * 4) <tvar|50> </> to the URL of <tvar|51>Special:BannerLoader</> on the central wiki, for example: <tvar|52> </>;
 * 5) either <tvar|60> </> to the name of the infrastructure wiki's database, or <tvar|70> </> to the API endpoint of the infrastructure wiki; and
 * 6) <tvar|80> </> to the URL of <tvar|81>Special:RecordImpression</> on the central wiki. For example: <tvar|82> </>.

Quick developer setup
For most development tasks, you can use a single wiki in both infrastructure and subscribing roles. Following are sample lines to include in <tvar|1> </>. (See notes in comments.)

All code that runs on subscribing wikis should be smoke-tested with <tvar|1>MobileFrontend</>, to ensure they work on the mobile version of the site.

Dependencies
Some CentralNotice features require other MediaWiki extensions, including <tvar|1>EventLogging</> and <tvar|2>Translate</>.

Getting help
The wikimedia fundraising team are the maintainers of CentralNotice. For questions about installation, bug reports, or usage of CentralNotice please send an email to <tvar|1>[mailto:wikitech-l@lists.wikimedia.org wikitech-l@lists.wikimedia.org]</> or join us on <tvar|2>Freenode</> in channel <tvar|3>#wikimedia-fundraising</>.

Permissions

 * <tvar|10> </> — Permission required to modify campaigns and banners. Relevant only to the infrastructure wikis (see also <tvar|11>26377</>).
 * <tvar|20> </> is required to edit banner content.

Design concepts
From a user facing perspective, the high level CentralNotice objects are <tvar|10>campaigns</> (a.k.a. notices) and <tvar|11>banners</> (a.k.a. templates). These are affected by the back end concepts of <tvar|12>selectors</> and <tvar|13>allocation</>.


 * <tvar|10>Banner</> — a single block of translatable <tvar|11>html/wikitext/css/javascript</> that will display at the top of 12>Manual:$wgContentNamespaces</>| pages. The user status, device type, UI language <tvar|13>selectors</> are applied to banners.
 * Banners may be grouped by <tvar|14>category</>. All banners in a category share user side cookies, such as the hiding cookie that is set when a user clicks a banner close button.


 * <tvar|20>Campaign</> — a collection of banners. The project, country and content language selectors apply at the campaign level. The system allows as many active campaigns at the same time as you want dynamically calculating an <tvar|21>allocation</> for each banner in an active campaign. Campaigns are defined as active if the central wiki time is greater than the campaign start time, less than the campaign end time, and the campaign is marked as enabled.
 * Banners in a campaign are assigned a <tvar|30>bucket</> and <tvar|31>weight</>. Buckets are yet another selector, and weight affects the relative allocation of banners inside a campaign.
 * There are four priority levels in CentralNotice. Higher priority campaigns will get a greater allocation of page views.
 * Campaigns may be locked which will prevent editing and deletion of the campaign; but not the banners inside a campaign.


 * <tvar|40>Selector</> — any property which may be filtered on for the purposes of allocation. This allows, for example, different banners to be shown to logged in versus logged out users in Argentina browsing Wikipedia in English.
 * A selection vector is the complete set of selectors a user presents to the central wiki when requesting a banner.


 * <tvar|50>Allocation</> — The chance a banner will be shown to a user under a given selection vector.

Design documents

 * 1>Extension:CentralNotice/Design Research 2017</>|Design Research Project 2017
 * 2>Extension:CentralNotice/Allocation system</>|Banner allocation algorithm
 * 3>Extension:CentralNotice/Database schema</>|Database schema / table layout

GeoIP lookup
By default, CentralNotice has no client-side GeoIP lookup service configured. This is optimised for the Wikimedia Foundation production configuration where Varnish populates the  cookie from the server-side.

You can configure CentralNotice to use a custom data source client-side through the  configuration variable. This variable expects the name of a ResourceLoader module that exports a function. The function will be called without parameters and should return a Promise that resolves with an object containing the following properties:
 * country: string - Two-letter country code.
 * region: string - Implementation specific.
 * city: string - City name.
 * lat: number.
 * lon: number.

Usage
Full usage instructions can be found at meta:Help:CentralNotice.

New Banner

 * 1) Load Special:CentralNoticeBanners
 * 2) Click on the add banner link at the bottom of the page (must be logged in as an admin).
 * 3) Enter in a name and the raw HTML for the given banner.
 * 4) If this banner is going to be translated then enclose any text to be translated with triple parens -.
 * 5) Submit

(TODO: move and expand this snippet)
 * Each banner has its banner definition stored in MediaWiki:Centralnotice-template-
 * All of its messages are stored below the banner def ala MediaWiki:Centralnotice-template- - /<language_code>

New Campaign

 * 1) Load Special:CentralNotice
 * 2) Add a campaign with a given start time at the bottom portion of the page, leave a comment, and click submit.
 * 3) If this campaign is only run on a specific wiki and or language then select it from the pull downs.
 * 4) Click on the new campaign and add the banners you want within this running campaign and their respective weights.
 * 5) If all looks well then set this campaign to enabled and it will show at the corresponding time.

Overriding selection
Add any of the following URL parameters to preview a specific banner, defeat "diet" schemes, or debug pseudorandom banner selection.


 * banner
 * You can test a banner directly on any wiki by adding  to the end of the URL.


 * randomcampaign
 * A decimal number between 0 and 1, to be used as the "random" seed for choosing a campaign.


 * randombanner
 * A decimal number between 0 and 1, to be used as the "random" seed for choosing a banner among banners available in the chosen campaign.


 * country
 * Override the country code, before filtering to geotargeted campaigns. Accepts two-character ISO 3166-1 codes.


 * uselang
 * Its usual meaning in MediaWiki, this determines which banners you may be shown. Beware of content language vs. user language.


 * force
 * Override any banner hiding code, show the banner.


 * reset
 * Zero out any cookies being used to customize banner display (e.g. delivered impression count).

For example,


 * https://en.wikipedia.org/wiki/Special:Random?banner=B18WMDE_authors_02_180801_2&uselang=en&force=1
 * https://it.wikisource.org/wiki/Speciale:RandomRootpage?randomcampaign=0.142

Limitations
Banners do not display on pages in the  namespace, as well as edit pages and diff pages.

API
CentralNotice adds two API modules,  and. (The API module centralnoticeallocations was deprecated and removed in MediaWiki 1.25.)