wantName = $newName;
$this->wantCR = $newCR;
$this->wantRole = $newRole;
#$this->wantMDT = $newMDT;
#$this->wantSize = $newSize;
}
function setCR($newCR) {
$this->wantCR = $newCR;
}
function setRole($newRole) {
$this->wantRole = $newRole;
}
#function setMDT($newMDT) {
# $this->wantMDT = $newMDT;
#}
#function setSize($newSize) {
# $this->wantSize = $newSize;
#}
function write($s) {
$this->output[] = $s;
}
#function doReplace($matches) {
# if (($matches[1] == 'CR') && ($this->wantCR != 0)) {
# return '| CR | ' . $this->wantCR . "\n";
# }
# if ($matches[1] == 'Role') {
# return "| Role | " . $this->wantRole . "\n";
# }
# return $matches[0];
#}
public function __toString() {
$rv = join('', $this->output);
$start = strpos($rv, '{{Template:Monster');
$end = strrpos($rv, '}}') + 1;
if (($start !== FALSE) && ($end !== FALSE) && ($start < $end)) {
$rv = htmlspecialchars_decode(substr($rv, $start,
$end - $start + 1));
}
$rv = preg_replace('//m', '', $rv);
$rv = preg_replace('/\|\s*CR\s*\|\s*[0-9]+/', '| CR | ' . $this->wantCR,
$rv);
// N.B., Henchman does nothing.
$rv = preg_replace('/\|\s*Role\s*\|\s*(Heavy|Henchman|Killer|Leader|Minion|Shooter|Sneak|Tank|Threat|Villain)?/', '| Role | ' . $this->wantRole, $rv);
#$rv = preg_replace('/\|\s*MultipliedDamageType\s*=\s*(Attacks|Damage|Hybrid)?/', '| MultipliedDamageType = ' . $this->wantMDT, $rv);
#if ($this->wantSize !== '') {
# $rv = preg_replace('/\|\s*Size\s*\|\s*(Fine|Diminutive|Tiny|Small|Medium|Large|Huge|Gargantuan|Colossal|Titanic)?/', '| Size | ' . $this->wantSize, $rv);
#}
return $rv;
}
}
class SpecialMMM extends SpecialPage {
public function __construct() {
parent::__construct('MillionMonsterMachine');
}
function makeCRList() {
$rv = [];
foreach (range(1, 40) as $r) {
$rv[strval($r)] = $r;
}
return $rv;
}
/**
* Show the page to the user
*
* @param string $sub The subpage string argument (if any).
* [[Special:MillionMonsterMachine/subpage]]. Not currently examined.
*/
public function execute($sub) {
$this->setHeaders();
$out = $this->getOutput();
$out->addModuleStyles('ext.milMonstMach');
$out->setPageTitle($this->msg('milmonstmach-title'));
//$out->addHTML('
');
//$out->addHelpLink('How to become a MediaWiki hacker');
//$out->addWikiMsg('milmonstmach-helloworld-intro');
$out->addInlineStyle('div#mw-content-text form { padding: 1em; border: inset; border-width: 1px; display: inline-block; }');
$request = $this->getRequest();
$dbr = wfGetDB(DB_REPLICA);
$mmmform = [
'cr' => [
'class' => 'HTMLIntField',
'default' => '1',
'size' => 4,
'maxlength'=> 4,
'min' => 1,
'max' => 40,
'label' => "Target CR (1\xe2\x80\x9340)",
'name' => 'cr',
'id' => 'cr',
'cssclass' => 'mmm-cr',
'options' => $this->makeCRList(),
],
];
$submitText = 'Next: Choose Base Monster';
$choseCR = $request->getInt('cr');
if (($choseCR != null) && is_numeric($choseCR)) {
$mmmform['cr']['default'] = strval($choseCR);
$patterns = [
'None' => '',
'Aerial' => 'Aerial',
'Agile' => 'Agile',
'Alchemical Waxwork' => 'Alchemical Waxwork',
'Aquatic' => 'Aquatic',
'Athletic' => 'Athletic',
'Attacker Mage' => 'Attacker Mage',
'Bewitcher Mage' => 'Bewitcher Mage',
'Blasting' => 'Blasting',
'Caustic' => 'Caustic',
'Celestial' => 'Celestial',
'Coursing' => 'Coursing',
'Defender Mage' => 'Defender Mage',
'Deflecting' => 'Deflecting',
'Draconic' => 'Draconic',
'Dripping' => 'Dripping',
'Eldritch' => 'Eldritch',
'Empyreal' => 'Empyreal',
'Entropic' => 'Entropic',
'Exploding' => 'Exploding',
'Fey' => 'Fey',
'Fiendish' => 'Fiendish',
'Fluidic' => 'Fluidic',
'Foo' => 'Foo',
'Frumious' => 'Frumious',
'Giant' => 'Giant',
'Grating' => 'Grating',
'Hateful' => 'Hateful',
'Hellish' => 'Hellish',
'Immolating' => 'Immolating',
'Intruding' => 'Intruding',
'Invisible' => 'Invisible',
'Invulnerable' => 'Invulnerable',
'Jarring' => 'Jarring',
'Leathery' => 'Leathery',
'Numbing' => 'Numbing',
'Powerful Mage' => 'Powerful Mage',
'Prescient' => 'Prescient',
'Resolute' => 'Resolute',
'Returning' => 'Returning',
'Searing' => 'Searing',
'Shadow' => 'Shadow',
'Shattering' => 'Shattering',
'Shredding' => 'Shredding',
'Skeletal' => 'Skeletal',
'Sticky' => 'Sticky',
'Striking' => 'Striking',
'Swollen' => 'Swollen',
'Tiny' => 'Tiny',
'Two-Headed' => 'Two-Headed',
'Unkind' => 'Unkind',
'Winged' => 'Winged',
'Wormskull' => 'Wormskull',
];
$mmmform['pattern1'] = [
'class' => 'HTMLSelectField',
'name' => 'pattern1',
'label' => 'First (optional) pattern',
// The options available within the checkboxes (displayed => value)
'options' => $patterns,
];
$chosePattern1 = $request->getVal('pattern1');
if (!empty($chosePattern1)) {
$mmmform['pattern1']['default'] = $chosePattern1;
$subarr = [ $chosePattern1 => $chosePattern1 ];
$mmmform['pattern2'] = [
'class' => 'HTMLSelectField',
'name' => 'pattern2',
'label' => 'Second (optional) pattern',
// The options available within the checkboxes (displayed => value)
'options' => array_diff($patterns, $subarr),
];
$submitText = 'Next: Choose Optional 2nd Pattern or Load Monster';
}
$chosePattern2 = $request->getVal('pattern2');
# Modify CR here by the pattern here.
# $realChoseCR -= $choseCR - pattern[0].cost - pattern[1].cost
$realChoseCR = $choseCR;
$mmmform['name'] = [
'label' => 'Select a monster',
'name' => 'name',
'id' => 'name',
'class' => 'HTMLSelectField',
'options' => [ ],
'width' => 60,
'cssclass' => 'mmm-name',
];
$monsDfl = null;
$min = $realChoseCR - 5;
$max = $realChoseCR + 2;
if ($min < 1) {
$min = 1;
}
if ($max > 40) {
$max = 40;
}
$datalist = [];
for ($i = $min; $i <= $max; $i++) {
// SELECT page_title FROM categorylinks LEFT JOIN page ON
// cl_from = page_id WHERE cl_to = 'Bestiary';
$res = $dbr->select(
array('categorylinks', 'page'),
array('page_title'),
array(
"cl_to = 'CR_" . $i . "'",
"page_title not like '%CR_" . $i . "_Blueprint'",
"page_title not like 'Transmogrified%_CR_" . $i . "'",
),
__METHOD__,
array(),
array(
'page' => array('LEFT JOIN', array('cl_from=page_id'))
)
);
foreach ($res as $row) {
if ($monsDfl === null) {
$monsDfl = $row->page_title;
}
$datalist[str_replace('_', ' ', $row->page_title)] =
$row->page_title;
}
}
if ($monsDfl !== null) {
$mmmform['name']['default'] = $monsDfl;
}
$mmmform['name']['options'] = $datalist;
$submitText = 'Next: Choose Optional Pattern or Load Monster';
}
$choseName = $request->getVal('name');
if (!empty($choseName)) {
$out->setPageTitle(str_replace('_', ' ', $choseName) . " (Million Monster Machine)");
$mmmform['name']['default'] = $choseName;
$mmmform['role'] = [
'class' => 'HTMLSelectField',
'cssclass' => 'mmm-role',
'label' => '(Optional) Change role to:',
'name' => 'role',
'id' => 'role',
'options' => [
'(none)' => '',
'Heavy' => 'Heavy',
// 'Henchman' => 'Henchman',
'Killer' => 'Killer',
'Leader' => 'Leader',
'Minion' => 'Minion',
'Shooter' => 'Shooter',
'Sneak' => 'Sneak',
'Tank' => 'Tank',
'Threat' => 'Threat',
'Villain' => 'Villain'
],
'default' => '',
];
#$mmmform['size'] = [
# 'class' => 'HTMLSelectField',
# 'cssclass' => 'mmm-size',
# 'label' => '(Optional) Change size to:',
# 'name' => 'size',
# 'id' => 'size',
# 'options' => [
# '(unchanged)' => '',
# 'Fine' => 'Fine',
# 'Diminutive' => 'Diminutive',
# 'Tiny' => 'Tiny',
# 'Small' => 'Small',
# 'Medium' => 'Medium',
# 'Large' => 'Large',
# 'Huge' => 'Huge',
# 'Gargantuan' => 'Gargantuan',
# 'Colossal' => 'Colossal',
# 'Titanic' => 'Titanic'
# ],
#];
$submitText = 'Update Monster';
}
$choseRole = $request->getVal('role');
#$choseSize = $request->getVal('size');
if (!empty($choseRole)) {
$mmmform['role']['default'] = $choseRole;
#$mmmform['subrole'] = [
# 'class' => 'HTMLRadioField',
# 'label' => 'Role Type',
# 'options' => [
# 'Attacks' => 'Attacks',
# 'Damage' => 'Damage',
# 'Hybrid' => 'Hybrid',
# ],
# 'name' => 'mdt',
# 'id' => 'mdt',
# 'default' => 'Hybrid',
#];
#$choseMDT = $request->getVal('mdt');
#if (!empty($choseMDT)) {
# $mmmform['subrole']['default'] = $choseMDT;
#}
}
// $htmlForm = new HTMLForm($mmmform, $this->getContext(), 'testform');
// Valid formats: table, div, raw, inline, vform, ooui
if (isset($_GET['format'])) {
$htmlForm = HTMLForm::factory($_GET['format'], $mmmform, $this->getContext(), 'testform');
} else {
$htmlForm = HTMLForm::factory('table', $mmmform, $this->getContext(), 'testform');
}
$htmlForm->setMethod('get');
$htmlForm->setSubmitText($submitText);
$htmlForm->setSubmitCallback([ $this, 'trySubmit' ]);
$htmlForm->show();
//if (($choseCR != null) && is_numeric($choseCR)) {
// $out->addHTML("");
//}
//$out->addHTML('
');
if (($choseCR != null) && is_numeric($choseCR) && !empty($choseName)) {
#if (empty($choseMDT)) {
# $choseMDT = 'Hybrid';
#}
#if (empty($choseSize)) {
# $choseSize = '';
#}
$exporter = new WikiExporter($dbr, WikiExporter::CURRENT, WikiExporter::BUFFER);
$buffer = new MonsterBuffer($choseName, $choseCR, $choseRole); # , $choseMDT, $choseSize);
$exporter->setOutputSink($buffer);
$title = Title::newFromText($choseName);
$exporter->pageByTitle($title);
//$out->addWikiText($buffer);
global $wgParser;
$options = ParserOptions::newFromContext($this->getContext());
$render = $wgParser->preprocess($buffer . "", $title, $options);
$options->setTargetLanguage($title->getPageLanguage());
$reparsed = $wgParser->parse($render, $title, $options);
$out->addParserOutputContent($reparsed);
//$out->addHTML('
');
//$out->addHTML('' . $buffer . '
');
}
}
static function trySubmit($formData) {
// return !empty($formData['name']);
// Always return false so the form renders.
return false;
}
protected function getGroupName() {
return 'other';
}
}