Difference between revisions of "Extension:SuperGallery"

From Organic Design wiki
(Extension works!)
m
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
<php>
 
<?php
 
<?php
# Extension:SuperGallery{{Category:Extensions}}{{php}}{{Category:Extensions created with Template:SpecialPage}}
+
# Extension:SuperGallery
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
# - Author: [http://www.organicdesign.co.nz/jack User:Jack]
+
# - Author: [http://www.flashkiwi.com Jack Henderson]
 
   
 
   
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
   
 
   
define('SUPERGALLERY_VERSION','1.0.0, 2008-11-28');
+
define('SUPERGALLERY_VERSION','1.0.0, 2008-12-15');
 
   
 
   
 
$wgExtensionFunctions[] = 'wfSetupSuperGallery';
 
$wgExtensionFunctions[] = 'wfSetupSuperGallery';
+
 
 +
$egSuperGalleryTag = "supergallery";
 +
 
 
$wgExtensionCredits['specialpage'][] = array(
 
$wgExtensionCredits['specialpage'][] = array(
 
'name'        => 'Special:SuperGallery',
 
'name'        => 'Special:SuperGallery',
'author'      => '[http://www.organicdesign.co.nz/jack User:Jack]',
+
'author'      => '[http://www.flashkiwi.com Jack Henderson]',
 
'description' => 'An special page for creating a supergallery of galleries, made with [http://www.organicdesign.co.nz/Template:SpecialPage Template:SpecialPage].',
 
'description' => 'An special page for creating a supergallery of galleries, made with [http://www.organicdesign.co.nz/Template:SpecialPage Template:SpecialPage].',
 
'url'        => 'http://www.organicdesign.co.nz/Extension:SuperGallery',
 
'url'        => 'http://www.organicdesign.co.nz/Extension:SuperGallery',
Line 25: Line 28:
 
# Constructor
 
# Constructor
 
function __construct() {
 
function __construct() {
 +
global $wgHooks, $wgParser, $egSuperGalleryTag;
 
SpecialPage::SpecialPage(
 
SpecialPage::SpecialPage(
 
'SuperGallery',    # name as seen in links etc
 
'SuperGallery',    # name as seen in links etc
Line 33: Line 37:
 
false          # includable
 
false          # includable
 
);
 
);
 +
# Add the tagHook
 +
$wgParser->setHook($egSuperGalleryTag, array($this, 'tagSupergallery'));
 +
 +
}
 +
 +
function tagSupergallery($text,$argv,&$parser) {
 +
global $egSuperGalleryTag, $wgServer, $wgScript;
 +
 +
# Make an array of the content
 +
$nz = 9; # All the styles
 +
$ny = count ($argv) - $nz;
 +
$par = $ny / 4;
 +
$conarr = array_slice($argv,9); # Array of content
 +
$uarr[] = array();
 +
$iarr[] = array();
 +
$barr[] = array();
 +
$carr[] = array();
 +
 +
foreach ($conarr as $k => $v){
 +
if (preg_replace ('%(.*)([0-9]{1,2})%','\1',$k) == "url") $uarr[preg_replace ('%(.*)([0-9]{1,2})%','\2',$k)] = $v;
 +
elseif (preg_replace ('%(.*)([0-9]{1,2})%','\1',$k) == "image") $iarr[preg_replace ('%(.*)([0-9]{1,2})%','\2',$k)] = $v;
 +
elseif (preg_replace ('%(.*)([0-9]{1,2})%','\1',$k) == "bkpre") $barr[preg_replace ('%(.*)([0-9]{1,2})%','\2',$k)] = $v;
 +
else $carr[preg_replace ('%(.*)([0-9]{1,2})%','\2',$k)] = "<a href='" . $wgServer . $wgScript . "/" . $v . "'>" . $v . "</a>";
 +
}
 +
 +
# Table css
 +
$gtext = "<style type='text/css'>table.supergallery" . $argv['gtitle'] . "{ border:" . $argv['border'] . "px solid " . $argv['bordercolor'] . ";margin:" . $argv['tablemargin'] . "px;padding:" . $argv['tablemargin'] . "px;background-color:" . $argv['backgroundcolor'] .";}</style>";
 +
 +
for ($i = 1; $i <= $par; $i++) {
 +
 +
# Set up rightsized thumbs silently by using the wiki thumbnail renderer.
 +
# These are used as backgrounds for the gallery cells.
 +
$gtext .= "<div style='display:none'>[[Image:" . $iarr[$i] . "|" . $argv['width'] . "px]]</div>";
 +
 +
# Set up css for the backgrounds
 +
$gtext .= "<style type='text/css'>.sgclass" . $i . "{background:url(" . $barr[$i] . $argv['width'] . "px-" . $iarr[$i] . ") center center no-repeat}</style>";
 +
}
 +
 +
# Render table code for copying
 +
$gtext .= "<table cellpadding='" . $argv['cellpadding'] . "' class ='supergallery" . $argv['gtitle'] . "'>";
 +
if ($argv['column'] == 1) {
 +
for ($j = 1; $j <= $par; $j++) {
 +
$caption = $carr[$j];
 +
if ($caption != "") {
 +
$gtext .= "<tr valign = 'center'>
 +
<td class = 'sgclass" . $j . "' height = '" . $argv['height'] . "' width = '" . $argv['width'] . "'>
 +
</td></tr>
 +
<tr valign = 'center'>
 +
<td><center>$caption</center>
 +
</td></tr>";
 +
}
 +
}
 +
}
 +
elseif ($argv['column'] == 2) {
 +
$z = 1;
 +
while ($z <= $par) {
 +
$m = $z;
 +
$caption = $carr[$m];
 +
if ($caption != "") {
 +
$gtext .= "<tr valign = 'center'>
 +
<td class = 'sgclass" . $z . "' height = '" . $argv['height'] . "' width = '" . $argv['width'] . "'>
 +
</td>";
 +
$z++;
 +
if ($z <= $par) {
 +
$gtext .= "<td class = 'sgclass" . $z . "' height = '" . $argv['height'] . "' width = '" . $argv['width'] . "'>
 +
</td>";
 +
$z++;
 +
}
 +
$gtext .= "</tr><tr valign = 'center'>
 +
<td><center>$caption</center>
 +
</td>";
 +
$m++;
 +
}
 +
if ($m <= $par) {
 +
$caption = $carr[$m];
 +
if ($caption != "") {
 +
$gtext .= "<td><center>$caption</center>
 +
</td>";
 +
}
 +
}
 +
$m++;
 +
$gtext .= "</tr>";
 +
}
 +
}
 +
else {
 +
$z = 1;
 +
while ($z <= $par) {
 +
$m = $z;
 +
$gtext .= "<tr valign = 'center'>";
 +
$gtext .= "<td class = 'sgclass" . $z . "' height = '" . $argv['height'] . "' width = '" . $argv['width'] . "'>
 +
</td>";
 +
$z++;
 +
if ($z <= $par) {
 +
$gtext .= "<td class = 'sgclass" . $z . "' height = '" . $argv['height'] . "' width = '" . $argv['width'] . "'>
 +
</td>";
 +
$z++;
 +
}
 +
if ($z <= $par) {
 +
$gtext .= "<td class = 'sgclass" . $z . "' height = '" . $argv['height'] . "' width = '" . $argv['width'] . "'>
 +
</td>";
 +
$z++;
 +
}
 +
$gtext .= "</tr>";
 +
$gtext .= "<tr valign = 'center'>";
 +
if ($m <= $par) {
 +
$caption = $carr[$m];
 +
if ($caption != "") {
 +
$gtext .= "<td><center>$caption</center>
 +
</td>";
 +
$m++;
 +
}
 +
}
 +
if ($m <= $par) {
 +
$caption = $carr[$m];
 +
if ($caption != "") {
 +
$gtext .= "<td><center>$caption</center>
 +
</td>";
 +
$m++;
 +
}
 +
}
 +
if ($m <= $par) {
 +
$caption = $carr[$m];
 +
if ($caption != "") {
 +
$gtext .= "<td><center>$caption</center>
 +
</td>";
 +
$m++;
 +
}
 +
}
 +
 +
$gtext .= "</tr>";
 +
}
 
}
 
}
 +
$gtext .= "</table>";
 +
return $gtext;
 +
 +
}
 
   
 
   
 
# Override SpecialPage::execute()
 
# Override SpecialPage::execute()
 
# - $param is from the URL, eg Special:{{{name}}}/param
 
# - $param is from the URL, eg Special:{{{name}}}/param
 
function execute($param) {
 
function execute($param) {
global $wgOut, $wgRequest;
+
global $wgOut, $wgRequest, $wgTitle, $wgUser, $wgMessageCache;
 
$this->setHeaders();
 
$this->setHeaders();
 
$title = Title::makeTitle(NS_SPECIAL,'SuperGallery');
 
$title = Title::makeTitle(NS_SPECIAL,'SuperGallery');
Line 55: Line 194:
 
 
 
# Extract any contents of fields
 
# Extract any contents of fields
 +
$gtitle = $wgRequest->getText('wpGtitle', "");
 
$width = $wgRequest->getText('wpWidth', "");
 
$width = $wgRequest->getText('wpWidth', "");
 
$height = $wgRequest->getText('wpHeight', "");
 
$height = $wgRequest->getText('wpHeight', "");
Line 69: Line 209:
 
wfElement('form', array('action' => $title->getLocalURL('action=submit'), 'method' => 'post'), null)
 
wfElement('form', array('action' => $title->getLocalURL('action=submit'), 'method' => 'post'), null)
 
. "<br /><p><b>Usage</b></p>
 
. "<br /><p><b>Usage</b></p>
<p>Fill out the form below for each gallery you want to include.</p>
+
<p>Fill out the form below for each gallery you want to include, with a unique name for your supergallery.</p>
 
<p>This extension defaults to four pairs of gallery inputs, unless the number of galleries in your intended supergallery is passed as this page's parameter, for example for five galleries:
 
<p>This extension defaults to four pairs of gallery inputs, unless the number of galleries in your intended supergallery is passed as this page's parameter, for example for five galleries:
 
<pre>http://localhost/wiki/index.php/Special:SuperGallery/5</pre></p>
 
<pre>http://localhost/wiki/index.php/Special:SuperGallery/5</pre></p>
<p>The galleries you link to can be made normally using the gallery tag.</p>
+
<p>The galleries you link to will be created if they do not exist, and can themselves be made as usual using the gallery tag.</p>
 
<p>Here is the expected form of the picture url and the article link:
 
<p>Here is the expected form of the picture url and the article link:
 
<pre>http://localhost/wiki/images/d/de/Boat.jpg
 
<pre>http://localhost/wiki/images/d/de/Boat.jpg
+
 
 
[[Pictures_of_Auckland|Pictures of Auckland]]</pre></p>
 
[[Pictures_of_Auckland|Pictures of Auckland]]</pre></p>
<p>Press the Submit Query button, then copy and paste the result below into the edit box of a new supergallery page.</p>
+
<p>Press the Submit Query button. A new page will be generated under your unique title, with a supergallery tag and your posted information, which you can edit.</p>
 
<br/ >
 
<br/ >
 
<p><b>Page Setup</b></p>
 
<p><b>Page Setup</b></p>
 +
<p>What is the title of your supergallery? This is a compulsory field.</p>
 +
<input name='wpGtitle' size = '35' />
 
<p>How many columns do you want the supergallery to have (up to 3)? If you leave the field empty it is 2.</p>
 
<p>How many columns do you want the supergallery to have (up to 3)? If you leave the field empty it is 2.</p>
 
<input name='wpColumn' size = '10' />
 
<input name='wpColumn' size = '10' />
<p>How wide do you want each thumbnail to be? Empty field is 150.</p>
+
<p>How wide do you want each thumbnail to be? Empty field is 120.</p>
 
<input name='wpWidth' size = '10' />
 
<input name='wpWidth' size = '10' />
<p>How high do you want each thumbnail's box to be? Empty field is 250.</p>
+
<p>How high do you want each thumbnail's box to be? Empty field is 200.</p>
 
<input name='wpHeight' size = '10' />
 
<input name='wpHeight' size = '10' />
 
<p>How wide do you want the supergallery's border to be? Empty field is 1. No border is 0.</p>
 
<p>How wide do you want the supergallery's border to be? Empty field is 1. No border is 0.</p>
Line 114: Line 256:
 
"<br /><br />"
 
"<br /><br />"
 
. wfElement('input', array('name' => 'wpSubmit', 'type' => 'submit'))
 
. wfElement('input', array('name' => 'wpSubmit', 'type' => 'submit'))
. "</form><br /><p>After submitting, copy and paste all the generated code below into the edit box of your new supergallery page.</p>"
+
. "</form><br /><p>When you submit this form, a supergallery page will be created with the name you specified, unless the name already exists. You can edit the tag in that page if you wish to change the supergallery.</p>"
 
);
 
);
 
 
Line 120: Line 262:
 
if ($posted) {
 
if ($posted) {
 
# Defaults for posted style elements
 
# Defaults for posted style elements
if ($width == "") $width = 150;
+
if ($width == "") $width = 120;
if ($height == "") $height = 250;
+
if ($height == "") $height = 200;
 
if ($column == "") $column = 2;
 
if ($column == "") $column = 2;
 
if ($border == "") $border = 1;
 
if ($border == "") $border = 1;
Line 129: Line 271:
 
if ($cellpadding == "") $cellpadding = 10;
 
if ($cellpadding == "") $cellpadding = 10;
 
 
# Table css
+
# Build tag
$wgOut->addWikiText(
+
$tag = '<supergallery
"<pre><html>
+
gtitle = "'.$gtitle.'"
<style type='text/css'>
+
width = "'.$width.'"
table.supergallery {
+
height = "'.$height.'"
border: " . $border . "px solid " . $bordercolor . ";
+
column = "'.$column.'"
margin: " . $tablemargin . "px;
+
border = "'.$border.'"
padding: " . $tablemargin . "px;
+
tablemargin = "'.$tablemargin.'"
background-color: " . $backgroundcolor .";
+
bordercolor = "'.$bordercolor.'"
}
+
backgroundcolor = "'.$backgroundcolor.'"
</style></html></pre>"
+
cellpadding = "'.$cellpadding.'"';
);
 
 
 
 
# Some arrays to populate with loops
 
# Some arrays to populate with loops
Line 146: Line 287:
 
$image[] = array();
 
$image[] = array();
 
$bkpre[] = array();
 
$bkpre[] = array();
+
$caption[] = array();
# Make some URL variables out of the posted fields
+
 
 +
# Make some variables out of the posted fields
 
for ($n = 1; $n <= $par; $n++) {
 
for ($n = 1; $n <= $par; $n++) {
 
$url[$n] = $wgRequest->getText('wpUrl' . $n, "");
 
$url[$n] = $wgRequest->getText('wpUrl' . $n, "");
 +
$image[$n] = preg_replace ('%(.*/images/)(.*/)(.*)(\.)(.*)%','\3\4\5',trim($url[$n]));
 +
$bkpre[$n] = preg_replace ('%(.*/images/)(.*/)(.*)(\.)(.*)%','\1thumb/\2\3\4\5/',trim($url[$n]));
 +
$caption[$n] = $wgRequest->getText('wpCaption' . $n, "");
 
}
 
}
for ($w = 1; $w <= $par; $w++) {
+
for ($n = 1; $n <= $par; $n++) {
 
+
if ($url[$n] != "") {
$image[$w] = preg_replace ('%(.*/images/)(.*/)(.*)(\.)(.*)%','\3\4\5',trim($url[$w]));
+
$tag .= ' url' .$n. ' = "' . $url[$n] . '"';
$bkpre[$w] = preg_replace ('%(.*/images/)(.*/)(.*)(\.)(.*)%','\1thumb/\2\3\4\5/',trim($url[$w]));
+
$tag .= ' image' .$n. ' = "' . $image[$n] . '"';
+
$tag .= ' bkpre' .$n. ' = "' . $bkpre[$n] . '"';
# No point in setting up css for empty fields
+
$tag .= ' caption' .$n. ' = "' . $caption[$n] . '"';
if ($url[$w] != "") {
 
 
# Set up rightsized thumbs silently by using the wiki thumbnail renderer.  
 
# These are used as backgrounds for the gallery cells.
 
$wgOut->addWikiText(
 
"<div style='display:none'>[[Image:" . $image[$w] . "|" . $width . "px]]</div>"
 
);
 
 
 
# Set up css for the backgrounds
 
$wgOut->addWikiText(
 
"<pre><html><style type='text/css'>.sgclass"
 
. $w . "{
 
background:url(" . $bkpre[$w] . $width . "px-" . $image[$w] . ")
 
center center no-repeat}
 
</style>
 
</html></pre>"
 
);
 
 
}
 
}
 
}
 
}
+
$tag .= '>';
# Render table code for copying
+
if ($wgUser->isAllowed('edit')) {
$wgOut->addWikiText(
+
$title = Title::newFromText( $gtitle );
"<pre><table cellpadding='" . $cellpadding . "' class ='supergallery'></pre>"
+
if (trim($wgRequest->getText('wpGtitle'))=='') {
);
+
$wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
if ($column == 1) {
+
$wgOut->errorpage( 'badtitle', 'badtitletext');
for ($j = 1; $j <= $par; $j++) {
+
}
$captionname = "wpCaption" . $j;
+
if((isset($title)) && ($title->getArticleID() == 0)) {
$caption = $wgRequest->getText($captionname, "");
+
$article  = new Article($title);
if ($caption != "") {
+
$article->doEdit($tag, "", EDIT_NEW);
$wgOut->addWikiText(
+
$wgOut->addHTML(wfMsg('supergallerySuccessMessage'));
"<pre><tr valign = 'center'>
+
}
<td class = 'sgclass" . $j . "' height = '" . $height . "' width = '" . $width . "'>
+
elseif (!isset($title)) {
</td></tr>
+
$wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
<tr valign = 'center'>
+
$wgOut->errorpage( 'badtitle', 'badtitletext');
<td><center>$caption</center>
 
</td></tr>
 
</pre>"
 
);
 
}
 
 
}
 
}
}
+
else {
else if ($column == 2) {
+
$wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
$k = 1;
+
$wgOut->errorpage( 'error', 'articleexists');
while ($k <= $par) {
 
$m = $k;
 
$captionname = "wpCaption" . $m;
 
$caption = $wgRequest->getText($captionname, "");
 
if ($caption != "") {
 
$wgOut->addWikiText(
 
"<pre><tr valign = 'center'>
 
<td class = 'sgclass" . $k . "' height = '" . $height . "' width = '" . $width . "'>
 
</td></pre>"
 
);
 
$k++;
 
if ($k <= $par) {
 
$wgOut->addWikiText(
 
"<pre><td class = 'sgclass" . $k . "' height = '" . $height . "' width = '" . $width . "'>
 
</td></pre>"
 
);
 
$k++;
 
}
 
$wgOut->addWikiText(
 
"<pre></tr></pre>"
 
);
 
$wgOut->addWikiText(
 
"<pre><tr valign = 'center'>
 
<td><center>$caption</center>
 
</td></pre>"
 
);
 
$m++;
 
}
 
if ($m <= $par) {
 
$captionname = "wpCaption" . $m;
 
$caption = $wgRequest->getText($captionname, "");
 
if ($caption != "") {
 
$wgOut->addWikiText(
 
"<pre>
 
<td><center>$caption</center>
 
</td></pre>"
 
);
 
}
 
}
 
$m++;
 
$wgOut->addWikiText(
 
"<pre></tr>
 
</pre>"
 
);
 
 
}
 
}
 
}
 
}
else {  
+
$k = 1;
+
else {
while ($k <= $par) {
+
$wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
$m = $k;
+
$wgOut->errorpage( 'error', 'badarticleerror');
$wgOut->addWikiText(
 
"<pre><tr valign = 'center'>
 
<td class = 'sgclass" . $k . "' height = '" . $height . "' width = '" . $width . "'>
 
</td></pre>"
 
);
 
$k++;
 
 
 
if ($k <= $par) {
 
$wgOut->addWikiText(
 
"<pre><td class = 'sgclass" . $k . "' height = '" . $height . "' width = '" . $width . "'>
 
</td></pre>"
 
);
 
$k++;
 
}
 
if ($k <= $par) {
 
$wgOut->addWikiText(
 
"<pre><td class = 'sgclass" . $k . "' height = '" . $height . "' width = '" . $width . "'>
 
</td></pre>"
 
);
 
$k++;
 
}
 
$wgOut->addWikiText(
 
"<pre></tr></pre>"
 
);
 
$captionname = "wpCaption" . $m;
 
$caption = $wgRequest->getText($captionname, "");
 
if ($caption != "") {
 
$wgOut->addWikiText(
 
"<pre><tr valign = 'center'>
 
<td><center>$caption</center>
 
</td></pre>"
 
);
 
$m++;
 
}
 
if ($m <= $par) {
 
$captionname = "wpCaption" . $m;
 
$caption = $wgRequest->getText($captionname, "");
 
if ($caption != "") {
 
$wgOut->addWikiText(
 
"<pre>
 
<td><center>$caption</center>
 
</td></pre>"
 
);
 
}
 
 
 
}
 
$m++;
 
if ($m <= $par) {
 
$captionname = "wpCaption" . $m;
 
$caption = $wgRequest->getText($captionname, "");
 
if ($caption != "") {
 
$wgOut->addWikiText(
 
"<pre>
 
<td><center>$caption</center>
 
</td></pre>"
 
);
 
}
 
 
 
}
 
$m++;
 
$wgOut->addWikiText(
 
"<pre></tr>
 
</pre>"
 
);
 
}
 
 
}
 
}
$wgOut->addWikiText(
 
"<pre></table></pre>"
 
);
 
 
}
 
}
 
}
 
}
Line 325: Line 336:
 
