EditPage Multiple InputBoxes Mediawiki
Inleiding
readme for editbox extension mediawiki
to be continued |
Stappen
Latest version 24-09-2007
- 0.4 Issues fixed with importing page without structure
Previous working versions
- 0.3 Choice added to use template or not 21-09-2007
- 0.2 Including textarea expanding javascript 20-09-2007
- 0.1 Improved customization 19-09-2007
- 0.0.1 Combining and separating textareas working fine
<?php if ( ! defined( 'MEDIAWIKI' ) ) die(); $wgExtensionCredits['parserhook'][] = array( 'name' => 'EditTextAreas', 'author' => 'Boudewijn Vahrmeijer', 'url' => 'http://www.leerwiki.nl', 'version' => '1.11,1.10.1/1.9.3/1.9.2/1.8.2', ); //####### Choose parameters ############## $BoxNames=array('Intro','Core','Conclusion','More'); //choose names, minimum is ONE $Separator='.//.'; //Choose dummy separator for combining text input //####### Used Hooks ###################### $wgHooks['EditPage::showEditForm:fields'][] = 'TextareaDisplay'; $wgHooks['EditPage::attemptSave'][] = 'CombineBeforeSave'; $wgHooks['EditPage::showEditForm:initial'][] = 'OptionSetting'; $wgHooks['OutputPageBeforeHTML'][] = 'LastMinuteStyleChange'; //####### Formula preparation ############## $TotalTB=count($BoxNames); ########## Hook 1 ################# function TextareaDisplay(&$q,&$out) { global $TotalTB,$BoxNames,$Separator,$wgTitle; $title=$wgTitle; $q->Structure='CHECK'; //set Structure as standard //if(!$q->mTitle->exists()) return true; //new articles no four fields ######### HTML 1 ####### $out->addHTML(<<<END <script type="text/javascript"> function Hider() { document.getElementById("div1").style.display = 'none'; document.getElementById("no").style.display = 'none'; document.getElementById("yes").style.display = 'block'; document.getElementById("wpStructure").value = 'UNCHECK'; } function unHider() { document.getElementById("div1").style.display = 'block'; document.getElementById("yes").style.display = 'none'; document.getElementById("no").style.display = 'block'; document.getElementById("wpStructure").value = 'CHECK'; } </script> <script type="text/javascript"> function resizeTextarea(t) { n = navigator; nua = n.userAgent.toLowerCase(); a = t.value.split('\\n'); b=1; for (x=0;x < a.length; x++) { if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols); } b+= a.length; if (b > t.rows && nua.indexOf('opera')==-1) t.rows = b; } </script> <style> textarea { width: 550px; padding: .1em; }'</style> <input value={$q->Structure} type='hidden' name="wpStructure" id="wpStructure"/>\n END ); ############# CUT TEXT AND PUT IN BOXES ############# if(TotalTB>1) return true; $AllText=$q->textbox1; $ArrayTextTemp=explode($Separator,$AllText); $title=$wgTitle; $titleKey=$title; $titleS = Title::newFromDBkey($titleKey); $titleS->mNamespace = $titleNS - ($titleNS % 2); $article = new Article($titleS); $aid = $article->mTitle->getArticleID( GAID_FOR_UPDATE ); if(count($ArrayTextTemp)>1||$aid==0){ $out->addHTML("<div id="div1" style="display:block"> <div id="yes" style="display:none"><input type='button' value='Give me Structure' OnClick='unHider()'/></div> <div id="no" style="display:block"><input type='button' value='No Structure?' OnClick='Hider()'/></div> <p>"); } else { $out->addHTML(" </p> <div id="yes" style="display:block"><input type='button' value='Give me Structure' OnClick='unHider()'/></div> <div id="no" style="display:none"><input type='button' value='No Structure?' OnClick='Hider()'/></div> <div id="div1" style="display:none">"); <p>} </p><p>for($i=0;$i<$TotalTB-1;$i++){ $out->addHTML($BoxNames[$i]." <textarea tabindex='1' onKeyUp='resizeTextarea(this)' accesskey=',' // display new textareas name='".$BoxNames[$i]."' id='".$BoxNames[$i]."' rows='4' cols='40'>".$ArrayTextTemp[$i+1]."</textarea> "); } </p> $out->addHTML( $BoxNames[$TotalTB-1]."</div>"); <p> if(count($ArrayTextTemp)>1){ $q->textbox1= $ArrayTextTemp[$TotalTB]; } </p><p> return true; } </p> <ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li> Hook 2 ################# </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> <p>function CombineBeforeSave(&$q) { global $wgRequest, $TotalTB,$BoxNames,$Separator; $request=$wgRequest; for($i=0;$i<$TotalTB-1;$i++){ $temp=$BoxNames[$i]; $allextraTB.= $Separator.$q->safeUnicodeInput( $request, $temp ); } $q->Structure = $request->getVal( 'wpStructure' ); if($q->Structure=='CHECK'){ $q->textbox1 = $allextraTB.$Separator.$q->textbox1; } return true; } </p> <ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li> Hook 3 ################# </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> <p>function OptionSetting(&$q) { global $wgUser; $wgUser->setOption('rows',10); $wgUser->setOption('showtoolbar',0); return true; } </p> <ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li><ol><li> Hook 4 ################# </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> </li></ol> <p>function LastMinuteStyleChange(&$q,&$b) { global $Separator,$BoxNames, $wgTitle; $title=$wgTitle; if ($_GET['action'] != "") return true; //not the edit areas $k=explode($Separator,$b); if(count($k)<2) return true; //if no separator existing, no structure wanted for($i=1;$i<count($k)+1;$i++){ </p> $b.='<h2>'.$BoxNames[$i-1].'</span></h2>'.$k[$i]; <p> } return true; } ?> </p>