diff --git a/javascripts/langviews/langviews.js b/javascripts/langviews/langviews.js index 7500122a5..89e025866 100644 --- a/javascripts/langviews/langviews.js +++ b/javascripts/langviews/langviews.js @@ -320,7 +320,7 @@ class LangViews extends mix(Pv).with(ChartHelpers, ListHelpers) { ${$.i18n('unique-titles', this.outputData.titles.length)} ${totalBadgesMarkup} ${this.formatNumber(this.outputData.sum)} - ${this.formatNumber(Math.round(this.outputData.average))} / ${$.i18n('day')}` + ${this.formatNumber(Math.round(this.outputData.average))}` ); $('#output_list').html(''); @@ -334,10 +334,10 @@ class LangViews extends mix(Pv).with(ChartHelpers, ListHelpers) { ` ${index + 1} ${item.lang} - ${item.label} + ${this.getPageLink(item.label, `${item.lang}.${this.baseProject}.org`)} ${badgeMarkup} ${this.formatNumber(item.sum)} - ${this.formatNumber(Math.round(item.average))} / ${$.i18n('day')} + ${this.formatNumber(Math.round(item.average))} ` ); }); diff --git a/javascripts/redirectviews/redirectviews.js b/javascripts/redirectviews/redirectviews.js index a8b2c2fc8..f749f1bff 100644 --- a/javascripts/redirectviews/redirectviews.js +++ b/javascripts/redirectviews/redirectviews.js @@ -306,7 +306,7 @@ class RedirectViews extends mix(Pv).with(ChartHelpers, ListHelpers) { ${$.i18n('num-redirects', this.formatNumber(numRedirects), numRedirects)} ${$.i18n('num-sections', this.formatNumber(this.outputData.sectionCount), this.outputData.sectionCount)} ${this.formatNumber(this.outputData.sum)} - ${this.formatNumber(Math.round(this.outputData.average))} / ${$.i18n('day')}` + ${this.formatNumber(Math.round(this.outputData.average))}` ); $('#output_list').html(''); @@ -316,17 +316,19 @@ class RedirectViews extends mix(Pv).with(ChartHelpers, ListHelpers) { let sectionMarkup = ''; if (item.section) { - const sectionUrl = `${this.getPageURL(this.outputData.source)}#${encodeURIComponent(item.section.score())}`; - sectionMarkup = `#${item.section}`; + sectionMarkup = this.getPageLink(this.outputData.source, this.project, '#' + item.section, item.section); } $('#output_list').append( ` ${index + 1} - ${item.label} ${isSource ? '(' + $.i18n('target') + ')' : ''} + + ${this.getPageLink(item.label, `${this.project}.org`)} + ${isSource ? '(' + $.i18n('target') + ')' : ''} + ${sectionMarkup} ${this.formatNumber(item.sum)} - ${this.formatNumber(Math.round(item.average))} / ${$.i18n('day')} + ${this.formatNumber(Math.round(item.average))} ` ); }); diff --git a/javascripts/shared/list_helpers.js b/javascripts/shared/list_helpers.js index 113495bb2..7aad1da2d 100644 --- a/javascripts/shared/list_helpers.js +++ b/javascripts/shared/list_helpers.js @@ -104,7 +104,7 @@ const ListHelpers = superclass => class extends superclass { } return `/pageviews?start=${startDate.format('YYYY-MM-DD')}&end=${endDate.format('YYYY-MM-DD')}` + - `&project=${project}&platform=${platform}&pages=${encodeURIComponent(page)}`; + `&project=${project}&platform=${platform}&pages=${encodeURIComponent(page.score()).replace("'", escape)}`; } /** diff --git a/javascripts/shared/pv.js b/javascripts/shared/pv.js index 8f822147f..6727c2f18 100644 --- a/javascripts/shared/pv.js +++ b/javascripts/shared/pv.js @@ -459,10 +459,20 @@ class Pv extends PvConfig { * Get a full link for the given page and project * @param {string} page - page to link to * @param {string} [project] - project link, defaults to `this.project` + * @param {string} [text] - Link text, defaults to page title + * @param {string} [section] - Link to a specific section on the page * @return {string} HTML markup */ - getPageLink(page, project) { - return `${page.descore().escape()}`; + getPageLink(page, project, text, section) { + let attrs = `target="_blank" href="${this.getPageURL(page, project)}${section ? '#' + section.score() : ''}"`; + + if (this.isMultilangProject(project)) { + const projectLang = this.getProjectLang(project); + + attrs += ` lang=${projectLang} dir="${this.config.rtlLangs.includes(projectLang) ? 'rtl' : 'ltr'}"`; + } + + return `${text || page.descore().escape()}`; } /** @@ -488,7 +498,7 @@ class Pv extends PvConfig { /** * Get the project name (without the .org) * - * @returns {boolean} lang.projectname + * @returns {string} lang.projectname */ get project() { const project = $(this.config.projectInput).val(); @@ -496,6 +506,16 @@ class Pv extends PvConfig { return project ? project.toLowerCase().replace(/.org$/, '') : null; } + /** + * Split project by . and get first result. + * Used to apply dir='rtl' on links to wikis that are RTL + * @param {string} [project] Project, defaults to this.project + * @returns {string} lang + */ + getProjectLang(project) { + return (project || this.project).split('.')[0]; + } + /** * get date format for the browser's locale * @return {String} format to be passed to moment.format() @@ -958,10 +978,11 @@ class Pv extends PvConfig { /** * Test if the current project is a multilingual project + * @param {String} [project] Project, defaults to this.project * @returns {Boolean} is multilingual or not */ - isMultilangProject() { - return new RegExp(`.*?\\.(${Pv.multilangProjects.join('|')})`).test(this.project); + isMultilangProject(project = this.project) { + return new RegExp(`.*?\\.(${Pv.multilangProjects.join('|')})`).test(project); } /** diff --git a/javascripts/shared/pv_config.js b/javascripts/shared/pv_config.js index c8a771a98..2da2476ee 100644 --- a/javascripts/shared/pv_config.js +++ b/javascripts/shared/pv_config.js @@ -233,6 +233,7 @@ class PvConfig { platform: ['all-access', 'desktop', 'mobile-app', 'mobile-web'], project: siteDomains }, + rtlLangs: ['ar', 'he', 'fa', 'ps', 'ur'], pageAssessmentProjects: ['en.wikipedia', 'en.wikivoyage'], pageAssessmentBadges: { 'en.wikipedia': { diff --git a/javascripts/topviews/topviews.js b/javascripts/topviews/topviews.js index fd0f6e4e9..34b43a30d 100644 --- a/javascripts/topviews/topviews.js +++ b/javascripts/topviews/topviews.js @@ -113,7 +113,7 @@ class TopViews extends Pv { - ${item.article} +
${this.getPageLink(item.article, this.project)}
${edits} ${editors} @@ -324,7 +324,7 @@ class TopViews extends Pv { project = $(this.config.projectInput).val(); return `/pageviews?start=${startDate}&end=${endDate}&project=${project}` + - `&platform=${platform}&pages=${encodeURIComponent(article)}`; + `&platform=${platform}&pages=${encodeURIComponent(article.score()).replace("'", escape)}`; } /** diff --git a/javascripts/userviews/userviews.js b/javascripts/userviews/userviews.js index f2d351f21..327db89f3 100644 --- a/javascripts/userviews/userviews.js +++ b/javascripts/userviews/userviews.js @@ -402,7 +402,7 @@ class UserViews extends mix(Pv).with(ChartHelpers, ListHelpers) { ${datestamp} ${this.formatNumber(item.size)} ${this.formatNumber(item.sum)} - ${this.formatNumber(Math.round(item.average))} / ${$.i18n('day')} + ${this.formatNumber(Math.round(item.average))} ` ); }); diff --git a/public_html/_data_links.php b/public_html/_data_links.php index bba050561..934f7ee7c 100644 --- a/public_html/_data_links.php +++ b/public_html/_data_links.php @@ -37,20 +37,20 @@ - - + + - + - +