Difference between revisions of "Extension:Download"

From Organic Design wiki
(Done :-))
m
Line 46: Line 46:
 
$icon = glob("$egDownloadImages/$ext.*");
 
$icon = glob("$egDownloadImages/$ext.*");
 
if (count($icon) == 0) $icon = glob("$egDownloadImages/default.*");
 
if (count($icon) == 0) $icon = glob("$egDownloadImages/default.*");
$icon = "$dir/".basename($icon[0]);
+
if (count($icon) > 0) {
$style = "background: transparent url($icon) no-repeat scroll right center; padding-right: 16px;";
+
$icon = "$dir/".basename($icon[0]);
$item = "<a style=\"$style\" href=\"$src\">$link</a>";
+
$style = " style=\"background: transparent url($icon) no-repeat scroll right center; padding-right: 16px;\"";
 +
} else $style = "";
 +
$item = "<a$style href=\"$src\">$link</a>";
 
} else $item = "<b>No file associated with \"$page\"</b>";
 
} else $item = "<b>No file associated with \"$page\"</b>";
 
$text .=  "<li>$item</li>\n";
 
$text .=  "<li>$item</li>\n";

Revision as of 03:50, 25 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.1, 2008-08-25');

$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";

return $text; }

 }

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