Diferència entre revisions de la pàgina «Desenvolupament d'extensions per a MediaWiki»

De binefa.com
Salta a la navegació Salta a la cerca
Línia 77: Línia 77:
 
   
 
   
 
  found 0 vulnerabilities
 
  found 0 vulnerabilities
  root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# /opt/composer.phar install
+
  root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# '''/opt/composer.phar install'''
  
 
= Creació de l'exensió DemoExension =
 
= Creació de l'exensió DemoExension =

Revisió del 19:32, 9 feb 2025

Previ

Heu hagut de seguir les passes de Instal·lació de MediaWiki amb dockers

Instal·lació de PHP Composer

jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ docker exec -it mediawiki bash
root@6396f9a287aa:/var/www/html# cd /opt
root@6396f9a287aa:/opt# php -r "copy('https://getcomposer.org/installer','composer-setup.php');"
root@6396f9a287aa:/opt# php composer-setup.php
All settings correct for using Composer
Downloading...

Composer (version 2.8.5) successfully installed to: /opt/composer.phar
Use it: php composer.phar
root@6396f9a287aa:/opt# php composer.phar
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.8.5 2025-01-21 15:23:40
...

Font: Complete guide to PHP Composer: what it is, how to install it, and how to use it to the fullest

Instal·lació de npm

Primer hem de saber sobre quina distribució s'ha fet el docker:

root@6396f9a287aa:/opt# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@6396f9a287aa:/opt#

Actualitzem la informació dels dipòsits i instal·lem npm

root@6396f9a287aa:/opt# apt update
...
root@6396f9a287aa:/opt# apt install nodejs -y
...
root@6396f9a287aa:/opt# node -v              
v18.19.0
root@6396f9a287aa:/opt# apt install npm -y
...
root@6396f9a287aa:/opt# npm -v
9.2.0

Baixada de BoilerPlate

Automatització

root@6396f9a287aa:/opt# ls -ls
total 2992
2992 -rwxr-xr-x 1 root root 3060478 Feb  9 19:04 composer.phar
root@6396f9a287aa:/opt# cd -
/var/www/html/extensions
root@6396f9a287aa:/var/www/html/extensions# cd BoilerPlate/
root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# ls -ls
total 352
  4 -rw-r--r-- 1 1000 1000    135 Feb  9 18:44 CODE_OF_CONDUCT.md
 20 -rw-r--r-- 1 1000 1000  18092 Feb  9 18:44 COPYING
  4 -rw-r--r-- 1 1000 1000    639 Feb  9 18:44 Gruntfile.js
  4 -rw-r--r-- 1 1000 1000    915 Feb  9 18:44 README.md
  4 -rw-r--r-- 1 1000 1000    609 Feb  9 18:44 composer.json
  4 -rw-r--r-- 1 1000 1000   1078 Feb  9 18:44 extension.json
  4 drwxr-xr-x 2 1000 1000   4096 Feb  9 18:44 i18n
  4 drwxr-xr-x 2 1000 1000   4096 Feb  9 18:44 maintenance
288 -rw-r--r-- 1 1000 1000 293557 Feb  9 18:44 package-lock.json
  4 -rw-r--r-- 1 1000 1000    344 Feb  9 18:44 package.json
  4 drwxr-xr-x 3 1000 1000   4096 Feb  9 18:44 resources
  4 drwxr-xr-x 2 1000 1000   4096 Feb  9 18:44 src
  4 drwxr-xr-x 3 1000 1000   4096 Feb  9 18:44 tests
root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# npm install

added 411 packages, and audited 412 packages in 10s

88 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# /opt/composer.phar install

Creació de l'exensió DemoExension

jordi@asix2:~/bin/mediawiki-docker$ cd mediawiki_extensions
jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ mkdir DemoExtension
jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ cd DemoExtension
jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions/DemoExtension$ nano DemoExtension.php
jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions/DemoExtension$ cat DemoExtension.php 
if(!defined('MEDIAWIKI')){
   die("This is a mediawiki extension and cannot be accessed directly.");
}
$wgExtensionCredits['DemoExtension']['other'] = array(
   'path'=>__FILE__, //path of the extension setup file
   'name'=>'DemoExtension', // name of extension
   'author'=>'Pere Camps i López', //Escriviu aquí el vostre nom
   'url'=>'http://www.examsmyantra.com', //extension url where a user can find details about the extension.
   'description'=>'Això és una demostració d\'extensió per a MediaWiki.', //description of extension
   'version'=>'1.0.0', //version of extension
   'licence-name'=>, //name or url to the license under which the extension is released
);
  • Entreu dins del contenidor i instal·leu-hi l'editor nano:
jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions/DemoExtension$ docker exec -it mediawiki bash
root@5c7c23878ac3:/var/www/html# apt update
root@5c7c23878ac3:/var/www/html# apt install nano
  • Afegiu al final de LocalSettings.php': require_once "$IP/extensions/DemoExtension/DemoExtension.php";
root@5c7c23878ac3:/var/www/html# nano LocalSettings.php
root@5c7c23878ac3:/var/www/html# tail LocalSettings.php
wfLoadExtension( 'Interwiki' );
wfLoadExtension( 'Nuke' );
wfLoadExtension( 'WikiEditor' );

# End of automatically generated settings.
# Add more configuration options below.

require_once "$IP/extensions/DemoExtension/DemoExtension.php";

root@5c7c23878ac3:/var/www/html# exit
exit

Font

MediaWiki Extension – How to develop custom extension in MediaWiki