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 233: Línia 233:
 
i comenteu l'activació de l'extensió BoilerPlate:
 
i comenteu l'activació de l'extensió BoilerPlate:
 
  # $wgBoilerPlateVandalizeEachPage = true;
 
  # $wgBoilerPlateVandalizeEachPage = true;
 +
== Reinicieu el contenidor ==
 +
jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ '''docker restart mediawiki'''
 +
mediawiki
  
 
= Font =
 
= Font =
 
[https://www.mediawiki.org/wiki/Extension:BoilerPlate Extension:BoilerPlate]
 
[https://www.mediawiki.org/wiki/Extension:BoilerPlate Extension:BoilerPlate]
 
<!-- [https://tutorialsjoint.com/mediawiki-extension-how-to-develop-custom-extension-in-mediawiki/ MediaWiki Extension – How to develop custom extension in MediaWiki] -->
 
<!-- [https://tutorialsjoint.com/mediawiki-extension-how-to-develop-custom-extension-in-mediawiki/ MediaWiki Extension – How to develop custom extension in MediaWiki] -->

Revisió del 22:05, 9 feb 2025

Previ

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

Baixada de l'extensió BoilerPlate

jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/BoilerPlate.git

Còpia per a fer una extensió personalitzada:

jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ cp -r BoilerPlate ./MyExtension
jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ rm -rf ./MyExtension/.git

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

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
...
  - Installing php-parallel-lint/php-parallel-lint (v1.4.0): Cloning 6db563514f from cache
2 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
16 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PHP CodeSniffer Config installed_paths set to ../../mediawiki/mediawiki-codesniffer,../../phpcsstandards/phpcsextra,../../phpcsstandards/phpcsutils
root@6396f9a287aa:/var/www/html/extensions/BoilerPlate#

Proves (testing)

root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# npm test

> test
> grunt test

Running "eslint:all" (eslint) task

Running "stylelint:all" (stylelint) task
>> Linted 0 files without errors

Running "banana:BoilerPlate" (banana) task
>> 1 message directory checked.

Done.
root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# /opt/composer.phar test 
The repository at "/var/www/html/extensions/BoilerPlate" does not have the correct ownership and git refuses to use it:

fatal: detected dubious ownership in repository at '/var/www/html/extensions/BoilerPlate'
To add an exception for this directory, call:

        git config --global --add safe.directory /var/www/html/extensions/BoilerPlate

> parallel-lint . --exclude vendor --exclude node_modules
PHP 8.1.31 | 10 parallel jobs
....                                                         4/4 (100%)
 

Checked 4 files in 0.1 seconds
No syntax error found
> phpcs -sp --cache
.... 4 / 4 (100%)


Time: 94ms; Memory: 8MB

> minus-x check .
MinusX
======
Processing /var/www/html/extensions/BoilerPlate...
.......................
All good!
root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# exit
exit
jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$

Activeu l'extensió a LocalSettings.php

Al final de l'arxiu LocalSettings.php afegiu-hi:

wfLoadExtension( 'BoilerPlate' );

I per activar que es vegi a totes les pàgines:

$wgBoilerPlateVandalizeEachPage = true;

Reinicieu el contenidor

jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ docker restart mediawiki
mediawiki

Visualització a extensions instal·lades

Aneu a http://localhost:8083/index.php/Especial:Versió i cerqueu BoilerPlate a extensions instal·lades:

BoilerPlate a extensions instal·lades

Visualització del funcionament de l'extensió BoilerPlate

Aneu a http://localhost:8083 i veureu que al peu de l'entrada de la pàgina principal hi surt BoilerPlate was here:

Funcionament de l'extensió BoilerPlate

Personalització

jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ cp -r BoilerPlate ./LaMevaExtensio
jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ rm -rf ./LaMevaExtensio/.git

Arxius json

extension.json

  • Canvieu l'autor pel vostre nom i cognoms
  • Canvieu la URL
  • Canvieu el valor de descriptionmsg (boilerplate-desc) per lamevaextensio-desc
  • Reemplaceu a tot arreu el text BoilerPlate per LaMevaExtensio

package-lock.json

  • Reemplaceu a tot arreu el text BoilerPlate per LaMevaExtensio

i18n Llengües (internacionalització)

  • Aneu a la carpeta i18n
  • Canvieu a en.json l'autor i hi escriviu el vostre nom i cognoms. Canvieu la variable descriptora per "lamevaextensio-desc":
"lamevaextensio-desc": "This is an example extension"
  • Copieu en.json a ca.json i canvieu la descripció:
"lamevaextensio-desc": "Exemple d'extensió"
  • A qqq.json canvieu l'autor pel vostre nom i cognoms i la variable descriptora per "lamevaextensio-desc".

Arxius PHP

  • Copia a la carpeta maintenance l'arxiu BoilThePlate.php a un nou arxiu anomenat LaMevaExtensio.php
  • Dins de LaMevaExtensio.php reemplaceu a tot arreu el text BoilerPlate per LaMevaExtensio
  • Reemplaceu els dos BoilThePlate per ClasseLaMevaExtensio
  • Canvieu el text del mètode execute() "LaMevaExtensio was here.\n" per "LaMevaExtensio és aquí.\n"

Hooks.php

  • Editeu l'arxiu Hooks.php que hi és a dins del directori src
  • Reemplaceu a tot arreu el text BoilerPlate per LaMevaExtensio
  • Canvieu al mètode onBeforePageDisplay el text 'LaMevaExtensio was here' per 'LaMevaExtensio és aquí'

HooksTest.php

  • Editeu l'arxiu HooksTest.php que hi és a dins del directori tests/phpunit/unit
  • Reemplaceu a tot arreu el text BoilerPlate per LaMevaExtensio

Recursos

  • Copieu la carpeta ext.boilerPlate a ext.laMevaExtensio:
jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions/LaMevaExtensio/resources$ cp -r ext.boilerPlate/ ./ext.laMevaExtensio
  • Dins de la carpeta ext.laMevaExtensio reemplaceu a l'arxiu init.js el text mw.boilerPlate per mw.laMevaExtensio

Activeu l'extensió a LocalSettings.php

Al final de l'arxiu LocalSettings.php afegiu-hi:

wfLoadExtension( 'LaMevaExtensio' );

i comenteu l'extensió BoilerPlate:

# wfLoadExtension( 'BoilerPlate' );

I per activar que es vegi a totes les pàgines:

$wgLaMevaExtensioVandalizeEachPage = true;

i comenteu l'activació de l'extensió BoilerPlate:

# $wgBoilerPlateVandalizeEachPage = true;

Reinicieu el contenidor

jordi@asix2:~/bin/mediawiki-docker/mediawiki_extensions$ docker restart mediawiki
mediawiki

Font

Extension:BoilerPlate