Commit JeLuF's register_globals fixes, first phase
[lhc/web/wiklou.git] / includes / SpecialImagelist.php
1 <?
2
3 function wfSpecialImagelist()
4 {
5 global $wgUser, $wgOut, $wgLang, $sort;
6 global $wpIlMatch, $wpIlSubmit;
7 $sort = $_REQUEST['sort'];
8 $wpIlMatch = $_REQUEST["wpIlMatch"];
9 $wpIlSubmit = $_REQUEST["wpIlSubmit"];
10
11 $fields = array( 'wpIlMatch' );
12 wfCleanFormFields( $fields );
13
14 $sql = "SELECT img_size,img_name,img_user,img_user_text," .
15 "img_description,img_timestamp FROM image";
16
17 $byname = wfMsg( "byname" );
18 $bydate = wfMsg( "bydate" );
19 $bysize = wfMsg( "bysize" );
20
21 if ( "bysize" == $sort ) {
22 $sql .= " ORDER BY img_size DESC";
23 $st = $bysize;
24 } else if ( "byname" == $sort ) {
25 if ( $wpIlMatch ) {
26 $nt = Title::newFromUrl( $wpIlMatch );
27 $m = wfStrencode( strtolower( $nt->getDBkey() ) );
28 $m = str_replace( "%", "\\%", $m );
29 $m = str_replace( "_", "\\_", $m );
30 $sql .= " WHERE LCASE(img_name) LIKE '%{$m}%'";
31 }
32 $sql .= " ORDER BY img_name";
33 $st = $byname;
34 } else {
35 $sql .= " ORDER BY img_timestamp DESC";
36 $st = $bydate;
37 }
38 list( $limit, $offset ) = wfCheckLimits( 50 );
39 if ( 0 == $limit ) {
40 $lt = wfMsg( "all" );
41 } else {
42 $lt = "${limit}";
43 $sql .= " LIMIT {$limit}";
44 }
45 $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "\n" );
46
47 $text = wfMsg( "imagelisttext",
48 "<strong>{$lt}</strong>", "<strong>{$st}</strong>" );
49 $wgOut->addHTML( "<p>{$text}\n<p>" );
50
51 $sk = $wgUser->getSkin();
52 $cap = wfMsg( "ilshowmatch" );
53 $sub = wfMsg( "ilsubmit" );
54 $action = wfLocalUrlE( $wgLang->specialPage( "Imagelist" ),
55 "sort=byname&limit={$limit}" );
56
57 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
58 "{$action}\">" .
59 "{$cap}: <input type=text size=8 name=\"wpIlMatch\" value=\"\"> " .
60 "<input type=submit name=\"wpIlSubmit\" value=\"{$sub}\"></form>" );
61
62 $nums = array( 50, 100, 250, 500 );
63 $here = $wgLang->specialPage( "Imagelist" );
64
65 $fill = "";
66 $first = true;
67 foreach ( $nums as $num ) {
68 if ( ! $first ) { $fill .= " | "; }
69 $first = false;
70
71 $fill .= $sk->makeKnownLink( $here, "{$num}",
72 "sort=bysize&limit={$num}" );
73 }
74 $text = wfMsg( "showlast", $fill, $bysize );
75 $wgOut->addHTML( "{$text}<br>\n" );
76
77 $fill = "";
78 $first = true;
79 foreach ( $nums as $num ) {
80 if ( ! $first ) { $fill .= " | "; }
81 $first = false;
82
83 $fill .= $sk->makeKnownLink( $here, $num,
84 "sort=bydate&limit={$num}" );
85 }
86 $text = wfMsg( "showlast", $fill, $bydate );
87 $wgOut->addHTML( "{$text}<br>\n<p>" );
88
89 $res = wfQuery( $sql, DB_READ, "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 = wfMsg( "nbytes", $s->img_size );
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 ?>