Skip to content

Commit

Permalink
Upgrade for new versions MW: extension registration and i18n
Browse files Browse the repository at this point in the history
* Modify MasonryMainPage.php to check for wfLoadExtension
  and use it if available
* Add extension.json to be used by wfLoadExtension
* Move i18n to /i18n directory and JSON files
* Leave magic word registration in its own i18n file, but
  rename to Magic.php
  • Loading branch information
jamesmontalvo3 committed Apr 18, 2017
1 parent e64421e commit 5ae46d2
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 74 deletions.
22 changes: 22 additions & 0 deletions Magic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Internationalisation file for extension MasonryMainPage magic words.
*
* @file
* @ingroup Extensions
*/
$magicWords = array();

# The $magicWords array is where we'll declare the name of our parser function
# Below we've declared that it will be called "masonry-block", and thus will be
# called in wikitext by doing {{#masonry-block: example | parameters }}
$magicWords['en'] = array(
'masonry-block' => array(
0, // zero means case-insensitive, 1 means case sensitive
'masonry-block' // parser function in this language. For English this will probably be the same as above
),
);

$magicWords['de'] = array(
'masonry-block' => array( 0, 'mauerwerksblock' ),
);
35 changes: 0 additions & 35 deletions MasonryMainPage.i18n.php

This file was deleted.

78 changes: 39 additions & 39 deletions MasonryMainPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,48 @@
die( "MasonryMainPage extension" );
}

$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'MasonryMainPage',
'url' => 'http://github.com/enterprisemediawiki/MasonryMainPage',
'author' => '[https://www.mediawiki.org/wiki/User:Darenwelsh Daren Welsh]',
'descriptionmsg' => 'masonrymainpage-desc',
'version' => '0.2.1'
);
// if wfLoadExtension exists (MW 1.25+) use that method of registering extensions
if ( function_exists( 'wfLoadExtension' ) ) {
wfLoadExtension( 'MasonryMainPage' );
// Keep i18n globals so mergeMessageFileList.php doesn't break
$wgMessagesDirs['MasonryMainPage'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['MasonryMainPageMagic'] = __DIR__ . '/Magic.php';
wfWarn(
'Deprecated PHP entry point used for MasonryMainPage extension. ' .
'Please use wfLoadExtension instead, ' .
'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
);
return;

# $dir: the directory of this file, e.g. something like:
# 1) /var/www/wiki/extensions/BlankParserFunction
# 2) C:/xampp/htdocs/wiki/extensions/BlankParserFunction
$dir = dirname( __FILE__ ) . '/';
// For MW 1.24 and lower, use normal extension registration
// This should be removed when this extension drops support for <1.25
} else {

# Internationalization
$wgExtensionMessagesFiles['MasonryMainPage'] = $dir . 'MasonryMainPage.i18n.php';
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'MasonryMainPage',
'url' => 'http://github.com/enterprisemediawiki/MasonryMainPage',
'author' => '[https://www.mediawiki.org/wiki/User:Darenwelsh Daren Welsh]',
'descriptionmsg' => 'masonrymainpage-desc',
'version' => '0.3.0'
);

# The "class" file contains the bulk of a simple parser function extension.
$wgAutoloadClasses['MasonryMainPage'] = $dir . 'MasonryMainPage.class.php';

// Currently loaded via OutputPage::addScript() from MasonryMainPage.class.php
// due to issues with loading Masonry with ResourceLoader
/*
$wgResourceModules['ext.masonrymainpage.deps'] = array(
'scripts' => array(
'imagesloaded.pkgd.js',
'masonry.pkgd.js'
),
'localBasePath' => __DIR__,
'remoteExtPath' => 'MasonryMainPage',
'position' => 'top',
);
*/
# Internationalization
$wgExtensionMessagesFiles['MasonryMainPageMagic'] = __DIR__ . '/Magic.php';

$wgResourceModules['ext.masonrymainpage.base'] = array(
'scripts' => array( 'masonry-common.js' ),
'styles' => 'Masonry.css',
//'dependencies' => 'ext.masonrymainpage.deps',
'localBasePath' => __DIR__,
'remoteExtPath' => 'MasonryMainPage',
'position' => 'top',
);
# The "class" file contains the bulk of a simple parser function extension.
$wgAutoloadClasses['MasonryMainPage'] = __DIR__ . '/MasonryMainPage.class.php';

# This specifies the function that will initialize the parser function.
$wgHooks['ParserFirstCallInit'][] = 'MasonryMainPage::setup';
$wgResourceModules['ext.masonrymainpage.base'] = array(
'scripts' => array( 'imagesloaded.pkgd.js', 'masonry.pkgd.js', 'masonry-common.js' ),
'styles' => 'Masonry.css',
'localBasePath' => __DIR__,
'remoteExtPath' => 'MasonryMainPage',
'position' => 'top',
);

# This specifies the function that will initialize the parser function.
$wgHooks['ParserFirstCallInit'][] = 'MasonryMainPage::setup';

}
38 changes: 38 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "MasonryMainPage",
"version": "0.3.0",
"author": "[https://www.mediawiki.org/wiki/User:Darenwelsh Daren Welsh]",
"url": "http://github.com/enterprisemediawiki/MasonryMainPage",
"descriptionmsg": "masonrymainpage-desc",
"type": "parserhook",
"ExtensionMessagesFiles": {
"MasonryMainPageMagic": "Magic.php"
},
"AutoloadClasses": {
"MasonryMainPage": "MasonryMainPage.class.php"
},
"ResourceModules": {
"ext.masonrymainpage.base": {
"scripts": [
"imagesloaded.pkgd.js",
"masonry.pkgd.js",
"masonry-common.js"
],
"styles": "Masonry.css",
"position": "top"
}
},
"ResourceFileModulePaths": {
"localBasePath": "",
"remoteExtPath": "MasonryMainPage"
},
"Hooks": {
"BeforePageDisplay": [
"MasonryMainPage::addIECompatibilityMetaTag"
],
"ParserFirstCallInit": [
"MasonryMainPage::setup"
]
},
"manifest_version": 1
}
4 changes: 4 additions & 0 deletions i18n/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"masonrymainpage": "MasonryMainPage",
"masonrymainpage-desc": "Ermöglicht die mauerwerksverbundartige Anordnung von Inhaltsblöcken auf Wikiseiten"
}
4 changes: 4 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"masonrymainpage": "MasonryMainPage",
"masonrymainpage-desc": "Enables use of Masonry blocks in MediaWiki via the masonry-block parser function"
}

0 comments on commit 5ae46d2

Please sign in to comment.