Jump to content

Parsoid

From mediawiki.org
This page is a translated version of the page Parsoid and the translation is 46% complete.
Outdated translations are marked like this.
Diagramma del runtime wiki di Parsoid compatibile con HTML5 + RDFa

Per la versione precedente di Parsoid scritta in JavaScript (Node.js), vedi Parsoid/JS .

Parsoid è una libreria PHP fornita con MediaWiki (a partire dalla versione 1.35) che permette di convertire wikitext in HTML e viceversa. È in via di sviluppo dal 2012, originariamente scritta in JavaScript e concepita per supportare VisualEditor . It has been bundled with MediaWiki since version 1.35. In MediaWiki 1.47, Parsoid is planned to become MediaWiki's default parser, replacing the current native parser , in a project known as parser unification .

Dettagli tecnici

Parsoid è un'applicazione capace di tradurre la sintassi wikitext in un modello di documento HTML/RDFa equivalente (e viceversa), con supporto esteso per l'elaborazione automatizzata e l'editing di testo formattato.

È sviluppato da un gruppo della Wikimedia Foundation, che ci lavora dal 2012. È utilizzato ampiamente da VisualEditor , Traduzione contenuti e altre applicazioni.

Parsoid ha lo scopo di fornire una conversione senza errori in entrambe le direzioni, evitando la perdita di informazioni e prevenendo le differenze involontarie ("dirty diffs").

Sulle wiki di Wikimedia, per diverse applicazioni, Parsoid è solitamente in proxy dietro RESTBase , che memorizza l'HTML tradotto da Parsoid. È previsto che RESTBase venga col tempo sostituito da una cache meglio integrata con MediaWiki.

Per maggiori dettagli sul progetto complessivo, vedere questo post di blog di marzo 2013. Per informazioni sul modello HTML in uso, vedere le specifiche DOM di MediaWiki.

In origine Parsoid era stato concepito come servizio web scritto in Javascript, utilizzando Node.js. Una discussione tecnica di febbraio 2019 (diapositive) e un post di blog descrivono il processo di riscrittura in PHP. L'API di estensione di Parsoid è attualmente in via di sviluppo; una discussione di agosto 2020 descrive questo lavoro.

Repository su GitHub: https://github.com/wikimedia/parsoid

Utilizzo

Installazione

This extension comes with MediaWiki 1.35 and later, so you do not need to download it. The remaining configuration instructions must still be followed.

Parsoid è incluso in Mediawiki a partire dalla versione 1.35. Non è necessaria alcuna configurazione per attivarlo.

Parsoid esporta una API REST interna che storicamente era usata da RESTBase e non era accessibile al di fuori del cluster interno della WMF. Ciò non è più necessario per Visual Editor né per le visualizzazioni di lettura del nucleo; l'API interna sta diventando obsoleta e si prevede che venga rimossa in MW 1.43.

Parsoid is nominally a composer library used by mediawiki core. If you still require the internal API for some reason, you can explicitly load Parsoid "as an extension" by adding the following to LocalSettings.php:

wfLoadExtension( 'Parsoid', "$IP/vendor/wikimedia/parsoid/extension.json" );

Any remaining third-party users of the internal Parsoid API are strongly encouraged to migrate to the core REST HTML page endpoint which provides equivalent functionality.

Sviluppo

Development happens in the Parsoid Git repository. Code review happens in Gerrit. See Gerrit/Getting started to set up an account for yourself.

If you use the MediaWiki-Vagrant development environment using a virtual machine, you can simply add the role visualeditor to it and it will set up a working Parsoid along with Extension:VisualEditor .

The instructions below are for MediaWiki 1.35 or later. Check Parsoid/JS if you are running the old version of Parsoid written in JavaScript, and used for MW 1.34 and earlier.

Linking a developer checkout of Parsoid

In a standard MediaWiki installation, Parsoid is included from MediaWiki as a composer library, wikimedia/parsoid.

For development purposes you usually want to use a git checkout of Parsoid, and not the version bundled in MediaWiki core as a composer library. The following lines added to LocalSettings.php allow use of a git checkout of Parsoid (optionally), load the Parsoid REST API with wfLoadExtension (rather than using the version bundled in VisualEditor) and manually do the Parsoid configuration which is usually done by VisualEditor:

