Parsoid
A bidirectional parser between wikitext and HTML5
|
This class supports the implementation of Parser Tests in a standalone mode and without network access. More...
Public Member Functions | |
__construct (?string $prefix=null) | |
setApiPrefix (string $prefix) | |
Update prefix. | |
addArticle (string $key, Article $article) | |
Register an article defined in parsertests so that we can return the proper known/missing information about that title. | |
makeRequest (array $params) | |
Public Member Functions inherited from Wikimedia\Parsoid\Config\Api\ApiHelper | |
__construct (array $opts) | |
Static Public Member Functions | |
static | transformHelper ( $width, $height, &$twidth, &$theight) |
Image scaling computation helper. | |
Static Public Member Functions inherited from Wikimedia\Parsoid\Config\Api\ApiHelper | |
static | fromSettings (array $parsoidSettings) |
This class supports the implementation of Parser Tests in a standalone mode and without network access.
In standalone mode, the config and data transformations needed by Parsoid cannot come from MediaWiki's database or its core classes.
Without network access, we cannot fetch site configs or do data transformations on a remote wiki. This class supports this by intercepting network requests and returning mock responses based on cached site configs, hardcoded network responses and config,
So, this API helper should be used with the Parsoid\Config\Api* set of config classes (and any subclasses derived from them).
A lot of the responses here are tuned to what ParserTests needed. But, presumably this can be used by PHP Unit tests as long as the specific set of mocked responses satisfies the needs of those tests. Ideally, this class should NOT be updated for anything but the needs of running parser tests.
Alternatively, PHP Unit tests could bypass the Api* classes altogether and use a (sub)set of mocked classes (Env, SiteConfig, PageConfig, DataAccess) if those classes and the data they provide satisfies the needs of those tests.
Wikimedia\Parsoid\ParserTests\MockApiHelper::__construct | ( | ?string | $prefix = null | ) |
?string | $prefix |
Wikimedia\Parsoid\ParserTests\MockApiHelper::addArticle | ( | string | $key, |
Article | $article ) |
Register an article defined in parsertests so that we can return the proper known/missing information about that title.
string | $key | The normalized title of the article |
Article | $article | The contents of the article |
Wikimedia\Parsoid\ParserTests\MockApiHelper::makeRequest | ( | array | $params | ) |
Wikimedia\Parsoid\ParserTests\MockApiHelper::setApiPrefix | ( | string | $prefix | ) |
Update prefix.
string | $prefix |
|
static |
Image scaling computation helper.
Linker.php in core calls File::transform(...) for each dimension (1x, 1.5x, 2x) which then scales the image dimensions, using round/ceil/floor as appropriate to yield integer dimensions. Note that the results may be unintuitive due to the conversion to integer: eg, a 442px width image may become 883px in 2x mode. Resist the temptation to "optimize" this by computing the transformed size once and then scaling that; always scale the input dimensions instead.
Either $twidth or $theight or both will be set when called; both will be set when this function returns.
int | $width | Original image width |
int | $height | Original image height |
int | float | null | &$twidth | Thumbnail width (inout parameter) |
int | float | null | &$theight | Thumbnail height (inout parameter) |