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