* Support for table name prefixes throughout the code. No support yet for converting...
[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 $dbr =& wfGetDB( DB_SLAVE );
10 $image = $dbr->tableName( 'image' );
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 = $dbr->strencode( 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 = $wgLang->formatNum( "${limit}" );
40 $sql .= " LIMIT {$limit}";
41 }
42 $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "</p>\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 $titleObj = Title::makeTitle( NS_SPECIAL, "Imagelist" );
52 $action = $titleObj->escapeLocalURL( "sort={$sort}&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 $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=byname&limit={$num}&wpIlMatch={$wpIlMatch}" );
69 }
70 $text = wfMsg( "showlast", $fill, $byname );
71 $wgOut->addHTML( "<p>{$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=bysize&limit={$num}&wpIlMatch={$wpIlMatch}" );
81 }
82 $text = wfMsg( "showlast", $fill, $bysize );
83 $wgOut->addHTML( "{$text}<br />\n" );
84
85 $fill = "";
86 $first = true;
87 foreach ( $nums as $num ) {
88 if ( ! $first ) { $fill .= " | "; }
89 $first = false;
90
91 $fill .= $sk->makeKnownLink( $here, $wgLang->formatNum( $num ),
92 "sort=bydate&limit={$num}&wpIlMatch={$wpIlMatch}" );
93 }
94 $text = wfMsg( "showlast", $fill, $bydate );
95 $wgOut->addHTML( "{$text}</p>\n<p>" );
96
97 $res = $dbr->query( $sql, "wfSpecialImagelist" );
98 while ( $s = $dbr->fetchObject( $res ) ) {
99 $name = $s->img_name;
100 $ut = $s->img_user_text;
101 if ( 0 == $s->img_user ) { $ul = $ut; }
102 else { $ul = $sk->makeLink( $wgLang->getNsText(
103 Namespace::getUser() ) . ":{$ut}", $ut ); }
104
105 $ilink = "<a href=\"" . Image::wfImageUrl( $name ) .
106 "\">{$name}</a>";
107
108 $nb = wfMsg( "nbytes", $wgLang->formatNum( $s->img_size ) );
109 $l = "(" .
110 $sk->makeKnownLink( $wgLang->getNsText(
111 Namespace::getImage() ) . ":{$name}", wfMsg( "imgdesc" ) ) .
112 ") {$ilink} . . {$nb} . . {$ul} . . " .
113 $wgLang->timeanddate( $s->img_timestamp, true );
114
115 if ( "" != $s->img_description ) {
116 $l .= " <em>({$s->img_description})</em>";
117 }
118 $wgOut->addHTML( "{$l}<br />\n" );
119 }
120 $wgOut->addHTML( "</p>" );
121 $dbr->freeResult( $res );
122 }
123
124 ?>