* Edit token no longer passed through htmlspecialchars()
[lhc/web/wiklou.git] / includes / SpecialImagelist.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 function wfSpecialImagelist() {
12 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
13
14 $sort = $wgRequest->getVal( 'sort' );
15 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
16 $dbr =& wfGetDB( DB_SLAVE );
17 $image = $dbr->tableName( 'image' );
18 $sql = "SELECT img_size,img_name,img_user,img_user_text," .
19 "img_description,img_timestamp FROM $image";
20
21 $byname = wfMsg( "byname" );
22 $bydate = wfMsg( "bydate" );
23 $bysize = wfMsg( "bysize" );
24
25 if ( !empty( $wpIlMatch ) ) {
26 $nt = Title::newFromUrl( $wpIlMatch );
27 if($nt ) {
28 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
29 $m = str_replace( "%", "\\%", $m );
30 $m = str_replace( "_", "\\_", $m );
31 $sql .= " WHERE LCASE(img_name) LIKE '%{$m}%'";
32 }
33 }
34 if ( "bysize" == $sort ) {
35 $sql .= " ORDER BY img_size DESC";
36 $st = $bysize;
37 } else if ( "byname" == $sort ) {
38 $sql .= " ORDER BY img_name";
39 $st = $byname;
40 } else {
41 $sort = "bydate";
42 $sql .= " ORDER BY img_timestamp DESC";
43 $st = $bydate;
44 }
45 list( $limit, $offset ) = wfCheckLimits( 50 );
46 if ( 0 == $limit ) {
47 $lt = wfMsg( 'imagelistall' );
48 } else {
49 $lt = $wgLang->formatNum( "${limit}" );
50 $sql .= " LIMIT {$limit}";
51 }
52 $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "</p>\n" );
53
54 $text = wfMsg( "imagelisttext",
55 "<strong>{$lt}</strong>", "<strong>{$st}</strong>" );
56 $wgOut->addHTML( "<p>{$text}\n</p>" );
57
58 $sk = $wgUser->getSkin();
59 $cap = wfMsg( "ilshowmatch" );
60 $sub = wfMsg( "ilsubmit" );
61 $titleObj = Title::makeTitle( NS_SPECIAL, "Imagelist" );
62 $action = $titleObj->escapeLocalURL( "sort={$sort}&limit={$limit}" );
63
64 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
65 "{$action}\">" .
66 "{$cap}: <input type='text' size='8' name=\"wpIlMatch\" value=\"" .
67 htmlspecialchars( $wpIlMatch ) . "\" /> " .
68 "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
69 $nums = array( 50, 100, 250, 500 );
70 $here = Title::makeTitle( NS_SPECIAL, 'Imagelist' );
71
72 $fill = "";
73 $first = true;
74 foreach ( $nums as $num ) {
75 if ( ! $first ) { $fill .= " | "; }
76 $first = false;
77
78 $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
79 "sort=byname&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
80 }
81 $text = wfMsg( "showlast", $fill, $byname );
82 $wgOut->addHTML( "<p>{$text}<br />\n" );
83
84 $fill = "";
85 $first = true;
86 foreach ( $nums as $num ) {
87 if ( ! $first ) { $fill .= " | "; }
88 $first = false;
89
90 $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
91 "sort=bysize&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
92 }
93 $text = wfMsg( "showlast", $fill, $bysize );
94 $wgOut->addHTML( "{$text}<br />\n" );
95
96 $fill = "";
97 $first = true;
98 foreach ( $nums as $num ) {
99 if ( ! $first ) { $fill .= " | "; }
100 $first = false;
101
102 $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
103 "sort=bydate&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
104 }
105 $text = wfMsg( "showlast", $fill, $bydate );
106 $wgOut->addHTML( "{$text}</p>\n<p>" );
107
108 $res = $dbr->query( $sql, "wfSpecialImagelist" );
109 while ( $s = $dbr->fetchObject( $res ) ) {
110 $name = $s->img_name;
111 $ut = $s->img_user_text;
112 if ( 0 == $s->img_user ) {
113 $ul = $ut;
114 } else {
115 $ul = $sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
116 }
117
118 $ilink = "<a href=\"" . htmlspecialchars( Image::imageUrl( $name ) ) .
119 "\">" . htmlspecialchars( $name ) . "</a>";
120
121 $nb = wfMsg( "nbytes", $wgLang->formatNum( $s->img_size ) );
122 $l = "(" .
123 $sk->makeKnownLinkObj( Title::makeTitle( NS_IMAGE, $name ),
124 wfMsg( "imgdesc" ) ) .
125 ") {$ilink} . . {$nb} . . {$ul} . . " .
126 $wgLang->timeanddate( $s->img_timestamp, true );
127
128 $l .= $sk->commentBlock( $s->img_description );
129 $wgOut->addHTML( "{$l}<br />\n" );
130 }
131 $wgOut->addHTML( "</p>" );
132 $dbr->freeResult( $res );
133 }
134
135 ?>