From 3d946b5c22c41669e842533a8befb51aef9e733b Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Tue, 14 Sep 2004 20:57:54 +0000 Subject: [PATCH] New Special page: Visual list of newly uploaded images Special:Newimages --- includes/Image.php | 26 +++++++++- includes/ImageGallery.php | 72 ++++++++++++++++++++++++++ includes/SpecialNewimages.php | 97 +++++++++++++++++++++++++++++++++++ includes/SpecialPage.php | 4 +- languages/Language.php | 2 + 5 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 includes/ImageGallery.php create mode 100644 includes/SpecialNewimages.php diff --git a/includes/Image.php b/includes/Image.php index 018be4610f..4eb161386c 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -71,6 +71,11 @@ class Image return $this->name; } + function getTitle() + { + return $this->title; + } + function getURL() { return $this->url; @@ -117,7 +122,6 @@ class Image return wfUrlencode( $url ); } - function exists() { return $this->fileExists; @@ -137,6 +141,24 @@ class Image return $width."px-".$this->name; } + function createThumb( $width, $height=-1 ) { + if ( $height == -1 ) { + return $this->renderThumb( $width ); + } + if ( $width < $this->width ) { + $thumbheight = $this->height * $width / $this->width; + $thumbwidth = $width; + } else { + $thumbheight = $this->height; + $thumbwidth = $this->width; + } + if ( $thumbheight > $height ) { + $thumbwidth = $thumbwidth * $height / $thumbheight; + $thumbheight = $height; + } + return $this->renderThumb( $thumbwidth ); + } + /** * Create a thumbnail of the image having the specified width. * The thumbnail will not be created if the width is larger than the @@ -145,7 +167,7 @@ class Image * file does not exist OR if it is older than the image. * Returns the URL. */ - function createThumb( $width ) { + function /* private */ renderThumb( $width ) { global $wgUploadDirectory; global $wgImageMagickConvertCommand; global $wgUseImageMagick; diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php new file mode 100644 index 0000000000..d4384289e0 --- /dev/null +++ b/includes/ImageGallery.php @@ -0,0 +1,72 @@ + +mImages=array(); + } + + function add( $image, $text='' ) { + $this->mImages[] = array( &$image, $text ); + } + + function toHTML() { + global $wgLang, $wgUser; + + $sk = $wgUser->getSkin(); + + $s = ''; + $i = 0; + foreach ( $this->mImages as $pair ) { + $img =& $pair[0]; + $text = $pair[1]; + + $name = $img->getName(); + $nt = $img->getTitle(); + + //TODO + //$ul = $sk->makeLink( $wgLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut ); + + $ilink = '' . $nt->getText() . ''; + $nb = wfMsg( "nbytes", $wgLang->formatNum( $img->getSize() ) ); + + $s .= ($i%4==0) ? '' : ''; + $s .= '' . (($i%4==3) ? '' : ''); + + $i++; + } + $s .= '
' . + ''. + '
' . + '
' . + '(' . $sk->makeKnownLinkObj( $nt, wfMsg( "imgdesc" ) ) . + ") {$ilink}
{$text}{$nb}
" ; + + $s .= '
'; + + return $s; + } + +} //class + + + + +} // defined( 'MEDIAWIKI' ) +?> diff --git a/includes/SpecialNewimages.php b/includes/SpecialNewimages.php new file mode 100644 index 0000000000..452d24edc9 --- /dev/null +++ b/includes/SpecialNewimages.php @@ -0,0 +1,97 @@ +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" ); + + if ( !empty( $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}%'"; + } + } + $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}"; + } + $wgOut->addHTML( "

" . wfMsg( "imglegend" ) . "

\n" ); + + $text = wfMsg( "imagelisttext", + "{$lt}", "{$st}" ); + $wgOut->addHTML( "

{$text}\n

" ); + + $sk = $wgUser->getSkin(); + $cap = wfMsg( "ilshowmatch" ); + $sub = wfMsg( "ilsubmit" ); + $titleObj = Title::makeTitle( NS_SPECIAL, "Imagelist" ); + $action = $titleObj->escapeLocalURL( "sort={$sort}&limit={$limit}" ); + + $wgOut->addHTML( "
" . + "{$cap}: " . + "
" ); + $nums = array( 50, 100, 250, 500 ); + $here = $wgLang->specialPage( "Imagelist" ); + + $fill = ""; + $first = true; + foreach ( $nums as $num ) { + if ( ! $first ) { $fill .= " | "; } + $first = false; + + $fill .= $sk->makeKnownLink( $here, $wgLang->formatNum( $num ), + "sort=bydate&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) ); + } + $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 ); + $img = Image::newFromTitle( $nt ); + $ul = $sk->makeLink( $wgLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut ); + + $gallery->add( $img, $ul.'
'.$wgLang->timeanddate( $s->img_timestamp, true ).'
' ); + $i++; + } + $wgOut->addHTML( $gallery->toHTML() ); + $dbr->freeResult( $res ); +} + +?> diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 9705f84a09..309ba76819 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -34,6 +34,7 @@ $wgSpecialPages = array( "Recentchanges" => new SpecialPage( "Recentchanges" ), "Upload" => new SpecialPage( "Upload" ), "Imagelist" => new SpecialPage( "Imagelist" ), + "Newimages" => new SpecialPage( "Newimages" ), "Listusers" => new SpecialPage( "Listusers" ), "Listadmins" => new SpecialPage( "Listadmins" ), "Statistics" => new SpecialPage( "Statistics" ), @@ -81,7 +82,8 @@ $wgSpecialPages = array_merge($wgSpecialPages, array ( # "Import" => new SpecialPage( "Import", "sysop" ), "Lockdb" => new SpecialPage( "Lockdb", "developer" ), - "Unlockdb" => new SpecialPage( "Unlockdb", "developer" ) + "Unlockdb" => new SpecialPage( "Unlockdb", "developer" ), +// "Sitesettings" => new SpecialPage( "Sitesettings" ) )); /** diff --git a/languages/Language.php b/languages/Language.php index 6463a3cc2c..41985e4126 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1539,6 +1539,8 @@ ta[\'ca-nstab-category\'] = new Array(\'c\',\'View the category page\'); 'imagemaxsize' => 'Limit images on image description pages to: ', 'showbigimage' => 'Download high resolution version ($1x$2, $3 KB)', +'newimages' => 'New images gallery', + ); -- 2.20.1