4c31fe06004bc4753a692dbfc9835434072df084
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup SpecialPage
23 * FIXME: this code is crap, should use Pager and Database::select().
26 function wfSpecialNewimages( $par, $specialPage ) {
27 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgMiserMode;
29 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
30 $dbr = wfGetDB( DB_SLAVE
);
31 $sk = $wgUser->getSkin();
32 $shownav = !$specialPage->including();
33 $hidebots = $wgRequest->getBool( 'hidebots' , 1 );
37 # Make a list of group names which have the 'bot' flag set.
39 foreach ( User
::getGroupsWithPermission('bot') as $groupname ) {
40 $botconds[] = 'ug_group = ' . $dbr->addQuotes( $groupname );
43 # If not bot groups, do not set $hidebotsql
45 $isbotmember = $dbr->makeList( $botconds, LIST_OR
);
47 # This join, in conjunction with WHERE ug_group IS NULL, returns
48 # only those rows from IMAGE where the uploading user is not a mem-
49 # ber of a group which has the 'bot' permission set.
50 $ug = $dbr->tableName( 'user_groups' );
51 $hidebotsql = " LEFT JOIN $ug ON img_user=ug_user AND ($isbotmember)";
55 $image = $dbr->tableName( 'image' );
57 $sql = "SELECT img_timestamp from $image";
59 $sql .= "$hidebotsql WHERE ug_group IS NULL";
61 $sql .= ' ORDER BY img_timestamp DESC';
62 $sql = $dbr->limitResult($sql, 1, false);
63 $res = $dbr->query( $sql, __FUNCTION__
);
64 $row = $dbr->fetchRow( $res );
65 if( $row !== false ) {
70 $dbr->freeResult( $res );
73 # If we were clever, we'd use this to cache.
74 $latestTimestamp = wfTimestamp( TS_MW
, $ts );
76 # Hardcode this for now.
79 if ( $parval = intval( $par ) ) {
80 if ( $parval <= $limit && $parval > 0 ) {
87 if ( $wpIlMatch != '' && !$wgMiserMode) {
88 $nt = Title
::newFromURL( $wpIlMatch );
90 $where[] = 'LOWER(img_name) ' . $dbr->buildLike( $dbr->anyString(), strtolower( $nt->getDBkey() ), $dbr->anyString() );
91 $searchpar['wpIlMatch'] = $wpIlMatch;
96 if( $until = $wgRequest->getVal( 'until' ) ) {
97 $where[] = "img_timestamp < '" . $dbr->timestamp( $until ) . "'";
99 if( $from = $wgRequest->getVal( 'from' ) ) {
100 $where[] = "img_timestamp >= '" . $dbr->timestamp( $from ) . "'";
103 $sql='SELECT img_size, img_name, img_user, img_user_text,'.
104 "img_description,img_timestamp FROM $image";
108 $where[] = 'ug_group IS NULL';
110 if( count( $where ) ) {
111 $sql .= ' WHERE ' . $dbr->makeList( $where, LIST_AND
);
113 $sql.=' ORDER BY img_timestamp '. ( $invertSort ?
'' : ' DESC' );
114 $sql = $dbr->limitResult($sql, ( $limit +
1 ), false);
115 $res = $dbr->query( $sql, __FUNCTION__
);
118 * We have to flip things around to get the last N after a certain date
121 while ( $s = $dbr->fetchObject( $res ) ) {
123 array_unshift( $images, $s );
125 array_push( $images, $s );
128 $dbr->freeResult( $res );
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' );