Preparing Environment for Developing Extensions
Introduction
This page is written to give readers a better experiences on how to prepare your local machine to develop Mediawiki Extension functionality.
Requirement
Below are the set of versions of each component, use to develop extension on PKC Implementation.
No | Description and Version |
---|---|
1 | PHP 7.4.29 |
2 | Maria DB |
3 | Mediawiki 1.37.1 |
The easiest method to get all the component to work is to install XAMPP Package, which can be found in Apache Friends Site. Also please see the PHP Component requirement list in Mediawiki Requirement Page. Most of the component required should be readily available at the XAMPP package, in the event the required component is not complete, please refer to Mediawiki Requirement Page for installation in Ubuntu Machine.
Known Issues
In XAMPP for MacOS, found that intl PHP component is not available. Hence, several steps need to be done, this step is the actual working step, after testing on Homebrew method, which not working correctly.
1. Install ICU
ICU4C can be installed through Homebrew, using below command
brew install icu
Then, we will need to find out where is the ICU4C installation folder, normally its installed on /usr/local/Cellar/icu4c/[some version number]
2. Download PHP
Download PHP from php.net according to you version, which is 7.4.29, and extract all the files to you chosen folder. Then navigate to sub-folder ./ext/intl. Please continue to next step by running the command from this folder.
3. Build intl.so
Please edit the Makefile on the folder to adjust the location of included files. At line number 37
INCLUDES = -I/Applications/XAMPP/xam ....
adds your ICU4C Location folder at the end of this line, or line which define the INCLUDE folder followed by /include subfolder.
INCLUDES = -I/Applications/XAMPP/xam .... -I/usr/local/Cellar/icu4c/70.1/include
And also edit line number 39, which defines the LDFLAGS to point at your ICU4C installation folder, followed by /lib subfolder
LDFLAGS = -L/usr/local/Cellar/icu4c/70.1/lib
and, Assuming that you are using the XAMPP package to install PHP and MariaDB, run below command
/Applications/XAMPP/bin/phpize ./configure --enable-intl --with-php-config=/Applications/XAMPP/bin/php-config --with-icu-dir=/Applications/XAMPP/xamppfiles/ make
Once the make process is done, you can proceed looking at the files on /modules subdirectory. You should be able to find intl.so at this folder. Copy this file into your PHP modules folder and enable it by adding below line into php.ini
extension="intl.so"
Restart PHP, and check by using below command
php -m | grep intl intl
If its returning intl, that means the installation is successful.
Writing your first extension
This is the tutorial to get up and running developing a very simple Mediawiki Extension to display certain message during editing session. This extension will display a sentences of "" in editing page display screen.
File Structure
First step, please create a new folder on your extension directory. The default will be [your-media-wiki-folder]/extension/DemoExtension. At this tutorial, we will create an extension called DemoExtension. Below are the files need to create.
- en.json; File contains localized messages
- Demo Extension.php; First file called by Localsettings.php, this file is the entry point for the extension.
- DemoExtension.body.php; The functionality of the extentions will be stored in this file.