İçeriğe atla

MediaWiki:Gadget-GalleryDetails.js

Vikipedi, özgür ansiklopedi

Not: Sayfayı kaydettikten sonra değişiklikleri görebilmek için tarayıcınızın önbelleğinizi temizlemeniz gerekir. Google Chrome, Firefox, Microsoft Edge ve Safari: ⇧ Shift tuşuna basılı tutun ve Yeniden Yükle araç çubuğu düğmesine tıklayın. Ayrıntılar ve diğer tarayıcılara yönelik yönergeler için Vikipedi:Önbelleğinizi atlayın sayfasını inceleyin.

includePage('MediaWiki:InstantAppendLink.js');

$( gallery_details_init ) ;

var gallery_details_good_tags = new Array (
"GFDL",
"CC-",
"Cc-",
"PD",
"Pd",
"Public domain",
"Copyrighted free use",
"Attribution",
"Images requiring attribution",
"FAL",
"UK Government images",
"User-created GFDL images"
) ;
var gallery_details_bad_tags = new Array (
"Images without ",
"Unknown as of ",
"Deletion requests",
"Other speedy deletions"
) ;


function gallery_details_init () {
  var li = document.createElement("li");
  li.setAttribute("id", "t-permalink");
  var a = document.createElement("a");
  a.href = 'javascript:gallery_details_rearrange();';
  a.appendChild( document.createTextNode( "GalleryDetails" ) ) ;
  li.appendChild(a);

  document.getElementById("p-tb").getElementsByTagName("ul")[0].appendChild(li) ;
  if ( mw.config.get('wgPageName') == "Special:Newimages" ) gallery_details_rearrange();
}

function gallery_details_catstart_in_array ( cat , arr ) {
  var c = cat.split ( ":" , 2 ) ;
  c.shift () ;
  c = c.join ( ":" ) ;
  for ( var i = 0 ; i < arr.length ; i++ ) {
    if ( c.substr ( 0 , arr[i].length ) == arr[i] ) return 1 ;
  }
  return 0 ;
}

function gallery_details_title_from_tr ( tr ) {
      var thumbdiv = getElementsByClassName ( tr.firstChild , "div" , "thumb" ) [0] ;
      var thumblink = thumbdiv.firstChild ;
      while ( thumblink.tagName != "A" ) thumblink = thumblink.firstChild ;
      return thumblink.getAttribute ( "title" ) ;
}

function gallery_details_linking_textNode ( text ) {
   var a = document.createElement("a");
   a.href = mw.config.get('wgArticlePath').replace( "$1", encodeURI(  text.replace ( / /g, '_' ) ) );
   a.appendChild( document.createTextNode ( text ) );
   return a;
}

