Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
PageConfig
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 6
42
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
 getNs
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 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 namespace ID
54     * @return int
55     * @deprecated Use ::getLinkTarget()->getNamespace() instead
56     */
57    public function getNs(): int {
58        return $this->getLinkTarget()->getNamespace();
59    }
60
61    /**
62     * The page's ID, if any
63     * @return int 0 if the page doesn't (yet?) exist
64     */
65    abstract public function getPageId(): int;
66
67    /**
68     * The page's language code.
69     *
70     * @return Bcp47Code a BCP-47 language code
71     */
72    abstract public function getPageLanguageBcp47(): Bcp47Code;
73
74    /**
75     * The page's language direction
76     * @return string 'ltr' or 'rtl'
77     */
78    abstract public function getPageLanguageDir(): string;
79
80    /**
81     * The revision's ID, if any
82     * @return int|null
83     */
84    abstract public function getRevisionId(): ?int;
85
86    /**
87     * The revision's parent ID, if any
88     * @return int|null
89     */
90    abstract public function getParentRevisionId(): ?int;
91
92    /**
93     * The revision's timestamp, if any
94     * @return string|null "YYYYMMDDHHIISS" format
95     */
96    abstract public function getRevisionTimestamp(): ?string;
97
98    /**
99     * The revision's SHA1 checksum, if any
100     * @return string|null Hex encoded
101     */
102    abstract public function getRevisionSha1(): ?string;
103
104    /**
105     * The revision's length, if known
106     * @return int|null Bytes
107     */
108    abstract public function getRevisionSize(): ?int;
109
110    /**
111     * The revision's content
112     * @return PageContent|null
113     */
114    abstract public function getRevisionContent(): ?PageContent;
115
116    /**
117     * Get the page's language variant
118     * @return ?Bcp47Code a BCP-47 language code
119     */
120    public function getVariantBcp47(): ?Bcp47Code {
121        return $this->htmlVariant; # stored as BCP-47
122    }
123
124    /**
125     * Set the page's language variant.  (Records the fact that
126     * conversion has been done in the parser pipeline.)
127     * @param Bcp47Code $htmlVariant a BCP-47 language code
128     */
129    public function setVariantBcp47( Bcp47Code $htmlVariant ): void {
130        $this->htmlVariant = $htmlVariant; # stored as BCP-47
131    }
132
133    /**
134     * FIXME: Once we remove the hardcoded slot name here,
135     * the name of this method could be updated, if necessary.
136     *
137     * Shortcut method to get page source
138     * @deprecated Use $this->topFrame->getSrcText()
139     * @return string
140     */
141    public function getPageMainContent(): string {
142        return $this->getRevisionContent()->getContent( 'main' );
143    }
144
145}