* Really support plural in imagelisttext
[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, $wgMiserMode;
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 if ( !$wgMiserMode && !empty( $wpIlMatch ) ) {
22 $nt = Title::newFromUrl( $wpIlMatch );
23 if($nt ) {
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 }
30
31 if ( "bysize" == $sort ) {
32 $sql .= " ORDER BY img_size DESC";
33 } else if ( "byname" == $sort ) {
34 $sql .= " ORDER BY img_name";
35 } else {
36 $sort = "bydate";
37 $sql .= " ORDER BY img_timestamp DESC";
38 }
39
40 list( $limit, $offset ) = wfCheckLimits( 50 );
41 $lt = $wgLang->formatNum( "${limit}" );
42 $sql .= " LIMIT {$limit}";
43
44 $wgOut->addWikiText( wfMsg( 'imglegend' ) );
45 $wgOut->addHTML( wfMsgExt( 'imagelisttext', array('parse'), $lt, wfMsg( $sort ) ) );
46
47 $sk = $wgUser->getSkin();
48 $titleObj = Title::makeTitle( NS_SPECIAL, "Imagelist" );
49 $action = $titleObj->escapeLocalURL( "sort={$sort}&limit={$limit}" );
50
51 if ( !$wgMiserMode ) {
52 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
53 "{$action}\">" .
54 wfElement( 'input',
55 array(
56 'type' => 'text',
57 'size' => '20',
58 'name' => 'wpIlMatch',
59 'value' => $wpIlMatch, )) .
60 wfElement( 'input',
61 array(
62 'type' => 'submit',
63 'name' => 'wpIlSubmit',
64 'value' => wfMsg( 'ilsubmit'), )) .
65 '</form>' );
66 }
67
68 $here = Title::makeTitle( NS_SPECIAL, 'Imagelist' );
69
70 foreach ( array( 'byname', 'bysize', 'bydate') as $sorttype ) {
71 $urls = null;
72 foreach ( array( 50, 100, 250, 500 ) as $num ) {
73 $urls[] = $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
74 "sort={$sorttype}&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
75 }
76 $sortlinks[] = wfMsgExt(
77 'showlast',
78 array( 'parseinline', 'replaceafter' ),
79 implode($urls, ' | '),
80 wfMsgExt( $sorttype, array('escape') )
81 );
82 }
83 $wgOut->addHTML( implode( $sortlinks, "<br />\n") . "\n\n<hr />" );
84
85 // lines
86 $wgOut->addHTML( '<p>' );
87 $res = $dbr->query( $sql, "wfSpecialImagelist" );
88
89 while ( $s = $dbr->fetchObject( $res ) ) {
90 $name = $s->img_name;
91 $ut = $s->img_user_text;
92 if ( 0 == $s->img_user ) {
93 $ul = $ut;
94 } else {
95 $ul = $sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
96 }
97
98 $dirmark = $wgContLang->getDirMark(); // to keep text in correct direction
99
100 $ilink = "<a href=\"" . htmlspecialchars( Image::imageUrl( $name ) ) .
101 "\">" . strtr(htmlspecialchars( $name ), '_', ' ') . "</a>";
102
103 $nb = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
104 $wgLang->formatNum( $s->img_size ) );
105
106 $desc = $sk->makeKnownLinkObj( Title::makeTitle( NS_IMAGE, $name ),
107 wfMsg( 'imgdesc' ) );
108
109 $date = $wgLang->timeanddate( $s->img_timestamp, true );
110 $comment = $sk->commentBlock( $s->img_description );
111
112 $l = "({$desc}) {$dirmark}{$ilink} . . {$dirmark}{$nb} . . {$dirmark}{$ul}".
113 " . . {$dirmark}{$date} . . {$dirmark}{$comment}<br />\n";
114 $wgOut->addHTML( $l );
115 }
116
117 $dbr->freeResult( $res );
118 $wgOut->addHTML( '</p>' );
119 }
120
121 ?>