mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-27 01:30:00 +00:00
0db3d7c6d2
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
32 lines
993 B
PHP
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 );
|
|
}
|
|
}
|