a3133a0d4e0789e62d439c33d3ca1c8d6405c09b
[lhc/web/wiklou.git] / includes / specials / SpecialUnusedimages.php
1 <?php
2 /**
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 /**
21 * @file
22 * @ingroup SpecialPage
23 */
24
25 /**
26 * implements Special:Unusedimages
27 * @ingroup SpecialPage
28 */
29 class UnusedimagesPage extends ImageQueryPage {
30
31 function isExpensive() { return true; }
32
33 function getName() {
34 return 'Unusedimages';
35 }
36
37 function sortDescending() {
38 return false;
39 }
40 function isSyndicated() { return false; }
41
42 function getSQL() {
43 global $wgCountCategorizedImagesAsUsed, $wgDBtype;
44 $dbr = wfGetDB( DB_SLAVE );
45
46 switch ($wgDBtype) {
47 case 'mysql':
48 $epoch = 'UNIX_TIMESTAMP(img_timestamp)';
49 break;
50 case 'oracle':
51 $epoch = '((trunc(img_timestamp) - to_date(\'19700101\',\'YYYYMMDD\')) * 86400)';
52 break;
53 case 'sqlite':
54 $epoch = 'img_timestamp';
55 break;
56 default:
57 $epoch = 'EXTRACT(epoch FROM img_timestamp)';
58 }
59
60 if ( $wgCountCategorizedImagesAsUsed ) {
61 list( $page, $image, $imagelinks, $categorylinks ) = $dbr->tableNamesN( 'page', 'image', 'imagelinks', 'categorylinks' );
62
63 return "SELECT 'Unusedimages' as type, 6 as namespace, img_name as title, $epoch as value,
64 img_user, img_user_text, img_description
65 FROM ((($page AS I LEFT JOIN $categorylinks AS L ON I.page_id = L.cl_from)
66 LEFT JOIN $imagelinks AS P ON I.page_title = P.il_to)
67 INNER JOIN $image AS G ON I.page_title = G.img_name)
68 WHERE I.page_namespace = ".NS_FILE." AND L.cl_from IS NULL AND P.il_to IS NULL";
69 } else {
70 list( $image, $imagelinks ) = $dbr->tableNamesN( 'image','imagelinks' );
71
72 return "SELECT 'Unusedimages' as type, 6 as namespace, img_name as title, $epoch as value,
73 img_user, img_user_text, img_description
74 FROM $image LEFT JOIN $imagelinks ON img_name=il_to WHERE il_to IS NULL ";
75 }
76 }
77
78 function getPageHeader() {
79 return wfMsgExt( 'unusedimagestext', array( 'parse' ) );
80 }
81
82 }
83
84 /**
85 * Entry point
86 */
87 function wfSpecialUnusedimages() {
88 list( $limit, $offset ) = wfCheckLimits();
89 $uip = new UnusedimagesPage();
90
91 return $uip->doQuery( $offset, $limit );
92 }