Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Mocks\MockDataAccess Class Reference

This implements some of the functionality that the tests/ParserTests/MockAPIHelper.php provides. More...

+ Inheritance diagram for Wikimedia\Parsoid\Mocks\MockDataAccess:
+ Collaboration diagram for Wikimedia\Parsoid\Mocks\MockDataAccess:

Public Member Functions

 __construct (SiteConfig $siteConfig, array $opts)
 
 getPageInfo ( $pageConfigOrTitle, array $titles)
 Return target data for formatting links.Replaces Batcher.getPageProps()
Parameters
PageConfig | LinkTarget$pageConfigOrTitleEither a PageConfig or else just the context title from the PageConfig (as a LinkTarget)
string[]$titles
Returns
array<string,array> [ string Title => array ], where the array contains
  • pageId: (int|null) Page ID
  • revId: (int|null) Current revision of the page
  • missing: (bool) Whether the page is missing
  • known: (bool) Whether the special page is known
  • redirect: (bool) Whether the page is a redirect
  • linkclasses: (string[]) Extensible "link color" information; see ApiQueryInfo::getLinkClasses() in MediaWiki core

 
 getFileInfo (PageConfig $pageConfig, array $files)
 Return information about files (images)This replaces ImageInfoRequest and Batcher.imageinfo()
Parameters
PageConfig$pageConfig
array$files[ [string Name, array Dims] ]. The array may contain
  • width: (int) Requested thumbnail width
  • height: (int) Requested thumbnail height
  • page: (int) Requested thumbnail page number
  • seek: (int) Requested thumbnail time offset
Returns
array [ array|null ], where the array contains
  • width: (int|false) File width, false if unknown
  • height: (int|false) File height, false if unknown
  • size: (int|false) File size in bytes, false if unknown
  • mediatype: (string) File media type
  • mime: (string) File MIME type
  • url: (string) File URL
  • mustRender: (bool) False if the file can be directly rendered by browsers
  • badFile: (bool) Whether the file is on the "bad image list"
  • duration: (float, optional) Duration of the media in seconds
  • thumberror: (string, optional) Error text if thumbnailing failed. Ugh.
  • responsiveUrls: (string[], optional) Map of display densities to URLs.
  • thumbdata: (mixed, optional) MediaWiki File->getAPIData()
  • thumburl: (string, optional) Thumbnail URL
  • thumbwidth: (int, optional) Thumbnail width
  • thumbheight: (int, optional) Thumbnail height
  • timestamp: (string, optional) Timestamp
  • sha1: (string, optional) SHA-1

 
 parseWikitext (PageConfig $pageConfig, ContentMetadataCollector $metadata, string $wikitext)
 Perform a parse on wikitext.This replaces PHPParseRequest with onlypst = false, and Batcher.parse()
Todo
Parsoid should be able to do this itself.
Parameters
PageConfig$pageConfig
ContentMetadataCollector$metadataWill collect metadata about the parsed content.
string$wikitext
Returns
string Output HTML

 
 preprocessWikitext (PageConfig $pageConfig, ContentMetadataCollector $metadata, string $wikitext)
 Preprocess wikitext.This replaces PreprocessorRequest and Batcher.preprocess()
Todo
Parsoid should be able to do this itself.
Parameters
PageConfig$pageConfig
ContentMetadataCollector$metadataWill collect metadata about the preprocessed content.
string$wikitext
Returns
string|PFragment Expanded wikitext

 
 fetchTemplateSource (PageConfig $pageConfig, LinkTarget $title)
 Fetch latest revision of article/template content for transclusion.Technically, the ParserOptions might select a different revision other than the latest via ParserOptions::getTemplateCallback() (used for FlaggedRevisions, etc), but the point is that template lookups are by title, not revision id.This replaces TemplateRequest
Todo
TemplateRequest also returns a bunch of other data, but seems to never use it except for TemplateRequest.setPageSrcInfo() which is replaced by PageConfig.
Parameters
PageConfig$pageConfig
LinkTarget$titleTitle of the page to fetch
Returns
PageContent|null

 
 fetchTemplateData (PageConfig $pageConfig, LinkTarget $title)
 Fetch templatedata for a title.This replaces TemplateDataRequest
Parameters
PageConfig$pageConfig
LinkTarget$title
Returns
array|null

 
 logLinterData (PageConfig $pageConfig, array $lints)
 Log linter data.
Parameters
PageConfig$pageConfig
array$lints

 
 addTrackingCategory (PageConfig $pageConfig, ContentMetadataCollector $metadata, string $key)
 Add a tracking category with the given key to the metadata for the page.
Parameters
PageConfig$pageConfigthe page on which the tracking category is to be added
ContentMetadataCollector$metadataThe metadata for the page
string$keyMessage key (not localized)

 
- Public Member Functions inherited from Wikimedia\Parsoid\Config\DataAccess
 __construct ()
 Base constructor.
 

Detailed Description

This implements some of the functionality that the tests/ParserTests/MockAPIHelper.php provides.

While originally implemented to support ParserTests, this is no longer used by parser tests.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Parsoid\Mocks\MockDataAccess::__construct ( SiteConfig $siteConfig,
array $opts )
Parameters
SiteConfig$siteConfig
array$opts

Member Function Documentation

◆ addTrackingCategory()

Wikimedia\Parsoid\Mocks\MockDataAccess::addTrackingCategory ( PageConfig $pageConfig,
ContentMetadataCollector $metadata,
string $key )

