GamerWiki:TemplateTemplates

From GamerWiki

Jump to: navigation, search

Contents

Install Instructions

Pop the Actual Page (below) into a file in the wiki's includes directory & name it SpecialTemplateTemplates.php. Edit your LocalSettings.php & add the following line:

require_once('includes/SpecialTemplateTemplates.php');

Uninstall Instructions

To temporarily disable, simply remove the above line from your LocalSettings.php.

To remove completely, remove the above line from your LocalSettings.php & delete the SpecialTemplateTemplates.php file from the wiki's includes directory.

Actual Page

... With samples for GameInfoBox & SystemInfobox.

<?

// The default template to use
$wgTemplateTemplatesDefault = 'GameInfoBox';

// The array entry which will hold the method for generating the page link.  This label, if found within a $wgTemplateTemplates[...] entry will get ignored for field-entry.
$wgTemplateTemplatesLink = 'LinkEntry';

// The array containing the various fields
$wgTemplateTemplates = array();
$wgTemplateTemplates['GameInfoBox']['gametitle'] = 'Game Name';
$wgTemplateTemplates['GameInfoBox']['gamecover'] = 'Coverpicture.jpg';
$wgTemplateTemplates['GameInfoBox']['publisher'] = "Publisher's name";
$wgTemplateTemplates['GameInfoBox']['developer'] = "Developer's name";
$wgTemplateTemplates['GameInfoBox']['alternativetitle'] = '[[Alternative title 1]] (Region)<br />[[Alternative title 2]] (Region)';
$wgTemplateTemplates['GameInfoBox']['jpdate'] = 'date/monthintext/year';
$wgTemplateTemplates['GameInfoBox']['nadate'] = 'date/monthintext/year';
$wgTemplateTemplates['GameInfoBox']['eudate'] = 'date/monthintext/year';
$wgTemplateTemplates['GameInfoBox']['audate'] = 'date/monthintext/year';
$wgTemplateTemplates['GameInfoBox']['genre'] = 'Genre Name';
$wgTemplateTemplates['GameInfoBox']['players'] = 'Number of players';
$wgTemplateTemplates['GameInfoBox']['esrb'] = 'ESRB-rating';
$wgTemplateTemplates['GameInfoBox']['pegi'] = 'PEGI-rating';
$wgTemplateTemplates['GameInfoBox']['cero'] = 'CERO-rating';
$wgTemplateTemplates['GameInfoBox']['platform'] = 'Platform Released on';
$wgTemplateTemplates['GameInfoBox']['media'] = 'Media-Type (cartridge, cd, etc)';
$wgTemplateTemplates['GameInfoBox']['online'] = 'Yes/No';

/* The page link that is to be generated.  If no page link is desired, just
   leave out this array for this template.  The array consists of type & value
   pairs.
   Two types currently support: text & valu
	text - literal text to be inserted into the text
	valu - the value lookup as defined in the rest of the array */
$wgTemplateTemplates['GameInfoBox'][$wgTemplateTemplatesLink]['valu1'] = 'gametitle';
$wgTemplateTemplates['GameInfoBox'][$wgTemplateTemplatesLink]['text1'] = ' (';
$wgTemplateTemplates['GameInfoBox'][$wgTemplateTemplatesLink]['valu2'] = 'platform';
$wgTemplateTemplates['GameInfoBox'][$wgTemplateTemplatesLink]['text2'] = ')';

$wgTemplateTemplates['SystemInfobox']['systemname'] = 'System Name';
$wgTemplateTemplates['SystemInfobox']['systempicture'] = 'systemPicture.jpg';
$wgTemplateTemplates['SystemInfobox']['manufacturercompanies'] = 'who made it?';
$wgTemplateTemplates['SystemInfobox']['alternatenames'] = 'Any other names the console has. Acronyms, prototype names etc';
$wgTemplateTemplates['SystemInfobox']['announceddate'] = 'Date the console was announced';
$wgTemplateTemplates['SystemInfobox']['jpdate'] = 'date/month in text/year';
$wgTemplateTemplates['SystemInfobox']['nadate'] = 'date/month in text/year';
$wgTemplateTemplates['SystemInfobox']['eudate'] = 'date/month in text/year';
$wgTemplateTemplates['SystemInfobox']['audate'] = 'date/month in text/year';
$wgTemplateTemplates['SystemInfobox']['jpprice'] = '?';
$wgTemplateTemplates['SystemInfobox']['naprice'] = '?';
$wgTemplateTemplates['SystemInfobox']['euprice'] = '?';
$wgTemplateTemplates['SystemInfobox']['auprice'] = '?';
$wgTemplateTemplates['SystemInfobox']['discountinueddate'] = 'Date discontinued';

