Difference between revisions of "Extension:Download"

From Organic Design wiki
m
(changed to gallery format)
Line 12: Line 12:
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
  
define('DOWNLOAD_VERSION', '1.0.1, 2008-08-25');
+
define('DOWNLOAD_VERSION', '1.0.2, 2008-08-26');
  
 
$egDownloadTag          = "download";
 
$egDownloadTag          = "download";
Line 33: Line 33:
 
  }
 
  }
  
function tagDownload($text,$argv,&$parser) {
+
function tagDownload($text, $argv, &$parser) {
 
global $wgScriptPath, $egDownloadImages;
 
global $wgScriptPath, $egDownloadImages;
 
$dir = preg_replace('|^.+(?=[/\\\\]extensions)|', $wgScriptPath, $egDownloadImages);
 
$dir = preg_replace('|^.+(?=[/\\\\]extensions)|', $wgScriptPath, $egDownloadImages);
 
preg_match_all('|^\s*(.+?)\s*(\|(.+?))?\s*$|m', $text, $links);
 
preg_match_all('|^\s*(.+?)\s*(\|(.+?))?\s*$|m', $text, $links);
$text = "<ul class='download-links'>\n";
+
$text = "<table class=\"gallery download-gallery\" cellspacing=\"0\" cellpadding=\"0\">\n";
 +
$cols = isset($argv['cols']) && is_numeric($argv['cols']) ? $argv['cols'] : 4;
 +
$row = "";
 
foreach ($links[3] as $i => $link) {
 
foreach ($links[3] as $i => $link) {
 
$page = $links[1][$i];
 
$page = $links[1][$i];
 
$img = Image::newFromTitle(Title::newFromText($page));
 
$img = Image::newFromTitle(Title::newFromText($page));
$src = $img && $img->exists() ? $img->getURL() : false;
+
$icon = glob("$egDownloadImages/default.*");
if ($src) {
+
if ($src = $img && $img->exists() ? $img->getURL() : false) {
 
$ext = preg_match('|^.+\.(.+?)$|', $src, $m) ? $m[1] : 'default';
 
$ext = preg_match('|^.+\.(.+?)$|', $src, $m) ? $m[1] : 'default';
$icon = glob("$egDownloadImages/$ext.*");
+
if (count($j = glob("$egDownloadImages/$ext.*")) > 0) $icon = $j;  
if (count($icon) == 0) $icon = glob("$egDownloadImages/default.*");
+
$item = "<a href=\"$src\">$link</a>";
if (count($icon) > 0) {
+
} else $item = "No file associated with <b>$page</b>";
$icon = "$dir/".basename($icon[0]);
+
$icon = "<img src=\"$dir/".basename($icon[0])."\" width=\"128\" height=\"128\" alt=\"\" />";
$style = " style=\"background: transparent url($icon) no-repeat scroll right center; padding-right: 16px;\"";
+
$icon = "<a class=\"image\" title=\"$page\" href=\"$src\">$icon</a>";
} else $style = "";
+
$row .= "<td><div class=\"gallerybox\" style=\"width: 158px;\">\n";
$item = "<a$style href=\"$src\">$link</a>";
+
$row .= "<div class=\"thumb\" style=\"padding: 13px 0pt; width: 158px;\">\n";
} else $item = "<b>No file associated with \"$page\"</b>";
+
$row .= "<div style=\"margin-left: auto; margin-right: auto; width: 128px;\">\n";
$text .= "<li>$item</li>\n";
+
$row .= "$icon\n</div>\n</div>\n";
 +
$row .= "<div class=\"gallerytext\">$item</div></div></td>\n";
 +
if ($i%$cols == 3) {
 +
$text .= "<tr>\n$row</tr>\n";
 +
$row = "";
 +
}
 
}
 
}
$text .= "</ul>\n";
+
$text .= "</table>\n";
 
return $text;
 
return $text;
 
}
 
}

Revision as of 01:47, 26 August 2008

<?php /**

* Download extension - Provides a tag which renders a list of image titles as downloadable links
*
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:PhpCategory:Extensions created with Template:Extension

* See http://www.organicdesign.co.nz/Extension:Download for installation and usage details
*
* @package MediaWiki
* @subpackage Extensions
* @author User:Nad
* @licence GNU General Public Licence 2.0 or later
*/

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('DOWNLOAD_VERSION', '1.0.2, 2008-08-26');

$egDownloadTag = "download"; $egDownloadImages = dirname(__FILE__)."/images"; $wgExtensionFunctions[] = 'efSetupDownload';

$wgExtensionCredits['parserhook'][] = array( 'name' => 'Download', 'author' => 'User:Nad', 'description' => 'Provides a tag which renders a list of image titles as downloadable links', 'url' => 'http://www.organicdesign.co.nz/Extension:Download', 'version' => DOWNLOAD_VERSION );

class Download {

function __construct() { global $wgParser, $egDownloadTag;

		$wgParser->setHook($egDownloadTag, array($this, 'tagDownload'));
	}

function tagDownload($text, $argv, &$parser) { global $wgScriptPath, $egDownloadImages; $dir = preg_replace('|^.+(?=[/\\\\]extensions)|', $wgScriptPath, $egDownloadImages); preg_match_all('|^\s*(.+?)\s*(\|(.+?))?\s*$|m', $text, $links);

$text = "

\n"; $cols = isset($argv['cols']) && is_numeric($argv['cols']) ? $argv['cols'] : 4; $row = ""; foreach ($links[3] as $i => $link) { $page = $links[1][$i]; $img = Image::newFromTitle(Title::newFromText($page)); $icon = glob("$egDownloadImages/default.*"); if ($src = $img && $img->exists() ? $img->getURL() : false) { $ext = preg_match('|^.+\.(.+?)$|', $src, $m) ? $m[1] : 'default'; if (count($j = glob("$egDownloadImages/$ext.*")) > 0) $icon = $j; $item = "<a href=\"$src\">$link</a>"; } else $item = "No file associated with $page"; $icon = "<img src=\"$dir/".basename($icon[0])."\" width=\"128\" height=\"128\" alt=\"\" />"; $icon = "<a class=\"image\" title=\"$page\" href=\"$src\">$icon</a>"; $row .= "\n";

if ($i%$cols == 3) {

$text .= "\n$row\n"; $row = ""; } } $text .= "
\n"; $row .= "
\n"; $row .= "
\n"; $row .= "$icon\n
\n
\n"; $row .= "
$item

\n";

return $text; }

 }

function efSetupDownload() { global $egDownload; $egDownload = new Download(); }