Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
PageConfig
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 5
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getContentModel
n/a
0 / 0
n/a
0 / 0
0
 getSuppressTOC
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getLinkTarget
n/a
0 / 0
n/a
0 / 0
0
 getPageId
n/a
0 / 0
n/a
0 / 0
0
 getPageLanguageBcp47
n/a
0 / 0
n/a
0 / 0
0
 getPageLanguageDir
n/a
0 / 0
n/a
0 / 0
0
 getRevisionId
n/a
0 / 0
n/a
0 / 0
0
 getParentRevisionId
n/a
0 / 0
n/a
0 / 0
0
 getRevisionTimestamp
n/a
0 / 0
n/a
0 / 0
0
 getRevisionSha1
n/a
0 / 0
n/a
0 / 0
0
 getRevisionSize
n/a
0 / 0
n/a
0 / 0
0
 getRevisionContent
n/a
0 / 0
n/a
0 / 0
0
 getVariantBcp47
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setVariantBcp47
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPageMainContent
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace Wikimedia\Parsoid\Config;
5
6use Wikimedia\Bcp47Code\Bcp47Code;
7use Wikimedia\Parsoid\Core\LinkTarget;
8
9/**
10 * Page-level configuration interface for Parsoid
11 */
12abstract class PageConfig {
13
14    /**
15     * Non-null to record the fact that conversion has been done on
16     * this page (to the specified variant).
17     * @var ?Bcp47Code
18     */
19    private $htmlVariant = null;
20
21    /**
22     * Base constructor.
23     *
24     * This constructor is public because it is used to create mock objects
25     * in our test suite.
26     */
27    public function __construct() {
28    }
29
30    /**
31     * Get content model
32     * @return string
33     */
34    abstract public function getContentModel(): string;
35
36    /**
37     * Whether to suppress the Table of Contents for this page
38     * (a function of content model).
39     * @return bool
40     */
41    public function getSuppressTOC(): bool {
42        // This will eventually be abstract; for now default to 'false'
43        return false;
44    }
45
46    /**
47     * The page's title, as a LinkTarget.
48     * @return LinkTarget
49     */
50    abstract public function getLinkTarget(): LinkTarget;
51
52    /**
53     * The page's ID, if any
54     * @return int 0 if the page doesn't (yet?) exist
55     */
56    abstract public function getPageId(): int;
57
58    /**
59     * The page's language code.
60     *
61     * @return Bcp47Code a BCP-47 language code
62     */
63    abstract public function getPageLanguageBcp47(): Bcp47Code;
64
65    /**
66     * The page's language direction
67     * @return string 'ltr' or 'rtl'
68     */
69    abstract public function getPageLanguageDir(): string;
70
71    /**
72     * The revision's ID, if any
73     * @return int|null
74     */
75    abstract public function getRevisionId(): ?int;
76
77    /**
78     * The revision's parent ID, if any
79     * @return int|null
80     */
81    abstract public function getParentRevisionId(): ?int;
82
83    /**
84     * The revision's timestamp, if any
85     * @return string|null "YYYYMMDDHHIISS" format
86     */
87    abstract public function getRevisionTimestamp(): ?string;
88
89    /**
90     * The revision's SHA1 checksum, if any
91     * @return string|null Hex encoded
92     */
93    abstract public function getRevisionSha1(): ?string;
94
95    /**
96     * The revision's length, if known
97     * @return int|null Bytes
98     */
99    abstract public function getRevisionSize(): ?int;
100
101    /**
102     * The revision's content
103     * @return PageContent|null
104     */
105    abstract public function getRevisionContent(): ?PageContent;
106
107    /**
108     * Get the page's language variant
109     * @return ?Bcp47Code a BCP-47 language code
110     */
111    public function getVariantBcp47(): ?Bcp47Code {
112        return $this->htmlVariant; # stored as BCP-47
113    }
114
115    /**
116     * Set the page's language variant.  (Records the fact that
117     * conversion has been done in the parser pipeline.)
118     * @param Bcp47Code $htmlVariant a BCP-47 language code
119     */
120    public function setVariantBcp47( Bcp47Code $htmlVariant ): void {
121        $this->htmlVariant = $htmlVariant; # stored as BCP-47
122    }
123
124    /**
125     * FIXME: Once we remove the hardcoded slot name here,
126     * the name of this method could be updated, if necessary.
127     *
128     * Shortcut method to get page source
129     * @deprecated Use $this->topFrame->getSource()->getSrcText()
130     * @return string
131     */
132    public function getPageMainContent(): string {
133        return $this->getRevisionContent()?->getContent( 'main' ) ?? '';
134    }
135
136}