Skip to content

Commit

Permalink
Convert deprecated msg formats; code format cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontalvo3 committed Feb 3, 2015
1 parent a06c320 commit fc5a159
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 48 deletions.
85 changes: 42 additions & 43 deletions HeaderFooter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,66 @@ class HeaderFooter
/**
* Main Hook
*/
public static function hOutputPageParserOutput( &$op, $parserOutput )
{
public static function hOutputPageParserOutput( &$op, $parserOutput ) {

$action = $op->parserOptions()->getUser()->getRequest()->getVal("action");
if ( ($action == 'edit') || ($action == 'submit') || ($action == 'history') )
if ( ($action == 'edit') || ($action == 'submit') || ($action == 'history') ) {
return true;

}

global $wgTitle;

$ns = $wgTitle->getNsText();
$name = $wgTitle->getPrefixedDBKey();

$text = $parserOutput->getText();

$nsheader = "hf-nsheader-$ns";
$nsfooter = "hf-nsfooter-$ns";
$nsfooter = "hf-nsfooter-$ns";

$header = "hf-header-$name";
$footer = "hf-footer-$name";
$footer = "hf-footer-$name";

$text = '<div class="hf-header">'.self::conditionalInclude( $text, '__NOHEADER__', $header ).'</div>'.$text;
$text = '<div class="hf-nsheader">'.self::conditionalInclude( $text, '__NONSHEADER__', $nsheader ).'</div>'.$text;

$text .= '<div class="hf-footer">'.self::conditionalInclude( $text, '__NOFOOTER__', $footer ).'</div>';
$text .= '<div class="hf-nsfooter">'.self::conditionalInclude( $text, '__NONSFOOTER__', $nsfooter ).'</div>';

$parserOutput->setText( $text );

return true;
}
}

/**
* Verifies & Strips ''disable command'', returns $content if all OK.
*/
static function conditionalInclude( &$text, $disableWord, &$msgId )
{
// is there a disable command lurking around?
$disable = strpos( $text, $disableWord ) !== false;

// if there is, get rid of it
// make sure that the disableWord does not break the REGEX below!
$text = preg_replace('/'.$disableWord.'/si', '', $text );

// if there is a disable command, then don't return anything
if ($disable)
return null;

// FIXME: make it look like this (though this doesn't work)
// $msgText = wfMessage( $msgId, array( 'parseinline' ) );
$msgText = wfMsgExt( $msgId, array( 'parseinline' ) );

// don't need to bother if there is no content.
if (empty( $msgText ))
return null;

// FIXME: make it look like this (though this may not work)
// if (wfMessage( $msgId, $msgText ))
if (wfEmptyMsg( $msgId, $msgText ))
return null;

return $msgText;
}

static function conditionalInclude( &$text, $disableWord, &$msgId ) {

} // END CLASS DEFINITION
// is there a disable command lurking around?
$disable = strpos( $text, $disableWord ) !== false;

// if there is, get rid of it
// make sure that the disableWord does not break the REGEX below!
$text = preg_replace('/'.$disableWord.'/si', '', $text );

// if there is a disable command, then don't return anything
if ( $disable ) {
return null;
}

$msgText = wfMessage( $msgId )->parse();

// don't need to bother if there is no content.
if ( empty( $msgText ) ) {
return null;
}

if ( wfMessage( $msgId )->inContentLanguage()->isBlank() ) {
return null;
}

return $msgText;
}

}
9 changes: 4 additions & 5 deletions HeaderFooter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
* @author Jean-Lou Dupont
* @author Jamesmontalvo3
* @package HeaderFooter
* @version 2.1.0
* @Id $Id: HeaderFooter.php 821 2008-01-04 02:36:30Z jeanlou.dupont $
* @version 2.1.1
*/

# Credits
$GLOBALS['wgExtensionCredits']['other'][] = array(
'name' => 'HeaderFooter',
'version' => '2.1.0',
'name' => 'HeaderFooter',
'version' => '2.1.1',
'author' => 'Jean-Lou Dupont, James Montalvo, Douglas Mason',
'description' => 'Enables per-page/per-namespace headers and footers',
'url' => 'http://mediawiki.org/wiki/Extension:HeaderFooter',
'url' => 'http://mediawiki.org/wiki/Extension:HeaderFooter',
);

# Hooks
Expand Down

0 comments on commit fc5a159

Please sign in to comment.