1 | <?php |
||
34 | class InterlanguageLinksLookup { |
||
35 | |||
36 | const NO_LANG = ''; |
||
37 | |||
38 | /** |
||
39 | * @var LanguageTargetLinksCache |
||
40 | */ |
||
41 | private $languageTargetLinksCache; |
||
42 | |||
43 | /** |
||
44 | * @var Store |
||
45 | */ |
||
46 | private $store; |
||
47 | |||
48 | /** |
||
49 | * @since 1.0 |
||
50 | * |
||
51 | * @param LanguageTargetLinksCache $languageTargetLinksCache |
||
52 | */ |
||
53 | 16 | public function __construct( LanguageTargetLinksCache $languageTargetLinksCache ) { |
|
56 | |||
57 | /** |
||
58 | * @since 1.0 |
||
59 | * |
||
60 | * @param Store $store |
||
61 | */ |
||
62 | 15 | public function setStore( Store $store ) { |
|
65 | |||
66 | |||
67 | /** |
||
68 | * @since 1.2 |
||
69 | * |
||
70 | * @param Title $title |
||
71 | * |
||
72 | * @return Title |
||
73 | */ |
||
74 | 3 | public function getRedirectTargetFor( Title $title ) { |
|
77 | |||
78 | /** |
||
79 | * @since 1.0 |
||
80 | * |
||
81 | * @param Title $title |
||
82 | */ |
||
83 | 3 | public function resetLookupCacheBy( Title $title ) { |
|
84 | |||
85 | 3 | $this->languageTargetLinksCache->deleteLanguageTargetLinksFromCache( |
|
86 | 3 | $this->findFullListOfReferenceTargetLinks( $title ) |
|
87 | ); |
||
88 | |||
89 | 3 | $this->languageTargetLinksCache->deletePageLanguageForTargetFromCache( |
|
90 | 3 | $title |
|
91 | ); |
||
92 | 3 | } |
|
93 | |||
94 | /** |
||
95 | * @since 1.0 |
||
96 | * |
||
97 | * @param Title|null $title |
||
98 | * @param string $languageCode |
||
99 | */ |
||
100 | 6 | public function pushPageLanguageToLookupCache( Title $title = null, $languageCode ) { |
|
111 | |||
112 | /** |
||
113 | * @since 1.0 |
||
114 | * |
||
115 | * @param InterlanguageLink $interlanguageLink |
||
116 | * @param Title|null $target |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | 6 | public function queryLanguageTargetLinks( InterlanguageLink $interlanguageLink, Title $target = null ) { |
|
121 | |||
122 | 6 | $languageTargetLinks = $this->languageTargetLinksCache->getLanguageTargetLinksFromCache( |
|
123 | 6 | $interlanguageLink |
|
124 | ); |
||
125 | |||
126 | 6 | if ( is_array( $languageTargetLinks ) && $languageTargetLinks !== [] ) { |
|
127 | 1 | return $languageTargetLinks; |
|
128 | } |
||
129 | |||
130 | 5 | $languageTargetLinks = []; |
|
131 | |||
132 | 5 | if ( $target !== null && $interlanguageLink->getLanguageCode() !== '' ) { |
|
133 | 3 | $languageTargetLinks[ $interlanguageLink->getLanguageCode() ] = $target; |
|
134 | } |
||
135 | |||
136 | 5 | $queryResult = $this->getQueryResultForInterlanguageLink( $interlanguageLink ); |
|
137 | |||
138 | 5 | $this->iterateQueryResultToFindLanguageTargetLinks( |
|
139 | 5 | $queryResult, |
|
140 | 5 | $languageTargetLinks |
|
141 | ); |
||
142 | |||
143 | 5 | $this->languageTargetLinksCache->saveLanguageTargetLinksToCache( |
|
144 | 5 | $interlanguageLink, |
|
145 | 5 | $languageTargetLinks |
|
146 | ); |
||
147 | |||
148 | 5 | return $languageTargetLinks; |
|
149 | } |
||
150 | |||
151 | /** |
||
152 | * @since 1.0 |
||
153 | * |
||
154 | * @param Title $title |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | 8 | public function findPageLanguageForTarget( Title $title ) { |
|
178 | |||
179 | /** |
||
180 | * @since 1.1 |
||
181 | * |
||
182 | * @param Title $title |
||
183 | * |
||
184 | * @return boolean |
||
185 | */ |
||
186 | 2 | public function hasSilAnnotationFor( Title $title ) { |
|
195 | |||
196 | /** |
||
197 | * @since 1.0 |
||
198 | * |
||
199 | * @param Title $title |
||
200 | * |
||
201 | * @return DIWikiPage[]|[] |
||
202 | */ |
||
203 | 6 | public function findFullListOfReferenceTargetLinks( Title $title ) { |
|
234 | |||
235 | /** |
||
236 | * @return QueryResult |
||
237 | */ |
||
238 | 5 | private function getQueryResultForInterlanguageLink( InterlanguageLink $interlanguageLink ) { |
|
279 | |||
280 | 5 | private function iterateQueryResultToFindLanguageTargetLinks( $queryResult, array &$languageTargetLinks ) { |
|
295 | |||
296 | 6 | private function lookupLastPageLanguageForTarget( Title $title ) { |
|
328 | |||
329 | } |
||
330 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: