5 * @subpackage SpecialPage
9 require_once( 'ImageGallery.php' );
14 function wfSpecialNewimages( $par, $specialPage ) {
15 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgGroupPermissions;
17 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
18 $dbr =& wfGetDB( DB_SLAVE
);
19 $sk = $wgUser->getSkin();
20 $shownav = !$specialPage->including();
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. */
69 if ( $parval = intval( $par ) )
70 if ( $parval <= $limit && $parval > 0 )
75 if ( $wpIlMatch != '' ) {
76 $nt = Title
::newFromUrl( $wpIlMatch );
78 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
79 $m = str_replace( '%', "\\%", $m );
80 $m = str_replace( '_', "\\_", $m );
81 $where[] = "LCASE(img_name) LIKE '%{$m}%'";
82 $searchpar = '&wpIlMatch=' . urlencode( $wpIlMatch );
87 if( $until = $wgRequest->getVal( 'until' ) ) {
88 $where[] = 'img_timestamp < ' . $dbr->timestamp( $until );
90 if( $from = $wgRequest->getVal( 'from' ) ) {
91 $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from );
94 $sql='SELECT img_size, img_name, img_user, img_user_text,'.
95 "img_description,img_timestamp FROM $image";
99 $where[]='ug_group IS NULL';
102 $sql.=' WHERE '.$dbr->makeList($where, LIST_AND
);
104 $sql.=' ORDER BY img_timestamp '. ( $invertSort ?
'' : ' DESC' );
105 $sql.=' LIMIT '.($limit+
1);
106 $res = $dbr->query($sql, 'wfSpecialNewImages');
109 * We have to flip things around to get the last N after a certain date
112 while ( $s = $dbr->fetchObject( $res ) ) {
114 array_unshift( $images, $s );
116 array_push( $images, $s );
119 $dbr->freeResult( $res );
121 $gallery = new ImageGallery();
122 $firstTimestamp = null;
123 $lastTimestamp = null;
125 foreach( $images as $s ) {
126 if( ++
$shownImages > $limit ) {
127 # One extra just to test for whether to show a page link;
128 # don't actually show it.
132 $name = $s->img_name
;
133 $ut = $s->img_user_text
;
135 $nt = Title
::newFromText( $name, NS_IMAGE
);
136 $img = Image
::newFromTitle( $nt );
137 $ul = $sk->makeLinkObj( Title
::makeTitle( NS_USER
, $ut ), $ut );
139 $gallery->add( $img, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp
, true )."</i><br />\n" );
141 $timestamp = wfTimestamp( TS_MW
, $s->img_timestamp
);
142 if( empty( $firstTimestamp ) ) {
143 $firstTimestamp = $timestamp;
145 $lastTimestamp = $timestamp;
148 $bydate = wfMsg( 'bydate' );
149 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
151 $text = wfMsg( 'imagelisttext', "<strong>{$lt}</strong>", "<strong>{$bydate}</strong>" );
152 $wgOut->addHTML( "<p>{$text}\n</p>" );
155 $sub = wfMsg( 'ilsubmit' );
156 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Newimages' );
157 $action = $titleObj->escapeLocalURL();
159 $action.='&hidebots=0';
162 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
164 "<input type='text' size='20' name=\"wpIlMatch\" value=\"" .
165 htmlspecialchars( $wpIlMatch ) . "\" /> " .
166 "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
168 $here = $wgContLang->specialPage( 'Newimages' );
174 # If we change bot visibility, this needs to be carried along.
176 $botpar='&hidebots=0';
180 $now = wfTimestampNow();
181 $date = $wgLang->timeanddate( $now );
182 $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'rclistfrom', $date ), 'from='.$now.$botpar.$searchpar );
184 $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg( 'showhidebots', ($hidebots ?
wfMsg('show') : wfMsg('hide'))),'hidebots='.($hidebots ?
'0' : '1').$searchpar);
186 $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) );
187 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
188 $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar );
191 $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) );
192 if( $shownImages > $limit && $lastTimestamp ) {
193 $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar.$searchpar );
196 $prevnext = '<p>' . $botLink . ' '. wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
199 $wgOut->addHTML( $prevnext );
201 if( count( $images ) ) {
202 $wgOut->addHTML( $gallery->toHTML() );
204 $wgOut->addHTML( $prevnext );
206 $wgOut->addWikiText( wfMsg( 'noimages' ) );