ميدياويكي:Extra-tabs.js

من أرابيكا، الموسوعة الحرة

هذه هي النسخة الحالية من هذه الصفحة، وقام بتعديلها عبود السكاف (نقاش | مساهمات) في 04:32، 20 يونيو 2014. العنوان الحالي (URL) هو وصلة دائمة لهذه النسخة.

(فرق) → نسخة أقدم | نسخة حالية (فرق) | نسخة أحدث ← (فرق)
اذهب إلى التنقل اذهب إلى البحث

ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.

/* <pre><nowiki> Top of Javascript */
/* tooltips and access keys */ 
// ==========================================================================
// BEGIN: MediaWiki interface button definition for Duesentrieb's image tools:
// "Check usage", "User image gallery", "Orphaned images of user" and 
// "Untagged images of user".
// If you are located at an "Image:" you get the "check usage" tab, if you
// are at a "User:" page you get the "gallery", "orphans" and "untagged" tab.
// If you are on other pages these tabs do not get shown. These functions are
// enabled in Wikimedia Commons by default via [[Mediawiki:Monobook.js]] and
// its local language subpages.
// This script has been tested with Konqueror 3.5 and Firefox 1.5 and other
// browsers including Opera and Internet Explorer have been reported to work
// as well. If you enhance or change this template please test it previous to
// editing here in your local monobook.js with as many as possible browsers
// (in order not to clash with the function names here change in your local
// monobook.js all "global_" to "local_").
// Be aware that the global JavaScripts do not get updated by the Wikimedia
// servers that fast after saving them.

// written by Dbenbenn, Avatar, Duesentrieb and Arnomane

// Translations (variables for internationalisation and localisation):

// project
var tab_project = 'ar.wikipedia.org';

// namespace names
var tab_ns_image = '%D8%B5%D9%88%D8%B1%D8%A9:';
var tab_ns_imagetalk = '%D9%86%D9%82%D8%A7%D8%B4_%D8%A7%D9%84%D8%B5%D9%88%D8%B1%D8%A9:';
var tab_ns_user = '%D9%85%D8%B3%D8%AA%D8%AE%D8%AF%D9%85:';
var tab_ns_usertalk = '%D9%86%D9%82%D8%A7%D8%B4_%D8%A7%D9%84%D9%85%D8%B3%D8%AA%D8%AE%D8%AF%D9%85:';
var tab_ns_category = '%D8%AA%D8%B5%D9%86%D9%8A%D9%81:';
var tab_ns_special = '%D8%AE%D8%A7%D8%B5:';

// Interface strings, get defined in the localised Mediawiki:Monobook.js/<ISO-Code>
// var tab_check_usage = 'دقق الاستعمال';
// var tab_categorize = 'صنّف';
// var tab_log = 'سجل';
// var tab_gallery = 'معرض';
// var tab_orphans = 'أيتام';
// var tab_untagged = 'غير مرخص';
// var tab_tree = 'شجرة';
// var tab_catscan = 'مسح التصنيف';
// var tab_blocklog = 'سجل المنع';

// Appends a new tab.
function local_append_tab(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);  
 
  var txt = document.createTextNode(name);
  na.appendChild(txt);
 
  var li = document.createElement('li');
  li.appendChild(na);

  // Grab the element we want to append the tab and append the tab to it.
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
  tabs.appendChild(li);
}

// Gets the article lemma, with the namespace and with sub pages.
function local_get_tidy_title()
{
  // get the article link from the label 'ca-edit' out of the document text.
  var editlk = document.getElementById('ca-edit');

  // If a page is write protected (for that user, a sysop will always have 'ca-edit')
  // we need 'ca-viewsource' as 'ca-edit' does not exist there.
  if (editlk == null)
  {
    editlk = document.getElementById('ca-viewsource');
  }

  // editlk will still be null on a Special page.  Now we try the ca-article tab.
  if (editlk == null)
  {
    editlk = document.getElementById('ca-article');
  }

  editlk = editlk.getElementsByTagName('a')[0].href;

  // If we found the ca-edit or ca-viewsource tab, the link will have title=.
  // If we found the ca-article tab (on a Special page) it won't.
  if (editlk.indexOf('title=') >= 0)
  {
    // Cut everything up to "title=" from the start and everything past "&action=edit"
    // from the end.
    editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.indexOf('&'));
  }
  else
  {
    // Cut everything up to "/wiki/" from the start.
    editlk = editlk.substring(editlk.indexOf('/wiki/') + 6);
  }

  return editlk;
}

