Skip to content

metalevel-tech/mw-Typography

Repository files navigation

mw-Typography

MediaWiki Extension that uses the repository php-typography and process the wiki text through it in order to hyphen the text. The first aim is to provide Hyphenation, but all features of the repository PHP-Typography are available.

This is a Beta stable version, that currently meets my desires and I decided to share it. I'm just enthusiast that can use Google search and Stack Exchange services. This is my first attempt with MediaWiki extensions. So this extension could be done in more professional way. I'm still learning.

Features

  • Hyphenation of the wiki text. The repository php-typography has more features (than this), and currently most of them are available via the user's configuration.

  • Wiki family support. The repository php-typography supports over 70 languages. So the extension has the following options:

    • Autodetect the wiki's language - in this case the extension will detect the wiki's language, and process the text within that wiki by this single language. There are some locales limitations of this autodetection - for example the locale en will be converted to en-US, but such filters are not applied for any other language. I would prefer the other option!

    • Manual set the wiki's languages - with this option you can manually set the wiki's content language. [Or you can set more than one content languages in order to translate your multi language wiki's content]. In order to activate this option you need to add a line as the follow in your LocalSettings.php file:

      $wgTypography['HyphenLanguages'] = array('bg', 'en-US', 'ru');

      You can see the list of the available language and their locales in the directory vendor/mundschenk-at/php-typography/src/lang.

  • Justify the text. The extension will add a small portion of CSS code in order to justify your wiki content. It is better (faster) to place CCS such this in your MediaWiki:Common.css. In the next version the loading of this CSS code will be optional.

  • Clear clipboard. The extension uses an additional JavaScript in order to remove the ­ signs from the text when you copy it. This JavaScript is borrowed from wp-Typography. The current implementation of the script has a bug: When you copy text from pre tag, the new line characters are dismissed. The temporal solution is to copy the entire pre tag plus small portion of text from any surrounded tag div, p, etc.

  • PHP-Typography settings. All settings of the main repository PHP-Typography are available via the array $wgTypography['Settings'] that should be added to your LocalSettings.php file in a way as this:

    $wgTypography['Settings'] = array(
        'set_tags_to_ignore' => array('code', 'kbd', 'pre'),
        'set_classes_to_ignore' => array( 'vcard', 'noTypo', 'mw-ui-button', 'mw-whatlinkshere-list'),
        'set_ids_to_ignore' => array('articlePhase', 'articleStatus', 'wspmTable', 'articleBelongsTo'),
        'set_hyphenation' => true,
        'set_min_length_hyphenation' => 4,
        'set_min_before_hyphenation' => 2,
        'set_single_character_word_spacing' => false,
    );

    You can read the extension's default values within the beginning of the file Typography.hooks.php. You can read about the meaning of each option within the file /vendor/mundschenk-at/php-typography/src/class-settings.php.

Installation

Clone (download) the extension's repository in your MediaWiki $IP/extensions directory:

cd $IP/extensions
sudo git clone https://github.com/metalevel-tech/mw-Typography.git Typography # HTTPS
sudo git clone git@github.com:metalevel-tech/mw-Typography.git Typography     # SSH

cd $IP/extensions/Typography
git branch -a
sudo git checkout the_desired_branch

The current repository redistributes php-typography, if you want to update it, you can use Composer in this way:

cd $IP/extensions/Typography
sudo composer update            # sudo chown -R www-data:www-data ./ && sudo -u www-data composer update
php vendor/bin/update-iana.php  # sudo -u www-data php vendor/bin/update-iana.php

Finally enable the extension in LocalSettings.php of your MediaWiki instance and optionnaly add some user's configuration settings:

wfLoadExtension( 'Typography' );

// Optionally apply your custom configuration
$wgTypography['HyphenLanguages'] = array('bg', 'en-US', 'ru');
$wgTypography['Settings'] = array(
    'set_tags_to_ignore' => array('code', 'kbd', 'pre'),
    'set_classes_to_ignore' => array( 'vcard', 'noTypo', 'mw-ui-button', 'mw-whatlinkshere-list'),
    'set_ids_to_ignore' => array('articlePhase', 'articleStatus', 'wspmTable', 'articleBelongsTo'),
    'set_hyphenation' => true,
    'set_min_length_hyphenation' => 4,
    'set_min_before_hyphenation' => 2,
    'set_single_character_word_spacing' => false,
);
  • Note all settings added by LocalSettings.php will override the default values!

  • The option $wgTypography['ColonWords'] is replaced by a litle moddification in the file class-hyphenate-compounds-fix.php, at line 71, where the regexp is changed from /(-)/ to /(-|\:)/.

Navigate to Special:Version to check whether Extension:Typography is enabled. It should works now.

Requirements

Requirements transcluded from Code by Der Mundschenk & Cie. /wp-Typography:

  • The host server must run PHP 5.6.0 or later,
  • The installation of PHP must include the mbstring extension,
  • The text must be UTF‐8 encoded.

MediaWiki version compatibility:

  • The extension is tested with MediaWiki 1.32, 1.33, 1.34 and 1.35. The hooks - ParserAfterTidy OutputPageBeforeHTML and BeforePageDisplay - used in the extension are available from version 1.5 1.6 and 1.7. According to that MediaWiki 1.7 should be the oldest version that could use this extension. Currently, independently of the branch, the minimal verion is set, by the extension.json file, to 1.30.

  • I will issue a branch of this extension after each MediaWiki's branch that I'm following on my production or test environment.

  • After a branch is issued I do not intent to apply further edits to it, so most recent updates will be available in the master branch of this repository.

Screen shots and tests

The extension is tested on a MediaWiki Family that supports Bulgarian, Russian and English languages and it works nice - as it is expected. In my opinion, of doctor of engineering science, this is must have feature for each CMS!

Example 1.

Performance

Here is a performance comparison between processing multilingual text (BG, RU, EN) with enabled or disabled Typography extension. You can see the performance difference is not so huge with a relatively large page that contains about 10k characters (which is about 5 printed pages).

Prerformance NewPP limit report CPU/Real time usage Language Browser total time
160,000 chars 0.190 / 0.200 sec (160k chars, 2Mb post size / 500 print pages) Mixed BG/EN/RU 1.8 sec
160,000 +Typo 0.226 / 0.308 sec (160k chars, 2Mb post size / 500 print pages) Mixed BG/EN/RU 8.9 sec

Note when the page is already rendered and loaded from the cache these are not the actual times.

Acknowledgement

Special thanks to Peter Putzer, the author of wp-Typography, who pointed me in the right direction.

Work in progress notes

About

MediaWiki Extension that uses the repository php-typography and process the wiki text through it in order to insert hyphens inside.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published