# Called from $wgExtensionFunctions array when initialising extensions
 
# Called from $wgExtensionFunctions array when initialising extensions
 
function wfSetupSuperGallery() {
 
function wfSetupSuperGallery() {
global $wgLanguageCode,$wgMessageCache;
+
global $wgLanguageCode,$wgMessageCache,$wgUser,$wgRequest;
+
# Add the messages used by the specialpage
+
# Ensure the code only runs if it is a Supergallery and the user is logged in
if ($wgLanguageCode == 'en') {
+
$sgnewtitle = Title::newFromText($wgRequest->getText('title'));
$wgMessageCache->addMessages(array(
+
if (preg_match('%(SuperGallery)(.*)%',$sgnewtitle) && !$wgUser->isAnon()) {
'supergallery' => 'SuperGallery Specialpage',        # The friendly page title
+
 
'supergalleryMessage' => "SuperGallery: <tt>Use this page to create a supergallery of galleries</tt>",)
+
# Add the messages used by the specialpage
);
+
if ($wgLanguageCode == 'en') {
 +
$wgMessageCache->addMessages(array(
 +
'supergallery' => 'SuperGallery Specialpage',        # The friendly page title
 +
'supergalleryMessage' => "SuperGallery: <tt>Use this page to create a supergallery of galleries</tt>",
 +
'supergallerySuccessMessage' => "<br /><b>Your SuperGallery has been successfully created.</b><br />")
 +
);
 +
 +
}
 +
 
 +
# Add the specialpage to the environment
 +
SpecialPage::addPage(new SpecialSuperGallery());
 
}
 
}
 
# Add the specialpage to the environment
 
SpecialPage::addPage(new SpecialSuperGallery());
 
 
}
 
}
 +
