5 * @subpackage SpecialPage
11 function wfSpecialNewimages( $par, $specialPage ) {
12 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgGroupPermissions;
14 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
15 $dbr =& wfGetDB( DB_SLAVE
);
16 $sk = $wgUser->getSkin();
17 $shownav = !$specialPage->including();
18 $hidebots = $wgRequest->getBool('hidebots',1);
22 /** Make a list of group names which have the 'bot' flag
26 foreach ($wgGroupPermissions as $groupname=>$perms) {
27 if(array_key_exists('bot',$perms) && $perms['bot']) {
28 $botconds[]="ug_group='$groupname'";
31 $isbotmember=$dbr->makeList($botconds, LIST_OR
);
33 /** This join, in conjunction with WHERE ug_group
34 IS NULL, returns only those rows from IMAGE
35 where the uploading user is not a member of
36 a group which has the 'bot' permission set.
38 $ug = $dbr->tableName('user_groups');
39 $joinsql=" LEFT OUTER JOIN $ug ON img_user=ug_user AND ("
43 $image = $dbr->tableName('image');
45 $sql="SELECT img_timestamp from $image";
47 $sql.=$joinsql.' WHERE ug_group IS NULL';
49 $sql.=' ORDER BY img_timestamp DESC LIMIT 1';
50 $res = $dbr->query($sql, 'wfSpecialNewImages');
51 $row = $dbr->fetchRow($res);
57 $dbr->freeResult($res);
60 /** If we were clever, we'd use this to cache. */
61 $latestTimestamp = wfTimestamp( TS_MW
, $ts);
63 /** Hardcode this for now. */
66 if ( $parval = intval( $par ) )
67 if ( $parval <= $limit && $parval > 0 )
72 if ( $wpIlMatch != '' ) {
73 $nt = Title
::newFromUrl( $wpIlMatch );
75 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
76 $m = str_replace( '%', "\\%", $m );
77 $m = str_replace( '_', "\\_", $m );
78 $where[] = "LCASE(img_name) LIKE '%{$m}%'";
79 $searchpar = '&wpIlMatch=' . urlencode( $wpIlMatch );
84 if( $until = $wgRequest->getVal( 'until' ) ) {
85 $where[] = 'img_timestamp < ' . $dbr->timestamp( $until );
87 if( $from = $wgRequest->getVal( 'from' ) ) {
88 $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from );
91 $sql='SELECT img_size, img_name, img_user, img_user_text,'.
92 "img_description,img_timestamp FROM $image";
96 $where[]='ug_group IS NULL';
99 $sql.=' WHERE '.$dbr->makeList($where, LIST_AND
);
101 $sql.=' ORDER BY img_timestamp '. ( $invertSort ?
'' : ' DESC' );
102 $sql.=' LIMIT '.($limit+
1);
103 $res = $dbr->query($sql, 'wfSpecialNewImages');
106 * We have to flip things around to get the last N after a certain date
109 while ( $s = $dbr->fetchObject( $res ) ) {
111 array_unshift( $images, $s );
113 array_push( $images, $s );
116 $dbr->freeResult( $res );
118 $gallery = new ImageGallery();
119 $firstTimestamp = null;
120 $lastTimestamp = null;
122 foreach( $images as $s ) {
123 if( ++
$shownImages > $limit ) {
124 # One extra just to test for whether to show a page link;
125 # don't actually show it.
129 $name = $s->img_name
;
130 $ut = $s->img_user_text
;
132 $nt = Title
::newFromText( $name, NS_IMAGE
);
133 $img = Image
::newFromTitle( $nt );
134 $ul = $sk->makeLinkObj( Title
::makeTitle( NS_USER
, $ut ), $ut );
136 $gallery->add( $img, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp
, true )."</i><br />\n" );
138 $timestamp = wfTimestamp( TS_MW
, $s->img_timestamp
);
139 if( empty( $firstTimestamp ) ) {
140 $firstTimestamp = $timestamp;
142 $lastTimestamp = $timestamp;
145 $bydate = wfMsg( 'bydate' );
146 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
148 $text = wfMsg( 'imagelisttext', $lt, $bydate );
149 $wgOut->addHTML( "<p>{$text}\n</p>" );
152 $sub = wfMsg( 'ilsubmit' );
153 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Newimages' );
154 $action = $titleObj->escapeLocalURL();
156 $action.='&hidebots=0';
159 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
161 "<input type='text' size='20' name=\"wpIlMatch\" value=\"" .
162 htmlspecialchars( $wpIlMatch ) . "\" /> " .
163 "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
165 $here = $wgContLang->specialPage( 'Newimages' );
171 # If we change bot visibility, this needs to be carried along.
173 $botpar='&hidebots=0';
177 $now = wfTimestampNow();
178 $date = $wgLang->timeanddate( $now, true );
179 $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'sp-newimages-showfrom', $date ), 'from='.$now.$botpar.$searchpar );
181 $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg( 'showhidebots', ($hidebots ?
wfMsg('show') : wfMsg('hide'))),'hidebots='.($hidebots ?
'0' : '1').$searchpar);
183 $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) );
184 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
185 $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar );
188 $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) );
189 if( $shownImages > $limit && $lastTimestamp ) {
190 $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar.$searchpar );
193 $prevnext = '<p>' . $botLink . ' '. wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
196 $wgOut->addHTML( $prevnext );
198 if( count( $images ) ) {
199 $wgOut->addHTML( $gallery->toHTML() );
201 $wgOut->addHTML( $prevnext );
203 $wgOut->addWikiText( wfMsg( 'noimages' ) );