r5233 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5232‎ | r5233 | r5234 >
Date:20:57, 14 September 2004
Author:jeluf
Status:old
Tags:
Comment:
New Special page: Visual list of newly uploaded images Special:Newimages
Modified paths:
  • /trunk/phase3/includes/Image.php (modified) (history)
  • /trunk/phase3/includes/ImageGallery.php (added) (history)
  • /trunk/phase3/includes/SpecialNewimages.php (added) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Image.php
@@ -71,6 +71,11 @@
7272 return $this->name;
7373 }
7474
 75+ function getTitle()
 76+ {
 77+ return $this->title;
 78+ }
 79+
7580 function getURL()
7681 {
7782 return $this->url;
@@ -117,7 +122,6 @@
118123 return wfUrlencode( $url );
119124 }
120125
121 -
122126 function exists()
123127 {
124128 return $this->fileExists;
@@ -137,6 +141,24 @@
138142 return $width."px-".$this->name;
139143 }
140144
 145+ function createThumb( $width, $height=-1 ) {
 146+ if ( $height == -1 ) {
 147+ return $this->renderThumb( $width );
 148+ }
 149+ if ( $width < $this->width ) {
 150+ $thumbheight = $this->height * $width / $this->width;
 151+ $thumbwidth = $width;
 152+ } else {
 153+ $thumbheight = $this->height;
 154+ $thumbwidth = $this->width;
 155+ }
 156+ if ( $thumbheight > $height ) {
 157+ $thumbwidth = $thumbwidth * $height / $thumbheight;
 158+ $thumbheight = $height;
 159+ }
 160+ return $this->renderThumb( $thumbwidth );
 161+ }
 162+
141163 /**
142164 * Create a thumbnail of the image having the specified width.
143165 * The thumbnail will not be created if the width is larger than the
@@ -145,7 +167,7 @@
146168 * file does not exist OR if it is older than the image.
147169 * Returns the URL.
148170 */
149 - function createThumb( $width ) {
 171+ function /* private */ renderThumb( $width ) {
150172 global $wgUploadDirectory;
151173 global $wgImageMagickConvertCommand;
152174 global $wgUseImageMagick;
Index: trunk/phase3/includes/SpecialPage.php
@@ -34,6 +34,7 @@
3535 "Recentchanges" => new SpecialPage( "Recentchanges" ),
3636 "Upload" => new SpecialPage( "Upload" ),
3737 "Imagelist" => new SpecialPage( "Imagelist" ),
 38+ "Newimages" => new SpecialPage( "Newimages" ),
3839 "Listusers" => new SpecialPage( "Listusers" ),
3940 "Listadmins" => new SpecialPage( "Listadmins" ),
4041 "Statistics" => new SpecialPage( "Statistics" ),
@@ -81,7 +82,8 @@
8283 # "Import" => new SpecialPage( "Import", "sysop" ),
8384
8485 "Lockdb" => new SpecialPage( "Lockdb", "developer" ),
85 - "Unlockdb" => new SpecialPage( "Unlockdb", "developer" )
 86+ "Unlockdb" => new SpecialPage( "Unlockdb", "developer" ),
 87+// "Sitesettings" => new SpecialPage( "Sitesettings" )
8688 ));
8789
8890 /**
Index: trunk/phase3/includes/ImageGallery.php
@@ -0,0 +1,72 @@
 2+
 3+<?php
 4+/**
 5+ * @package MediaWiki
 6+ */
 7+
 8+/**
 9+ * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
 10+ */
 11+if( defined( 'MEDIAWIKI' ) ) {
 12+
 13+
 14+/**
 15+ * Image gallery
 16+ * @package MediaWiki
 17+ */
 18+class ImageGallery
 19+{
 20+ var $mImages;
 21+
 22+ function ImageGallery( ) {
 23+ $this->mImages=array();
 24+ }
 25+
 26+ function add( $image, $text='' ) {
 27+ $this->mImages[] = array( &$image, $text );
 28+ }
 29+
 30+ function toHTML() {
 31+ global $wgLang, $wgUser;
 32+
 33+ $sk = $wgUser->getSkin();
 34+
 35+ $s = '<table style="border:solid 1px #DDDDDD; cellspacing:0; cellpadding:0; margin:1em;">';
 36+ $i = 0;
 37+ foreach ( $this->mImages as $pair ) {
 38+ $img =& $pair[0];
 39+ $text = $pair[1];
 40+
 41+ $name = $img->getName();
 42+ $nt = $img->getTitle();
 43+
 44+ //TODO
 45+ //$ul = $sk->makeLink( $wgLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
 46+
 47+ $ilink = '<a href="' . $img->getURL() . '">' . $nt->getText() . '</a>';
 48+ $nb = wfMsg( "nbytes", $wgLang->formatNum( $img->getSize() ) );
 49+
 50+ $s .= ($i%4==0) ? '<tr>' : '';
 51+ $s .= '<td valign="top" width="150px" style="background-color:#F0F0F0;">' .
 52+ '<table width="100%" height="150px">'.
 53+ '<tr><td align="center" valign="center" style="background-color:#F8F8F8;border:solid 1px #888888;">' .
 54+ '<img src="'.$img->createThumb(120,120).'" alt=""></td></tr></table> ' .
 55+ '(' . $sk->makeKnownLinkObj( $nt, wfMsg( "imgdesc" ) ) .
 56+ ") {$ilink}<br />{$text}{$nb}<br />" ;
 57+
 58+ $s .= '</td>' . (($i%4==3) ? '</tr>' : '');
 59+
 60+ $i++;
 61+ }
 62+ $s .= '</table>';
 63+
 64+ return $s;
 65+ }
 66+
 67+} //class
 68+
 69+
 70+
 71+
 72+} // defined( 'MEDIAWIKI' )
 73+?>
