Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
WikifunctionsPendingFragment
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 fallbackContent
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * WikiLambda extension Parsoid pending result for our parser function
5 *
6 * @file
7 * @ingroup Extensions
8 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
9 * @license MIT
10 */
11
12namespace MediaWiki\Extension\WikiLambda\ParserFunction;
13
14use MediaWiki\MediaWikiServices;
15use Wikimedia\Bcp47Code\Bcp47Code;
16use Wikimedia\Parsoid\Ext\AsyncResult;
17use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
18use Wikimedia\Parsoid\Fragments\HtmlPFragment;
19use Wikimedia\Parsoid\Fragments\PFragment;
20
21class WikifunctionsPendingFragment extends AsyncResult {
22    public ?PFragment $content;
23
24    /**
25     * Create a pending fragment to display to end-users in the page if the content is not yet available for some
26     * reason. Default assumption when using this is that it's a temporary cache-miss, but this can also be used
27     * to indicate that the content is not available for some other reason, such as a systems error.
28     *
29     * @param Bcp47Code $languageCode The language in which to render messages.
30     * @param ?PFragment $messageFragment An optional message fragment to display, instead of the default.
31     */
32    public function __construct( Bcp47Code $languageCode, ?PFragment $messageFragment ) {
33        $messageCache = MediaWikiServices::getInstance()->getMessageCache();
34
35        if ( $messageFragment ) {
36            $this->content = $messageFragment;
37            return;
38        }
39        $standardMessage = $messageCache->get( 'wikilambda-fragment-pending', true, $languageCode->toBcp47Code() );
40
41        $htmlString =
42            '<span class="mw-async-not-ready mw-wikifunctions-fragment-pending">'
43                . $standardMessage
44            . '</span>';
45
46        $fragment = HtmlPFragment::newFromHtmlString( $htmlString, null );
47        $this->content = $fragment;
48    }
49
50    public function fallbackContent( ParsoidExtensionAPI $extAPI ): ?PFragment {
51        return $this->content;
52    }
53}