Difference between revisions of "Preparing Environment for Developing Extensions"
(Created page with "=Introduction= =Stack Requirement= =Component Requirement=") |
|||
(29 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Introduction= | =Introduction= | ||
= | This page is written to give readers a better experiences on how to prepare your local machine to develop Mediawiki Extension functionality. | ||
=Component Requirement= | |||
=Requirement= | |||
Below are the set of versions of each component, use to develop extension on PKC Implementation. | |||
{| class="wikitable" | |||
|- | |||
! 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 [https://www.apachefriends.org/download.html Apache Friends Site]. Also please see the PHP Component requirement list in [https://www.mediawiki.org/wiki/Manual:Installation_requirements 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 [https://www.mediawiki.org/wiki/Manual:Installation_requirements 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 [https://www.php.net/downloads 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:File Struction DemoExtension.png|File Structure for Demo Extension|350px|thumb|center]] | |||
# en.json; File contains localized messages | |||
# DemoExtension.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. | |||
==== File content: DemoExtension.php ==== | |||
The files containing entry point code that called by LocalSettings.php. Please refer to below code and the commented lines. | |||
<pre> | |||
<?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'; | |||
?> | |||
</pre> | |||
==== File content: DemoExtension.body.php ==== | |||
This is the conten of file DemoExtension.body.php; This file contains the code functionality and refer by DemoExtensions.php. Please see below code and the commented lines. | |||
<pre> | |||
<?php | |||
class DemoExtension { | |||
// This is the example from one of functionality exposed by mediawiki core. | |||
// called by DemoExtension.php file | |||
public static function injectHTMLInEditor(&$editPage,&$output) | |||
$editPage->editFormTextAfterWarn .='<div id="demoDiv" class="highlight-green">****Hi This is HTML Injected via Demo Extension****</div>'; | |||
return true; | |||
// Will display above text on Editing Area. | |||
} | |||
} | |||
?> | |||
</pre> | |||
= Further Readings = | |||
There are several types of extensions based on their functionality. Below are the types of extension with short desription of what are these extension does. | |||
* '''Parser tags'''; Parser tags extend the built-in wiki markup with additional capabilities, whether simple string processing, or full-blown information retrieval. | |||
* '''Parser functions'''; Parser functions are special wiki markup syntax that can 'interact' with other wiki elements in the page, and give a specific output. | |||
* '''Hooks'''; Hooks allow custom code to be executed when some defined event (such as saving a page or a user logging in) occurs. | |||
* '''Special pages'''; Special pages are pages that are created by the software on demand to perform a specific function. | |||
* '''Skins'''; Skins allow users to customize the look and feel of MediaWiki. | |||
* '''Magic words'''; Magic words are a technique for mapping a variety of wiki text strings to a single ID that is associated with a function. | |||
* '''API'''; MediaWiki provides an action API, a web service that allows access to some wiki-features like authentication, page operations, and search. | |||
* '''Page content models'''; The ContentHandler introduced in MediaWiki 1.21 makes it possible for wiki pages to be composed of data other than wikitext, such as JSON or Markdown. | |||
* '''Authentication'''; MediaWiki provides SessionManager and AuthManager, two authentication-related frameworks to enhance security via custom authentication mechanisms. | |||
= External Links = | |||
* [https://www.mediawiki.org/wiki/Manual:Extensions Manual:Extensions] Mediawiki Documentation explaining the types of extension. This is a good beginning to design your extension functionality. | |||
* [https://www.mediawiki.org/wiki/Manual:Developing_extensions Manual:Developing extensions] Mediawiki Documentation on how to develop extensions. | |||
[[Category:DevOps]] | |||
[[Category:Media Wiki]] | |||
[[Category:Media Extension]] |
Latest revision as of 12:02, 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.
- en.json; File contains localized messages
- DemoExtension.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.
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
This is the conten of file DemoExtension.body.php; This file contains the code functionality and refer by DemoExtensions.php. Please see below code and the commented lines.
<?php class DemoExtension { // This is the example from one of functionality exposed by mediawiki core. // called by DemoExtension.php file public static function injectHTMLInEditor(&$editPage,&$output) $editPage->editFormTextAfterWarn .='<div id="demoDiv" class="highlight-green">****Hi This is HTML Injected via Demo Extension****</div>'; return true; // Will display above text on Editing Area. } } ?>
Further Readings
There are several types of extensions based on their functionality. Below are the types of extension with short desription of what are these extension does.
- Parser tags; Parser tags extend the built-in wiki markup with additional capabilities, whether simple string processing, or full-blown information retrieval.
- Parser functions; Parser functions are special wiki markup syntax that can 'interact' with other wiki elements in the page, and give a specific output.
- Hooks; Hooks allow custom code to be executed when some defined event (such as saving a page or a user logging in) occurs.
- Special pages; Special pages are pages that are created by the software on demand to perform a specific function.
- Skins; Skins allow users to customize the look and feel of MediaWiki.
- Magic words; Magic words are a technique for mapping a variety of wiki text strings to a single ID that is associated with a function.
- API; MediaWiki provides an action API, a web service that allows access to some wiki-features like authentication, page operations, and search.
- Page content models; The ContentHandler introduced in MediaWiki 1.21 makes it possible for wiki pages to be composed of data other than wikitext, such as JSON or Markdown.
- Authentication; MediaWiki provides SessionManager and AuthManager, two authentication-related frameworks to enhance security via custom authentication mechanisms.
External Links
- Manual:Extensions Mediawiki Documentation explaining the types of extension. This is a good beginning to design your extension functionality.
- Manual:Developing extensions Mediawiki Documentation on how to develop extensions.