|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SIL\Category; |
|
4
|
|
|
|
|
5
|
|
|
use CategoryViewer; |
|
6
|
|
|
use Title; |
|
7
|
|
|
use Category; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Modifies list of available pages based on the language a category has assigned |
|
11
|
|
|
* |
|
12
|
|
|
* @license GNU GPL v2+ |
|
13
|
|
|
* @since 1.0 |
|
14
|
|
|
* |
|
15
|
|
|
* @author mwjames |
|
16
|
|
|
*/ |
|
17
|
|
|
class ByLanguageCategoryViewer extends CategoryViewer { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Avoid a possible category-empty message |
|
21
|
|
|
* |
|
22
|
|
|
* @see CategoryViewer::getCategoryTop |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function getCategoryTop() { |
|
25
|
1 |
|
return parent::getCategoryTop() . '<span></span>'; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @see CategoryViewer::addImage |
|
30
|
|
|
*/ |
|
31
|
2 |
|
public function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) { |
|
32
|
|
|
|
|
33
|
2 |
|
if ( !$this->canMatchCategoryLanguageToPageLanguage( $title ) ) { |
|
34
|
1 |
|
return null; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
1 |
|
parent::addImage( $title, $sortkey, $pageLength, $isRedirect ); |
|
38
|
1 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @see CategoryViewer::addSubcategoryObject |
|
42
|
|
|
*/ |
|
43
|
2 |
|
public function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) { |
|
44
|
|
|
|
|
45
|
2 |
|
if ( !$this->canMatchCategoryLanguageToPageLanguage( $cat->getTitle() ) ) { |
|
46
|
1 |
|
return null; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
parent::addSubcategoryObject( $cat, $sortkey, $pageLength ); |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @see CategoryViewer::addPage |
|
54
|
|
|
*/ |
|
55
|
6 |
|
public function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) { |
|
56
|
|
|
|
|
57
|
6 |
|
if ( !$this->canMatchCategoryLanguageToPageLanguage( $title ) ) { |
|
58
|
3 |
|
return null; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
4 |
|
parent::addPage( $title, $sortkey, $pageLength, $isRedirect ); |
|
62
|
4 |
|
} |
|
63
|
|
|
|
|
64
|
10 |
|
private function hasInterlanguageLinksLookup() { |
|
65
|
10 |
|
return isset( $this->title->interlanguageLinksLookup ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
10 |
|
private function canMatchCategoryLanguageToPageLanguage( $title ) { |
|
69
|
|
|
|
|
70
|
10 |
|
if ( !$this->hasInterlanguageLinksLookup() || !$title instanceOf Title ) { |
|
71
|
3 |
|
return true; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
7 |
|
if ( !$this->title->interlanguageLinksLookup->hasSilAnnotationFor( $title ) ) { |
|
75
|
1 |
|
return false; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
6 |
|
$categoryLanguageCode = $this->title->interlanguageLinksLookup->findPageLanguageForTarget( $this->title ); |
|
79
|
|
|
|
|
80
|
6 |
|
if ( $categoryLanguageCode === null || $categoryLanguageCode === '' ) { |
|
81
|
1 |
|
return true; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
5 |
|
if ( $categoryLanguageCode === $this->title->interlanguageLinksLookup->findPageLanguageForTarget( $title ) ) { |
|
85
|
2 |
|
return true; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
4 |
|
return false; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|