mediawiki-extensions-Scribunto/engines/LuaCommon/TextLibrary.php
Brad Jorsch 0db3d7c6d2 Add text module
This exists for some common text-processing functions that aren't
included in string (and therefore also aren't in mw.ustring), as well as
a logical place for the "unstrip" function requested in bug 45085.

Bug: 45085
Change-Id: I47356215fcc8ddeed5f901cd933a30021394bd78
2013-03-20 10:10:15 -04:00

32 lines
993 B
PHP

<?php
class Scribunto_LuaTextLibrary extends Scribunto_LuaLibraryBase {
function register() {
$lib = array(
'unstrip' => array( $this, 'textUnstrip' ),
'getEntityTable' => array( $this, 'getEntityTable' ),
);
$this->getEngine()->registerInterface( 'mw.text.lua', $lib, array(
'comma' => wfMessage( 'comma-separator' )->inContentLanguage()->text(),
'and' => wfMessage( 'and' )->inContentLanguage()->text() .
wfMessage( 'word-separator' )->inContentLanguage()->text(),
'ellipsis' => wfMessage( 'ellipsis' )->inContentLanguage()->text(),
) );
}
function textUnstrip( $s ) {
$this->checkType( 'unstrip', 1, $s, 'string' );
return array( $this->getParser()->mStripState->unstripBoth( $s ) );
}
function getEntityTable() {
$flags = ENT_QUOTES;
// PHP 5.3 compat
if ( defined( "ENT_HTML5" ) ) {
$flags |= constant( "ENT_HTML5" );
}
$table = array_flip( get_html_translation_table( HTML_ENTITIES, $flags, "UTF-8" ) );
return array( $table );
}
}