</php>

Latest revision as of 00:38, 30 July 2013

<php> <?php

  1. Extension:SuperGallery
  2. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  3. - Author: Jack Henderson

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

define('SUPERGALLERY_VERSION','1.0.0, 2008-12-15');

$wgExtensionFunctions[] = 'wfSetupSuperGallery';

$egSuperGalleryTag = "supergallery";

$wgExtensionCredits['specialpage'][] = array( 'name' => 'Special:SuperGallery', 'author' => 'Jack Henderson', 'description' => 'An special page for creating a supergallery of galleries, made with Template:SpecialPage.', 'url' => 'http://www.organicdesign.co.nz/Extension:SuperGallery', 'version' => SUPERGALLERY_VERSION );

require_once "$IP/includes/SpecialPage.php";

  1. Define a new class based on the SpecialPage class

class SpecialSuperGallery extends SpecialPage {

# Constructor function __construct() { global $wgHooks, $wgParser, $egSuperGalleryTag; SpecialPage::SpecialPage( 'SuperGallery', # name as seen in links etc 'sysop', # user rights required true, # listed in special:specialpages false, # function called by execute() - defaults to wfSpecial{$name} false, # file included by execute() - defaults to Special{$name}.php, only used if no function false # includable ); # Add the tagHook $wgParser->setHook($egSuperGalleryTag, array($this, 'tagSupergallery'));

}

