3 * Implements Special:Newimages
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * @todo FIXME: this code is crap, should use Pager and Database::select().
27 function wfSpecialNewimages( $par, $specialPage ) {
28 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgMiserMode;
30 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
31 $dbr = wfGetDB( DB_SLAVE
);
32 $sk = $wgUser->getSkin();
33 $shownav = !$specialPage->including();
34 $hidebots = $wgRequest->getBool( 'hidebots' , 1 );
38 # Make a list of group names which have the 'bot' flag set.
40 foreach ( User
::getGroupsWithPermission('bot') as $groupname ) {
41 $botconds[] = 'ug_group = ' . $dbr->addQuotes( $groupname );
44 # If not bot groups, do not set $hidebotsql
46 $isbotmember = $dbr->makeList( $botconds, LIST_OR
);
48 # This join, in conjunction with WHERE ug_group IS NULL, returns
49 # only those rows from IMAGE where the uploading user is not a mem-
50 # ber of a group which has the 'bot' permission set.
51 $ug = $dbr->tableName( 'user_groups' );
52 $hidebotsql = " LEFT JOIN $ug ON img_user=ug_user AND ($isbotmember)";
56 $image = $dbr->tableName( 'image' );
58 $sql = "SELECT img_timestamp from $image";
60 $sql .= "$hidebotsql WHERE ug_group IS NULL";
62 $sql .= ' ORDER BY img_timestamp DESC';
63 $sql = $dbr->limitResult($sql, 1, false);
64 $res = $dbr->query( $sql, __FUNCTION__
);
65 $row = $dbr->fetchRow( $res );
66 if( $row !== false ) {
72 # If we were clever, we'd use this to cache.
73 $latestTimestamp = wfTimestamp( TS_MW
, $ts );
75 # Hardcode this for now.
77 $parval = intval( $par );
79 if ( $parval <= $limit && $parval > 0 ) {
86 if ( $wpIlMatch != '' && !$wgMiserMode) {
87 $nt = Title
::newFromURL( $wpIlMatch );
89 $where[] = 'LOWER(img_name) ' . $dbr->buildLike( $dbr->anyString(), strtolower( $nt->getDBkey() ), $dbr->anyString() );
90 $searchpar['wpIlMatch'] = $wpIlMatch;
95 $until = $wgRequest->getVal( 'until' );
97 $where[] = "img_timestamp < '" . $dbr->timestamp( $until ) . "'";
99 $from = $wgRequest->getVal( 'from' );
101 $where[] = "img_timestamp >= '" . $dbr->timestamp( $from ) . "'";
104 $sql = 'SELECT img_size, img_name, img_user, img_user_text,'.
105 "img_description,img_timestamp FROM $image";
109 $where[] = 'ug_group IS NULL';
111 if( count( $where ) ) {
112 $sql .= ' WHERE ' . $dbr->makeList( $where, LIST_AND
);
114 $sql.=' ORDER BY img_timestamp '. ( $invertSort ?
'' : ' DESC' );
115 $sql = $dbr->limitResult($sql, ( $limit +
1 ), false);
116 $res = $dbr->query( $sql, __FUNCTION__
);
119 * We have to flip things around to get the last N after a certain date
122 foreach ( $res as $s ) {
124 array_unshift( $images, $s );
126 array_push( $images, $s );
130 $gallery = new ImageGallery();
131 $firstTimestamp = null;
132 $lastTimestamp = null;
134 foreach( $images as $s ) {
136 if( $shownImages > $limit ) {
137 # One extra just to test for whether to show a page link;
138 # don't actually show it.
142 $name = $s->img_name
;
143 $ut = $s->img_user_text
;
145 $nt = Title
::newFromText( $name, NS_FILE
);
146 $ul = $sk->link( Title
::makeTitle( NS_USER
, $ut ), $ut );
148 $gallery->add( $nt, "$ul<br />\n<i>".htmlspecialchars($wgLang->timeanddate( $s->img_timestamp
, true ))."</i><br />\n" );
150 $timestamp = wfTimestamp( TS_MW
, $s->img_timestamp
);
151 if( empty( $firstTimestamp ) ) {
152 $firstTimestamp = $timestamp;
154 $lastTimestamp = $timestamp;
157 $titleObj = SpecialPage
::getTitleFor( 'Newimages' );
158 $action = $titleObj->getLocalURL( $hidebots ?
'' : 'hidebots=0' );
159 if ( $shownav && !$wgMiserMode ) {
161 Xml
::openElement( 'form', array( 'action' => $action, 'method' => 'post', 'id' => 'imagesearch' ) ) .
162 Xml
::fieldset( wfMsg( 'newimages-legend' ) ) .
163 Xml
::inputLabel( wfMsg( 'newimages-label' ), 'wpIlMatch', 'wpIlMatch', 20, $wpIlMatch ) . ' ' .
164 Xml
::submitButton( wfMsg( 'ilsubmit' ), array( 'name' => 'wpIlSubmit' ) ) .
165 Xml
::closeElement( 'fieldset' ) .
166 Xml
::closeElement( 'form' )
170 $bydate = wfMsg( 'bydate' );
171 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
173 $text = wfMsgExt( 'imagelisttext', array('parse'), $lt, $bydate );
174 $wgOut->addHTML( $text . "\n" );
181 # If we change bot visibility, this needs to be carried along.
183 $botpar = array( 'hidebots' => 0 );
187 $now = wfTimestampNow();
188 $d = $wgLang->date( $now, true );
189 $t = $wgLang->time( $now, true );
190 $query = array_merge(
191 array( 'from' => $now ),
196 $dateLink = $sk->linkKnown(
198 htmlspecialchars( wfMsg( 'sp-newimages-showfrom', $d, $t ) ),
203 $query = array_merge(
204 array( 'hidebots' => ( $hidebots ?
0 : 1 ) ),
208 $showhide = $hidebots ?
wfMsg( 'show' ) : wfMsg( 'hide' );
210 $botLink = $sk->linkKnown(
212 htmlspecialchars( wfMsg( 'showhidebots', $showhide ) ),
217 $opts = array( 'parsemag', 'escapenoentities' );
218 $prevLink = wfMsgExt( 'pager-newer-n', $opts, $wgLang->formatNum( $limit ) );
219 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
220 $query = array_merge(
221 array( 'from' => $firstTimestamp ),
226 $prevLink = $sk->linkKnown(
234 $nextLink = wfMsgExt( 'pager-older-n', $opts, $wgLang->formatNum( $limit ) );
235 if( $invertSort ||
( $shownImages > $limit && $lastTimestamp ) ) {
236 $query = array_merge(
237 array( 'until' => ( $lastTimestamp ?
$lastTimestamp : "" ) ),
242 $nextLink = $sk->linkKnown(
251 $prevnext = '<p>' . $botLink . ' '. wfMsgHtml( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
254 $wgOut->addHTML( $prevnext );
256 if( count( $images ) ) {
257 $wgOut->addHTML( $gallery->toHTML() );
259 $wgOut->addHTML( $prevnext );
261 $wgOut->addWikiMsg( 'noimages' );