5 * FIXME: this code is crap, should use Pager and Database::select().
8 function wfSpecialNewimages( $par, $specialPage ) {
9 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgMiserMode;
11 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
12 $dbr = wfGetDB( DB_SLAVE
);
13 $sk = $wgUser->getSkin();
14 $shownav = !$specialPage->including();
15 $hidebots = $wgRequest->getBool( 'hidebots' , 1 );
19 # Make a list of group names which have the 'bot' flag set.
21 foreach ( User
::getGroupsWithPermission('bot') as $groupname ) {
22 $botconds[] = 'ug_group = ' . $dbr->addQuotes( $groupname );
25 # If not bot groups, do not set $hidebotsql
27 $isbotmember = $dbr->makeList( $botconds, LIST_OR
);
29 # This join, in conjunction with WHERE ug_group IS NULL, returns
30 # only those rows from IMAGE where the uploading user is not a mem-
31 # ber of a group which has the 'bot' permission set.
32 $ug = $dbr->tableName( 'user_groups' );
33 $hidebotsql = " LEFT JOIN $ug ON img_user=ug_user AND ($isbotmember)";
37 $image = $dbr->tableName( 'image' );
39 $sql = "SELECT img_timestamp from $image";
41 $sql .= "$hidebotsql WHERE ug_group IS NULL";
43 $sql .= ' ORDER BY img_timestamp DESC';
44 $sql = $dbr->limitResult($sql, 1, false);
45 $res = $dbr->query( $sql, __FUNCTION__
);
46 $row = $dbr->fetchRow( $res );
47 if( $row !== false ) {
52 $dbr->freeResult( $res );
55 # If we were clever, we'd use this to cache.
56 $latestTimestamp = wfTimestamp( TS_MW
, $ts );
58 # Hardcode this for now.
61 if ( $parval = intval( $par ) ) {
62 if ( $parval <= $limit && $parval > 0 ) {
69 if ( $wpIlMatch != '' && !$wgMiserMode) {
70 $nt = Title
::newFromUrl( $wpIlMatch );
72 $m = $dbr->escapeLike( strtolower( $nt->getDBkey() ) );
73 $where[] = "LOWER(img_name) LIKE '%{$m}%'";
74 $searchpar = '&wpIlMatch=' . urlencode( $wpIlMatch );
79 if( $until = $wgRequest->getVal( 'until' ) ) {
80 $where[] = "img_timestamp < '" . $dbr->timestamp( $until ) . "'";
82 if( $from = $wgRequest->getVal( 'from' ) ) {
83 $where[] = "img_timestamp >= '" . $dbr->timestamp( $from ) . "'";
86 $sql='SELECT img_size, img_name, img_user, img_user_text,'.
87 "img_description,img_timestamp FROM $image";
91 $where[] = 'ug_group IS NULL';
93 if( count( $where ) ) {
94 $sql .= ' WHERE ' . $dbr->makeList( $where, LIST_AND
);
96 $sql.=' ORDER BY img_timestamp '. ( $invertSort ?
'' : ' DESC' );
97 $sql = $dbr->limitResult($sql, ( $limit +
1 ), false);
98 $res = $dbr->query( $sql, __FUNCTION__
);
101 * We have to flip things around to get the last N after a certain date
104 while ( $s = $dbr->fetchObject( $res ) ) {
106 array_unshift( $images, $s );
108 array_push( $images, $s );
111 $dbr->freeResult( $res );
113 $gallery = new ImageGallery();
114 $firstTimestamp = null;
115 $lastTimestamp = null;
117 foreach( $images as $s ) {
119 if( $shownImages > $limit ) {
120 # One extra just to test for whether to show a page link;
121 # don't actually show it.
125 $name = $s->img_name
;
126 $ut = $s->img_user_text
;
128 $nt = Title
::newFromText( $name, NS_FILE
);
129 $ul = $sk->link( Title
::makeTitle( NS_USER
, $ut ), $ut );
131 $gallery->add( $nt, "$ul<br />\n<i>".htmlspecialchars($wgLang->timeanddate( $s->img_timestamp
, true ))."</i><br />\n" );
133 $timestamp = wfTimestamp( TS_MW
, $s->img_timestamp
);
134 if( empty( $firstTimestamp ) ) {
135 $firstTimestamp = $timestamp;
137 $lastTimestamp = $timestamp;
140 $titleObj = SpecialPage
::getTitleFor( 'Newimages' );
141 $action = $titleObj->getLocalURL( $hidebots ?
'' : 'hidebots=0' );
142 if ( $shownav && !$wgMiserMode ) {
144 Xml
::openElement( 'form', array( 'action' => $action, 'method' => 'post', 'id' => 'imagesearch' ) ) .
145 Xml
::fieldset( wfMsg( 'newimages-legend' ) ) .
146 Xml
::inputLabel( wfMsg( 'newimages-label' ), 'wpIlMatch', 'wpIlMatch', 20, $wpIlMatch ) . ' ' .
147 Xml
::submitButton( wfMsg( 'ilsubmit' ), array( 'name' => 'wpIlSubmit' ) ) .
148 Xml
::closeElement( 'fieldset' ) .
149 Xml
::closeElement( 'form' )
153 $bydate = wfMsg( 'bydate' );
154 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
156 $text = wfMsgExt( 'imagelisttext', array('parse'), $lt, $bydate );
157 $wgOut->addHTML( $text . "\n" );
164 # If we change bot visibility, this needs to be carried along.
166 $botpar = '&hidebots=0';
170 $now = wfTimestampNow();
171 $d = $wgLang->date( $now, true );
172 $t = $wgLang->time( $now, true );
173 $dateLink = $sk->makeKnownLinkObj( $titleObj, htmlspecialchars( wfMsg( 'sp-newimages-showfrom', $d, $t ) ),
174 'from='.$now.$botpar.$searchpar );
176 $botLink = $sk->makeKnownLinkObj($titleObj, wfMsgHtml( 'showhidebots',
177 ($hidebots ?
wfMsgHtml('show') : wfMsgHtml('hide'))),'hidebots='.($hidebots ?
'0' : '1').$searchpar);
180 $opts = array( 'parsemag', 'escapenoentities' );
181 $prevLink = wfMsgExt( 'pager-newer-n', $opts, $wgLang->formatNum( $limit ) );
182 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
183 $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar );
186 $nextLink = wfMsgExt( 'pager-older-n', $opts, $wgLang->formatNum( $limit ) );
187 if( $shownImages > $limit && $lastTimestamp ) {
188 $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar.$searchpar );
191 $prevnext = '<p>' . $botLink . ' '. wfMsgHtml( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
194 $wgOut->addHTML( $prevnext );
196 if( count( $images ) ) {
197 $wgOut->addHTML( $gallery->toHTML() );
199 $wgOut->addHTML( $prevnext );
201 $wgOut->addWikiMsg( 'noimages' );