function tagSupergallery($text,$argv,&$parser) { global $egSuperGalleryTag, $wgServer, $wgScript;

# Make an array of the content $nz = 9; # All the styles $ny = count ($argv) - $nz; $par = $ny / 4; $conarr = array_slice($argv,9); # Array of content $uarr[] = array(); $iarr[] = array(); $barr[] = array(); $carr[] = array();

foreach ($conarr as $k => $v){ if (preg_replace ('%(.*)([0-9]{1,2})%','\1',$k) == "url") $uarr[preg_replace ('%(.*)([0-9]{1,2})%','\2',$k)] = $v; elseif (preg_replace ('%(.*)([0-9]{1,2})%','\1',$k) == "image") $iarr[preg_replace ('%(.*)([0-9]{1,2})%','\2',$k)] = $v; elseif (preg_replace ('%(.*)([0-9]{1,2})%','\1',$k) == "bkpre") $barr[preg_replace ('%(.*)([0-9]{1,2})%','\2',$k)] = $v; else $carr[preg_replace ('%(.*)([0-9]{1,2})%','\2',$k)] = "<a href='" . $wgServer . $wgScript . "/" . $v . "'>" . $v . "</a>"; }

# Table css $gtext = "<style type='text/css'>table.supergallery" . $argv['gtitle'] . "{ border:" . $argv['border'] . "px solid " . $argv['bordercolor'] . ";margin:" . $argv['tablemargin'] . "px;padding:" . $argv['tablemargin'] . "px;background-color:" . $argv['backgroundcolor'] .";}</style>";

for ($i = 1; $i <= $par; $i++) {

# Set up rightsized thumbs silently by using the wiki thumbnail renderer. # These are used as backgrounds for the gallery cells.

$gtext .= "

[[Image:" . $iarr[$i] . "|" . $argv['width'] . "px]]

";

# Set up css for the backgrounds $gtext .= "<style type='text/css'>.sgclass" . $i . "{background:url(" . $barr[$i] . $argv['width'] . "px-" . $iarr[$i] . ") center center no-repeat}</style>"; }

# Render table code for copying

$gtext .= "

"; if ($argv['column'] == 1) { for ($j = 1; $j <= $par; $j++) { $caption = $carr[$j]; if ($caption != "") { $gtext .= ""; } } } elseif ($argv['column'] == 2) { $z = 1; while ($z <= $par) { $m = $z; $caption = $carr[$m]; if ($caption != "") { $gtext .= ""; $z++; if ($z <= $par) { $gtext .= ""; $z++; } $gtext .= ""; $m++; } if ($m <= $par) { $caption = $carr[$m]; if ($caption != "") { $gtext .= ""; } } $m++; $gtext .= ""; } } else { $z = 1; while ($z <= $par) { $m = $z; $gtext .= ""; $gtext .= ""; $z++; if ($z <= $par) { $gtext .= ""; $z++; } if ($z <= $par) { $gtext .= ""; $z++; } $gtext .= ""; $gtext .= ""; if ($m <= $par) { $caption = $carr[$m]; if ($caption != "") { $gtext .= ""; $m++; } } if ($m <= $par) { $caption = $carr[$m]; if ($caption != "") { $gtext .= ""; $m++; } } if ($m <= $par) { $caption = $carr[$m]; if ($caption != "") { $gtext .= ""; $m++; } } $gtext .= ""; } } $gtext .= "
$caption
$caption
$caption
$caption
$caption
$caption

";

return $gtext;

}

# Override SpecialPage::execute() # - $param is from the URL, eg Special:{{{name}}}/param function execute($param) { global $wgOut, $wgRequest, $wgTitle, $wgUser, $wgMessageCache; $this->setHeaders(); $title = Title::makeTitle(NS_SPECIAL,'SuperGallery');

# The $param is the number of text inputs to be replicated in the form if (isset($param)) $par = $param;

# If posted, we want to keep $par from the previous execution so we extract data from the hidden field else if ($wgRequest->getText('wpParam', "")) $par = $wgRequest->getText('wpParam', "");

# A low default to encourage users to use the switch else $par = 4;

# Extract any posted data $posted = $wgRequest->getText('wpSubmit', false);

# Extract any contents of fields $gtitle = $wgRequest->getText('wpGtitle', ""); $width = $wgRequest->getText('wpWidth', ""); $height = $wgRequest->getText('wpHeight', ""); $column = $wgRequest->getText('wpColumn', ""); $border = $wgRequest->getText('wpBorder', ""); $tablemargin = $wgRequest->getText('wpTableMargin', ""); $bordercolor = $wgRequest->getText('wpBorderColor', ""); $backgroundcolor = $wgRequest->getText('wpBackgroundColor', ""); $cellpadding = $wgRequest->getText('wpCellPadding', "");

# Render the form $wgOut->addWikiText(wfMsg('supergalleryMessage', 'supergalleryParameter')); $wgOut->addHTML( wfElement('form', array('action' => $title->getLocalURL('action=submit'), 'method' => 'post'), null)

. "

Usage

Fill out the form below for each gallery you want to include, with a unique name for your supergallery.

This extension defaults to four pairs of gallery inputs, unless the number of galleries in your intended supergallery is passed as this page's parameter, for example for five galleries:

http://localhost/wiki/index.php/Special:SuperGallery/5

The galleries you link to will be created if they do not exist, and can themselves be made as usual using the gallery tag.

Here is the expected form of the picture url and the article link:

http://localhost/wiki/images/d/de/Boat.jpg

[[Pictures_of_Auckland|Pictures of Auckland]]

Press the Submit Query button. A new page will be generated under your unique title, with a supergallery tag and your posted information, which you can edit.


Page Setup

What is the title of your supergallery? This is a compulsory field.

<input name='wpGtitle' size = '35' />

How many columns do you want the supergallery to have (up to 3)? If you leave the field empty it is 2.

<input name='wpColumn' size = '10' />

How wide do you want each thumbnail to be? Empty field is 120.

<input name='wpWidth' size = '10' />

How high do you want each thumbnail's box to be? Empty field is 200.

<input name='wpHeight' size = '10' />

How wide do you want the supergallery's border to be? Empty field is 1. No border is 0.

<input name='wpBorder' size = '10' />

What color do you want the supergallery's border to be? Empty field is #cccccc.

<input name='wpBorderColor' size = '10' />

What do you want the supergallery's margin to be? Empty field is 2.

<input name='wpTableMargin' size = '10' />

How much cellpadding to you want? Empty field is 20.

<input name='wpCellPadding' size = '10' />

What color do you want the supergallery's background to be? Empty field is #ffffff.

<input name='wpBackgroundColor' size = '10' /> <input type='hidden' name='wpParam' value=$par>

" );

# Render multiple inputs using the /$par from the url for ($ctr = 1; $ctr <= $par; $ctr++) { $wgOut->addHTML(

"

Gallery " . $ctr ."

The full URL of the image you want for the thumbnail.

<input name='wpUrl" . $ctr . "' size = '50' />

The caption for this gallery, which is also its link.

<input name='wpCaption" . $ctr . "' size = '50' />" ); }

# Post $wgOut->addHTML( "

" . wfElement('input', array('name' => 'wpSubmit', 'type' => 'submit'))

. "</form>

When you submit this form, a supergallery page will be created with the name you specified, unless the name already exists. You can edit the tag in that page if you wish to change the supergallery.

"

);