Add a tracking category with the given key to the metadata for the page.

Parameters
PageConfig$pageConfigthe page on which the tracking category is to be added
ContentMetadataCollector$metadataThe metadata for the page
string$keyMessage key (not localized)

Reimplemented from Wikimedia\Parsoid\Config\DataAccess.

◆ fetchTemplateData()

Wikimedia\Parsoid\Mocks\MockDataAccess::fetchTemplateData ( PageConfig $pageConfig,
LinkTarget $title )

Fetch templatedata for a title.This replaces TemplateDataRequest

Parameters
PageConfig$pageConfig
LinkTarget$title
Returns
array|null

Reimplemented from Wikimedia\Parsoid\Config\DataAccess.

◆ fetchTemplateSource()

Wikimedia\Parsoid\Mocks\MockDataAccess::fetchTemplateSource ( PageConfig $pageConfig,
LinkTarget $title )

Fetch latest revision of article/template content for transclusion.Technically, the ParserOptions might select a different revision other than the latest via ParserOptions::getTemplateCallback() (used for FlaggedRevisions, etc), but the point is that template lookups are by title, not revision id.This replaces TemplateRequest

Todo
TemplateRequest also returns a bunch of other data, but seems to never use it except for TemplateRequest.setPageSrcInfo() which is replaced by PageConfig.
Parameters
PageConfig$pageConfig
LinkTarget$titleTitle of the page to fetch
Returns
PageContent|null

Reimplemented from Wikimedia\Parsoid\Config\DataAccess.

◆ getFileInfo()

Wikimedia\Parsoid\Mocks\MockDataAccess::getFileInfo ( PageConfig $pageConfig,
array $files )

Return information about files (images)This replaces ImageInfoRequest and Batcher.imageinfo()

Parameters
PageConfig$pageConfig
array$files[ [string Name, array Dims] ]. The array may contain
  • width: (int) Requested thumbnail width
  • height: (int) Requested thumbnail height
  • page: (int) Requested thumbnail page number
  • seek: (int) Requested thumbnail time offset
Returns
array [ array|null ], where the array contains
  • width: (int|false) File width, false if unknown
  • height: (int|false) File height, false if unknown
  • size: (int|false) File size in bytes, false if unknown
  • mediatype: (string) File media type
  • mime: (string) File MIME type
  • url: (string) File URL
  • mustRender: (bool) False if the file can be directly rendered by browsers
  • badFile: (bool) Whether the file is on the "bad image list"
  • duration: (float, optional) Duration of the media in seconds
  • thumberror: (string, optional) Error text if thumbnailing failed. Ugh.
  • responsiveUrls: (string[], optional) Map of display densities to URLs.
  • thumbdata: (mixed, optional) MediaWiki File->getAPIData()
  • thumburl: (string, optional) Thumbnail URL
  • thumbwidth: (int, optional) Thumbnail width
  • thumbheight: (int, optional) Thumbnail height
  • timestamp: (string, optional) Timestamp
  • sha1: (string, optional) SHA-1

Reimplemented from Wikimedia\Parsoid\Config\DataAccess.

◆ getPageInfo()

Wikimedia\Parsoid\Mocks\MockDataAccess::getPageInfo ( $pageConfigOrTitle,
array $titles )

Return target data for formatting links.Replaces Batcher.getPageProps()

Parameters
PageConfig | LinkTarget$pageConfigOrTitleEither a PageConfig or else just the context title from the PageConfig (as a LinkTarget)
string[]$titles
Returns
array<string,array> [ string Title => array ], where the array contains
  • pageId: (int|null) Page ID
  • revId: (int|null) Current revision of the page
  • missing: (bool) Whether the page is missing
  • known: (bool) Whether the special page is known
  • redirect: (bool) Whether the page is a redirect
  • linkclasses: (string[]) Extensible "link color" information; see ApiQueryInfo::getLinkClasses() in MediaWiki core

Reimplemented from Wikimedia\Parsoid\Config\DataAccess.

◆ logLinterData()

Wikimedia\Parsoid\Mocks\MockDataAccess::logLinterData ( PageConfig $pageConfig,
array $lints )

Log linter data.

Parameters
PageConfig$pageConfig
array$lints

Reimplemented from Wikimedia\Parsoid\Config\DataAccess.

◆ parseWikitext()

Wikimedia\Parsoid\Mocks\MockDataAccess::parseWikitext ( PageConfig $pageConfig,
ContentMetadataCollector $metadata,
string $wikitext )

Perform a parse on wikitext.This replaces PHPParseRequest with onlypst = false, and Batcher.parse()

Todo
Parsoid should be able to do this itself.
Parameters
PageConfig$pageConfig
ContentMetadataCollector$metadataWill collect metadata about the parsed content.
string$wikitext
Returns
string Output HTML

Reimplemented from Wikimedia\Parsoid\Config\DataAccess.

◆ preprocessWikitext()

Wikimedia\Parsoid\Mocks\MockDataAccess::preprocessWikitext ( PageConfig $pageConfig,
ContentMetadataCollector $metadata,
string $wikitext )

Preprocess wikitext.This replaces PreprocessorRequest and Batcher.preprocess()

Todo
Parsoid should be able to do this itself.
Parameters
PageConfig$pageConfig
ContentMetadataCollector$metadataWill collect metadata about the preprocessed content.
string$wikitext
Returns
string|PFragment Expanded wikitext

Reimplemented from Wikimedia\Parsoid\Config\DataAccess.


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