$parsoidInstallDir = 'vendor/wikimedia/parsoid'; # bundled copy
#$parsoidInstallDir = '/my/path/to/git/checkout/of/Parsoid';

// For developers: ensure Parsoid is executed from $parsoidInstallDir,
// (not the version included in mediawiki-core by default)
// Must occur *before* wfLoadExtension()
if ( $parsoidInstallDir !== 'vendor/wikimedia/parsoid' ) {
    function wfInterceptParsoidLoading( $className ) {
        // Only intercept Parsoid namespace classes
        if ( preg_match( '/(MW|Wikimedia\\\\)Parsoid\\\\/', $className ) ) {
           $fileName = Autoloader::find( $className );
           if ( $fileName !== null ) {
               require $fileName;
           }
        }
    }
    spl_autoload_register( 'wfInterceptParsoidLoading', true, true );
    // AutoLoader::registerNamespaces was added in MW 1.39
    AutoLoader::registerNamespaces( [
        // Keep this in sync with the "autoload" clause in
        // $parsoidInstallDir/composer.json
        'Wikimedia\\Parsoid\\' => "$parsoidInstallDir/src/",
    ] );
}

wfLoadExtension( 'Parsoid', "$parsoidInstallDir/extension.json" );
unset( $parsoidInstallDir );

These lines are not necessary for most users of VisualEditor, who can use VisualEditor's auto-configuration and the bundled Parsoid code included in MediaWiki, but they will be required for most developers.

If you're serving MediaWiki with Nginx, you'll need to also add something like this in your server block (Assuming your MediaWiki setup has its files residing in /w/):

location /w/rest.php/ {
    try_files $uri $uri/ /w/rest.php?$query_string;
}

If you are running Mediawiki using Docker, and linking your local Parsoid repository to Mediawiki, you need to map additional volume to the docker container in docker-compose.override.yml file in media wiki project. To do so, the simplest way is to create docker-compose.override.yml in mediawiki project and put code bellow inside (with path modification). If you already have docker-compose.override.yml file, modify it accordingly.

services:
  mediawiki:
    volumes:
      - ./:/var/www/html/w:cached
      - /my/path/to/git/checkout/of/Parsoid:/my/path/to/git/checkout/of/Parsoid

Per verificare la corretta configurazione, visitare {$wgScriptPath}/rest.php/{$domain}/v3/page/html/Main%20Page dove $domain è il nome dell'host in $wgCanonicalServer. (Si noti che i server WMF di produzione non espongono l'API REST di Parsoid alla rete esterna).

Eseguire i test

Per eseguire tutti i test dell'analizzatore e i test di Mocha:

$ composer test

I test dell'analizzatore ora hanno un gran numero di opzioni, che possono essere elencate usando php bin/parserTests.php --help.

Se la variabile d'ambiente MW_INSTALL_DIR punta a un'installazione di MediaWiki configurata, è possibile eseguire alcuni test aggiuntivi con:

$ composer phan-integrated

Convertire wikitesto semplice

È possibile convertire semplici frammenti di wikitext dalla riga di comando utilizzando lo script parse.php nella directory bin/:

$ echo '[[Foo]]' | php bin/parse.php

Lo script parse dà molte opzioni. php bin/parse.php --help offre informazioni a riguardo.

Debugging di Parsoid (per sviluppatori)

Vedi Parsoid/Debugging per consigli sul debugging.

Integrazione Continua

Parsoid è sempre disponibile come libreria, poiché è una dipendenza del nucleo di MediaWiki. Ma due pezzi non sono abilitati:

  • Parsoid ServiceWiring
  • API REST esterna di Parsoid

Il test runner Quibble lo abilita se rileva che mediawiki/services/parsoid.git è stato clonato come parte della compilazione. In questo caso:

  • punta l'autoloader per Wikimedia\Parsoid al codice clonato (sostituendo di fatto la versione installata da composer)
  • Carica l'estensione wfLoadExtension( 'Parsoid', '/path/to/cloned/repo' );

Il ServiceWiring dovrebbe essere abilitato in MediaWiki a partire dalla versione 1.38.

