Diferència entre revisions de la pàgina «Desenvolupament d'extensions per a MediaWiki»
Salta a la navegació
Salta a la cerca
m (→Automatització) |
|||
Línia 87: | Línia 87: | ||
root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# | root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# | ||
== Proves (''testing'') == | == Proves (''testing'') == | ||
− | root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# npm test | + | root@6396f9a287aa:/var/www/html/extensions/BoilerPlate# '''npm test''' |
> test | > test |
Revisió del 19:39, 9 feb 2025
Contingut
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 ... - 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#
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