X-Git-Url: https://git.cyclocoop.org/admin/?a=blobdiff_plain;f=includes%2FSpecialNewimages.php;h=744eb0ea705134418841285ee51a2dc14a4c595d;hb=b76be11a85418b32235eaec3fd42e3a0d9af83dc;hp=4ea315bfb32a57416ff8ba63ae2dcd6ad7c2f09d;hpb=96c69181aeb5421f608e84cdf61118e4bc9194c7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialNewimages.php b/includes/SpecialNewimages.php index 4ea315bfb3..744eb0ea70 100644 --- a/includes/SpecialNewimages.php +++ b/includes/SpecialNewimages.php @@ -5,6 +5,7 @@ * @subpackage SpecialPage */ +/** */ require_once( 'ImageGallery.php' ); /** @@ -13,89 +14,132 @@ require_once( 'ImageGallery.php' ); function wfSpecialNewimages() { global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest; - $sort = $wgRequest->getVal( 'sort' ); $wpIlMatch = $wgRequest->getText( 'wpIlMatch' ); $dbr =& wfGetDB( DB_SLAVE ); - $image = $dbr->tableName( 'image' ); - $sql = "SELECT img_size,img_name,img_user,img_user_text," . - "img_description,img_timestamp FROM $image"; - - $bydate = wfMsg( 'bydate' ); + $sk = $wgUser->getSkin(); - if ( !empty( $wpIlMatch ) ) { + /** If we were clever, we'd use this to cache. */ + $latestTimestamp = wfTimestamp( TS_MW, $dbr->selectField( + 'image', 'img_timestamp', + '', 'wfSpecialNewimages', + array( 'ORDER BY' => 'img_timestamp DESC', + 'LIMIT' => 1 ) ) ); + + /** Hardcode this for now. */ + $limit = 48; + + $where = array(); + if ( $wpIlMatch != '' ) { $nt = Title::newFromUrl( $wpIlMatch ); if($nt ) { $m = $dbr->strencode( strtolower( $nt->getDBkey() ) ); $m = str_replace( '%', "\\%", $m ); $m = str_replace( '_', "\\_", $m ); - $sql .= " WHERE LCASE(img_name) LIKE '%{$m}%'"; + $where[] = "LCASE(img_name) LIKE '%{$m}%'"; } + } + + $invertSort = false; + if( $until = $wgRequest->getVal( 'until' ) ) { + $where[] = 'img_timestamp < ' . $dbr->timestamp( $until ); + } + if( $from = $wgRequest->getVal( 'from' ) ) { + $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from ); + $invertSort = true; } - $sort = 'bydate'; - $sql .= ' ORDER BY img_timestamp DESC'; - $st = $bydate; - list( $limit, $offset ) = wfCheckLimits( 50 ); - if ( 0 == $limit ) { - $lt = wfMsg( 'all' ); - } else { - $lt = $wgLang->formatNum( "${limit}" ); - $sql .= " LIMIT {$limit}"; + $res = $dbr->select( 'image', + array( 'img_size', 'img_name', 'img_user', 'img_user_text', + 'img_description', 'img_timestamp' ), + $where, + 'wfSpecialNewimages', + array( 'LIMIT' => $limit + 1, + 'ORDER BY' => 'img_timestamp' . ( $invertSort ? '' : ' DESC' ) ) + ); + + /** + * We have to flip things around to get the last N after a certain date + */ + $images = array(); + while ( $s = $dbr->fetchObject( $res ) ) { + if( $invertSort ) { + array_unshift( $images, $s ); + } else { + array_push( $images, $s ); + } } - $wgOut->addHTML( "

" . wfMsg( "imglegend" ) . "

\n" ); + $dbr->freeResult( $res ); + + $gallery = new ImageGallery(); + $firstTimestamp = null; + $lastTimestamp = null; + $shownImages = 0; + foreach( $images as $s ) { + if( ++$shownImages > $limit ) { + # One extra just to test for whether to show a page link; + # don't actually show it. + break; + } + + $name = $s->img_name; + $ut = $s->img_user_text; + + $nt = Title::newFromText( $name, NS_IMAGE ); + $img = Image::newFromTitle( $nt ); + $ul = $sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut ); + $gallery->add( $img, "$ul
\n".$wgLang->timeanddate( $s->img_timestamp, true )."
\n" ); + + $timestamp = wfTimestamp( TS_MW, $s->img_timestamp ); + if( empty( $firstTimestamp ) ) { + $firstTimestamp = $timestamp; + } + $lastTimestamp = $timestamp; + } + + $bydate = wfMsg( 'bydate' ); + $lt = $wgLang->formatNum( min( $shownImages, $limit ) ); $text = wfMsg( "imagelisttext", - "{$lt}", "{$st}" ); + "{$lt}", "{$bydate}" ); $wgOut->addHTML( "

{$text}\n

" ); - $sk = $wgUser->getSkin(); - $cap = wfMsg( 'ilshowmatch' ); $sub = wfMsg( 'ilsubmit' ); $titleObj = Title::makeTitle( NS_SPECIAL, 'Newimages' ); - $action = $titleObj->escapeLocalURL( "sort={$sort}&limit={$limit}" ); + $action = $titleObj->escapeLocalURL( "limit={$limit}" ); $wgOut->addHTML( "
" . - "{$cap}: " . "
" ); - $nums = array( 50, 100, 250, 500 ); - $here = $wgContLang->specialPage( 'Imagelist' ); - - $fill = ''; - $first = true; - foreach ( $nums as $num ) { - if ( ! $first ) { $fill .= ' | '; } - $first = false; + $here = $wgContLang->specialPage( 'Newimages' ); - $fill .= $sk->makeKnownLink( $here, $wgLang->formatNum( $num ), - "sort=bydate&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) ); + /** + * Paging controls... + */ + $now = wfTimestampNow(); + $date = $wgLang->timeanddate( $now ); + $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'rclistfrom', $date ), 'from=' . $now ); + + $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) ); + if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) { + $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp ); } - $text = wfMsg( 'showlast', $fill, $bydate ); - $wgOut->addHTML( $text."\n" ); - - $i=0; - $res = $dbr->query( $sql, 'wfSpecialImagelist' ); - - $gallery = new ImageGallery(); - - while ( $s = $dbr->fetchObject( $res ) ) { - $name = $s->img_name; - $ut = $s->img_user_text; - - $nt = Title::newFromText( $name, NS_IMAGE ); - - # We may not get an object back from Title if there is name problem. - if ( is_object($nt) ) { - $img = Image::newFromTitle( $nt ); - $ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut ); - $gallery->add( $img, $ul.'
'.$wgLang->timeanddate( $s->img_timestamp, true ).'
' ); - $i++; - } + $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) ); + if( $shownImages > $limit && $lastTimestamp ) { + $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp ); + } + + $prevnext = '

' . wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) . '

'; + $wgOut->addHTML( $prevnext ); + + if( count( $images ) ) { + $wgOut->addHTML( $gallery->toHTML() ); + $wgOut->addHTML( $prevnext ); + } else { + $wgOut->addWikiText( wfMsg( 'noimages' ) ); } - $wgOut->addHTML( $gallery->toHTML() ); - $dbr->freeResult( $res ); } ?>