New date formatter
[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 = wfMsg( "showlast", $fill, $bysize );
72 $wgOut->addHTML( "{$text}<br>\n" );
73
74 $fill = "";
75 $first = true;
76 foreach ( $nums as $num ) {
77 if ( ! $first ) { $fill .= " | "; }
78 $first = false;
79
80 $fill .= $sk->makeKnownLink( $here, $num,
81 "sort=bydate&limit={$num}" );
82 }
83 $text = wfMsg( "showlast", $fill, $bydate );
84 $wgOut->addHTML( "{$text}<br>\n<p>" );
85
86 $res = wfQuery( $sql, DB_READ, "wfSpecialImagelist" );
87 while ( $s = wfFetchObject( $res ) ) {
88 $name = $s->img_name;
89 $ut = $s->img_user_text;
90 if ( 0 == $s->img_user ) { $ul = $ut; }
91 else { $ul = $sk->makeLink( $wgLang->getNsText(
92 Namespace::getUser() ) . ":{$ut}", $ut ); }
93
94 $ilink = "<a href=\"" . wfImageUrl( $name ) .
95 "\">{$name}</a>";
96
97 $nb = wfMsg( "nbytes", $s->img_size );
98 $l = "(" .
99 $sk->makeKnownLink( $wgLang->getNsText(
100 Namespace::getImage() ) . ":{$name}", wfMsg( "imgdesc" ) ) .
101 ") {$ilink} . . {$nb} . . {$ul} . . " .
102 $wgLang->timeanddate( $s->img_timestamp, true );
103
104 if ( "" != $s->img_description ) {
105 $l .= " <em>({$s->img_description})</em>";
106 }
107 $wgOut->addHTML( "{$l}<br>\n" );
108 }
109 wfFreeResult( $res );
110 }
111
112 ?>