Teoricamente l'API REST non verrebbe mai fusa in MediaWiki: a) non è mai stata esposta al pubblico in produzione, è un'API interna usata da RESTBase che sta per scomparire; b) non è mai stata sottoposta a controlli di sicurezza e c) è ridondante con l'API MediaWiki aziendale. La soluzione sarà che VisualEditor invochi Parsoid direttamente tramite l'Action API di VisualEditor, risparmiando un viaggio di andata e ritorno attraverso l'API REST.

Il caricamento dell'estensione è quindi un hack che consente di utilizzare interfacce soggette a modifiche e che non vogliamo che vengano ancora utilizzate.

Per la maggior parte degli scopi, parsoid non dovrebbe quindi essere aggiunto come dipendenza di CI; l'unica eccezione, a partire da ottobre 2021, è l'estensione MediaWiki Disambiguator.

Caricare parsoid come estensione ci permette di eseguire test di integrazione di MediaWiki con mediawiki/services/parsoid.git (come Quibble, apitesting) e di assicurarci che Parsoid e MediaWiki funzionino insieme.

Un'estensione può essere in grado di scrivere test con Parsoid anche quando il repository non è stato clonato. Poiché è una dipendenza da MediaWiki core, lo spazio dei nomi MediaWiki\Parsoid è disponibile, ma la parte di cablaggio del servizio non lo è (è extension/src nel repository Parsoid ed è esposto come spazio dei nomi \MWParsoid). Il ParsoidTestFileSuite.php codice esegue i test del parser solo se è stato caricato Parsoid (che dovrebbe essere l'impostazione predefinita con MediaWiki 1.38).

Per l'integrazione continua, Parsoid è testato rispetto alla versione più recente di MediaWiki, mentre MediaWiki è testato con la dipendenza di Composer. In caso di modifica incompatibile, la modifica di Parsoid viene fusa per prima (quella che rompe la sua integrazione continua ma non quella di MediaWiki) e MediaWiki viene modificato quando Parsoid viene aggiornato. Si tratta quindi di un cambiamento a senso unico.

Versione di rilascio

Per le build di rilascio di MediaWiki, abbiamo un'integrazione di Parsoid ServiceWiring in VisualEditor, in modo che VisualEditor funzioni senza ulteriori configurazioni (a parte wfLoadExtension( 'VisualEditor' )). La build di rilascio abilita anche l'API REST e aggancia tutto in modo che parsoid funzioni subito. Questo viene fatto copiando un pezzo del codice Parsoid dentro Visual Editor il quale non si trova nel master di Visual Editor, poiché sarebbe obsoleto non appena Parsoid venisse aggiornato. Il codice viene invece conservato in due posti.

Documenti tecnici

Storia

The original application was written in JavaScript (using Node.js) and started running on the Wikimedia cluster in December 2012. In 2019, Parsoid was ported to PHP, and the PHP version replaced the JS version on the Wikimedia cluster in December 2019. Parsoid is being integrated into core MediaWiki, with the goal of eventually replacing MediaWiki's current native parser. In early 2024, Parsoid began to be used on some production wikis of the Wikimedia Foundation as the default parser for read views. You can see them in the production config list.

Parsoid (the PHP version) has been natively bundled with MediaWiki since version 1.35, released in September 2020. For non-Wikimedia installations, Parsoid/JS was supported until the end-of-life of MediaWiki 1.31 (LTS) in September 2021.

Domande frequenti

  • How do I see if a page was rendered with Parsoid?
    • The footer will say "Page was rendered with Parsoid".
  • How do I set a page to temporarily render with Parsoid?
  • How do I get an entire wiki to render with Parsoid?
    • Install Extension:ParserMigration
    • Set $wgParserMigrationEnableParsoidArticlePages = true;
    • Set $wgParserMigrationEnableParsoidDiscussionTools = true;
  • Which Wikimedia wikis render with Parsoid?
    • The list is at parsoidrendered.dblist. As of August 2025, it is approximately 250 of the 1000 wikis. Rollout will continue until all wikis are using Parsoid.

Voci correlate

Collegamenti esterni

Contatti

If you need help or have questions/feedback, you can contact us in #mediawiki-parsoid connect or the wikitext-l mailing list. If all that fails, you can also contact us by email at content-transform-team at the wikimedia.org domain.