Difference between revisions of "Extension:Download"

From Organic Design wiki
(Done :-))
m (new svn path)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
<?php
+
{{svn|extensions|MediaWiki/Download/Download.php}}
/**
+
[[Category:Extensions|Download]]
* Download extension - Provides a tag which renders a list of image titles as downloadable links
 
*{{Category:Extensions|Download}}{{php}}{{Category:Extensions created with Template:Extension}}
 
* See http://www.organicdesign.co.nz/Extension:Download for installation and usage details
 
*
 
* @package MediaWiki
 
* @subpackage Extensions
 
* @author [http://www.mediawiki.org/wiki/User:Nad User:Nad]
 
* @licence GNU General Public Licence 2.0 or later
 
*/
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
 
 
define('DOWNLOAD_VERSION', '1.0.1, 2008-08-25');
 
 
 
$egDownloadTag          = "download";
 
$egDownloadImages      = dirname(__FILE__)."/images";
 
$wgExtensionFunctions[] = 'efSetupDownload';
 
 
 
$wgExtensionCredits['parserhook'][] = array(
 
'name'        => 'Download',
 
'author'      => '[http://www.mediawiki.org/wiki/User:Nad 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 = "<ul class='download-links'>\n";
 
foreach ($links[3] as $i => $link) {
 
$page = $links[1][$i];
 
$img = Image::newFromTitle(Title::newFromText($page));
 
$src = $img && $img->exists() ? $img->getURL() : false;
 
if ($src) {
 
$ext = preg_match('|^.+\.(.+?)$|', $src, $m) ? $m[1] : 'default';
 
$icon = glob("$egDownloadImages/$ext.*");
 
if (count($icon) == 0) $icon = glob("$egDownloadImages/default.*");
 
$icon = "$dir/".basename($icon[0]);
 
$style = "background: transparent url($icon) no-repeat scroll right center; padding-right: 16px;";
 
$item = "<a style=\"$style\" href=\"$src\">$link</a>";
 
} else $item = "<b>No file associated with \"$page\"</b>";
 
$text .=  "<li>$item</li>\n";
 
}
 
$text .= "</ul>\n";
 
return $text;
 
}
 
  }
 
 
 
function efSetupDownload() {
 
global $egDownload;
 
$egDownload = new Download();
 
}
 

Latest revision as of 10:26, 30 April 2015

Info.svg This code is in our Git repository here.

Note: If there is no information in this page about this code and it's a MediaWiki extension, there may be something at mediawiki.org.