Property changes on: trunk/phase3/includes/ImageGallery.php
___________________________________________________________________
Added: svn:eol-style
174 + native
Added: svn:keywords
275 + Author Date Id Revision
Index: trunk/phase3/includes/SpecialNewimages.php
@@ -0,0 +1,97 @@
 2+<?php
 3+/**
 4+ *
 5+ * @package MediaWiki
 6+ * @subpackage SpecialPage
 7+ */
 8+
 9+require_once( 'ImageGallery.php' );
 10+
 11+/**
 12+ *
 13+ */
 14+function wfSpecialNewimages() {
 15+ global $wgUser, $wgOut, $wgLang, $wgRequest;
 16+
 17+ $sort = $wgRequest->getVal( 'sort' );
 18+ $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
 19+ $dbr =& wfGetDB( DB_SLAVE );
 20+ $image = $dbr->tableName( 'image' );
 21+ $sql = "SELECT img_size,img_name,img_user,img_user_text," .
 22+ "img_description,img_timestamp FROM $image";
 23+
 24+ $bydate = wfMsg( "bydate" );
 25+
 26+ if ( !empty( $wpIlMatch ) ) {
 27+ $nt = Title::newFromUrl( $wpIlMatch );
 28+ if($nt ) {
 29+ $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
 30+ $m = str_replace( "%", "\\%", $m );
 31+ $m = str_replace( "_", "\\_", $m );
 32+ $sql .= " WHERE LCASE(img_name) LIKE '%{$m}%'";
 33+ }
 34+ }
 35+ $sort = "bydate";
 36+ $sql .= " ORDER BY img_timestamp DESC";
 37+ $st = $bydate;
 38+
 39+ list( $limit, $offset ) = wfCheckLimits( 50 );
 40+ if ( 0 == $limit ) {
 41+ $lt = wfMsg( "all" );
 42+ } else {
 43+ $lt = $wgLang->formatNum( "${limit}" );
 44+ $sql .= " LIMIT {$limit}";
 45+ }
 46+ $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "</p>\n" );
 47+
 48+ $text = wfMsg( "imagelisttext",
 49+ "<strong>{$lt}</strong>", "<strong>{$st}</strong>" );
 50+ $wgOut->addHTML( "<p>{$text}\n</p>" );
 51+
 52+ $sk = $wgUser->getSkin();
 53+ $cap = wfMsg( "ilshowmatch" );
 54+ $sub = wfMsg( "ilsubmit" );
 55+ $titleObj = Title::makeTitle( NS_SPECIAL, "Imagelist" );
 56+ $action = $titleObj->escapeLocalURL( "sort={$sort}&limit={$limit}" );
 57+
 58+ $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
 59+ "{$action}\">" .
 60+ "{$cap}: <input type='text' size='8' name=\"wpIlMatch\" value=\"" .
 61+ htmlspecialchars( $wpIlMatch ) . "\" /> " .
 62+ "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
 63+ $nums = array( 50, 100, 250, 500 );
 64+ $here = $wgLang->specialPage( "Imagelist" );
 65+
 66+ $fill = "";
 67+ $first = true;
 68+ foreach ( $nums as $num ) {
 69+ if ( ! $first ) { $fill .= " | "; }
 70+ $first = false;
 71+
 72+ $fill .= $sk->makeKnownLink( $here, $wgLang->formatNum( $num ),
 73+ "sort=bydate&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
 74+ }
 75+ $text = wfMsg( "showlast", $fill, $bydate );
 76+ $wgOut->addHTML( "{$text}</p>\n" );
 77+
 78+ $i=0;
 79+ $res = $dbr->query( $sql, "wfSpecialImagelist" );
 80+
 81+ $gallery = new ImageGallery();
 82+
 83+ while ( $s = $dbr->fetchObject( $res ) ) {
 84+ $name = $s->img_name;
 85+ $ut = $s->img_user_text;
 86+
 87+ $nt = Title::newFromText( $name, NS_IMAGE );
 88+ $img = Image::newFromTitle( $nt );
 89+ $ul = $sk->makeLink( $wgLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
 90+
 91+ $gallery->add( $img, $ul.'<br /><i>'.$wgLang->timeanddate( $s->img_timestamp, true ).'</i><br />' );
 92+ $i++;
 93+ }
 94+ $wgOut->addHTML( $gallery->toHTML() );
 95+ $dbr->freeResult( $res );
 96+}
 97+
 98+?>
Property changes on: trunk/phase3/includes/SpecialNewimages.php
___________________________________________________________________
Added: svn:eol-style
199 + native
Added: svn:keywords
2100 + Author Date Id Revision
Index: trunk/phase3/languages/Language.php
@@ -1539,7 +1539,9 @@
15401540 'imagemaxsize' => 'Limit images on image description pages to: ',
15411541 'showbigimage' => 'Download high resolution version ($1x$2, $3 KB)',
15421542
 1543+'newimages' => 'New images gallery',
15431544
 1545+
15441546 );
15451547
15461548 #--------------------------------------------------------------------------

Status & tagging log