Add stylesheet and script in mediawiki extension

It simple method to add new style sheet and scripts files in mediawiki extension.

open your main file and create parser Hook.

$wgHooks[‘ParserFirstCallInit’][]=’SpecialBenchmark::onParserInit’;

parser:- A parser reads the page definition and creates the HTML-code for the actual page, and must know from the beginning that there may be a poll-tag which it should process.

Now Add this simple code in file

$wgResourceModules[‘bootstrap’]=array(
‘localBasePath’=>__DIR__,
‘remoteExtPath’=>’Benchmark’,
‘styles’=>’modules/bootstrap.css’,
‘scripts’=>array(‘modules/js/jquery.js’,
‘modules/js/bootstrap-datepicker.js’,
‘modules/js/bootstrap-transition.js’,
‘modules/js/bootstrap-alert.js’,
‘modules/js/bootstrap-modal.js’,
‘modules/js/bootstrap-dropdown.js’,
‘modules/js/bootstrap-scrollspy.js’,
‘modules/js/bootstrap-tab.js’,
‘modules/js/bootstrap-tooltip.js’,
‘modules/js/bootstrap-popover.js’,
‘modules/js/bootstrap-button.js’,
‘modules/js/bootstrap-collapse.js’,
‘modules/js/bootstrap-carousel.js’,
‘modules/js/bootstrap-typeahead.js’
)
);

 

Step2:-Now open your class file and register your parser.

static function onParserInit(Parser $parser){
$parser->setHook(‘Benchmark’,__CLASS__);
return true;
}

Now register your modules.

$wgOut->addModules(‘bootstrap’);

now run your extension. And see work is done.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s