<?php
define( 'WS_WEB', true );
require_once('common/WebInit.php');
require_once('WikiQuery.php');
function getOrphanActions($field, $row, $format) {
$u= "CommonSense.php?i=".urlencode($row['img_name'])."&go-clean=yes";
if ($format=='wiki') return "[$u CommonSense]";
else {
$html= '';
$html.= "<small>";
$html.= "[<a href='$u'>CommonSense</a>]";
$html.= "</small>";
return $html;
}
}
$icats= array(
'GFDL',
'GPL',
'LGPL',
'Public_domain',
'PD',
'PD-self',
'PD-user',
'PD_Old',
'PD_Art',
'PD_US',
'PD_US_Government',
'PD_NASA',
'PD_US_Military',
'Patents',
'Russian_official_symbols',
'PD_Soviet',
'CC-BY-SA-2.5',
'CC-BY-SA-2.1',
'CC-BY-SA-2.0',
'CC-BY-SA-1.0',
'CC-SA-1.0',
'CC-BY-1.0',
'CC-BY-2.0',
'CC-BY-2.5',
'BSD_images',
'Copyrighted_free_use',
'Copyrighted_free_use_provided_that',
'Self-published_work',
'Unknown',
'Own_work',
'Incomplete_license',
'Unknown',
'Flickr',
'Possibly_unfree_Flickr_images',
'FlickrLickr_images',
'Flickr_review_needed',
'Admin_reviewed_Flickr_images',
'Edited_versions_of_Flickr_originals',
'Flickr_images_not_found',
#much much more....
#FIXME: add user galleries here!
#TODO: fetch user galleries, license- and meta-categories recursively!
);
$ignoreCats= '';
foreach ($icats as $c) {
if ($ignoreCats) $ignoreCats.= ', ';
$ignoreCats.= '"'.addslashes($c).'"';
}
$grouped= $wgRequest->getVal("grouped");
$filter= $wgRequest->getVal("filter");
if ($filter=='main') $nsfilter= ' A.page_namespace = 0 ';
else if ($filter=='notalk') $nsfilter= ' ( A.page_namespace % 2 ) = 0 ';
else $nsfilter= ' 1 ';
if ($grouped) {
$sql= 'SELECT img_user_text, count(img_name) as num
FROM page AS I
JOIN image AS G ON I.page_title = G.img_name
LEFT JOIN categorylinks AS L ON (I.page_id = L.cl_from AND L.cl_to NOT IN ('.$ignoreCats.'))
LEFT JOIN ( imagelinks AS P JOIN page as A ON A.page_id = P.il_from AND '.$nsfilter.') ON I.page_title = P.il_to
WHERE I.page_namespace = '.NS_IMAGE.' AND L.cl_from IS NULL AND P.il_to IS NULL
GROUP BY img_user_text';
$wq= new WikiQuery('Orphan Images per User', $sql);
#$wq->setWikiDomain('commons.wikimedia.org');
#img_name as title, img_user, img_user_text, img_timestamp as value, img_description
$wq->fields['num']= array(
'label' => 'Orphans',
'sort' => true,
'html' => true,
'pattern' => 'return $this->makeOptionLink(array("img_user_text" => $row["img_user_text"], "grouped" => false), $row["num"]);',
'wiki-pattern' => 'return $row["num"];',
'attributes' => 'align="right"',
);
$wq->fields['img_user_text']= array(
'label' => 'User',
'html' => true,
'attributes' => 'style="white-space:nowrap;"',
'pattern' => 'return $this->makeLink($row["img_user_text"], NS_USER, false);',
'wiki-pattern' => 'return $this->makeWikiLink($row["img_user_text"], NS_USER, false);',
'sort' => true,
#'filter' => true,
'filter-normalize' => 'title',
);
$wq->defaultOrder= '-num';
}
else {
$sql= 'SELECT img_name, img_user, img_user_text, img_timestamp, img_description
FROM page AS I
JOIN image AS G ON I.page_title = G.img_name
LEFT JOIN categorylinks AS L ON (I.page_id = L.cl_from AND L.cl_to NOT IN ('.$ignoreCats.'))
LEFT JOIN ( imagelinks AS P JOIN page as A ON A.page_id = P.il_from AND '.$nsfilter.' ) ON I.page_title = P.il_to
WHERE I.page_namespace = '.NS_IMAGE.' AND L.cl_from IS NULL AND P.il_to IS NULL';
$wq= new WikiQuery('Orphan Images', $sql);
#$wq->setWikiDomain('commons.wikimedia.org');
#img_name as title, img_user, img_user_text, img_timestamp as value, img_description
$wq->fields['img_timestamp']= array(
'label' => 'Date',
'html' => true,
'pattern' => 'return $this->makeDate($row["img_timestamp"]);',
'sort' => true,
);
$wq->fields['img_user_text']= array(
'label' => 'User',
'html' => true,
'pattern' => 'return $this->makeLink($row["img_user_text"], NS_USER, false);',
'wiki-pattern' => 'return $this->makeWikiLink($row["img_user_text"], NS_USER, false);',
'sort' => true,
'filter' => true,
'filter-normalize' => 'title',
);
$wq->fields['img_name']= array(
'label' => 'Name',
'html' => true,
'pattern' => 'return $this->makeLink($row["img_name"], NS_IMAGE, false);',
'wiki-pattern' => 'return $this->makeWikiLink($row["img_name"], NS_IMAGE, false);',
'sort' => true,
);
$wq->fields['actions']= array(
'label' => 'Actions',
'html' => true,
'function' => 'getOrphanActions',
);
/*
$wq->fields['page_random']= array(
'label' => 'Shuffle',
'hidden' => true,
'sort' => true,
);
*/
}
$wq->options["grouped"]= 'group by user';
$wq->options["filter"]= array(
'main' => 'use main namespace only',
'notalk' => 'use non-talk pages only',
'all' => 'use all pages',
);
#$wq->dumpSQL= true;
$wq->allowWiki= true;
$wq->helpPageName= 'OrphanImages';
$wq->printPage();
$wq->close();
?>OrphanImages.php
application/x-php, 5309 bytes (load raw)