function gallery_details_add_info ( gallery_details_trs ) {
  var titles = "";

  for (var tr_num in gallery_details_trs) {
    titles += "|Image:" + encodeURIComponent ( gallery_details_title_from_tr(gallery_details_trs[tr_num]) ) ;
    }
  titles = titles.substr(1); //Remove beginning |

  var api = mw.config.get('wgServer') + wgScriptPath + "/api.php" ;
  var xmlHttp = sajax_init_object();
  var xml ;

  // Get image info
  var api_param = "format=xml&action=query&prop=imageinfo|categories|revisions&iiprop=timestamp|user|comment|url|size&rvdir=older&rvprop=content&titles=" + titles ;
  xmlHttp.open('POST', api, false);
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", api_param.length);
  xmlHttp.send ( api_param ) ;
  xml = xmlHttp.responseXML ;

  for (var tr_index in gallery_details_trs) {
    var tr = gallery_details_trs[tr_index];
    var title = gallery_details_title_from_tr(tr);

    //API results are sorted, so we must perform a search
    for (var page = xml.getElementsByTagName("page")[0]; page; page = page.nextSibling )
      if ( "Image:" + title == page.getAttribute ( "title" ) )
        break;

    if ( page && ( page.getAttribute ( "missing" ) === null ) ) {
      var imagedata = page.getElementsByTagName("ii")[page.getElementsByTagName("ii").length - 1] ; //Get last node. Work around API bug. ii from previous pages keep on the following.
      var user = imagedata.getAttribute ( "user" ) ;
      var size = imagedata.getAttribute ( "size" ) ;
      var width = imagedata.getAttribute ( "width" ) ;
      var height = imagedata.getAttribute ( "height" ) ;
      var url = imagedata.getAttribute ( "url" ) ;
      var comment = imagedata.getAttribute ( "comment" ) ;

      var catdata = page.getElementsByTagName("cl") ;
      var categories = new Array () ;
      var lastcat = "" ;
      var goodcat = 0 ;
      var badcat = 0 ;
      for ( var i = 0 ; i < catdata.length ; i++ ) {
        var cat = catdata[i].getAttribute ( "title" ) ;
        if ( cat == lastcat ) continue ;
        lastcat = cat ;
        goodcat = goodcat | gallery_details_catstart_in_array ( cat , gallery_details_good_tags ) ;
        badcat = badcat | gallery_details_catstart_in_array ( cat , gallery_details_bad_tags ) ;
        categories.push ( cat ) ;
      }

      // Details...
      var small = 0 ;
      if ( width < 600 && height < 600 && width > 0 && height > 0 ) small = 1 ;


      // Output

      var t = document.createElement ( "span" ) ;
      t.appendChild ( document.createTextNode( width + "×" /*"&times;"*/ + height + "px" ) ) ;
      if ( small ) t.style.fontcolor = 'red';

      var ntd = document.createElement ( "td" ) ;
      var ndiv = document.createElement ( "div" ) ;
      ndiv.style.margin = "5px" ;
      ndiv.style.padding = "5px" ;
      ndiv.appendChild ( gallery_details_linking_textNode ( page.getAttribute ( "title" ) ) ) ;
      ndiv.appendChild ( document.createElement( 'br' ) );
      ndiv.appendChild ( t );
      for (var i in categories ) {
        ndiv.appendChild ( document.createElement( 'br' ) );
        ndiv.appendChild ( gallery_details_linking_textNode ( categories[i] ) ) ;    
      }

      var user_notification = "\n\
==Image Tagging [[:" + title + "]]==\n\
{{Image source/lang}}\n\
<div style=\"clear:both\"></div>\n\
{| align=\"center\"  style=\"background-color:#FFFFF8; border:2px solid #FF0000; padding:5px;\"\n\
|-\n\
|[[Image:Nuvola apps important.svg|45px|Warning sign]]\n\
| <center><big>This media may be '''deleted'''.</big></center>\n\
|}\n\
Thanks for uploading '''[[:" + title + "]]'''. I notice the image page currently doesn't specify who created the content, so the [[Commons:Licensing|copyright]] status is unclear. If you have not created this media yourself then you need to argue that we have the right to use the media on Wikimedia Commons (see copyright tagging below). If you have not created the media yourself then you should also specify where you found it, i.e., in most cases link to the website where you got it, and the terms of use for content from that page. If the content is a [[Commons:Derivative works|derivative]] of a copyrighted work, you need to supply the names and a licence of the original authors as well.\n\
\n\
If the media also doesn't have a copyright tag, then you must also add one. If you created/took the picture, audio, or video then you can use {{tlx|self|GFDL|cc-by-sa-all}} to release it under the multilicense GFDL plus [[Commons:Copyright_tags#Free_Creative_Commons_licenses|Creative Commons]] Attribution-ShareAlike All-version license or {{tl|PD-self}} to release it into the public domain. See [[Commons:Copyright tags]] for the full list of copyright tags that you can use.\n\
\n\
Note that any unsourced and untagged images will be deleted one week after they have been uploaded, as described on [[Commons:Deletion guidelines|criteria for speedy deletion]]. If you have uploaded other media, please check that you have specified their source and copyright tagged them, too. You can find all your uploads using the [http://tools.wikimedia.de/~daniel/WikiSense/Gallery.php?wiki=commons.wikimedia.org&img_user_text={{PAGENAMEE}} Gallery] tool. Thank you.  \n\
~~"+"~~" ;
      var adiv = document.createElement ( "div" ) ;
      adiv.style.background = "#DDDDDD" ;
      adiv.appendChild ( get_instant_append_link ( title , "{{no source since|month=December|day=31|year=2007}}\n" , "No source" , 1 ) ) ;
      adiv.appendChild ( get_instant_append_link ( title , "{{no license|month=December|day=31|year=2007}}\n" , "No license" , 1 ) ) ;
      adiv.appendChild ( get_instant_append_link ( "User_talk:"+user , user_notification , "Notify user" , 0 ) ) ;

      ndiv.appendChild ( adiv );

      ntd.appendChild ( ndiv ) ;
      tr.appendChild ( ntd ) ;

      if ( badcat ) {
        ndiv.style.border = "3px solid red" ;
      } else if ( goodcat ) {
        ndiv.style.border = "3px solid green" ;
      } else {
        ndiv.style.border = "3px solid yellow" ;
      }

      //Page text
      var rev = page.getElementsByTagName("rev")[0] ;
      var text = ( rev && rev.firstChild ) ? rev.firstChild.nodeValue : "" ;
      ntd = document.createElement ( "td" ) ;
      ndiv = document.createElement ( "div" ) ;
      ndiv.style.margin = "5px" ;
      ndiv.style.padding = "5px" ;
      ndiv.style.fontSize = "8pt" ;
      ndiv.style.lineHeight = "9pt" ;
      var s = text.split('\n');
      for (var i in s) {
        ndiv.appendChild ( document.createTextNode ( s[i] ) ) ;
        ndiv.appendChild ( document.createElement ( 'br' ) ) ;
      }
      ntd.appendChild ( ndiv ) ;
      tr.appendChild ( ntd ) ;
    } else {
      ntd = document.createElement ( "td" ) ;
      ntd.colspan = 2;
      ntd.appendChild ( document.createTextNode ( 'Missing image' ) ) ;
      tr.appendChild ( ntd ) ;
    }
  }
}

