Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MediaWiki\Extension\Translate\Utilities\Utilities Class Reference

Essentially random collection of helper functions, similar to GlobalFunctions.php. More...

Static Public Member Functions

static title (string $message, string $code, int $ns=NS_MEDIAWIKI)
 Does quick normalisation of message name so that in can be looked from the database.
 
static figureMessage (string $text)
 Splits page name into message key and language code.
 
static getMessageContent (string $key, string $language, int $namespace=NS_MEDIAWIKI)
 Loads page content without side effects.
 
static getContents ( $titles, int $namespace)
 Fetches contents for pagenames in given namespace without side effects.
 
static getContentForTitle (Title $title, bool $addFuzzy=false)
 Returns the content for a given title and adds the fuzzy tag if requested.
 
static getLanguageName (string $code, ?string $language='en')
 Returns a localised language name.
 
static getLanguageSelector ( $language, ?string $labelOption=null)
 Standard language selector in Translate extension.
 
static getLanguageNames (?string $code)
 Get translated language names for the languages generally supported for translation in the current wiki.
 
static fieldset (string $legend, string $contents, array $attributes=[])
 Constructs a fieldset with contents.
 
static convertWhiteSpaceToHTML (string $message)
 Escapes the message, and does some mangling to whitespace, so that it is preserved when outputted as-is to html page.
 
static cacheFile (string $filename)
 Gets the path for cache files.
 
static getPlaceholder ()
 Returns a random string that can be used as placeholder in strings.
 
static getIcon (MessageGroup $g, int $size)
 Get URLs for icons if available.
 
static getSafeReadDB ()
 Get a DB handle suitable for read and read-for-write cases.
 
static shouldReadFromPrimary ()
 Check whether primary should be used for reads to avoid reading stale data.
 
static getEditorUrl (MessageHandle $handle)
 Get a URL that points to an editor for this message handle.
 
static serialize ( $value)
 Serialize the given value.
 
static deserialize (string $str, array $opts=[ 'allowed_classes'=> false])
 Deserialize the given string.
 
static getVersion ()
 
static allowsSubpages (Title $title)
 Checks if the namespace that the title belongs to allows subpages.
 
static isSupportedLanguageCode (string $code)
 Checks whether a language code is supported for translation at the wiki level.
 
static getTextFromTextContent (?Content $content)
 
static getTranslations (MessageHandle $handle)
 Returns all translations of a given message.
 
static isTranslationPage (MessageHandle $handle)
 

Detailed Description

Essentially random collection of helper functions, similar to GlobalFunctions.php.

Author
Niklas Laxström @license GPL-2.0-or-later

Definition at line 31 of file Utilities.php.

Member Function Documentation

◆ allowsSubpages()

static MediaWiki\Extension\Translate\Utilities\Utilities::allowsSubpages ( Title $title)
static

Checks if the namespace that the title belongs to allows subpages.

Definition at line 387 of file Utilities.php.

◆ cacheFile()

static MediaWiki\Extension\Translate\Utilities\Utilities::cacheFile ( string $filename)
static

Gets the path for cache files.

The cache directory must be configured to use this method.

Parameters
string$filename
Returns
string Full path.

Definition at line 256 of file Utilities.php.

◆ convertWhiteSpaceToHTML()

static MediaWiki\Extension\Translate\Utilities\Utilities::convertWhiteSpaceToHTML ( string $message)
static

Escapes the message, and does some mangling to whitespace, so that it is preserved when outputted as-is to html page.

Line feeds are converted to <br /> and occurrences of leading and trailing and multiple consecutive spaces to non-breaking spaces.

This is also implemented in JavaScript in ext.translate.quickedit.

Parameters
string$messagePlain text string.
Returns
string Text string that is ready for outputting.

Definition at line 241 of file Utilities.php.

◆ deserialize()

static MediaWiki\Extension\Translate\Utilities\Utilities::deserialize ( string $str,
array $opts = [ 'allowed_classes' => false ] )
static

Deserialize the given string.

Returns
mixed

Definition at line 367 of file Utilities.php.

◆ fieldset()

static MediaWiki\Extension\Translate\Utilities\Utilities::fieldset ( string $legend,
string $contents,
array $attributes = [] )
static

Constructs a fieldset with contents.

Parameters
string$legendRaw html.
string$contentsRaw html.
array$attributesHtml attributes for the fieldset.
Returns
string Html.

Definition at line 224 of file Utilities.php.

◆ figureMessage()

static MediaWiki\Extension\Translate\Utilities\Utilities::figureMessage ( string $text)
static

Splits page name into message key and language code.

Parameters
string$text
Returns
array ( string, string ) Key and language code.
Todo
Handle names without slash.

Definition at line 62 of file Utilities.php.

◆ getContentForTitle()

static MediaWiki\Extension\Translate\Utilities\Utilities::getContentForTitle ( Title $title,
bool $addFuzzy = false )
static

Returns the content for a given title and adds the fuzzy tag if requested.

Parameters
Title$title
bool$addFuzzyAdd the fuzzy tag if appropriate.
Returns
string|null

Definition at line 136 of file Utilities.php.

◆ getContents()

static MediaWiki\Extension\Translate\Utilities\Utilities::getContents ( $titles,
int $namespace )
static

