Major update! Adding SpecialFilelist.php to replace both SpecialNewimages.php and...
[lhc/web/wiklou.git] / includes / SpecialNewimages.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 require_once ( "SpecialFilelist.php" ) ;
9
10 function wfSpecialNewimages( $par, $specialPage ) {
11 wfSpecialFilelist ( $par , $specialPage , true ) ;
12 }
13
14 # _____________________________________________
15 # The rest of this file is obsolete
16 # _____________________________________________
17
18
19 /** */
20 require_once( 'ImageGallery.php' );
21
22 /**
23 *
24 */
25 function OLD_wfSpecialNewimages( $par, $specialPage ) {
26 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest,
27 $wgGroupPermissions;
28
29 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
30 $dbr =& wfGetDB( DB_SLAVE );
31 $sk = $wgUser->getSkin();
32 $shownav = !$specialPage->including();
33 $hidebots = $wgRequest->getBool('hidebots',1);
34
35 if($hidebots) {
36
37 /** Make a list of group names which have the 'bot' flag
38 set.
39 */
40 $botconds=array();
41 foreach ($wgGroupPermissions as $groupname=>$perms) {
42 if(array_key_exists('bot',$perms) && $perms['bot']) {
43 $botconds[]="ug_group='$groupname'";
44 }
45 }
46 $isbotmember=$dbr->makeList($botconds, LIST_OR);
47
48 /** This join, in conjunction with WHERE ug_group
49 IS NULL, returns only those rows from IMAGE
50 where the uploading user is not a member of
51 a group which has the 'bot' permission set.
52 */
53 $ug = $dbr->tableName('user_groups');
54 $joinsql=" LEFT OUTER JOIN $ug ON img_user=ug_user AND ("
55 . $isbotmember.')';
56 }
57
58 $image = $dbr->tableName('image');
59
60 $sql="SELECT img_timestamp from $image";
61 if($hidebots) {
62 $sql.=$joinsql.' WHERE ug_group IS NULL';
63 }
64 $sql.=' ORDER BY img_timestamp DESC LIMIT 1';
65 $res = $dbr->query($sql, 'wfSpecialNewImages');
66 $row = $dbr->fetchRow($res);
67 if($row!==false) {
68 $ts=$row[0];
69 } else {
70 $ts=false;
71 }
72 $dbr->freeResult($res);
73 $sql='';
74
75 /** If we were clever, we'd use this to cache. */
76 $latestTimestamp = wfTimestamp( TS_MW, $ts);
77
78 /** Hardcode this for now. */
79 $limit = 48;
80
81 if ( $parval = intval( $par ) )
82 if ( $parval <= $limit && $parval > 0 )
83 $limit = $parval;
84
85 $where = array();
86 $searchpar = '';
87 if ( $wpIlMatch != '' ) {
88 $nt = Title::newFromUrl( $wpIlMatch );
89 if($nt ) {
90 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
91 $m = str_replace( '%', "\\%", $m );
92 $m = str_replace( '_', "\\_", $m );
93 $where[] = "LCASE(img_name) LIKE '%{$m}%'";
94 $searchpar = '&wpIlMatch=' . urlencode( $wpIlMatch );
95 }
96 }
97
98 $invertSort = false;
99 if( $until = $wgRequest->getVal( 'until' ) ) {
100 $where[] = 'img_timestamp < ' . $dbr->timestamp( $until );
101 }
102 if( $from = $wgRequest->getVal( 'from' ) ) {
103 $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from );
104 $invertSort = true;
105 }
106 $sql='SELECT img_size, img_name, img_user, img_user_text,'.
107 "img_description,img_timestamp FROM $image";
108
109 if($hidebots) {
110 $sql.=$joinsql;
111 $where[]='ug_group IS NULL';
112 }
113 if(count($where)) {
114 $sql.=' WHERE '.$dbr->makeList($where, LIST_AND);
115 }
116 $sql.=' ORDER BY img_timestamp '. ( $invertSort ? '' : ' DESC' );
117 $sql.=' LIMIT '.($limit+1);
118 $res = $dbr->query($sql, 'wfSpecialNewImages');
119
120 /**
121 * We have to flip things around to get the last N after a certain date
122 */
123 $images = array();
124 while ( $s = $dbr->fetchObject( $res ) ) {
125 if( $invertSort ) {
126 array_unshift( $images, $s );
127 } else {
128 array_push( $images, $s );
129 }
130 }
131 $dbr->freeResult( $res );
132
133 $gallery = new ImageGallery();
134 $firstTimestamp = null;
135 $lastTimestamp = null;
136 $shownImages = 0;
137 foreach( $images as $s ) {
138 if( ++$shownImages > $limit ) {
139 # One extra just to test for whether to show a page link;
140 # don't actually show it.
141 break;
142 }
143
144 $name = $s->img_name;
145 $ut = $s->img_user_text;
146
147 $nt = Title::newFromText( $name, NS_IMAGE );
148 $img = Image::newFromTitle( $nt );
149 $ul = $sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
150
151 $gallery->add( $img, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp, true )."</i><br />\n" );
152
153 $timestamp = wfTimestamp( TS_MW, $s->img_timestamp );
154 if( empty( $firstTimestamp ) ) {
155 $firstTimestamp = $timestamp;
156 }
157 $lastTimestamp = $timestamp;
158 }
159
160 $bydate = wfMsg( 'bydate' );
161 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
162 if ($shownav) {
163 $text = wfMsg( 'imagelisttext', "<strong>{$lt}</strong>", "<strong>{$bydate}</strong>" );
164 $wgOut->addHTML( "<p>{$text}\n</p>" );
165 }
166
167 $sub = wfMsg( 'ilsubmit' );
168 $titleObj = Title::makeTitle( NS_SPECIAL, 'Newimages' );
169 $action = $titleObj->escapeLocalURL();
170 if(!$hidebots) {
171 $action.='&hidebots=0';
172 }
173 if ($shownav) {
174 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
175 "{$action}\">" .
176 "<input type='text' size='20' name=\"wpIlMatch\" value=\"" .
177 htmlspecialchars( $wpIlMatch ) . "\" /> " .
178 "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
179 }
180 $here = $wgContLang->specialPage( 'Newimages' );
181
182 /**
183 * Paging controls...
184 */
185
186 # If we change bot visibility, this needs to be carried along.
187 if(!$hidebots) {
188 $botpar='&hidebots=0';
189 } else {
190 $botpar='';
191 }
192 $now = wfTimestampNow();
193 $date = $wgLang->timeanddate( $now );
194 $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'rclistfrom', $date ), 'from='.$now.$botpar.$searchpar );
195
196 $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg( 'showhidebots', ($hidebots ? wfMsg('show') : wfMsg('hide'))),'hidebots='.($hidebots ? '0' : '1').$searchpar);
197
198 $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) );
199 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
200 $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar );
201 }
202
203 $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) );
204 if( $shownImages > $limit && $lastTimestamp ) {
205 $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar.$searchpar );
206 }
207
208 $prevnext = '<p>' . $botLink . ' '. wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
209
210 if ($shownav)
211 $wgOut->addHTML( $prevnext );
212
213 if( count( $images ) ) {
214 $wgOut->addHTML( $gallery->toHTML() );
215 if ($shownav)
216 $wgOut->addHTML( $prevnext );
217 } else {
218 $wgOut->addWikiText( wfMsg( 'noimages' ) );
219 }
220 }
221
222 ?>