MobileFrontend
Mobile optimised frontend for MediaWiki
Loading...
Searching...
No Matches
MobileFormatter Class Reference

Converts HTML into a mobile-friendly version. More...

+ Inheritance diagram for MobileFormatter:
+ Collaboration diagram for MobileFormatter:

Public Member Functions

 __construct ( $html, Title $title, Config $config, MobileContext $context)
 
 disableScripts ()
 Disables the generation of script tags in output HTML.
 
 enableExpandableSections ( $flag=true)
 Set support of page for expandable sections to $flag (standard: true)
 
 setIsMainPage ( $value=true)
 Change mainPage (is this the main page) to $value (standard: true) This enables special casing for the main page.
 
 filterContent ( $removeDefaults=true, $unused=false, $removeImages=false, $showFirstParagraphBeforeInfobox=false)
 Performs various transformations to the content to make it appropriate for mobile devices.
 
 disableLegacyTransforms (bool $disable)
 Disable any legacy transforms.
 
 getText ( $element=null)
 Performs final transformations to mobile format and returns resulting HTML.
 

Static Public Member Functions

static newFromContext (MobileContext $context, IContentProvider $provider, $enableSections, Config $config)
 Creates and returns a MobileFormatter.
 
static canApply ( $text, $options)
 Check whether the MobileFormatter can be applied to the text of a page.
 

Public Attributes

const STYLE_COLLAPSIBLE_SECTION_CLASS = 'collapsible-block'
 Class name for collapsible section wrappers.
 
 $topHeadingTags = []
 
const SHOW_FIRST_PARAGRAPH_BEFORE_INFOBOX = 'showFirstParagraphBeforeInfobox'
 Name of the transformation option.
 

Protected Member Functions

 makeSections (DOMDocument $doc, array $headings, array $transformOptions)
 Splits the body of the document into sections demarcated by the $headings elements.
 
 makeHeadingsEditable (array $headings)
 Marks the headings as editable by adding the in-block class to each of them, if it hasn't already been added.
 

Protected Attributes

 $lazyTransform
 
 $title
 
 $expandableSections = false
 
 $mainPage = false
 

Detailed Description

Converts HTML into a mobile-friendly version.

Constructor & Destructor Documentation

◆ __construct()

MobileFormatter::__construct (   $html,
Title  $title,
Config  $config,
MobileContext  $context 
)
Parameters
string$htmlText to process
Title$titleTitle to which $html belongs
Config$config
MobileContext$context

Member Function Documentation

◆ canApply()

static MobileFormatter::canApply (   $text,
  $options 
)
static

Check whether the MobileFormatter can be applied to the text of a page.

Parameters
string$text
array$optionswith 'maxHeadings' and 'maxImages' keys that limit the MobileFormatter to pages with less than or equal to that number of headings and images.
Returns
bool

◆ disableLegacyTransforms()

MobileFormatter::disableLegacyTransforms ( bool  $disable)

Disable any legacy transforms.

Parameters
bool$disablewhether legacy transforms should be disabled.

◆ enableExpandableSections()

MobileFormatter::enableExpandableSections (   $flag = true)

Set support of page for expandable sections to $flag (standard: true)

Todo:
kill with fire when there will be minimum of pre-1.1 app users remaining
Parameters
bool$flagshould expandable sections be supported?

◆ filterContent()

MobileFormatter::filterContent (   $removeDefaults = true,
  $unused = false,
  $removeImages = false,
  $showFirstParagraphBeforeInfobox = false 
)

Performs various transformations to the content to make it appropriate for mobile devices.

Parameters
bool$removeDefaultsWhether default settings at $wgMFRemovableClasses should be used
bool$unusedkept for backwards compatibility - previously used for lazy loaded references
bool$removeImagesWhether to move images into noscript tags
bool$showFirstParagraphBeforeInfoboxWhether the first paragraph from the lead section should be shown before all infoboxes that come earlier.
Returns
array

◆ getText()

MobileFormatter::getText (   $element = null)

Performs final transformations to mobile format and returns resulting HTML.

Parameters
DOMElement | string | null$elementID of element to get HTML from or false to get it from the whole tree
Returns
string Processed HTML

@phan-suppress-next-line PhanTypeMismatchArgument DOMNode vs. DOMElement

◆ makeHeadingsEditable()

MobileFormatter::makeHeadingsEditable ( array  $headings)
protected

Marks the headings as editable by adding the in-block class to each of them, if it hasn't already been added.

FIXME: in-block isn't semantic in that it isn't obviously connected to being editable.

Parameters
DOMElement[]$headingsHeading elements

◆ makeSections()

MobileFormatter::makeSections ( DOMDocument  $doc,
array  $headings,
array  $transformOptions 
)
protected

Splits the body of the document into sections demarcated by the $headings elements.

Also moves the first paragraph in the lead section above the infobox.

All member elements of the sections are added to a

so that the section bodies are clearly defined (to be "expandable" for example).

Parameters
DOMDocument$docrepresenting the HTML of the current article. In the HTML the sections should not be wrapped.
DOMElement[]$headingsThe headings returned by {
See also
MobileFormatter::getHeadings}
Parameters
array$transformOptionsOptions to pass when transforming content per section

@phan-suppress-next-line PhanTypeMismatchArgument DOMNode vs. DOMElement

◆ newFromContext()

static MobileFormatter::newFromContext ( MobileContext  $context,
IContentProvider  $provider,
  $enableSections,
Config  $config 
)
static

Creates and returns a MobileFormatter.

Parameters
MobileContext$contextin which the page is being rendered. Needed to access page title and MobileFrontend configuration.
IContentProvider$provider
bool$enableSectionswhether to wrap the content of sections
Config$config
Returns
self

◆ setIsMainPage()

MobileFormatter::setIsMainPage (   $value = true)

Change mainPage (is this the main page) to $value (standard: true) This enables special casing for the main page.

Deprecated:
Parameters
bool$value

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