Fetches contents for pagenames in given namespace without side effects.

Parameters
string | string[]$titlesDatabase page names.
int$namespaceThe number of the namespace.
Returns
array ( string => array ( string, string ) ) Tuples of page text and last author indexed by page name.

Definition at line 92 of file Utilities.php.

◆ getEditorUrl()

static MediaWiki\Extension\Translate\Utilities\Utilities::getEditorUrl ( MessageHandle $handle)
static

Get a URL that points to an editor for this message handle.

Parameters
MessageHandle$handle
Returns
string Domain relative URL

Definition at line 341 of file Utilities.php.

◆ getIcon()

static MediaWiki\Extension\Translate\Utilities\Utilities::getIcon ( MessageGroup $g,
int $size )
static

Get URLs for icons if available.

Parameters
MessageGroup$g
int$sizeLength of the edge of a bounding box to fit the icon.
Returns
null|array

Definition at line 284 of file Utilities.php.

◆ getLanguageName()

static MediaWiki\Extension\Translate\Utilities\Utilities::getLanguageName ( string $code,
?string $language = 'en' )
static

Returns a localised language name.

Parameters
string$codeLanguage code.
null | string$languageLanguage code of the language that the name should be in.
Returns
string Best-effort localisation of wanted language name.

Definition at line 170 of file Utilities.php.

◆ getLanguageNames()

static MediaWiki\Extension\Translate\Utilities\Utilities::getLanguageNames ( ?string $code)
static

Get translated language names for the languages generally supported for translation in the current wiki.

Message groups can have further exclusions.

Parameters
null | string$code
Returns
array ( language code => language name )

Definition at line 204 of file Utilities.php.

◆ getLanguageSelector()

static MediaWiki\Extension\Translate\Utilities\Utilities::getLanguageSelector ( $language,
?string $labelOption = null )
static

Standard language selector in Translate extension.

Parameters
string$languageLanguage code of the language the names should be localised to.
?string$labelOption
Returns
XmlSelect

Definition at line 181 of file Utilities.php.

◆ getMessageContent()

static MediaWiki\Extension\Translate\Utilities\Utilities::getMessageContent ( string $key,
string $language,
int $namespace = NS_MEDIAWIKI )
static

Loads page content without side effects.

Parameters
string$keyMessage key.
string$languageLanguage code.
int$namespaceNamespace number.
Returns
string|null The contents or null.

Definition at line 77 of file Utilities.php.

◆ getPlaceholder()

static MediaWiki\Extension\Translate\Utilities\Utilities::getPlaceholder ( )
static

Returns a random string that can be used as placeholder in strings.

Definition at line 271 of file Utilities.php.

◆ getSafeReadDB()

static MediaWiki\Extension\Translate\Utilities\Utilities::getSafeReadDB ( )
static

Get a DB handle suitable for read and read-for-write cases.

Returns
IDatabase Primary for HTTP POST, CLI, DB already changed; replica otherwise

Definition at line 315 of file Utilities.php.

◆ getTextFromTextContent()

static MediaWiki\Extension\Translate\Utilities\Utilities::getTextFromTextContent ( ?Content $content)
static

Definition at line 404 of file Utilities.php.

◆ getTranslations()

static MediaWiki\Extension\Translate\Utilities\Utilities::getTranslations ( MessageHandle $handle)
static

Returns all translations of a given message.

Parameters
MessageHandle$handleLanguage code is ignored.
Returns
array ( string => array ( string, string ) ) Tuples of page text and last author indexed by page name.

Definition at line 422 of file Utilities.php.

◆ getVersion()

static MediaWiki\Extension\Translate\Utilities\Utilities::getVersion ( )
static

Definition at line 371 of file Utilities.php.

◆ isSupportedLanguageCode()

static MediaWiki\Extension\Translate\Utilities\Utilities::isSupportedLanguageCode ( string $code)
static

Checks whether a language code is supported for translation at the wiki level.

Note that it is possible that message groups define other language codes which are not supported by the wiki, in which case this function would return false for those.

Definition at line 399 of file Utilities.php.

◆ isTranslationPage()

static MediaWiki\Extension\Translate\Utilities\Utilities::isTranslationPage ( MessageHandle $handle)
static

Definition at line 448 of file Utilities.php.

◆ serialize()

static MediaWiki\Extension\Translate\Utilities\Utilities::serialize ( $value)
static

Serialize the given value.

Parameters
mixed$value

Definition at line 359 of file Utilities.php.

◆ shouldReadFromPrimary()

static MediaWiki\Extension\Translate\Utilities\Utilities::shouldReadFromPrimary ( )
static

Check whether primary should be used for reads to avoid reading stale data.

Definition at line 323 of file Utilities.php.

◆ title()

static MediaWiki\Extension\Translate\Utilities\Utilities::title ( string $message,
string $code,
int $ns = NS_MEDIAWIKI )
static

Does quick normalisation of message name so that in can be looked from the database.

Parameters
string$messageName of the message
string$codeLanguage code in lower case and with dash as delimiter
int$nsNamespace constant
Returns
string The normalised title as a string.

Definition at line 40 of file Utilities.php.


The documentation for this class was generated from the following file: