Commit cc79d0d3 authored by Dave Lane's avatar Dave Lane
Browse files

interim working internationalised date for WEnotes feed and Posting

parent b78339a2
......@@ -5,3 +5,5 @@ WEnotesClient.js: WEnotes.js node_modules/faye/browser/faye-browser.js
/bin/cat node_modules/timeago/jquery.timeago.js node_modules/faye/browser/faye-browser.js \
WEnotes.js > WEnotesClient.js
clean:
rm WEnotes-min.js && mv WEnotesClient.js WEnotesClient.js-prev
......@@ -4,13 +4,15 @@ WEnotes
WEnotes consists of several parts:
* harvesting tools for:
* ASKBOT (special RSS feed)
* ASKBOT (special RSS feed) (defunct)
* blogs (db table of RSS feeds)
* g+
* g+ (defunct)
* [GroupServer](http://groupserver.org/) mailing lists (special RSS feed) (defunct)
* identica (defunct)
* Moodle instances (special RSS feed)
* Twitter
* [GroupServer](http://groupserver.org/) mailing lists (special RSS feed)
* various Mastodon instances
* various Discourse instances
* a Mediawiki extension
* verifies user is logged in
......
This diff is collapsed.
......@@ -50,7 +50,6 @@ if ( !Date.prototype.toISOString ) {
// variables made public to simplify debugging/monitoring
var wendivs = [];
var wenlang = 'en_EN'; // set language to default...
var WEnotes = {};
var protocol = window.location.protocol + '//';
// hard coded locations of things
......@@ -163,8 +162,7 @@ var msg_counter = [];
forums: 'https://forums.oeru.org/users/',
community: 'https://community.oeru.org/users/',
saylordiscourse: 'https://discourse.saylor.org/users/',
connectoeglobal: 'https://connect.oeglobal.org/users/',
'g+': '#'
connectoeglobal: 'https://connect.oeglobal.org/users/'
};
var sourceTag = {
bookmarks: 'https://bookmarks.oeru.org/tags.php/',
......@@ -173,8 +171,7 @@ var msg_counter = [];
mastodon: 'https://mastodon.oeru.org/web/timelines/tag/',
twitter: 'https://twitter.com/#!/search?q=%23',
wikieducator: protocol + 'WikiEducator.org/',
connectoeglobal: 'https://connect.oeglobal.org/users/',
'g+': 'https://plus.google.com/s/%23'
connectoeglobal: 'https://connect.oeglobal.org/users/'
};
// fix changed source tags...
var source = d.we_source;
......@@ -239,18 +236,6 @@ var msg_counter = [];
console.log('profileURL = ' + JSON.stringify(profileURL));
console.log('(mastodon) tag, we_tags, we_tag = ' + tag + ', ' + d.we_tags + ', ' + d.we_tag);
break;
case 'g+':
timeLink = d.url;
text = d.title;
profileURL = d.actor.url;
profileIMG = d.actor.image.url;
userFullname = d.actor.displayName;
user = '';
userName = userFullname;
// old versions of IE don't understand ISO date format
var dp = d.published.split(/[-T.Z]/);
d.created_at = [dp[2], months[dp[1]-1], dp[0], ''].join(' ') + dp[3] + ' +0000';
break;
case 'feed':
timeLink = d.we_link;
break;
......@@ -348,7 +333,6 @@ var msg_counter = [];
case 'identica':
case 'bookmarks':
case 'hypothesis':
case 'g+':
case 'medium':
text = text.replace(/\.\.\.$/, '<a href="' + timeLink + '">...</a>');
break;
......@@ -425,10 +409,15 @@ var msg_counter = [];
}
msg += '<br />';
msg += text;
var dt = new Date(d.created_at);
var dt_ago = '<abbr class="timeago" title="' + dt.toISOString() + '">' +
dt.getUTCDate() + ' ' + months[dt.getUTCMonth()] + '</abbr>';
var lang = getLang();
//var dt = new Date(d.created_at);
//console.log('in flow, got lang '+lang);
var created_date = getDate(d.created_at, lang);
console.log('created date is '+ created_date);
var dt_ago = '<abbr class="timeago" title="' + created_date + '">'+created_date+'</abbr>';
msg += '<br /><span class="WEnotesub">';
console.log('.... dt_ago = '+dt_ago);
if (tag === '_') {
if (d.we_tags) {
//console.log('%%% type = ' + d.we_source + ' num tags = ' + d.we_tags.length);
......@@ -472,23 +461,11 @@ var msg_counter = [];
msg += d.we_source;
}
msg += '&nbsp;&nbsp;&nbsp;<a href="' + timeLink +
'" title="' + dt.toUTCString() + '" style="text-decoration: none;" target="_wenotes">' +
'" title="' + created_date + '" style="text-decoration: none;" target="_wenotes">' +
dt_ago + '</a>';
if (!novoting && wgUserName) {
msg += '&nbsp;&nbsp;&nbsp;<i title="favorite" class="icon-star-empty"></i>';
}
switch (source) {
case 'twitter':
// if the message is too old, don't show the conversation links
if (((new Date().getTime() - dt.getTime())/86400000) > 5.0) {
break;
}
// fall through to show links
case 'g+':
msg += '&nbsp;&nbsp;&nbsp;<i title="reply" class="icon-mail-reply"></i>';
msg += '&nbsp;&nbsp;&nbsp;<i title="thread" class="icon-th-list"></i>';
break;
}
msg += '&nbsp;<span class="wevtct"></span>';
// add the "sysop-only" links to view the mention in the db, or delete it
if ($.inArray('sysop', window.wgUserGroups) > -1) {
......@@ -518,6 +495,35 @@ var msg_counter = [];
return optionList.join('&');
}
// find the current language setting, if any. Otherwise, return en_EN...
function getLang() {
console.log('in getLang');
var wenlang = 'en_EN';
$('div.WEnotes').each(function() {
var $details = $(this).attr('class').split(/\s+/);
$.each($details, function(i, v) {
if (v.indexOf('WEnotes-') === 0) {
console.log('+++++ v = ', v);
var args = v.split('-');
console.log('+++++ args = '+JSON.stringify(args));
if (args.length > 3) {
wenlang = (args[3] !== '') ? args[3] : 'en_NZ';
console.log('found lang = '+wenlang);
}
}
});
});
return wenlang;
}
function getDate(date, lang) {
var dt = new Date(date); // create date object
lang = (typeof lang !== 'undefined') ? lang.replace('_','-') : 'en-EN';
console.log('in getDate, lang is '+lang);
const options = {weekday: 'short', year: 'numeric', month: 'short', day: 'numeric'};
return dt.toLocaleDateString(lang, options);
}
function getMore(event) {
//console.log('in getMore');
var options, url;
......@@ -525,11 +531,8 @@ var msg_counter = [];
tag = wendivs[ix].tag,
taglc = tag.toLowerCase(),
count = wendivs[ix].moreCount + 1,
language = wendivs[ix].language,
$wenm = $('#WEnotesMore' + ix),
$wenmdi = $('#WEnotesMoreDiv' + ix + ' img');
wenlang = language;
console.log('setting wenlang = '+language);
$wenmdi.show();
$wenm.hide();
if (tag === '_') {
......@@ -540,8 +543,7 @@ var msg_counter = [];
endkey: '"2011-01-01T00:00:00.000Z"',
descending: true,
include_docs: true,
limit: count,
language: language
limit: count
};
} else {
url = couchURL;
......@@ -551,14 +553,10 @@ var msg_counter = [];
endkey: '["' + taglc + '", "2011-01-01T00:00:00.000Z"]',
descending: true,
include_docs: true,
limit: count,
language: language
limit: count
};
}
//console.log("url1 = " + url);
//console.log("options = " + options);
$.ajax({
url: url + makeCouchqs(options),
cache: false,
......@@ -579,6 +577,8 @@ var msg_counter = [];
$(mid).hide();
return;
}
var lang = getLang();
console.log('in CouchReturn, got lang '+lang);
for (i=1; i < rows.length; i++) {
d = rows[i].doc;
if (d.we_timestamp > wendivs[ix].last) {
......@@ -660,8 +660,8 @@ var msg_counter = [];
.triggerHandler('WEnotes', [dx.tag]);}, refreshtime);
},
success: function(data) {
console.log("data = " + JSON.stringify(data));
console.log('current setting for wenlang '+ wenlang);
//console.log("data = " + JSON.stringify(data));
//console.log('current setting for wenlang '+ wenlang);
var i;
var lid = '.WEnotes';
var rows = data.rows;
......@@ -674,8 +674,8 @@ var msg_counter = [];
}
if (!dx.nomore && (data.total_rows - data.offset > rows.length)) {
wendivs[ix].nomore = true;
console.log('language for wendivs '+ix+' is ', data.language);
if (wenlang == 'fr_FR') {
//console.log('language for wendivs '+ix+' is ', data.language);
if (getLang() == 'fr_FR') {
button_text = "Des notes plus " + tag;
if (tag === '_') {
button_text = "Plus de notes";
......@@ -847,7 +847,7 @@ var msg_counter = [];
// in the example above, 20 is the 'count' of messages to show,
// and lida101 is the tag, lida is the 'context', and fr_FR is the language
$.each(classes, function(i, v) {
console.log('==== v = ', v);
//console.log('==== v = ', v);
if (v.indexOf('WEnotes-') === 0) {
var tag;
var args = v.split('-', 5);
......@@ -858,15 +858,15 @@ var msg_counter = [];
$d: $thisd,
count: args[1], // how many of this to show
tag: tag, // from which tag
context: args[3],
context: args[3],
language: args[4],
last: '2011-01-01T00:00:00.000Z',
first: '2999-12-31T23:59:59.999Z',
moreCount: 20 // how many more to show if the user clicks "show more"
});
wenlang = args[4];
console.log('wenlang for WEnote: '+wenlang);
wenlang = args[4];
console.log('wenlang for WEnote: '+wenlang);
// actually subscribe to the Faye services for the relevant combo
combo = '/WEnotes/' + ((tag === '_') ? '*' : tag.toLowerCase());
console.log('combo = ', combo);
......
......@@ -168,6 +168,13 @@ class APIWEnotes extends ApiQueryBase {
$result = $this->getResult();
$result->addValue('post', $this->getModuleName(), true);
// pass through the language value
if (isset($params['wenlang'])) {
error_log('setting value for wenlang '.$params['wenlang']);
$result->addValue('wenlang', $params['wenlang'], true);
} else {
error_log('no value for wenlang...');
}
}
}
......
......@@ -2440,7 +2440,6 @@ if ( !Date.prototype.toISOString ) {
// variables made public to simplify debugging/monitoring
var wendivs = [];
var wenlang = 'en_EN'; // set language to default...
var WEnotes = {};
var protocol = window.location.protocol + '//';
// hard coded locations of things
......@@ -2553,8 +2552,7 @@ var msg_counter = [];
forums: 'https://forums.oeru.org/users/',
community: 'https://community.oeru.org/users/',
saylordiscourse: 'https://discourse.saylor.org/users/',
connectoeglobal: 'https://connect.oeglobal.org/users/',
'g+': '#'
connectoeglobal: 'https://connect.oeglobal.org/users/'
};
var sourceTag = {
bookmarks: 'https://bookmarks.oeru.org/tags.php/',
......@@ -2563,8 +2561,7 @@ var msg_counter = [];
mastodon: 'https://mastodon.oeru.org/web/timelines/tag/',
twitter: 'https://twitter.com/#!/search?q=%23',
wikieducator: protocol + 'WikiEducator.org/',
connectoeglobal: 'https://connect.oeglobal.org/users/',
'g+': 'https://plus.google.com/s/%23'
connectoeglobal: 'https://connect.oeglobal.org/users/'
};
// fix changed source tags...
var source = d.we_source;
......@@ -2629,18 +2626,6 @@ var msg_counter = [];
console.log('profileURL = ' + JSON.stringify(profileURL));
console.log('(mastodon) tag, we_tags, we_tag = ' + tag + ', ' + d.we_tags + ', ' + d.we_tag);
break;
case 'g+':
timeLink = d.url;
text = d.title;
profileURL = d.actor.url;
profileIMG = d.actor.image.url;
userFullname = d.actor.displayName;
user = '';
userName = userFullname;
// old versions of IE don't understand ISO date format
var dp = d.published.split(/[-T.Z]/);
d.created_at = [dp[2], months[dp[1]-1], dp[0], ''].join(' ') + dp[3] + ' +0000';
break;
case 'feed':
timeLink = d.we_link;
break;
......@@ -2738,7 +2723,6 @@ var msg_counter = [];
case 'identica':
case 'bookmarks':
case 'hypothesis':
case 'g+':
case 'medium':
text = text.replace(/\.\.\.$/, '<a href="' + timeLink + '">...</a>');
break;
......@@ -2815,10 +2799,15 @@ var msg_counter = [];
}
msg += '<br />';
msg += text;
var dt = new Date(d.created_at);
var dt_ago = '<abbr class="timeago" title="' + dt.toISOString() + '">' +
dt.getUTCDate() + ' ' + months[dt.getUTCMonth()] + '</abbr>';
var lang = getLang();
//var dt = new Date(d.created_at);
//console.log('in flow, got lang '+lang);
var created_date = getDate(d.created_at, lang);
console.log('created date is '+ created_date);
var dt_ago = '<abbr class="timeago" title="' + created_date + '">'+created_date+'</abbr>';
msg += '<br /><span class="WEnotesub">';
console.log('.... dt_ago = '+dt_ago);
if (tag === '_') {
if (d.we_tags) {
//console.log('%%% type = ' + d.we_source + ' num tags = ' + d.we_tags.length);
......@@ -2862,23 +2851,11 @@ var msg_counter = [];
msg += d.we_source;
}
msg += '&nbsp;&nbsp;&nbsp;<a href="' + timeLink +
'" title="' + dt.toUTCString() + '" style="text-decoration: none;" target="_wenotes">' +
'" title="' + created_date + '" style="text-decoration: none;" target="_wenotes">' +
dt_ago + '</a>';
if (!novoting && wgUserName) {
msg += '&nbsp;&nbsp;&nbsp;<i title="favorite" class="icon-star-empty"></i>';
}
switch (source) {
case 'twitter':
// if the message is too old, don't show the conversation links
if (((new Date().getTime() - dt.getTime())/86400000) > 5.0) {
break;
}
// fall through to show links
case 'g+':
msg += '&nbsp;&nbsp;&nbsp;<i title="reply" class="icon-mail-reply"></i>';
msg += '&nbsp;&nbsp;&nbsp;<i title="thread" class="icon-th-list"></i>';
break;
}
msg += '&nbsp;<span class="wevtct"></span>';
// add the "sysop-only" links to view the mention in the db, or delete it
if ($.inArray('sysop', window.wgUserGroups) > -1) {
......@@ -2908,6 +2885,35 @@ var msg_counter = [];
return optionList.join('&');
}
// find the current language setting, if any. Otherwise, return en_EN...
function getLang() {
console.log('in getLang');
var wenlang = 'en_EN';
$('div.WEnotes').each(function() {
var $details = $(this).attr('class').split(/\s+/);
$.each($details, function(i, v) {
if (v.indexOf('WEnotes-') === 0) {
console.log('+++++ v = ', v);
var args = v.split('-');
console.log('+++++ args = '+JSON.stringify(args));
if (args.length > 3) {
wenlang = (args[3] !== '') ? args[3] : 'en_NZ';
console.log('found lang = '+wenlang);
}
}
});
});
return wenlang;
}
function getDate(date, lang) {
var dt = new Date(date); // create date object
lang = (typeof lang !== 'undefined') ? lang.replace('_','-') : 'en-EN';
console.log('in getDate, lang is '+lang);
const options = {weekday: 'short', year: 'numeric', month: 'short', day: 'numeric'};
return dt.toLocaleDateString(lang, options);
}
function getMore(event) {
//console.log('in getMore');
var options, url;
......@@ -2915,11 +2921,8 @@ var msg_counter = [];
tag = wendivs[ix].tag,
taglc = tag.toLowerCase(),
count = wendivs[ix].moreCount + 1,
language = wendivs[ix].language,
$wenm = $('#WEnotesMore' + ix),
$wenmdi = $('#WEnotesMoreDiv' + ix + ' img');
wenlang = language;
console.log('setting wenlang = '+language);
$wenmdi.show();
$wenm.hide();
if (tag === '_') {
......@@ -2930,8 +2933,7 @@ var msg_counter = [];
endkey: '"2011-01-01T00:00:00.000Z"',
descending: true,
include_docs: true,
limit: count,
language: language
limit: count
};
} else {
url = couchURL;
......@@ -2941,14 +2943,10 @@ var msg_counter = [];
endkey: '["' + taglc + '", "2011-01-01T00:00:00.000Z"]',
descending: true,
include_docs: true,
limit: count,
language: language
limit: count
};
}
//console.log("url1 = " + url);
//console.log("options = " + options);
$.ajax({
url: url + makeCouchqs(options),
cache: false,
......@@ -2969,6 +2967,8 @@ var msg_counter = [];
$(mid).hide();
return;
}
var lang = getLang();
console.log('in CouchReturn, got lang '+lang);
for (i=1; i < rows.length; i++) {
d = rows[i].doc;
if (d.we_timestamp > wendivs[ix].last) {
......@@ -2978,8 +2978,7 @@ var msg_counter = [];
wendivs[ix].first = d.we_timestamp;
}
$(mid).before(formatMessage(d, tag));
$('#WEitf'+d._id).find('abbr.timeago').timeago();
//$(lid).effect("highlight", {}, 1500);
//$('#WEitf'+d._id).find('abbr.timeago').timeago();
}
$wenmdi.hide();
$wenm.show();
......@@ -3050,8 +3049,8 @@ var msg_counter = [];
.triggerHandler('WEnotes', [dx.tag]);}, refreshtime);
},
success: function(data) {
console.log("data = " + JSON.stringify(data));
console.log('current setting for wenlang '+ wenlang);
//console.log("data = " + JSON.stringify(data));
//console.log('current setting for wenlang '+ wenlang);
var i;
var lid = '.WEnotes';
var rows = data.rows;
......@@ -3064,8 +3063,8 @@ var msg_counter = [];
}
if (!dx.nomore && (data.total_rows - data.offset > rows.length)) {
wendivs[ix].nomore = true;
console.log('language for wendivs '+ix+' is ', data.language);
if (wenlang == 'fr_FR') {
//console.log('language for wendivs '+ix+' is ', data.language);
if (getLang() == 'fr_FR') {
button_text = "Des notes plus " + tag;
if (tag === '_') {
button_text = "Plus de notes";
......@@ -3237,7 +3236,7 @@ var msg_counter = [];
// in the example above, 20 is the 'count' of messages to show,
// and lida101 is the tag, lida is the 'context', and fr_FR is the language
$.each(classes, function(i, v) {
console.log('==== v = ', v);
//console.log('==== v = ', v);
if (v.indexOf('WEnotes-') === 0) {
var tag;
var args = v.split('-', 5);
......@@ -3248,15 +3247,15 @@ var msg_counter = [];
$d: $thisd,
count: args[1], // how many of this to show
tag: tag, // from which tag
context: args[3],
context: args[3],
language: args[4],
last: '2011-01-01T00:00:00.000Z',
first: '2999-12-31T23:59:59.999Z',
moreCount: 20 // how many more to show if the user clicks "show more"
});
wenlang = args[4];
console.log('wenlang for WEnote: '+wenlang);
wenlang = args[4];
console.log('wenlang for WEnote: '+wenlang);
// actually subscribe to the Faye services for the relevant combo
combo = '/WEnotes/' + ((tag === '_') ? '*' : tag.toLowerCase());
console.log('combo = ', combo);
......
......@@ -4,12 +4,20 @@
*/
/* global wgPageName, oeru_user_object */
/* exported WEnotesPostWP */
function WEnotesPostWP(id, tag, button, leftmargin) {
function WEnotesPostWP(id, tag, button, leftmargin, language) {
console.log('in WEnotesPostWP - language = '+language);
var weAPI = '/api.php',
postLength = 300,
rawPostLength = postLength + 20;
leftmargin = (leftmargin === '') ? 53 : leftmargin;
button = (button === '') ? 'Post a WEnote' : unescape(button);
default_button_text = 'Post a WEnote';
language = (language === '') ? 'en_EN' : language;
if (language == 'fr_FR' && (button === '' || button === default_button_text)) {
console.log('setting button language!');
button = 'Soumettre un WEnote';
}
button = (button === '') ? default_button_text : unescape(button);
if (id.charAt(0) !== '#') {
id = '#' + id;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment