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