User:Saibo/CatNewsTabs.js

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/*
 *    See [[Commons:Village_pump/Archive/2011/03#sort_files_with_toolbox_by_date_.28upload_or_better_date_of_exposure.29]]
 *
 *    Adds two (currently - may change in future!) tabs to each category to access recent uploads to a category:
 *        http://toolserver.org/~magnus/catscan_rewrite.php
 *        http://toolserver.org/~magnus/catfood.php
 *    Tested on Monobook and Vector skin, on Firefox 3.6.13 and Opera 11.
 *        Known not to work with catfood: IE 6.0.2900.5512@WXPSP3
 *        For the thumbnails the browser must be able to display the RSS 2.0 feed.
 *    Usage: add the following line to your [[Special:Mypage/monobook.js]]/[[Special:Mypage/vector.js]]/[[Special:Mypage/common.js]]:
 *    mw.loader.load("//commons.wikimedia.org/w/index.php?title=User:Saibo/CatNewsTabs.js&action=raw&ctype=text/javascript"); // use tracking: [[User:Saibo/CatNewsTabs.js]]
 *
 *    Watch this page to be notified on changes! This is not a totally stable gadget!
 *
 *    Authors of the base code at http://de.wikipedia.org/w/index.php?title=MediaWiki:Gadget-toolserver-integration.js&action=history  (Merlissimo, Arnomane, ...)
 *    This script is JSHint valid.
 */
/*global jQuery:false, mw:false */
jQuery(document).ready(function () {
  'use strict';

  if (mw.config.get('wgNamespaceNumber') === 14 && mw.config.get('wgAction') === 'view' && !mw.util.getParamValue('diff')) {
    var tab_SaiboCNT_currentDate = new Date();
    var tab_SaiboCNT_1 = 'CN-T';
    var tab_SaiboCNT_1_tooltip = 'Cat. news with thumbnails (with 10 subcategories - possible to change in URL)';
    var tab_SaiboCNT_2 = 'CN-↓';
    var tab_SaiboCNT_2_tooltip = 'Cat. news without thumbnails (with 10 subcategories - possible to change in URL or GUI)';
    var tab_SaiboCNT_2_afterDate = new Date();
    tab_SaiboCNT_2_afterDate.setDate(tab_SaiboCNT_currentDate.getDate() - 180); //180 days in the past
    var tab_SaiboCNT_2_afterDate_String = tab_SaiboCNT_2_afterDate.getFullYear() + '';
    if ((tab_SaiboCNT_2_afterDate.getMonth() + 1) < 10) {
      tab_SaiboCNT_2_afterDate_String = tab_SaiboCNT_2_afterDate_String + '0' + (tab_SaiboCNT_2_afterDate.getMonth() + 1);
    } else {
      tab_SaiboCNT_2_afterDate_String = tab_SaiboCNT_2_afterDate_String + '' + (tab_SaiboCNT_2_afterDate.getMonth() + 1);
    }

    mw.util.addPortletLink('p-cactions', '//toolserver.org/~magnus/catfood.php?language=commons&project=wikimedia&depth=10&namespace=6&user=&size=300&last=10&doit=Do+it&category=' + mw.util.rawurlencode(mw.config.get('wgTitle')), tab_SaiboCNT_1, 'ca-CNT_1', tab_SaiboCNT_1_tooltip);
    mw.util.addPortletLink('p-cactions', '//toolserver.org/~magnus/catscan_rewrite.php?language=commons&project=wikimedia&depth=10&ns%5B6%5D=1&after=' + tab_SaiboCNT_2_afterDate_String + '&sortby=uploaddate&sortorder=descending&ext_image_data=1&categories=' + mw.util.rawurlencode(mw.config.get('wgTitle')), tab_SaiboCNT_2, 'ca-CNT_2', tab_SaiboCNT_2_tooltip);
  }
});

// [[Category:User scripts]]