Initial revision
[lhc/web/wiklou.git] / includes / SpecialImagelist.php
1 <?
2
3 function wfSpecialImagelist()
4 {
5 global $wgUser, $wgOut, $wgLang, $sort, $limit;
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 if ( ! isset( $limit ) ) { $limit = 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 = str_replace( "$1", "<strong>{$lt}</strong>",
45 wfMsg( "imagelisttext" ) );
46 $text = str_replace( "$2", "<strong>{$st}</strong>", $text );
47 $wgOut->addHTML( "<p>{$text}\n<p>" );
48
49 $sk = $wgUser->getSkin();
50 $cap = wfMsg( "ilshowmatch" );
51 $sub = wfMsg( "ilsubmit" );
52 $action = wfLocalUrlE( $wgLang->specialPage( "Imagelist" ),
53 "sort=byname&limit={$limit}" );
54
55 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
56 "{$action}\">" .
57 "{$cap}: <input type=text size=8 name=\"wpIlMatch\" value=\"\"> " .
58 "<input type=submit name=\"wpIlSubmit\" value=\"{$sub}\"></form>" );
59
60 $nums = array( 50, 100, 250, 500 );
61 $here = $wgLang->specialPage( "Imagelist" );
62
63 $fill = "";
64 $first = true;
65 foreach ( $nums as $num ) {
66 if ( ! $first ) { $fill .= " | "; }
67 $first = false;
68
69 $fill .= $sk->makeKnownLink( $here, "{$num}",
70 "sort=bysize&limit={$num}" );
71 }
72 $text = str_replace( "$1", $fill, wfMsg( "showlast" ) );
73 $text = str_replace( "$2", $bysize, $text );
74 $wgOut->addHTML( "{$text}<br>\n" );
75
76 $fill = "";
77 $first = true;
78 foreach ( $nums as $num ) {
79 if ( ! $first ) { $fill .= " | "; }
80 $first = false;
81
82 $fill .= $sk->makeKnownLink( $here, $num,
83 "sort=bydate&limit={$num}" );
84 }
85 $text = str_replace( "$1", $fill, wfMsg( "showlast" ) );
86 $text = str_replace( "$2", $bydate, $text );
87 $wgOut->addHTML( "{$text}<br>\n<p>" );
88
89 $res = wfQuery( $sql, "wfSpecialImagelist" );
90 while ( $s = wfFetchObject( $res ) ) {
91 $name = $s->img_name;
92 $ut = $s->img_user_text;
93 if ( 0 == $s->img_user ) { $ul = $ut; }
94 else { $ul = $sk->makeLink( $wgLang->getNsText(
95 Namespace::getUser() ) . ":{$ut}", $ut ); }
96
97 $ilink = "<a href=\"" . wfImageUrl( $name ) .
98 "\">{$name}</a>";
99
100 $nb = str_replace( "$1", $s->img_size, wfMsg( "nbytes" ) );
101 $l = "(" .
102 $sk->makeKnownLink( $wgLang->getNsText(
103 Namespace::getImage() ) . ":{$name}", wfMsg( "imgdesc" ) ) .
104 ") {$ilink} . . {$nb} . . {$ul} . . " .
105 $wgLang->timeanddate( $s->img_timestamp, true );
106
107 if ( "" != $s->img_description ) {
108 $l .= " <em>({$s->img_description})</em>";
109 }
110 $wgOut->addHTML( "{$l}<br>\n" );
111 }
112 wfFreeResult( $res );
113 }
114
115 ?>