Merge "Migrate to IDatabase::newInsertQueryBuilder/newDeleteQueryBuilder"
tree: a80b38d61c8d2fe2b5b0368ad6a92f22978c8432
  1. .github/
  2. .phan/
  3. docs/
  4. i18n/
  5. maintenance/
  6. sql/
  7. src/
  8. tests/
  9. .eslintrc.json
  10. .gitignore
  11. .gitreview
  12. .phpcs.xml
  13. CODE_OF_CONDUCT.md
  14. composer.json
  15. COPYING
  16. extension.json
  17. Gruntfile.js
  18. package-lock.json
  19. package.json
  20. README.md
README.md

Cognate extension

This MediaWiki extension creates a central store where the page titles for a group of sites are stored. The extension can then generate interwiki links across wiki projects in cases where the titles are the same.

It works on the assumption that (most) page titles are the same across languages, as it is the case for the Wiktionary projects. Some normalization is already applied to titles. Only titles in default MediaWiki namespaces can currently be used with the extension.

This extension is an attempt to solve the task "Centralize interwiki language links for Wiktionary"

"Cognate" is a linguistic concept, meaning same words in different languages developed from the same origin. Since this extension has a similar translation mechanism, it makes for a nice short extension name, even when the actual concept is different.

This extension can be used along side the InterwikiSorting extension to sort the interwiki links that are displayed.

Notes

  • Sites should have the same interwiki structure for language links.
  • In the case that two different titles result in the same hash during normal operation this will be logged in the 'Cognate' channel.
  • If two different titles result in the same hash during database population using one of the maintenance scripts there will be no log.

Installation

Requirements

PHP 5.5 64bit

Single-Wiki setup

To just test the extension, check out this extension into the extensions folder of your MediaWiki installation and add the following line to your LocalSettings.php:

wfLoadExtension( 'Cognate' );

Now call the maintenance/update.php script from the command line to set up the new database table of the extension.

You can now run the unit tests and check if saving pages writes their titles to the database table. No translation links will be generated, except if you add manual entries to the database table.

Multiple language setup

For the multiple language setup (that reflects the state of the Wiktionary projects), you need to have at least 2 MediaWiki installations in different languages that act as the different Wiktionary projects. You can use virtual domain mapping so that a central database is used for your entire wiki farm.

$wgVirtualDomainsMapping['virtual-cognate'] = [ 'db' => 'wiktionary' ];

If the database is on an external cluster, you will also need to configure that.

$wgVirtualDomainsMapping['virtual-cognate'] = [ 'cluster' => 'extension1', 'db' => 'wiktionary' ];

Development

To run Cognate locally for a single wiki setup you can follow the steps in single-wiki setup section.

To run Cognate locally in multiple language setup (that reflects the state of the Wiktionary projects), please follow the steps below:

  1. Prerequisites

    • Download Cognate into you extensions folder and load it in your LocalSetting.php with wfLoadExtension( 'Cognate' ).
    • You will need to have two wikis running locally. If you're using mediawiki-docker-dev that can be achieved easily by running ./addsite wikiname.
  2. Set the following in your LocalSetting.php:

$wgEnableParserCache = false; // Disable the parser cache to be able to see the interwiki links added immediately after you create a page.

$wgCognateNamespaces = [ 0 ]; // Cognate will work only for entries in the main namespace

$wgWBClientSettings['excludeNamespaces'] = [ 0 ]; // Exclude the main namespace where Cognate works in from WikibaseClient to avoid Wikibase trying to setup sitelinks
  1. Run php maintenance/update.php for the wiki that will have the Cognate database. In the example's case that would be default. This will create the Cognate tables in the db.

  2. Both wikis need to be added as sites to the wiki that has the Cognate db. There's a maintenance script that does that. Consider the following examples:

php maintenance/addSite.php enwiki wiktionary --pagepath 'http://enwiki.web.mw.localhost:8080/mediawiki/index.php?title=$1' --filepath 'http://enwiki.web.mw.localhost:8080/mediawiki/$1' --language 'enwiki'
php maintenance/addSite.php default wiktionary --pagepath 'http://default.web.mw.localhost:8080/mediawiki/index.php?title=$1' --filepath 'http://default.web.mw.localhost:8080/mediawiki/$1' --language 'default'

where wiktionary is the name of the site group. It's important to pass language because Cognate is made to work on Wiktionary, where each wiki has a different language code and that language code is also setup to work as an interwiki link. The maintenance script to populate the Cognate sites table only uses the lang code of the wiki from the mediawiki sites table.

  1. Add the interwiki ids and links to the interwiki table as well. For example, if your first wiki is called default and your second wiki is called enwiki, execute the following in the default db:
INSERT INTO interwiki (iw_prefix, iw_url, iw_api, iw_wikiid, iw_local, iw_trans) VALUES ('enwiki', 'http://enwiki.web.mw.localhost:8080/mediawiki/index.php?title=', '', '', 1, 0);

and then in the enwiki db:

INSERT INTO interwiki (iw_prefix, iw_url, iw_api, iw_wikiid, iw_local, iw_trans) VALUES ('default', 'http://default.web.mw.localhost:8080/mediawiki/index.php?title=', '', '', 1, 0);
  1. For the wiki that has the Cognate db, execute the Cognate maintenance script: php maintenance/populateCognateSites.php --site-group wiktionary which will populate the cognate_sites table with the info from the sites table.

  2. Optionally, execute php ./maintenance/populateCognatePages.php to populate the cognate_pages table with the pages on the wiki that were created prior to installing and configuring Cognate.

  3. Test the setup by creating a page on one of the wikis and then creating a page with the same title on the other wiki. You should see an interwiki link in the sidebar pointing to the same page on the first wiki.