5 * @subpackage SpecialPage
9 require_once( 'ImageGallery.php' );
14 function wfSpecialNewimages( $par, $specialPage ) {
15 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest,
18 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
19 $dbr =& wfGetDB( DB_SLAVE
);
20 $sk = $wgUser->getSkin();
21 $shownav = !$specialPage->including();
22 $hidebots = $wgRequest->getBool('hidebots',1);
24 # Show only for a single user?
25 $targetUser = isset($par) ?
$par : $wgRequest->getVal( 'target' );
26 if ( $targetUser != "" ) { #AND !is_numeric ( $targetUser ) ) { # There might be some ambiguity between this and the $limit later on!
27 $singleUser = User
::newFromName ( $targetUser ) ;
32 /** Make a list of group names which have the 'bot' flag
36 foreach ($wgGroupPermissions as $groupname=>$perms) {
37 if(array_key_exists('bot',$perms) && $perms['bot']) {
38 $botconds[]="ug_group='$groupname'";
41 $isbotmember=$dbr->makeList($botconds, LIST_OR
);
43 /** This join, in conjunction with WHERE ug_group
44 IS NULL, returns only those rows from IMAGE
45 where the uploading user is not a member of
46 a group which has the 'bot' permission set.
48 $ug = $dbr->tableName('user_groups');
49 $joinsql=" LEFT OUTER JOIN $ug ON img_user=ug_user AND ("
53 $image = $dbr->tableName('image');
55 $sql="SELECT img_timestamp from $image";
59 $sql.=$joinsql.' WHERE ug_group IS NULL';
62 $sql.=' ORDER BY img_timestamp DESC LIMIT 1';
63 $res = $dbr->query($sql, 'wfSpecialNewImages');
64 $row = $dbr->fetchRow($res);
70 $dbr->freeResult($res);
73 /** If we were clever, we'd use this to cache. */
74 $latestTimestamp = wfTimestamp( TS_MW
, $ts);
76 /** Hardcode this for now. */
79 if ( $parval = intval( $par ) )
80 if ( $parval <= $limit && $parval > 0 )
85 if ( $wpIlMatch != '' ) {
86 $nt = Title
::newFromUrl( $wpIlMatch );
88 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
89 $m = str_replace( '%', "\\%", $m );
90 $m = str_replace( '_', "\\_", $m );
91 $where[] = "LCASE(img_name) LIKE '%{$m}%'";
92 $searchpar = '&wpIlMatch=' . urlencode( $wpIlMatch );
96 # SQL for single user only?
97 if ( isset ( $singleUser ) ) {
98 $where[] .= "img_user='" . $singleUser->getID() . "'" ;
102 if( $until = $wgRequest->getVal( 'until' ) ) {
103 $where[] = 'img_timestamp < ' . $dbr->timestamp( $until );
105 if( $from = $wgRequest->getVal( 'from' ) ) {
106 $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from );
109 $sql='SELECT img_size, img_name, img_user, img_user_text,'.
110 "img_description,img_timestamp FROM $image";
114 $where[]='ug_group IS NULL';
117 $sql.=' WHERE '.$dbr->makeList($where, LIST_AND
);
119 $sql.=' ORDER BY img_timestamp '. ( $invertSort ?
'' : ' DESC' );
120 $sql.=' LIMIT '.($limit+
1);
121 $res = $dbr->query($sql, 'wfSpecialNewImages');
124 * We have to flip things around to get the last N after a certain date
127 while ( $s = $dbr->fetchObject( $res ) ) {
129 array_unshift( $images, $s );
131 array_push( $images, $s );
134 $dbr->freeResult( $res );
136 $gallery = new ImageGallery();
137 $firstTimestamp = null;
138 $lastTimestamp = null;
140 foreach( $images as $s ) {
141 if( ++
$shownImages > $limit ) {
142 # One extra just to test for whether to show a page link;
143 # don't actually show it.
147 $name = $s->img_name
;
148 $ut = $s->img_user_text
;
150 $nt = Title
::newFromText( $name, NS_IMAGE
);
151 $img = Image
::newFromTitle( $nt );
152 $ul = $sk->makeLinkObj( Title
::makeTitle( NS_USER
, $ut ), $ut );
154 $gallery->add( $img, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp
, true )."</i><br />\n" );
156 $timestamp = wfTimestamp( TS_MW
, $s->img_timestamp
);
157 if( empty( $firstTimestamp ) ) {
158 $firstTimestamp = $timestamp;
160 $lastTimestamp = $timestamp;
163 $bydate = wfMsg( 'bydate' );
164 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
166 $text = wfMsg( 'imagelisttext', "<strong>{$lt}</strong>", "<strong>{$bydate}</strong>" );
167 $wgOut->addHTML( "<p>{$text}\n</p>" );
170 # Single user search note
171 if ( isset ( $singleUser ) ) {
172 $t = $singleUser->getUserPage() ;
173 $uPage = $sk->makeLinkObj( $t ) ;
174 $wgOut->addHTML ( wfMsg ( 'imagelistforuser' , $uPage ) ) ;
177 $sub = wfMsg( 'ilsubmit' );
178 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Newimages' );
179 $action = $titleObj->escapeLocalURL();
181 $action.='&hidebots=0';
184 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
186 "<input type='text' size='20' name=\"wpIlMatch\" value=\"" .
187 htmlspecialchars( $wpIlMatch ) . "\" /> " .
188 "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
190 $here = $wgContLang->specialPage( 'Newimages' );
196 # If we change bot visibility, this needs to be carried along.
198 $botpar='&hidebots=0';
202 $now = wfTimestampNow();
203 $date = $wgLang->timeanddate( $now );
204 $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'rclistfrom', $date ), 'from='.$now.$botpar.$searchpar );
206 $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg( 'showhidebots', ($hidebots ?
wfMsg('show') : wfMsg('hide'))),'hidebots='.($hidebots ?
'0' : '1').$searchpar);
208 $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) );
209 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
210 $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar );
213 $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) );
214 if( $shownImages > $limit && $lastTimestamp ) {
215 $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar.$searchpar );
218 $prevnext = '<p>' . $botLink . ' '. wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
221 $wgOut->addHTML( $prevnext );
223 if( count( $images ) ) {
224 $wgOut->addHTML( $gallery->toHTML() );
226 $wgOut->addHTML( $prevnext );
228 $wgOut->addWikiText( wfMsg( 'noimages' ) );