5 * @subpackage SpecialPage
9 require_once( 'ImageGallery.php' );
14 function wfSpecialNewimages() {
15 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest,
18 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
19 $dbr =& wfGetDB( DB_SLAVE
);
20 $sk = $wgUser->getSkin();
21 $hidebots = $wgRequest->getBool('hidebots',1);
25 /** Make a list of group names which have the 'bot' flag
29 foreach ($wgGroupPermissions as $groupname=>$perms) {
30 if(array_key_exists('bot',$perms) && $perms['bot']) {
31 $botconds[]="ug_group='$groupname'";
34 $isbotmember=$dbr->makeList($botconds, LIST_OR
);
36 /** This join, in conjunction with WHERE ug_group
37 IS NULL, returns only those rows from IMAGE
38 where the uploading user is not a member of
39 a group which has the 'bot' permission set.
41 $ug = $dbr->tableName('user_groups');
42 $joinsql=" LEFT OUTER JOIN $ug ON img_user=ug_user AND ("
46 $image = $dbr->tableName('image');
48 $sql="SELECT img_timestamp from $image";
50 $sql.=$joinsql.' WHERE ug_group IS NULL';
52 $sql.=' ORDER BY img_timestamp DESC LIMIT 1';
53 $res = $dbr->query($sql, 'wfSpecialNewImages');
54 $row = $dbr->fetchRow($res);
60 $dbr->freeResult($res);
63 /** If we were clever, we'd use this to cache. */
64 $latestTimestamp = wfTimestamp( TS_MW
, $ts);
66 /** Hardcode this for now. */
70 if ( $wpIlMatch != '' ) {
71 $nt = Title
::newFromUrl( $wpIlMatch );
73 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
74 $m = str_replace( '%', "\\%", $m );
75 $m = str_replace( '_', "\\_", $m );
76 $where[] = "LCASE(img_name) LIKE '%{$m}%'";
81 if( $until = $wgRequest->getVal( 'until' ) ) {
82 $where[] = 'img_timestamp < ' . $dbr->timestamp( $until );
84 if( $from = $wgRequest->getVal( 'from' ) ) {
85 $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from );
88 $sql='SELECT img_size, img_name, img_user, img_user_text,'.
89 "img_description,img_timestamp FROM $image";
93 $where[]='ug_group IS NULL';
96 $sql.=' WHERE '.$dbr->makeList($where, LIST_AND
);
98 $sql.=' ORDER BY img_timestamp '. ( $invertSort ?
'' : ' DESC' );
99 $sql.=' LIMIT '.($limit+
1);
100 $res = $dbr->query($sql, 'wfSpecialNewImages');
103 * We have to flip things around to get the last N after a certain date
106 while ( $s = $dbr->fetchObject( $res ) ) {
108 array_unshift( $images, $s );
110 array_push( $images, $s );
113 $dbr->freeResult( $res );
115 $gallery = new ImageGallery();
116 $firstTimestamp = null;
117 $lastTimestamp = null;
119 foreach( $images as $s ) {
120 if( ++
$shownImages > $limit ) {
121 # One extra just to test for whether to show a page link;
122 # don't actually show it.
126 $name = $s->img_name
;
127 $ut = $s->img_user_text
;
129 $nt = Title
::newFromText( $name, NS_IMAGE
);
130 $img = Image
::newFromTitle( $nt );
131 $ul = $sk->makeLinkObj( Title
::makeTitle( NS_USER
, $ut ), $ut );
133 $gallery->add( $img, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp
, true )."</i><br />\n" );
135 $timestamp = wfTimestamp( TS_MW
, $s->img_timestamp
);
136 if( empty( $firstTimestamp ) ) {
137 $firstTimestamp = $timestamp;
139 $lastTimestamp = $timestamp;
142 $bydate = wfMsg( 'bydate' );
143 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
144 $text = wfMsg( "imagelisttext",
145 "<strong>{$lt}</strong>", "<strong>{$bydate}</strong>" );
146 $wgOut->addHTML( "<p>{$text}\n</p>" );
148 $sub = wfMsg( 'ilsubmit' );
149 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Newimages' );
150 $action = $titleObj->escapeLocalURL( "limit={$limit}" );
152 $action.='&hidebots=0';
154 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
156 "<input type='text' size='20' name=\"wpIlMatch\" value=\"" .
157 htmlspecialchars( $wpIlMatch ) . "\" /> " .
158 "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
159 $here = $wgContLang->specialPage( 'Newimages' );
165 # If we change bot visibility, this needs to be carried along.
167 $botpar='&hidebots=0';
171 $now = wfTimestampNow();
172 $date = $wgLang->timeanddate( $now );
173 $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'rclistfrom', $date ), 'from='.$now.$botpar );
175 $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg( 'showhidebots', ($hidebots ?
wfMsg('show') : wfMsg('hide'))),'hidebots='.($hidebots ?
'0' : '1'));
177 $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) );
178 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
179 $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar );
182 $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) );
183 if( $shownImages > $limit && $lastTimestamp ) {
184 $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar );
187 $prevnext = '<p>' . $botLink . ' '. wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
189 $wgOut->addHTML( $prevnext );
191 if( count( $images ) ) {
192 $wgOut->addHTML( $gallery->toHTML() );
193 $wgOut->addHTML( $prevnext );
195 $wgOut->addWikiText( wfMsg( 'noimages' ) );