Difference between revisions of "Preparing Environment for Developing Extensions"

From PKC
Jump to navigation Jump to search
Line 55: Line 55:
# DemoExtension.body.php; The functionality of the extentions will be stored in this file.
# DemoExtension.body.php; The functionality of the extentions will be stored in this file.
==== File content: DemoExtension.php ====
==== File content: DemoExtension.php ====
The files containing entry point code that called by LocalSettings.php. Please refer to below code
The files containing entry point code that called by LocalSettings.php. Please refer to below code and the commented lines.
<pre>
<pre>
<?php
<?php
Line 74: Line 74:
);
);


//autoload classes
//autoload classes, content from DemoExtension.body.php
$wgAutoloadClasses['DemoExtension'] = __DIR__.'/DemoExtension.body.php';
$wgAutoloadClasses['DemoExtension'] = __DIR__.'/DemoExtension.body.php';


//hook function
//hook function, this is one of the extension of hook.
$wgHooks['EditPage::showEditForm:initial'][] = 'DemoExtension::injectHTMLInEditor';
$wgHooks['EditPage::showEditForm:initial'][] = 'DemoExtension::injectHTMLInEditor';



Revision as of 11:41, 3 June 2022

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.

File Structure for Demo Extension
  1. en.json; File contains localized messages
  2. DemoExtension.php; First file called by Localsettings.php, this file is the entry point for the extension.
  3. DemoExtension.body.php; The functionality of the extentions will be stored in this file.

File content: DemoExtension.php

The files containing entry point code that called by LocalSettings.php. Please refer to below code and the commented lines.

<?php
// this lines is to ensure that no direct call to extension file
if(!defined('MEDIAWIKI')){
    die("This is a mediawiki extension and cannot be accessed directly.");
}

// required for credit items displayed on Special:Version
$wgExtensionCredits['DemoExtension']['other'] = array(
    'path'=>__FILE__, //path of the extension setup file
    'name'=>'DemoExtension', // name of extension
    'author'=>'Muhammad Haviz', //name of author
    'url'=>'https://www.pkc.pub/index.php/Preparing_Environment_for_Developing_Extensions', //extension url where a user can find details about the extension.
    'description'=>'This is only a Demo version, it will serve as wireframe for starting new extension', //description of extension
     'version'=>'1.0.0', //version of extension
    'licence-name'=>'', //name or url to the license under which the extension is released
);

//autoload classes, content from DemoExtension.body.php
$wgAutoloadClasses['DemoExtension'] = __DIR__.'/DemoExtension.body.php';

//hook function, this is one of the extension of hook. 
$wgHooks['EditPage::showEditForm:initial'][] = 'DemoExtension::injectHTMLInEditor';

?>

File content: DemoExtension.body.php