root > WikiSense-trunk > web > CommonsClash.php

CommonsClash.php

application/x-php, 6085 bytes (load raw)
<?php

define( 'WS_WEB', true );

require_once('common/WebInit.php');
require_once('WikiQuery.php');

function getClashTitle($field, $row, $format) {
  global $wq, $commons;
 
  if ($format!='html') return $row['img_name'];

  $html= $wq->makeLink($row["img_name"], NS_IMAGE, false);
 
  $html.= " <small>";
  $html.= '|&nbsp;'.$wq->makeLink($row["img_name"], NS_IMAGE, false,$commons,'^');
  $html.= "</small>";
 
  return $html;
}

function getImageInfo($field, $row, $format, $prefix = '') {
  $html= '<small>';
  #$html.= escapeHtml($row[$prefix."img_minor_mime"]).", ";
  if ($row[$prefix.'img_width']>0 || $row[$prefix.'img_height']>0 ) $html.= escapeHtml($row[$prefix."img_width"].'x'.$row[$prefix."img_height"]).", ";
  $html.= ceil($row[$prefix."img_size"]/1024)."KB";
  $html.= '</small>';
  return $html;
}

function getUploader($field, $row, $format, $prefix = '') {
  global $wq, $commons;

  $u= $row['img_user_text'];
  $cu= $row['c_img_user_text'];
 
  if ($format=='html') {
      $u$wq->makeLink($u, NS_USER, false);
      $cu= $wq->makeLink($cu, NS_USER, false, $commons);
  }
 
  if ($format!='html') {
      return "$u | $cu";
  }
  else if ($row['img_user_text'] == $row['c_img_user_text']) {
      return "<small class='uploader'><b class='selfupload'>$u</b></small> <b class='self'>(self)</b>";
  }
  else {
      return "<small class='uploader'>$u | $cu</small>";
  }
}

function getUsage($field, $row, $format) {
    global $wq;

    $sql= "
    select page_namespace, page_title
    from page
    join imagelinks on il_from = page_id
    where il_to = "
.$wq->wiki->wikiDB->addQuotes($row['img_name'])."
    limit 30
    "
;
   
    $res= $wq->wiki->wikiDB->query($sql, 'getUsage');
   
    $html= '';
   
    while ($r = $wq->wiki->wikiDB->fetchRow($res)) {
        if ($format=='html') {
            if ($html!=='') $html.= ', ';
            $html.= $wq->makeLink($r['page_title'], $r['page_namespace']);
        }
        else {
            if ($html!=='') $html.= '|';
           
            $t= $r['page_title'];
            if ($r['page_namespace']) $t= $wq->wiki->getNsText($r['page_namespace']).':'.$t;
           
            $html.= $t;
        }
    }
   
    if ($format!='html') return $html;
    else if (!$html) return '<b class="unused">(not used)</b>';
    else return "<small>$html</small>";
}

function getClashStatus($field, $row, $format) {
  global $wq, $commons;
 
  $info= getImageInfo($field, $row, $format);
  $html= '';

  if ( $row['img_size'] == $row['c_img_size']
     && $row['img_width'] == $row['c_img_width']
     && $row['img_height'] == $row['c_img_height']
     && $row['img_minor_mime'] == $row['c_img_minor_mime']
     && $row['img_metadata']  == $row['c_img_metadata'] ) {
     
     $html.= "$info <span class='dupe'>(duplicate)</space> "
  }
  else {
     $html.= "$info <small class='diff'>|</small> " . getImageInfo($field,$row,$format,'c_') . ""
  }
 
  return $html;
}

    $format= @$_REQUEST['format'];
    if (!$format) $format= 'html';

    $dupesonly = $wgRequest->getCheck('dupes');
    $selfonly = $wgRequest->getCheck('self');

    $sql'SELECT L.img_name, L.img_size, L.img_width, L.img_height, L.img_major_mime, L.img_minor_mime, L.img_metadata, L.img_user_text,
                   C.img_name as c_img_name, C.img_size as c_img_size, C.img_width as c_img_width, C.img_height as c_img_height,
                   C.img_major_mime as c_major_mime, C.img_minor_mime as c_img_minor_mime, C.img_metadata as c_img_metadata, C.img_user_text as c_img_user_text
            FROM image as L
            JOIN commonswiki_p.image as C on L.img_name = C.img_name
            '
;

    $where = array();
    if ($dupesonly) $where[] = 'L.img_size = C.img_size
                                AND L.img_size = C.img_size
                                AND L.img_width = C.img_width
                                AND L.img_height = C.img_height
                                AND L.img_major_mime = C.img_major_mime
                                AND L.img_minor_mime = C.img_minor_mime
                                AND L.img_metadata = C.img_metadata'
;

    if ($selfonly) $where[] = 'L.img_user_text = C.img_user_text';

    if ($where) $sql .= ' WHERE ' . implode(' AND ', $where);
   
    $wq= new WikiQuery('CommonsClash', $sql);
   
    $wq->options['dupes'] = 'duplicates only';
    $wq->options['self'] = 'self-copied only';

    $wq->fields['img_name']= array(
      'label' => 'Name',
      'html' => true,
      'function' => 'getClashTitle',
      'sort' => true,
      #'attributes' => 'nowrap="nowrap"'
    );
   
    $wq->fields['status']= array(
      'label' => 'Status',
      'html' => true,
      'function' => 'getClashStatus',
      #'attributes' => 'nowrap="nowrap"'
    );
   
    /*
    $wq->fields['img_user_text']= array(
      'label' => 'Original Uploader',
      'html' => false,
      'sort' => true,
      'attributes' => 'nowrap="nowrap"'
    );
    */


    if ($format=='html') {   
        #print "[[HTML]]";
        $wq->fields['uploader']= array(
          'label' => 'Uploader',
          'html' => true,
          'sort' => false,
          'function' => 'getUploader',
          #'attributes' => 'nowrap="nowrap"'
        );
    }
   
    $wq->fields['img_user_text']= array(
      'label' => 'Local Uploader',
      'sort' => true,
      'hidden' => $format == 'html'
    );
   
    $wq->fields['c_img_user_text']= array(
      'label' => 'Commons Uploader',
      'sort' => true,
      'hidden' => $format == 'html'
    );
   
    $wq->fields['usage']= array(
      'label' => 'Usage',
      'html' => true,
      'function' => 'getUsage',
      'attributes' => 'width="33%"'
    );
   
$commons= NULL;   
       
if ($wq->wikiSelector->domain) {
  $commons= WikiAccess::newInstance('commons.wikimedia.org');
}

$wq->helpPageName= 'Tools';

$wq->styles[]= '.dupe { font-weight:bold; }';
$wq->styles[]= '.self { font-weight:bold; }';
$wq->styles[]= 'table.query-result td { padding-top:1ex; }';

$wq->printPage();
$wq->close();
?>