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