function gallery_details_rearrange () {
  var gallery_details_trs = new Array();
  var bc = document.getElementById ( "bodyContent" ) ;
  var tables = getElementsByClassName ( document , "table" , "gallery" ) ;

  if ( tables.length == 0 ) return ;

  var details = getElementsByClassName ( document , "table" , "gallery_details" );

  if ( details.length > 0 ) {
     //We already have the data, hidden... switch visibility

     for ( var i in details ) {
         var a = tables[i].style.display;
         tables[i].style.display = details[i].style.display;
         details[i].style.display = a;   
     }
     return;
  }

  for ( var tablecount = 0 ; tablecount < tables.length ; tablecount++ ) {
    var t = tables[tablecount] ;
    var t_det = document.createElement('table');
    t_det.className = "gallery_details";
    t_det.style.display = 'block';
    t.style.display = 'none';
    t.parentNode.insertBefore(t_det, t);

    // Get DIVs and their parent nodes (TDs)
    var divs = getElementsByClassName ( t , "div" , "gallerybox" ) ;
    var tds = new Array () ;

    for ( var i = 0 ; i < divs.length ; i++ ) tds.push ( divs[i].parentNode.cloneNode(true) ) ;

    // Reorder
    var tb = document.createElement("tbody");
    var tr ;
    for ( var i = 0 ; i < tds.length ; i++ ) {
      tr = document.createElement ( "tr" ) ;
      tb.appendChild ( tr ) ;
      tr.appendChild ( tds[i] ) ;
      var p = gallery_details_trs.length ;
      gallery_details_trs.push ( tr ) ;
    }
    t_det.appendChild(tb);
  }
  gallery_details_add_info ( gallery_details_trs ) ;
}