// The page name is generated based on only the systemname
$wgTemplateTemplates['SystemInfobox'][$wgTemplateTemplatesLink]['value'] = 'systemname';

function returnValueOrDefault($Template, $Value)
{
	global $wgRequest, $wgOut, $wgTemplateTemplates;

	if ($wgRequest->getVal($Template.$Value) != null)
	{
		return $wgRequest->getVal($Template.$Value);
	} else
	{
		return $wgTemplateTemplates[$Template][$Value];
	}
}

function wfSpecialTemplateTemplates() {
	global $wgOut, $wgTemplateTemplates, $wgTemplateTemplatesDefault, $wgTemplateTemplatesLink, $wgRequest;

	$lclTemplate = $wgTemplateTemplatesDefault;
	if ($wgRequest->getVal('Template') != null)
	{
		$lclTemplate =$wgRequest->getVal('Template'); 
	}

	// Begin the form - no need for an action parameter as we'll let the browser post back to the same page.
	$wgOut->addHTML("<form method='post' name='TemplateTemplates'>");

	// Write the combo box to select the template
	$wgOut->addHTML("Select a template: <select id='Template' name='Template' onChange='this.form.submit(); return true;'>");
	foreach ($wgTemplateTemplates as $Template => $TemplateElements)
	{
		$wgOut->addHTML("<option id='".$Template."' name='".$Template."'");
		if ($lclTemplate == $Template)
		{
			$wgOut->addHTML(" selected");
		}
		$wgOut->addHTML(">".$Template."</option>");
	}
	$wgOut->addHTML("</select>");

	// Generate the page link
	$pageLink = '';
	foreach($wgTemplateTemplates[$lclTemplate][$wgTemplateTemplatesLink] as $style => $value)
	{
		$type = substr($style, 0, 4);
		if ($type == 'text')
		{
			$pageLink .= $value;
		}
		if ($type = 'value')
		{
			$pageLink .= returnValueOrDefault($lclTemplate, $value);
		}
	}
	$wgOut->addWikiText("[[".$pageLink."]]");

	// Now add the elements
	$outputHTML = "<table border='0'>";
	$outputWiki = "{{".$lclTemplate."|\n";
	foreach($wgTemplateTemplates[$lclTemplate] as $Variable => $Value)
	{
		if (is_array($Value))
		{
			continue;
		}
		// Grab the value inputted or default value for this field
		$currentValue = returnValueOrDefault($lclTemplate, $Variable);

		// Generate the text fields
		$outputHTML .= "<tr>";
		$outputHTML .= "<td>".$Variable."</td>";
		$outputHTML .= "<td><input type='text' size='60' name='".$lclTemplate.$Variable."' value='".htmlentities($currentValue)."'></input></td>";
		$outputHTML .= "</tr>";

		// Generate the wiki text
		$outputWiki .= $Variable."=".$currentValue."|\n";
	}
	$outputHTML .= "</table>";
	$outputWiki .= "}}";

	// Output a standard wiki header
	$wgOut->addWikiText("== Template example ==");

	// Output the template in use to show the current data being used
	$wgOut->addWikiText($outputWiki);

	// Output the code to use the template with the current data set
	$wgOut->addHTML("<br/>The following is the entry which you can copy & paste.  Be sure to enter the details below for most simplicity.<pre>".htmlentities($outputWiki)."</pre>");

	// Output the form to alter the data's values.
	$wgOut->addHTML($outputHTML);

	//End the form
	$wgOut->addHTML("<input type='submit' value='Generate'");
	$wgOut->addHTML("</form>");
}

$wgExtensionCredits['other'][] = array(
        'name' => 'Special:TemplateTemplates',
        'description' => 'Adds a special page to generate sample template includes.',
        'author' => 'A. Peter Mee, A.K.A. Barthax'
);

$wgExtensionFunctions[] = "wfExtensionSpecialTemplateTemplates";
function wfExtensionSpecialTemplateTemplates() {
	global $wgMessageCache, $IP;
        require_once( "$IP/includes/SpecialPage.php" );
	$wgMessageCache->addMessages(array('templatetemplates' => 'Template Templates'));
	SpecialPage::addPage( new SpecialPage( 'TemplateTemplates') );
}

?>

Usage

(Once installed!) Pop over to Special:TemplateTemplates, if the drop-down list is the wrong template, change it! Once the page re-loads, enter all the details as appropriate & hit the Generate button. If the template uses an automated data-based link, copy the Template example given, click the link & paste the Template example into the page.

Personal tools