MediaWiki:Geonotice.js

Ka Wikipedia

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
var notices = {

LondonONApril13:
{ begin : '15 April 2013 00:00 UTC',
  end : '25 April 2013 00:00 UTC',
  corners : [ [42.5,-80.75], [43.5,-81.75] ],
  text : "Join one of two Contribution Month in Canada events at London Central Library on 24 and 27 April - [[Wikipedia talk:Contribution Month in Canada#London, Ontario|sign up here]]!"
},

WalsallApril13: 
{
   begin: '16 April 2013 12:00 UTC',
   end: '1 June 2013 12:00 UTC',
   corners:[ [51,-5], [55, 1] ],
   text: "A series of [[Wikipedia:GLAM/NAGW|backstage pass tours and editathons]] will be held at The New Art Gallery, Walsall, throughout May and early June 2013. All welcome, but booking essential!" 
},

DCGWApril13:
{ begin : '16 April 2013 00:00 UTC',
  end : '21 April 2013 00:00 UTC',
  corners : [ [40.2, -74.6], [37.3, -78.3] ],
  text : "On Saturday, April 20, Wikimedia DC is partnering with the George Washington University to host the [[Wikipedia:Meetup/DC/All Things GW|All Things GW editathon]] at the Teamsters Labor History Research Center. Please join us for behind-the-scenes tours of the University Archives and help edit articles about GWU and DC history."
},

UKMeetups20130419: /* last 8 chars of ID is date of last amendment in CCYYMMDD format - change this if making major amendment or adding a meetup; leave alone if minor amendment or removing a meetup */
{
   begin: '18 April 2013 12:00 UTC',
   end: '12 May 2013 15:00 UTC', /* set this to date of last meetup shown */
   corners:[ [60,-9], [50, 2] ],
   text: "Interested in having a chat with fellow Wikipedians? There are forthcoming meetups in: [[m:Meetup/Oxford/4|Oxford, 5 May]]; [[m:Meetup/Glasgow/1|Glasgow, 12 May]]; [[m:Meetup/London/69|London, 12 May]]; and [[m:Meetup/Nottingham/1|Nottingham, 12 May]]!" /* try to limit this to four meetups, no more than one per town/city, and no more than four weeks in advance; shorten month names to three letters if four meetups are shown */
},

BurnleyMay13: 
{
   begin: '10 April 2013 12:00 UTC',
   end: '5 May 2013 00:00 UTC',
   corners:[ [52,-5], [56, 0] ],
   text: "A [[Wikipedia:GLAM/QSMM/event|backstage pass tour and editathon]] will be held at Queen Street Mill Textile Museum, Burnley, Lancashire, on 4 May 2013. All welcome, but booking essential!" 
}

/*******************************************
 *             End of list.
 *           Edit only above!
 *tt
 * Format is:
 *
 * ID:
 * { begin: 'date',
 *   end: 'date',
 *   corners: [ [lat,lon], [lat,lon] ],
 *   text: 'message'
 * }
 *
 * There should be commas between the notices, but not after the last one. BE SURE TO ESCAPE YOUR APOSTROPHES (put a backslash in front of it, like this: \')!
 * Use [[meta:w:en:link|link]] format for internal links, so that they work properly on the other projects where the geonotice is displayed.
 *
 *******************************************/
};

function geoWikiLinker (str, page, text) {
	text = text || page;
	return mw.html.element(
		'a', {
			href: mw.util.getUrl( page ),
			title: page
		}, text
	);
}
 
 
if ( Geo !== undefined ) {
 
  var now = new Date(),
      id, notice, insertsub, minlat, maxlat, minlon, maxlon, firstnotice=true,
      regexForInternalLinks = /\[\[([^{|}\[\]\n]+)(?:\|(.*?))?\]\]/g;
 
  for (id in notices) {
 
    if (!document.cookie.match('hidegeonotice'+id+'=1')) {
 
      notice = notices[id];
      if (!notice || !notice.corners) {
           continue;
      }
      minlat = Math.min(notice.corners[0][0], notice.corners[1][0]);
      maxlat = Math.max(notice.corners[0][0], notice.corners[1][0]);
      minlon = Math.min(notice.corners[0][1], notice.corners[1][1]);
      maxlon = Math.max(notice.corners[0][1], notice.corners[1][1]);
 
      if ( now.getTime() > Date.parse(notice.begin)
           && now.getTime() < Date.parse(notice.end)
           && minlat<Geo.lat && Geo.lat<maxlat
           && minlon<Geo.lon && Geo.lon<maxlon
         ) {
 
        if (firstnotice) {
            firstnotice = false;
            $('#watchlist-message').prepend('<hr>');
            mw.util.addCSS( [
                '#watchlist-message .geonotice {',
                    'width:98%;',
                    'background:transparent;',
                    'text-align:left;',
                    'line-height:1.8em;',
                '}',
                '#watchlist-message .geonotice span {',
                    'font-size:144.5%;',
                '}',
                '#watchlist-message .geonotice small {',
                    'font-style:italic;',
                '}'
            ].join( ' ' ) );
        }
        $('#watchlist-message').prepend(
            '<li class="geonotice plainlinks" id="geonotice'+id+'">'+
                '<span>'+notice.text.replace( regexForInternalLinks, geoWikiLinker )+'</span> '+
                '<small>['+
                    '<a href="#" onClick="'+
                            'var date = new Date();'+
                            'date.setTime(date.getTime()+8640000000);'+
                            'document.cookie = \'hidegeonotice'+id+'=1;'+
                            'expires=\' + date.toGMTString() + \';'+
                            'path=/\';'+
                            'document.getElementById(\'geonotice'+id+'\').style.visibility = \'hidden\';'+
                            'return false;'+
                        '">hide</a>'+
            ']</small></li>');
      }
    }
  }
}