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 177: Línia 177:
  
 
= Font =
 
= Font =
[https://tutorialsjoint.com/mediawiki-extension-how-to-develop-custom-extension-in-mediawiki/ MediaWiki Extension – How to develop custom extension in MediaWiki]
+
[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] -->

Revisió del 19:50, 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$

Reinicieu el contenidor

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


Font

Extension:BoilerPlate