function local_add_image_tabs(imagetitle)
{
  imagetitle = imagetitle.substring(imagetitle.indexOf(':') + 1); // strip off "Image:" namespace

  local_append_tab('http://tools.wmflabs.org/~daniel/WikiSense/CheckUsage.php?i=' + imagetitle + '&w=_100000', tab_check_usage);

  local_append_tab('http://tools.wmflabs.org/~daniel/WikiSense/CommonSense.php?i=' + imagetitle + '&go-clean=yes' , tab_categorize);

  local_append_tab('/w/index.php?title=' + tab_ns_special + 'Log&page=' + tab_ns_image + imagetitle, tab_log);
}
 
function local_add_user_tabs(username)
{
  username = username.substring(username.indexOf(':') + 1); // strip off namespaces like "User:"

  username = username.replace(/\/.*$/, ''); //removing subpages from the link

  local_append_tab('http://tools.wmflabs.org/~daniel/WikiSense/Gallery.php?&wiki=' + tab_project + '&img_user_text=' + username , tab_gallery);
  local_append_tab('http://tools.wmflabs.org/~daniel/WikiSense/OrphanImages.php?wiki=' + tab_project + '&img_user_text=' + username , tab_orphans);
  local_append_tab('http://tools.wmflabs.org/~daniel/WikiSense/UntaggedImages.php?wiki=' + tab_project + '&img_user_text=' + username , tab_untagged);
}

function local_add_category_tabs(category)
{
  category = category.substring(category.indexOf(':') + 1); // strip off "Category:" namespace

  local_append_tab('http://tools.wmflabs.org/~daniel/WikiSense/CategoryTree.php?wiki=' + tab_project + '&cat=' + category , tab_tree);
  local_append_tab('http://tools.wmflabs.org/~daniel/WikiSense/CategoryIntersect.php?wiki=' + tab_project + '&basecat=' + category , tab_catscan);
}

// On Special:Contributions, we add the user tabs just like for a user page.
// On Special:Blockip, we add a blocklog tab.
function local_add_special_tabs(title)
{
  if (title.indexOf(tab_ns_special + 'Blockip') == 0)
  {
    var username = document.getElementsByName('wpBlockAddress')[0].defaultValue;

    if (username != '')
    {
      local_append_tab('/w/index.php?title=' + tab_ns_special + 'Log&type=block&page=' + tab_ns_user + username, tab_blocklog);
    }
  }
  else if (title.indexOf(tab_ns_special + 'Contributions') == 0)
  {
    var username = document.getElementById('contentSub').getElementsByTagName('a')[0].firstChild.nodeValue;
    local_add_user_tabs(tab_ns_user + username);
  }
}
 
function local_do_onload()
{
    // extract the namespace
    var title = local_get_tidy_title();

    if (title.indexOf(tab_ns_image) == 0 || title.indexOf(tab_ns_imagetalk) == 0)
    {
      local_add_image_tabs(title);
    }
    else if (title.indexOf(tab_ns_user) == 0 || title.indexOf(tab_ns_usertalk) == 0)
    {
      local_add_user_tabs(title);
    }
    else if (title.indexOf(tab_ns_category) == 0)
    {
      local_add_category_tabs(title);
    }
    else if (title.indexOf(tab_ns_special) == 0)
    {
      local_add_special_tabs(title);
    }
}

if (window.addEventListener) 
  window.addEventListener("load", local_do_onload, false);
else if (window.attachEvent) 
  window.attachEvent("onload", local_do_onload);

// END: MediaWiki interface button definition for Duesentrieb's image tools.
// ========================================================================
/* Bottom of Javascript </nowiki></pre> */