Stop loading feed.php every time by moving available feeds classes in defines.php...
[lhc/web/wiklou.git] / includes / SpecialNewimages.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 require_once( 'ImageGallery.php' );
9
10 /**
11 *
12 */
13 function wfSpecialNewimages() {
14 global $wgUser, $wgOut, $wgLang, $wgRequest;
15
16 $sort = $wgRequest->getVal( 'sort' );
17 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
18 $dbr =& wfGetDB( DB_SLAVE );
19 $image = $dbr->tableName( 'image' );
20 $sql = "SELECT img_size,img_name,img_user,img_user_text," .
21 "img_description,img_timestamp FROM $image";
22
23 $bydate = wfMsg( "bydate" );
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 $sort = "bydate";
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 = $wgLang->formatNum( "${limit}" );
43 $sql .= " LIMIT {$limit}";
44 }
45 $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "</p>\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 $titleObj = Title::makeTitle( NS_SPECIAL, "Imagelist" );
55 $action = $titleObj->escapeLocalURL( "sort={$sort}&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 htmlspecialchars( $wpIlMatch ) . "\" /> " .
61 "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
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, $wgLang->formatNum( $num ),
72 "sort=bydate&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
73 }
74 $text = wfMsg( "showlast", $fill, $bydate );
75 $wgOut->addHTML( "{$text}</p>\n" );
76
77 $i=0;
78 $res = $dbr->query( $sql, "wfSpecialImagelist" );
79
80 $gallery = new ImageGallery();
81
82 while ( $s = $dbr->fetchObject( $res ) ) {
83 $name = $s->img_name;
84 $ut = $s->img_user_text;
85
86 $nt = Title::newFromText( $name, NS_IMAGE );
87 $img = Image::newFromTitle( $nt );
88 $ul = $sk->makeLink( $wgLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
89
90 $gallery->add( $img, $ul.'<br /><i>'.$wgLang->timeanddate( $s->img_timestamp, true ).'</i><br />' );
91 $i++;
92 }
93 $wgOut->addHTML( $gallery->toHTML() );
94 $dbr->freeResult( $res );
95 }
96
97 ?>