MobileFrontend
MobileoptimisedfrontendforMediaWiki
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)
 
 disableScripts ()
 Disables the generation of script tags in output HTML.
 
 enableTOCPlaceholder ( $flag=true)
 Mark whether a placeholder table of contents should be included at the end of the lead section. More...
 
 enableExpandableSections ( $flag=true)
 Set support of page for expandable sections to $flag (standard: true) More...
 
 setIsMainPage ( $value=true)
 Change mainPage (is this the main page) to $value (standard: true) This enables special casing for the main page. More...
 
 filterContent ( $removeDefaults=true, $removeReferences=false, $removeImages=false, $showFirstParagraphBeforeInfobox=false)
 Performs various transformations to the content to make it appropiate for mobile devices. More...
 
 getText ( $element=null)
 Performs final transformations to mobile format and returns resulting HTML. More...
 

Static Public Member Functions

static newFromContext (MobileContext $context, IContentProvider $provider, $enableSections=false)
 Creates and returns a MobileFormatter. More...
 

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 @const string SHOW_FIRST_PARAGRAPH_BEFORE_INFOBOX.
 

Protected Member Functions

 makeSections (DOMDocument $doc, array $headings, array $transformOptions)
 Splits the body of the document into sections demarcated by the $headings elements. More...
 
 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. More...
 

Protected Attributes

 $lazyTransform
 
 $title
 Saves a Title Object.
 
 $isTOCEnabled = false
 Whether the table of contents is needed on this page.
 
 $expandableSections = false
 Are sections expandable?
 
 $mainPage = false
 Whether actual page is the main page and should be special cased.
 

Detailed Description

Converts HTML into a mobile-friendly version.

Constructor & Destructor Documentation

◆ __construct()

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

Member Function Documentation

◆ 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?

◆ enableTOCPlaceholder()

MobileFormatter::enableTOCPlaceholder (   $flag = true)

Mark whether a placeholder table of contents should be included at the end of the lead section.

Parameters
bool$flagshould TOC be included?

◆ filterContent()

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

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

Parameters
bool$removeDefaultsWhether default settings at $wgMFRemovableClasses should be used
bool$removeReferencesWhether to remove references from the output
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

◆ 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

◆ newFromContext()

static MobileFormatter::newFromContext ( MobileContext  $context,
IContentProvider  $provider,
  $enableSections = false 
)
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$enableSections(optional) whether to wrap the content of sections
Returns
MobileFormatter

◆ 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: