User:Woozle/MoreBoxes

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search

About

MoreBoxes is a quick extension to allow adding additional dynamic content to a MediaWiki skin. I originally created it so I could add Flattr and Kachingle buttons to Issuepedia, but discontinued that after a few months; I am not currently using the extension, so I don't know if it works with more recent MediaWiki versions. (It's simple enough, though, so it should.)

Example Usage

...where $txtHdr is already defined (see MediaWiki/Flattr for an example): <php>$wxgMoreBoxes = array (

   'head' => array (
     array (

'html' => $txtHdr

     )
   ),
   'foot' => array (	// "foot" to put it in the footer, "side" to put it in the control sidebar
     array (

'title' => 'support free sites', 'html' =>

'

' ."<script type=\"text/javascript\">if (!window.kachingle_loaded) {var _protocol = 'http'+(window.location.protocol == 'https:' ? 's' : );document.writeln(unescape(\"%3Cscript type='text/javascript' src='\"+_protocol+\"://medallion.kachingle.com/kachingle_controls_revb.js'>%3C/script>\"));}</script>
<iframe site='1376' stylename='wide' style='display:none;' allowtransparency='true' scrolling='no' frameborder='0'>Upgrade your browser to support the sites you love with <a href=".'"http://www.kachingle.com/">Kachingle</a>!</iframe>
'
.'
'

.'<a class="FlattrButton" style="display:none;" href="http://issuepedia.org"></a>'

.'

'

     )
   ),
 );</php>

Code

<php><?php /*

 FILE: MoreBoxes.php
 PURPOSE: Allows admin-configurable arbitrary HTML to be displayed below toolboxes
 HISTORY:
   2010-08-13 0.1 First generally-usable version: supports multiple boxes in sidebar; supports footer and header HTML.
     Need a tag for inserting boxes within wikitext.
  • /
  1. Confirm MW environment (huge wrapper)

if (defined('MEDIAWIKI')) {

  1. Credits

$wgExtensionCredits['parserhook'][] = array(

   'name'=>'MoreBoxes',
   'author'=>'Woozle Staddon',
   //'url'=>'http://jimbojw.com/wiki/index.php?title=ShareThis',
   'description'=>'Allows admin-configurable arbitrary HTML to be displayed below toolboxes',
   'version'=>'0.1'

);

  1. Add Extension Functions

$wgExtensionFunctions[] = 'wfMoreBoxesExtensionSetup';

  1. Sets up the parser hook and global messages

function wfMoreBoxesExtensionSetup() {

   global $wgMessageCache; //, $wgParser, $wxgMoreBoxesTitle;

// start a sequence of one or more toolboxes:

   $wgMessageCache->addMessage('more-boxes-toolbox-escape-html',

"\n\t\t\t\n\t\t\n\t"

   );

// start an individual toolbox:

   $wgMessageCache->addMessage('more-boxes-toolbox-open-html',

"\n\t

". "\n\t\t
$1
". "\n\t\t
"
   );

// close an individual toolbox:

$wgMessageCache->addMessage('more-boxes-toolbox-shut-html',"\n\t
");

// finish a sequence of one or more toolboxes - open empty tags for skin code to close, so everything is balanced:

$wgMessageCache->addMessage('more-boxes-toolbox-return-html',"\n\t
    ");

    } /**

    * Parser hook for the <moreboxes /> tag extension.
    */
    

    /* function wfMoreBoxesParserHook($text, $params, &$parser) {

       global $wgMoreBoxesHTML, $wgTitle, $wgStylePath;
       
       $output = $wgMoreBoxesHTML;
     
       return $output;
    

    }

    • /
    1. Add hook for Monobook sidebar integration

    $wgHooks['MonoBookTemplateToolboxEnd'][] = 'wxfInsertMoreBoxesSidebar'; $wgHooks['SkinAfterBottomScripts'][] = 'wxfInsertMoreBoxesFooter'; $wgHooks['BeforePageDisplay'][] = 'wxfInsertMoreBoxesHeader';


    /**

    * Injects MoreBoxes code into the sidebar (hooks MonoBookTemplateToolboxEnd).
    * Note: This must be activiated by setting $wgShowMoreBoxesSidebar = true in Localsettings
    */
    

    function wxfInsertMoreBoxesSidebar($template) {

       global $wxgMoreBoxes;
    
       if (is_array($wxgMoreBoxes)) {
    

    if (is_array($wxgMoreBoxes['side'])) { $arHere = $wxgMoreBoxes['side']; $out = NULL; # Close out the MonoBook toolbox and create a new "moreboxes" portlet $out .= wfMsgForContent('more-boxes-toolbox-escape-html',nz($box['title'])); $idx = 0; foreach ($arHere as $id => $box) { $idx++; $strTitle = nz($box['title']); $out .= wfMsgForContent('more-boxes-toolbox-open-html',$strTitle,$idx); $out .= nz($box['html']); $out .= wfMsgForContent('more-boxes-toolbox-shut-html'); } $out .= wfMsgForContent('more-boxes-toolbox-return-html'); # Output the code and close the final box: echo($out); }

       }
       return true;
    

    } function wxfInsertMoreBoxesFooter( $skin, &$text ) {

       global $wxgMoreBoxes;
    
       if (is_array($wxgMoreBoxes)) {
    

    if (is_array($wxgMoreBoxes['foot'])) { $arHere = $wxgMoreBoxes['foot']; $out = NULL; foreach ($arHere as $id => $box) { $out .= nz($box['html']); } $text .= $out; }

       }
       return TRUE;
    

    } function wxfInsertMoreBoxesHeader( &$objOut, &$objSkin ) {

       global $wxgMoreBoxes;
    
       if (is_array($wxgMoreBoxes)) {
    

    if (is_array(nz($wxgMoreBoxes['head']))) { $out = NULL; $arHere = $wxgMoreBoxes['head']; foreach ($arHere as $id => $box) { $out .= nz($box['html']); } $objOut->addScript($out); }

       }
       return TRUE;
    

    }

    } # Closing MW Environment wrapper </php>