53a92fc18190140e1d4a6e20b0ceaa1f8c404edc
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.
78 if ( $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 if( $until = $wgRequest->getVal( 'until' ) ) {
96 $where[] = "img_timestamp < '" . $dbr->timestamp( $until ) . "'";
98 if( $from = $wgRequest->getVal( 'from' ) ) {
99 $where[] = "img_timestamp >= '" . $dbr->timestamp( $from ) . "'";
102 $sql = 'SELECT img_size, img_name, img_user, img_user_text,'.
103 "img_description,img_timestamp FROM $image";
107 $where[] = 'ug_group IS NULL';
109 if( count( $where ) ) {
110 $sql .= ' WHERE ' . $dbr->makeList( $where, LIST_AND
);
112 $sql.=' ORDER BY img_timestamp '. ( $invertSort ?
'' : ' DESC' );
113 $sql = $dbr->limitResult($sql, ( $limit +
1 ), false);
114 $res = $dbr->query( $sql, __FUNCTION__
);
117 * We have to flip things around to get the last N after a certain date
120 while ( $s = $dbr->fetchObject( $res ) ) {
122 array_unshift( $images, $s );
124 array_push( $images, $s );
128 $gallery = new ImageGallery();
129 $firstTimestamp = null;
130 $lastTimestamp = null;
132 foreach( $images as $s ) {
134 if( $shownImages > $limit ) {
135 # One extra just to test for whether to show a page link;
136 # don't actually show it.
140 $name = $s->img_name
;
141 $ut = $s->img_user_text
;
143 $nt = Title
::newFromText( $name, NS_FILE
);
144 $ul = $sk->link( Title
::makeTitle( NS_USER
, $ut ), $ut );
146 $gallery->add( $nt, "$ul<br />\n<i>".htmlspecialchars($wgLang->timeanddate( $s->img_timestamp
, true ))."</i><br />\n" );
148 $timestamp = wfTimestamp( TS_MW
, $s->img_timestamp
);
149 if( empty( $firstTimestamp ) ) {
150 $firstTimestamp = $timestamp;
152 $lastTimestamp = $timestamp;
155 $titleObj = SpecialPage
::getTitleFor( 'Newimages' );
156 $action = $titleObj->getLocalURL( $hidebots ?
'' : 'hidebots=0' );
157 if ( $shownav && !$wgMiserMode ) {
159 Xml
::openElement( 'form', array( 'action' => $action, 'method' => 'post', 'id' => 'imagesearch' ) ) .
160 Xml
::fieldset( wfMsg( 'newimages-legend' ) ) .
161 Xml
::inputLabel( wfMsg( 'newimages-label' ), 'wpIlMatch', 'wpIlMatch', 20, $wpIlMatch ) . ' ' .
162 Xml
::submitButton( wfMsg( 'ilsubmit' ), array( 'name' => 'wpIlSubmit' ) ) .
163 Xml
::closeElement( 'fieldset' ) .
164 Xml
::closeElement( 'form' )
168 $bydate = wfMsg( 'bydate' );
169 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
171 $text = wfMsgExt( 'imagelisttext', array('parse'), $lt, $bydate );
172 $wgOut->addHTML( $text . "\n" );
179 # If we change bot visibility, this needs to be carried along.
181 $botpar = array( 'hidebots' => 0 );
185 $now = wfTimestampNow();
186 $d = $wgLang->date( $now, true );
187 $t = $wgLang->time( $now, true );
188 $query = array_merge(
189 array( 'from' => $now ),
194 $dateLink = $sk->linkKnown(
196 htmlspecialchars( wfMsg( 'sp-newimages-showfrom', $d, $t ) ),
201 $query = array_merge(
202 array( 'hidebots' => ( $hidebots ?
0 : 1 ) ),
206 $showhide = $hidebots ?
wfMsg( 'show' ) : wfMsg( 'hide' );
208 $botLink = $sk->linkKnown(
210 htmlspecialchars( wfMsg( 'showhidebots', $showhide ) ),
215 $opts = array( 'parsemag', 'escapenoentities' );
216 $prevLink = wfMsgExt( 'pager-newer-n', $opts, $wgLang->formatNum( $limit ) );
217 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
218 $query = array_merge(
219 array( 'from' => $firstTimestamp ),
224 $prevLink = $sk->linkKnown(
232 $nextLink = wfMsgExt( 'pager-older-n', $opts, $wgLang->formatNum( $limit ) );
233 if( $invertSort ||
( $shownImages > $limit && $lastTimestamp ) ) {
234 $query = array_merge(
235 array( 'until' => ( $lastTimestamp ?
$lastTimestamp : "" ) ),
240 $nextLink = $sk->linkKnown(
249 $prevnext = '<p>' . $botLink . ' '. wfMsgHtml( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
252 $wgOut->addHTML( $prevnext );
254 if( count( $images ) ) {
255 $wgOut->addHTML( $gallery->toHTML() );
257 $wgOut->addHTML( $prevnext );
259 $wgOut->addWikiMsg( 'noimages' );