6a8f3fa15129da14d3a3941f1dfa0a78d94727bc
[lhc/web/wiklou.git] / includes / SpecialImagelist.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 function wfSpecialImagelist() {
12 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
13
14 $sort = $wgRequest->getVal( 'sort' );
15 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
16 $dbr =& wfGetDB( DB_SLAVE );
17 $image = $dbr->tableName( 'image' );
18 $sql = "SELECT img_size,img_name,img_user,img_user_text," .
19 "img_description,img_timestamp FROM $image";
20
21 $byname = wfMsg( "byname" );
22 $bydate = wfMsg( "bydate" );
23 $bysize = wfMsg( "bysize" );
24
25 if ( !empty( $wpIlMatch ) ) {
26 $nt = Title::newFromUrl( $wpIlMatch );
27 if($nt ) {
28 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
29 $m = str_replace( "%", "\\%", $m );
30 $m = str_replace( "_", "\\_", $m );
31 $sql .= " WHERE LCASE(img_name) LIKE '%{$m}%'";
32 }
33 }
34 if ( "bysize" == $sort ) {
35 $sql .= " ORDER BY img_size DESC";
36 $st = $bysize;
37 } else if ( "byname" == $sort ) {
38 $sql .= " ORDER BY img_name";
39 $st = $byname;
40 } else {
41 $sort = "bydate";
42 $sql .= " ORDER BY img_timestamp DESC";
43 $st = $bydate;
44 }
45 list( $limit, $offset ) = wfCheckLimits( 50 );
46 if ( 0 == $limit ) {
47 $lt = wfMsg( 'imagelistall' );
48 } else {
49 $lt = $wgLang->formatNum( "${limit}" );
50 $sql .= " LIMIT {$limit}";
51 }
52 $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "</p>\n" );
53
54 $text = wfMsg( "imagelisttext",
55 "<strong>{$lt}</strong>", "<strong>{$st}</strong>" );
56 $wgOut->addHTML( "<p>{$text}\n</p>" );
57
58 $sk = $wgUser->getSkin();
59 $sub = wfMsg( "ilsubmit" );
60 $titleObj = Title::makeTitle( NS_SPECIAL, "Imagelist" );
61 $action = $titleObj->escapeLocalURL( "sort={$sort}&limit={$limit}" );
62
63 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
64 "{$action}\">" .
65 "<input type='text' size='20' name=\"wpIlMatch\" value=\"" .
66 htmlspecialchars( $wpIlMatch ) . "\" /> " .
67 "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
68 $nums = array( 50, 100, 250, 500 );
69 $here = Title::makeTitle( NS_SPECIAL, 'Imagelist' );
70
71 $fill = "";
72 $first = true;
73 foreach ( $nums as $num ) {
74 if ( ! $first ) { $fill .= " | "; }
75 $first = false;
76
77 $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
78 "sort=byname&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
79 }
80 $text = wfMsg( "showlast", $fill, $byname );
81 $wgOut->addHTML( "<p>{$text}<br />\n" );
82
83 $fill = "";
84 $first = true;
85 foreach ( $nums as $num ) {
86 if ( ! $first ) { $fill .= " | "; }
87 $first = false;
88
89 $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
90 "sort=bysize&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
91 }
92 $text = wfMsg( "showlast", $fill, $bysize );
93 $wgOut->addHTML( "{$text}<br />\n" );
94
95 $fill = "";
96 $first = true;
97 foreach ( $nums as $num ) {
98 if ( ! $first ) { $fill .= " | "; }
99 $first = false;
100
101 $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
102 "sort=bydate&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
103 }
104 $text = wfMsg( "showlast", $fill, $bydate );
105 $wgOut->addHTML( "{$text}</p>\n<p>" );
106
107 $res = $dbr->query( $sql, "wfSpecialImagelist" );
108 while ( $s = $dbr->fetchObject( $res ) ) {
109 $name = $s->img_name;
110 $ut = $s->img_user_text;
111 if ( 0 == $s->img_user ) {
112 $ul = $ut;
113 } else {
114 $ul = $sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
115 }
116
117 $ilink = "<a href=\"" . htmlspecialchars( Image::imageUrl( $name ) ) .
118 "\">" . htmlspecialchars( $name ) . "</a>";
119
120 $nb = wfMsg( "nbytes", $wgLang->formatNum( $s->img_size ) );
121 $l = "(" .
122 $sk->makeKnownLinkObj( Title::makeTitle( NS_IMAGE, $name ),
123 wfMsg( "imgdesc" ) ) .
124 ") {$ilink} . . {$nb} . . {$ul} . . " .
125 $wgLang->timeanddate( $s->img_timestamp, true );
126
127 $l .= $sk->commentBlock( $s->img_description );
128 $wgOut->addHTML( "{$l}<br />\n" );
129 }
130 $wgOut->addHTML( "</p>" );
131 $dbr->freeResult( $res );
132 }
133
134 ?>