MediaWiki:RailWAM/code.js

/* WARNING: Entering test mode will automatically create a WAM log page. It is recommended that testing be done on a separate test wiki or that you configure the log page as a sub page of your user page before entering test mode. */ /* ==RailWAM== - A JavaScript script for displaying a wiki's WAM score in the right rail and - logging it on a specific page - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Author: User:Blaster Niceshot - Suggested by: User:Demotivator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Usable in personal or sitewide JS

if (typeof window.railWAMLoaded === 'undefined') { window.railWAMLoaded = true; var token = mw.user.tokens.get('editToken'), wikiId = mw.config.get('wgCityId'), siteName = mw.config.get('wgSiteName'), serverName = mw.config.get('wgServer'), pageName = mw.config.get('wgPageName'), namespaceNum = mw.config.get('wgNamespaceNumber'), date = new Date, today = date.getUTCDate.toString + date.getUTCMonth.toString + date.getUTCFullYear.toString, yesterday = (date.getUTCDate - 1).toString + date.getUTCMonth.toString + date.getUTCFullYear.toString, wamScore = 0, railWAM = $.extend({               logPage:siteName + ':WAM Log',                load:true,                loadOnPage:pageName,                loadOnNamespace:namespaceNum,                lang: mw.config.get('wgUserLanguage')            }, window.railWAM), namespaceIndex; if (typeof railWAM.loadOnNamespace === 'object') { namespaceIndex = railWAM.loadOnNamespace.indexOf(namespaceNum); } else { namespaceIndex = railWAM.loadOnNamespace.toString.indexOf(namespaceNum); }       if (typeof railWAM.loadOnPage === 'object') { $.each(railWAM.loadOnPage,function(i,page){               railWAM.loadOnPage[i] = page.toString.replace(/ /g,'_');            }); } else { railWAM.loadOnPage = railWAM.loadOnPage.toString.replace(/ /g,'_'); }       var pageIndex = railWAM.loadOnPage.indexOf(pageName); var i18n = { en: { // WAM module messages faq:'FAQ', poweredBy:'Powered by', todayTitle:'Today\'s WAM score', unknown:'Unknown', wamPage:'Official WAM Page', yesterdayNotLogged:'Yesterday\'s WAM score is not logged.', // FAQ headers/answers faqTitle:'Frequently Asked Questions', faqWelcome:'Welcome to the RailWAM FAQ. You may also want to visit Wikia\'s official WAM FAQ.', sectionWAM:'Information about WAM scores', quesWhatIsWAM:'What is WAM?', ansWhatIsWAM:'The Wikia Activity Monitor (WAM) is a numeric value between 0 and 100 that measures activity on a given wiki. By monitoring WAM, users can see how their wiki\'s health is changing over time.', quesCalcWAM:'How is WAM calculated?', ansCalcWAM:'According to Wikia\'s official WAM FAQ, WAM scores are a combination of "traffic, engagement and growth." Wikia does not provide specifics on how these factors are measured and weighted in order to avoid wikis trying to manipulate the scores.', quesImproveWAM:'How can I improve my wiki\'s WAM score?', ansImproveWAM:'You can improve a wiki\'s WAM score by encouraging contribution (such as personally welcoming new contributors or writing a blog about your wiki on Community Central) and creating high-quality content that will keep readers coming back. You can also increase your wiki\'s rank in search engines by adding useful and relevant images and links. Keep in mind that adding irrelevant content, images and/or links could negatively your wiki\'s WAM score and search rankings.', quesScoreZero:'What does it mean if a wiki\'s WAM score is 0?', ansScoreZero:'WAM is calculated for only the top 5,000 wikis. Wikis that are not in the top 5,000 have a WAM score of 0.', sectionRailWAM:'Information about RailWAM', quesWhatIsRailWAM:'What is RailWAM?', ansWhatIsRailWAM:'RailWAM is a JavaScript enhancement for Wikia sites which displays the day\'s WAM score for a wiki along with the difference between today\'s and yesterday\'s score underneath. You can find more information in the RailWAM documentation.', quesInstallRailWAM:'How can I install RailWAM on my wiki?', ansInstallRailWAM:'Please visit the RailWAM documentation for installation instructions.', quesCreators:'Who created RailWAM?', ansCreators:'RailWAM was coded and designed by Blaster Niceshot, and the idea for the script was originally suggested by Demotivator.', // Error messages errorLoad:'failed to load because it is disabled. Set your "load" configuration option to true to enable it.', errorPage:'failed to load because the current page is not specified as one of the pages RailWAM shoud load on. Add this page\'s name to the "loadOnPage" configuration option to allow it to load on this page.', errorNamespace:'failed to load because the current page\'s namespace is not specified as one of the namespaces RailWAM shoud load on. Add this page\'s namespace to the "loadOnNamespace" configuration option to allow it to load on this page.' }       };        if (typeof i18n[railWAM.lang] === 'string') { $.extend(i18n,i18n.railWAM.lang); } else { $.extend(i18n,i18n.en); }       if (railWAM.load === true && (railWAM.loadOnPage[pageIndex] == pageName || railWAM.loadOnPage == pageName) && (railWAM.loadOnNamespace == namespaceNum || railWAM.loadOnNamespace[namespaceIndex] == namespaceNum)) { $.get(serverName + '/wiki/' + encodeURIComponent(railWAM.logPage) + '?action=raw') .done(function(wamLog){               var wamLogHtml = $(wamLog);                var todayElm = wamLogHtml.filter('#railwam-' + today);                if (todayElm.length) {                    wamScore = todayElm.text;                    addModule(wamScore,wamLogHtml);                } else {                    $.get('http://www.wikia.com/api/v1/Wikis/Details?ids=' + wikiId).done(function(data) { wamScore = data.items[wikiId].wam_score; logWAMScore(wamScore); addModule(wamScore,wamLogHtml); });               }            }).fail(function{                $.get('http://www.wikia.com/api/v1/Wikis/Details?ids=' + wikiId).done(function(data) { wamScore = data.items[wikiId].wam_score; logWAMScore(wamScore); addModule(wamScore,[]); });           });        } else if (railWAM.load === false) { console.log('RailWAM: RailWAM ' + i18n.errorLoad); } else if ((railWAM.loadOnPage[pageIndex] != pageName && railWAM.loadOnPage != pageName)) { console.log('RailWAM: RailWAM ' + i18n.errorPage); } else if ((railWAM.loadOnNamespace != namespaceNum && railWAM.loadOnNamespace[namespaceIndex] != namespaceNum)) { console.log('RailWAM: RailWAM ' + i18n.errorNamespace); }       function addModule(wamScore,wamLogHtml) { $('.WikiaRail').prepend(' ' + i18n.todayTitle + ' ' + wamScore + ' +/- ' + i18n.unknown + ' ' + i18n.yesterdayNotLogged +' <span style="text-align:center; display:inline-block; margin-top:10px; position:relative; left:50%; transform:translateX(-50%);">' + i18n.wamPage + '</a>' + i18n.faq + '</a> '+ i18n.poweredBy + ' RailWAM</a> '); $('#railwam-faq').click(function{frequentQuestions;}); calcDiff(wamScore,wamLogHtml); }       function logWAMScore(score) { $.post(serverName + '/api.php?action=edit&title=' + encodeURIComponent(railWAM.logPage) + '&recreate=true&appendtext='+ encodeURIComponent('\n*<span id="railwam-' + today + '">' + score + ' ') + '&summary=RailWAM: Adding new WAM score entry&format=json&token=' + encodeURIComponent(token)); }       function calcDiff(score,wamLogHtml) { var yesterdayElm = wamLogHtml.filter('#railwam-' + yesterday); var yesterdayScore = yesterdayElm.text; var diffElm = $('#railwam-difference'); if (yesterdayElm.length) { var diff = score - yesterdayScore; $('#railwam-not-logged').css('display','none'); if (diff > 0) { diffElm.html('<img src="http://vignette2.wikia.nocookie.net/bniceshottest/images/3/3b/Wam-arrow-up.png" style="height:13px; vertical-align:middle; margin-top:-4px;"> ' + diff); } else if(diff < 0) { diffElm.html('<img src="http://vignette2.wikia.nocookie.net/bniceshottest/images/3/3b/Wam-arrow-down.png" style="height:13px; vertical-align:middle; margin-top:-3px;"> ' + Math.abs(diff)); } else if (diff === 0) { diffElm.html('<img src="http://vignette1.wikia.nocookie.net/bniceshottest/images/f/fa/Wam-arrow-zero.png" style="height:13px; vertical-align:middle; margin-top:-3px;"> 0'); }           }        }        function frequentQuestions { $.showCustomModal('RailWAM: ' + i18n.faqTitle, i18n.faqWelcome + ' ' + i18n.sectionWAM + ' <h2 style="margin-top:10px; font-size:1.3em;">' + i18n.quesWhatIsWAM + ' ' + i18n.ansWhatIsWAM + ' <h2 style="margin-top:10px; font-size:1.3em;">' + i18n.quesCalcWAM + ' ' + i18n.ansCalcWAM + ' <h2 style="margin-top:10px; font-size:1.3em;">' + i18n.quesImproveWAM + ' ' + i18n.ansImproveWAM + ' <h2 style="margin-top:10px; font-size:1.3em;">' + i18n.quesScoreZero + ' ' + i18n.ansScoreZero + ' ' + i18n.sectionRailWAM + ' <h2 style="margin-top:10px; font-size:1.3em;">' + i18n.quesWhatIsRailWAM + ' ' + i18n.ansWhatIsRailWAM + ' <h2 style="margin-top:10px; font-size:1.3em;">' + i18n.quesInstallRailWAM + ' ' + i18n.ansInstallRailWAM + ' <h2 style="margin-top:10px; font-size:1.3em;">' + i18n.quesCreators + ' ' + i18n.ansCreators + ' ', {               width:850            }); var bgColor = $('.modalWrapper > h1').css('color'); var fontColor = $('.modalWrapper').css('background-color'); $('.faqHeader').css('background',bgColor); $('.faqHeader').css('color',fontColor); }   } }) (this.jQuery, this.mediaWiki);
 * (function($, mw) {