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 LIMIT 1';
00044 $res = $dbr->query( $sql, __FUNCTION__ );
00045 $row = $dbr->fetchRow( $res );
00046 if( $row !== false ) {
00047 $ts = $row[0];
00048 } else {
00049 $ts = false;
00050 }
00051 $dbr->freeResult( $res );
00052 $sql = '';
00053
00054 # If we were clever, we'd use this to cache.
00055 $latestTimestamp = wfTimestamp( TS_MW, $ts );
00056
00057 # Hardcode this for now.
00058 $limit = 48;
00059
00060 if ( $parval = intval( $par ) ) {
00061 if ( $parval <= $limit && $parval > 0 ) {
00062 $limit = $parval;
00063 }
00064 }
00065
00066 $where = array();
00067 $searchpar = '';
00068 if ( $wpIlMatch != '' && !$wgMiserMode) {
00069 $nt = Title::newFromUrl( $wpIlMatch );
00070 if( $nt ) {
00071 $m = $dbr->escapeLike( strtolower( $nt->getDBkey() ) );
00072 $where[] = "LOWER(img_name) LIKE '%{$m}%'";
00073 $searchpar = '&wpIlMatch=' . urlencode( $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.=' LIMIT ' . ( $limit + 1 );
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->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
00129
00130 $gallery->add( $nt, "$ul<br />\n<i>".$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 = '&hidebots=0';
00166 } else {
00167 $botpar = '';
00168 }
00169 $now = wfTimestampNow();
00170 $d = $wgLang->date( $now, true );
00171 $t = $wgLang->time( $now, true );
00172 $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsgHtml( 'sp-newimages-showfrom', $d, $t ),
00173 'from='.$now.$botpar.$searchpar );
00174
00175 $botLink = $sk->makeKnownLinkObj($titleObj, wfMsgHtml( 'showhidebots',
00176 ($hidebots ? wfMsgHtml('show') : wfMsgHtml('hide'))),'hidebots='.($hidebots ? '0' : '1').$searchpar);
00177
00178
00179 $opts = array( 'parsemag', 'escapenoentities' );
00180 $prevLink = wfMsgExt( 'pager-newer-n', $opts, $wgLang->formatNum( $limit ) );
00181 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
00182 $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar );
00183 }
00184
00185 $nextLink = wfMsgExt( 'pager-older-n', $opts, $wgLang->formatNum( $limit ) );
00186 if( $shownImages > $limit && $lastTimestamp ) {
00187 $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar.$searchpar );
00188 }
00189
00190 $prevnext = '<p>' . $botLink . ' '. wfMsgHtml( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
00191
00192 if ($shownav)
00193 $wgOut->addHTML( $prevnext );
00194
00195 if( count( $images ) ) {
00196 $wgOut->addHTML( $gallery->toHTML() );
00197 if ($shownav)
00198 $wgOut->addHTML( $prevnext );
00199 } else {
00200 $wgOut->addWikiMsg( 'noimages' );
00201 }
00202 }