5 * @subpackage SpecialPage
11 function wfSpecialNewimages( $par, $specialPage ) {
12 global $wgUser, $wgOut, $wgLang, $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);
23 /** Make a list of group names which have the 'bot' flag
27 foreach ($wgGroupPermissions as $groupname=>$perms) {
28 if(array_key_exists('bot',$perms) && $perms['bot']) {
29 $botconds[]="ug_group='$groupname'";
33 /* If not bot groups, do not set $hidebotsql */
35 $isbotmember=$dbr->makeList($botconds, LIST_OR
);
37 /** This join, in conjunction with WHERE ug_group
38 IS NULL, returns only those rows from IMAGE
39 where the uploading user is not a member of
40 a group which has the 'bot' permission set.
42 $ug = $dbr->tableName('user_groups');
43 $hidebotsql = " LEFT OUTER JOIN $ug ON img_user=ug_user AND ($isbotmember)";
47 $image = $dbr->tableName('image');
49 $sql="SELECT img_timestamp from $image";
51 $sql .= "$hidebotsql WHERE ug_group IS NULL";
53 $sql.=' ORDER BY img_timestamp DESC LIMIT 1';
54 $res = $dbr->query($sql, 'wfSpecialNewImages');
55 $row = $dbr->fetchRow($res);
61 $dbr->freeResult($res);
64 /** If we were clever, we'd use this to cache. */
65 $latestTimestamp = wfTimestamp( TS_MW
, $ts);
67 /** Hardcode this for now. */
70 if ( $parval = intval( $par ) ) {
71 if ( $parval <= $limit && $parval > 0 ) {
78 if ( $wpIlMatch != '' ) {
79 $nt = Title
::newFromUrl( $wpIlMatch );
81 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
82 $m = str_replace( '%', "\\%", $m );
83 $m = str_replace( '_', "\\_", $m );
84 $where[] = "LCASE(img_name) LIKE '%{$m}%'";
85 $searchpar = '&wpIlMatch=' . urlencode( $wpIlMatch );
90 if( $until = $wgRequest->getVal( 'until' ) ) {
91 $where[] = 'img_timestamp < ' . $dbr->timestamp( $until );
93 if( $from = $wgRequest->getVal( 'from' ) ) {
94 $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from );
97 $sql='SELECT img_size, img_name, img_user, img_user_text,'.
98 "img_description,img_timestamp FROM $image";
102 $where[]='ug_group IS NULL';
105 $sql.=' WHERE '.$dbr->makeList($where, LIST_AND
);
107 $sql.=' ORDER BY img_timestamp '. ( $invertSort ?
'' : ' DESC' );
108 $sql.=' LIMIT '.($limit+
1);
109 $res = $dbr->query($sql, 'wfSpecialNewImages');
112 * We have to flip things around to get the last N after a certain date
115 while ( $s = $dbr->fetchObject( $res ) ) {
117 array_unshift( $images, $s );
119 array_push( $images, $s );
122 $dbr->freeResult( $res );
124 $gallery = new ImageGallery();
125 $firstTimestamp = null;
126 $lastTimestamp = null;
128 foreach( $images as $s ) {
129 if( ++
$shownImages > $limit ) {
130 # One extra just to test for whether to show a page link;
131 # don't actually show it.
135 $name = $s->img_name
;
136 $ut = $s->img_user_text
;
138 $nt = Title
::newFromText( $name, NS_IMAGE
);
139 $img = new Image( $nt );
140 $ul = $sk->makeLinkObj( Title
::makeTitle( NS_USER
, $ut ), $ut );
142 $gallery->add( $img, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp
, true )."</i><br />\n" );
144 $timestamp = wfTimestamp( TS_MW
, $s->img_timestamp
);
145 if( empty( $firstTimestamp ) ) {
146 $firstTimestamp = $timestamp;
148 $lastTimestamp = $timestamp;
151 $bydate = wfMsg( 'bydate' );
152 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
154 $text = wfMsgExt( 'imagelisttext', array('parse'), $lt, $bydate );
155 $wgOut->addHTML( $text . "\n" );
158 $sub = wfMsg( 'ilsubmit' );
159 $titleObj = SpecialPage
::getTitleFor( 'Newimages' );
160 $action = $titleObj->escapeLocalURL( $hidebots ?
'' : '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>" );
173 # If we change bot visibility, this needs to be carried along.
175 $botpar='&hidebots=0';
179 $now = wfTimestampNow();
180 $date = $wgLang->timeanddate( $now, true );
181 $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'sp-newimages-showfrom', $date ), 'from='.$now.$botpar.$searchpar );
183 $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg( 'showhidebots', ($hidebots ?
wfMsg('show') : wfMsg('hide'))),'hidebots='.($hidebots ?
'0' : '1').$searchpar);
185 $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) );
186 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
187 $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar );
190 $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) );
191 if( $shownImages > $limit && $lastTimestamp ) {
192 $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar.$searchpar );
195 $prevnext = '<p>' . $botLink . ' '. wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
198 $wgOut->addHTML( $prevnext );
200 if( count( $images ) ) {
201 $wgOut->addHTML( $gallery->toHTML() );
203 $wgOut->addHTML( $prevnext );
205 $wgOut->addWikiText( wfMsg( 'noimages' ) );