1 | <?php |
||
13 | class MediaWikiNsContentMapper { |
||
14 | |||
15 | /** |
||
16 | * @var MediaWikiNsContentReader |
||
17 | */ |
||
18 | private $mediaWikiNsContentReader; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | private static $identifierToPropertyMap = []; |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | private static $typeToTemplateMap = []; |
||
29 | |||
30 | /** |
||
31 | * Only set during testing to circumvent the MessageCache |
||
32 | * |
||
33 | * @var boolean |
||
34 | */ |
||
35 | public static $skipMessageCache = false; |
||
36 | |||
37 | /** |
||
38 | * @since 1.0 |
||
39 | * |
||
40 | * @param MediaWikiNsContentReader $mediaWikiNsContentReader |
||
41 | */ |
||
42 | 24 | public function __construct( MediaWikiNsContentReader $mediaWikiNsContentReader ) { |
|
45 | |||
46 | /** |
||
47 | * @since 1.0 |
||
48 | */ |
||
49 | 14 | public static function clear() { |
|
54 | |||
55 | /** |
||
56 | * @since 1.0 |
||
57 | * |
||
58 | * @param string $id |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | 23 | public function findPropertyForId( $id ) { |
|
63 | |||
64 | 23 | $id = strtolower( trim( $id ) ); |
|
65 | |||
66 | 23 | if ( self::$identifierToPropertyMap === [] ) { |
|
67 | |||
68 | // Fixed by definition due to usage of |
||
69 | // pre-defined properties |
||
70 | self::$identifierToPropertyMap = [ |
||
71 | 15 | 'viaf' => SCI_PROP_VIAF, |
|
72 | 15 | 'doi' => SCI_PROP_DOI, |
|
73 | 15 | 'oclc' => SCI_PROP_OCLC, |
|
74 | 15 | 'olid' => SCI_PROP_OLID, |
|
75 | 15 | 'pmcid' => SCI_PROP_PMCID, |
|
76 | 15 | 'pmid' => SCI_PROP_PMID, |
|
77 | 15 | 'reference' => SCI_PROP_CITE_KEY, |
|
78 | 15 | 'citation text' => SCI_PROP_CITE_TEXT, |
|
79 | 15 | 'sortkey' => '_SKEY' |
|
80 | 15 | ] + $this->parseContentFor( "sci-property-definition" ); |
|
81 | } |
||
82 | |||
83 | 23 | return isset( self::$identifierToPropertyMap[$id] ) ? self::$identifierToPropertyMap[$id] : null; |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * @since 1.0 |
||
88 | * |
||
89 | * @param string $type |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | 2 | public function findTemplateForType( $type ) { |
|
103 | |||
104 | /** |
||
105 | * @param string $name |
||
106 | */ |
||
107 | 15 | private function parseContentFor( $name ) { |
|
139 | |||
140 | } |
||
141 |