# Process results if data posted if ($posted) { # Defaults for posted style elements if ($width == "") $width = 120; if ($height == "") $height = 200; if ($column == "") $column = 2; if ($border == "") $border = 1; if ($tablemargin == "") $tablemargin = 2; if ($bordercolor == "") $bordercolor = "#cccccc"; if ($backgroundcolor == "") $backgroundcolor = "#ffffff"; if ($cellpadding == "") $cellpadding = 10;

# Build tag $tag = '<supergallery gtitle = "'.$gtitle.'" width = "'.$width.'" height = "'.$height.'" column = "'.$column.'" border = "'.$border.'" tablemargin = "'.$tablemargin.'" bordercolor = "'.$bordercolor.'" backgroundcolor = "'.$backgroundcolor.'" cellpadding = "'.$cellpadding.'"';

# Some arrays to populate with loops $url[] = array(); $image[] = array(); $bkpre[] = array(); $caption[] = array();

# Make some variables out of the posted fields for ($n = 1; $n <= $par; $n++) { $url[$n] = $wgRequest->getText('wpUrl' . $n, ""); $image[$n] = preg_replace ('%(.*/images/)(.*/)(.*)(\.)(.*)%','\3\4\5',trim($url[$n])); $bkpre[$n] = preg_replace ('%(.*/images/)(.*/)(.*)(\.)(.*)%','\1thumb/\2\3\4\5/',trim($url[$n])); $caption[$n] = $wgRequest->getText('wpCaption' . $n, ""); } for ($n = 1; $n <= $par; $n++) { if ($url[$n] != "") { $tag .= ' url' .$n. ' = "' . $url[$n] . '"'; $tag .= ' image' .$n. ' = "' . $image[$n] . '"'; $tag .= ' bkpre' .$n. ' = "' . $bkpre[$n] . '"'; $tag .= ' caption' .$n. ' = "' . $caption[$n] . '"'; } } $tag .= '>'; if ($wgUser->isAllowed('edit')) { $title = Title::newFromText( $gtitle ); if (trim($wgRequest->getText('wpGtitle'))==) { $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) ); $wgOut->errorpage( 'badtitle', 'badtitletext'); } if((isset($title)) && ($title->getArticleID() == 0)) { $article = new Article($title); $article->doEdit($tag, "", EDIT_NEW); $wgOut->addHTML(wfMsg('supergallerySuccessMessage')); } elseif (!isset($title)) { $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) ); $wgOut->errorpage( 'badtitle', 'badtitletext'); } else { $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) ); $wgOut->errorpage( 'error', 'articleexists'); } }

else { $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) ); $wgOut->errorpage( 'error', 'badarticleerror'); } } } }

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupSuperGallery() { global $wgLanguageCode,$wgMessageCache,$wgUser,$wgRequest;

# Ensure the code only runs if it is a Supergallery and the user is logged in $sgnewtitle = Title::newFromText($wgRequest->getText('title')); if (preg_match('%(SuperGallery)(.*)%',$sgnewtitle) && !$wgUser->isAnon()) {

# Add the messages used by the specialpage if ($wgLanguageCode == 'en') { $wgMessageCache->addMessages(array( 'supergallery' => 'SuperGallery Specialpage', # The friendly page title 'supergalleryMessage' => "SuperGallery: Use this page to create a supergallery of galleries", 'supergallerySuccessMessage' => "
Your SuperGallery has been successfully created.
") );

}

# Add the specialpage to the environment SpecialPage::addPage(new SpecialSuperGallery()); } } </php>