3 * Implements Special:Unusedimages
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * A special page that lists unused images
27 * @ingroup SpecialPage
29 class UnusedimagesPage
extends ImageQueryPage
{
31 function isExpensive() { return true; }
34 return 'Unusedimages';
37 function sortDescending() {
40 function isSyndicated() { return false; }
43 global $wgCountCategorizedImagesAsUsed, $wgDBtype;
44 $dbr = wfGetDB( DB_SLAVE
);
48 $epoch = 'UNIX_TIMESTAMP(img_timestamp)';
51 $epoch = '((trunc(img_timestamp) - to_date(\'19700101\',\'YYYYMMDD\')) * 86400)';
54 $epoch = 'img_timestamp';
57 $epoch = 'DATEDIFF(s,CONVERT(datetime,\'1/1/1970\'),img_timestamp)';
60 $epoch = 'EXTRACT(epoch FROM img_timestamp)';
63 if ( $wgCountCategorizedImagesAsUsed ) {
64 list( $page, $image, $imagelinks, $categorylinks ) = $dbr->tableNamesN( 'page', 'image', 'imagelinks', 'categorylinks' );
66 return "SELECT 'Unusedimages' as type, 6 as namespace, img_name as title, $epoch as value,
67 img_user, img_user_text, img_description
68 FROM ((($page AS I LEFT JOIN $categorylinks AS L ON I.page_id = L.cl_from)
69 LEFT JOIN $imagelinks AS P ON I.page_title = P.il_to)
70 INNER JOIN $image AS G ON I.page_title = G.img_name)
71 WHERE I.page_namespace = ".NS_FILE
." AND L.cl_from IS NULL AND P.il_to IS NULL";
73 list( $image, $imagelinks ) = $dbr->tableNamesN( 'image','imagelinks' );
75 return "SELECT 'Unusedimages' as type, 6 as namespace, img_name as title, $epoch as value,
76 img_user, img_user_text, img_description
77 FROM $image LEFT JOIN $imagelinks ON img_name=il_to WHERE il_to IS NULL ";
81 function getPageHeader() {
82 return wfMsgExt( 'unusedimagestext', array( 'parse' ) );
90 function wfSpecialUnusedimages() {
91 list( $limit, $offset ) = wfCheckLimits();
92 $uip = new UnusedimagesPage();
94 return $uip->doQuery( $offset, $limit );