don't just assume we get a valid title object
[lhc/web/wiklou.git] / includes / SpecialUnusedimages.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /** */
9 require_once("QueryPage.php");
10
11 /**
12 * @package MediaWiki
13 * @subpackage SpecialPage
14 */
15 class UnusedimagesPage extends QueryPage {
16
17 function getName() {
18 return 'Unusedimages';
19 }
20
21 function sortDescending() {
22 return false;
23 }
24 function isSyndicated() { return false; }
25
26 function getSQL() {
27 global $wgCountCategorizedImagesAsUsed;
28 $dbr =& wfGetDB( DB_SLAVE );
29
30 if ( $wgCountCategorizedImagesAsUsed ) {
31 extract( $dbr->tableNames( 'page', 'image', 'imagelinks', 'categorylinks' ) );
32
33 return 'SELECT img_name as title, img_user, img_user_text, img_timestamp as value, img_description
34 FROM ((('.$page.' AS I LEFT JOIN '.$categorylinks.' AS L ON I.page_id = L.cl_from)
35 LEFT JOIN '.$imagelinks.' AS P ON I.page_title = P.il_to)
36 INNER JOIN '.$image.' AS G ON I.page_title = G.img_name)
37 WHERE I.page_namespace = '.NS_IMAGE.' AND L.cl_from IS NULL AND P.il_to IS NULL';
38 } else {
39 extract( $dbr->tableNames( 'image','imagelinks' ) );
40
41 return 'SELECT img_name as title, img_user, img_user_text, img_timestamp as value, img_description' .
42 ' FROM '.$image.' LEFT JOIN '.$imagelinks.' ON img_name=il_to WHERE il_to IS NULL ';
43 }
44 }
45
46 function formatResult( $skin, $result ) {
47 global $wgLang, $wgContLang;
48 $title = Title::makeTitle( NS_IMAGE, $result->title );
49
50 $imageUrl = htmlspecialchars( Image::imageUrl( $result->title ) );
51 $return =
52 # The 'desc' linking to the image page
53 '('.$skin->makeKnownLinkObj( $title, wfMsg('imgdesc') ).') '
54 # Link to the image itself
55 . '<a href="' . $imageUrl . '">' . htmlspecialchars( $title->getText() ) . '</a>'
56 # Last modified date
57 . ' . . '.$wgLang->timeanddate($result->value)
58 # Link to username
59 . ' . . '.$skin->makeLinkObj( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text)
60 # If there is a description, show it
61 . $skin->commentBlock( $wgContLang->convert( $result->img_description ) );
62
63 return $return;
64 }
65
66 function getPageHeader() {
67 return wfMsg( "unusedimagestext" );
68 }
69
70 }
71
72 /**
73 * Entry point
74 */
75 function wfSpecialUnusedimages() {
76 list( $limit, $offset ) = wfCheckLimits();
77 $uip = new UnusedimagesPage();
78
79 return $uip->doQuery( $offset, $limit );
80 }
81 ?>