00001 <?php
00008 function wfSpecialNewimages( $par, $specialPage ) {
00009 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgMiserMode;
00010
00011 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
00012 $dbr = wfGetDB( DB_SLAVE );
00013 $sk = $wgUser->getSkin();
00014 $shownav = !$specialPage->including();
00015 $hidebots = $wgRequest->getBool( 'hidebots' , 1 );
00016
00017 $hidebotsql = '';
00018 if ( $hidebots ) {
00019 # Make a list of group names which have the 'bot' flag set.
00020 $botconds = array();
00021 foreach ( User::getGroupsWithPermission('bot') as $groupname ) {
00022 $botconds[] = 'ug_group = ' . $dbr->addQuotes( $groupname );
00023 }
00024
00025 # If not bot groups, do not set $hidebotsql
00026 if ( $botconds ) {
00027 $isbotmember = $dbr->makeList( $botconds, LIST_OR );
00028
00029 # This join, in conjunction with WHERE ug_group IS NULL, returns
00030 # only those rows from IMAGE where the uploading user is not a mem-
00031 # ber of a group which has the 'bot' permission set.
00032 $ug = $dbr->tableName( 'user_groups' );
00033 $hidebotsql = " LEFT JOIN $ug ON img_user=ug_user AND ($isbotmember)";
00034 }
00035 }
00036
00037 $image = $dbr->tableName( 'image' );
00038
00039 $sql = "SELECT img_timestamp from $image";
00040 if ($hidebotsql) {
00041 $sql .= "$hidebotsql WHERE ug_group IS NULL";
00042 }
00043 $sql .= ' ORDER BY img_timestamp DESC';
00044 $sql = $dbr->limitResult($sql, 1, false);
00045 $res = $dbr->query( $sql, __FUNCTION__ );
00046 $row = $dbr->fetchRow( $res );
00047 if( $row !== false ) {
00048 $ts = $row[0];
00049 } else {
00050 $ts = false;
00051 }
00052 $dbr->freeResult( $res );
00053 $sql = '';
00054
00055 # If we were clever, we'd use this to cache.
00056 $latestTimestamp = wfTimestamp( TS_MW, $ts );
00057
00058 # Hardcode this for now.
00059 $limit = 48;
00060
00061 if ( $parval = intval( $par ) ) {
00062 if ( $parval <= $limit && $parval > 0 ) {
00063 $limit = $parval;
00064 }
00065 }
00066
00067 $where = array();
00068 $searchpar = array();
00069 if ( $wpIlMatch != '' && !$wgMiserMode) {
00070 $nt = Title::newFromURL( $wpIlMatch );
00071 if( $nt ) {
00072 $where[] = 'LOWER(img_name) ' . $dbr->buildLike( $dbr->anyString(), strtolower( $nt->getDBkey() ), $dbr->anyString() );
00073 $searchpar['wpIlMatch'] = $wpIlMatch;
00074 }
00075 }
00076
00077 $invertSort = false;
00078 if( $until = $wgRequest->getVal( 'until' ) ) {
00079 $where[] = "img_timestamp < '" . $dbr->timestamp( $until ) . "'";
00080 }
00081 if( $from = $wgRequest->getVal( 'from' ) ) {
00082 $where[] = "img_timestamp >= '" . $dbr->timestamp( $from ) . "'";
00083 $invertSort = true;
00084 }
00085 $sql='SELECT img_size, img_name, img_user, img_user_text,'.
00086 "img_description,img_timestamp FROM $image";
00087
00088 if( $hidebotsql ) {
00089 $sql .= $hidebotsql;
00090 $where[] = 'ug_group IS NULL';
00091 }
00092 if( count( $where ) ) {
00093 $sql .= ' WHERE ' . $dbr->makeList( $where, LIST_AND );
00094 }
00095 $sql.=' ORDER BY img_timestamp '. ( $invertSort ? '' : ' DESC' );
00096 $sql = $dbr->limitResult($sql, ( $limit + 1 ), false);
00097 $res = $dbr->query( $sql, __FUNCTION__ );
00098
00102 $images = array();
00103 while ( $s = $dbr->fetchObject( $res ) ) {
00104 if( $invertSort ) {
00105 array_unshift( $images, $s );
00106 } else {
00107 array_push( $images, $s );
00108 }
00109 }
00110 $dbr->freeResult( $res );
00111
00112 $gallery = new ImageGallery();
00113 $firstTimestamp = null;
00114 $lastTimestamp = null;
00115 $shownImages = 0;
00116 foreach( $images as $s ) {
00117 $shownImages++;
00118 if( $shownImages > $limit ) {
00119 # One extra just to test for whether to show a page link;
00120 # don't actually show it.
00121 break;
00122 }
00123
00124 $name = $s->img_name;
00125 $ut = $s->img_user_text;
00126
00127 $nt = Title::newFromText( $name, NS_FILE );
00128 $ul = $sk->link( Title::makeTitle( NS_USER, $ut ), $ut );
00129
00130 $gallery->add( $nt, "$ul<br />\n<i>".htmlspecialchars($wgLang->timeanddate( $s->img_timestamp, true ))."</i><br />\n" );
00131
00132 $timestamp = wfTimestamp( TS_MW, $s->img_timestamp );
00133 if( empty( $firstTimestamp ) ) {
00134 $firstTimestamp = $timestamp;
00135 }
00136 $lastTimestamp = $timestamp;
00137 }
00138
00139 $titleObj = SpecialPage::getTitleFor( 'Newimages' );
00140 $action = $titleObj->getLocalURL( $hidebots ? '' : 'hidebots=0' );
00141 if ( $shownav && !$wgMiserMode ) {
00142 $wgOut->addHTML(
00143 Xml::openElement( 'form', array( 'action' => $action, 'method' => 'post', 'id' => 'imagesearch' ) ) .
00144 Xml::fieldset( wfMsg( 'newimages-legend' ) ) .
00145 Xml::inputLabel( wfMsg( 'newimages-label' ), 'wpIlMatch', 'wpIlMatch', 20, $wpIlMatch ) . ' ' .
00146 Xml::submitButton( wfMsg( 'ilsubmit' ), array( 'name' => 'wpIlSubmit' ) ) .
00147 Xml::closeElement( 'fieldset' ) .
00148 Xml::closeElement( 'form' )
00149 );
00150 }
00151
00152 $bydate = wfMsg( 'bydate' );
00153 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
00154 if ( $shownav ) {
00155 $text = wfMsgExt( 'imagelisttext', array('parse'), $lt, $bydate );
00156 $wgOut->addHTML( $text . "\n" );
00157 }
00158
00163 # If we change bot visibility, this needs to be carried along.
00164 if( !$hidebots ) {
00165 $botpar = array( 'hidebots' => 0 );
00166 } else {
00167 $botpar = array();
00168 }
00169 $now = wfTimestampNow();
00170 $d = $wgLang->date( $now, true );
00171 $t = $wgLang->time( $now, true );
00172 $query = array_merge(
00173 array( 'from' => $now ),
00174 $botpar,
00175 $searchpar
00176 );
00177
00178 $dateLink = $sk->linkKnown(
00179 $titleObj,
00180 htmlspecialchars( wfMsg( 'sp-newimages-showfrom', $d, $t ) ),
00181 array(),
00182 $query
00183 );
00184
00185 $query = array_merge(
00186 array( 'hidebots' => ( $hidebots ? 0 : 1 ) ),
00187 $searchpar
00188 );
00189
00190 $showhide = $hidebots ? wfMsg( 'show' ) : wfMsg( 'hide' );
00191
00192 $botLink = $sk->linkKnown(
00193 $titleObj,
00194 htmlspecialchars( wfMsg( 'showhidebots', $showhide ) ),
00195 array(),
00196 $query
00197 );
00198
00199 $opts = array( 'parsemag', 'escapenoentities' );
00200 $prevLink = wfMsgExt( 'pager-newer-n', $opts, $wgLang->formatNum( $limit ) );
00201 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
00202 $query = array_merge(
00203 array( 'from' => $firstTimestamp ),
00204 $botpar,
00205 $searchpar
00206 );
00207
00208 $prevLink = $sk->linkKnown(
00209 $titleObj,
00210 $prevLink,
00211 array(),
00212 $query
00213 );
00214 }
00215
00216 $nextLink = wfMsgExt( 'pager-older-n', $opts, $wgLang->formatNum( $limit ) );
00217 if( $shownImages > $limit && $lastTimestamp ) {
00218 $query = array_merge(
00219 array( 'until' => $lastTimestamp ),
00220 $botpar,
00221 $searchpar
00222 );
00223
00224 $nextLink = $sk->linkKnown(
00225 $titleObj,
00226 $nextLink,
00227 array(),
00228 $query
00229 );
00230
00231 }
00232
00233 $prevnext = '<p>' . $botLink . ' '. wfMsgHtml( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
00234
00235 if ($shownav)
00236 $wgOut->addHTML( $prevnext );
00237
00238 if( count( $images ) ) {
00239 $wgOut->addHTML( $gallery->toHTML() );
00240 if ($shownav)
00241 $wgOut->addHTML( $prevnext );
00242 } else {
00243 $wgOut->addWikiMsg( 'noimages' );
00244 }
00245 }