Skip to content

Commit f97cc0b

Browse files
committed
Changes to ByLanguageCategoryPage
1 parent dd8cb7b commit f97cc0b

File tree

6 files changed

+94
-11
lines changed

6 files changed

+94
-11
lines changed

i18n/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
"sil-search-profile-tooltip":"Filter articles by language annotation",
2323
"sil-search-languagefilter-label":"Filter by Language",
2424
"sil-search-nolanguagefilter":"No language filter",
25-
"sil-categorypage-languagefilter-active":"This category contains information (page, subcategory, and image) that is filtered by language."
25+
"sil-categorypage-languagefilter-active":"This category contains information (page, subcategory, and image) that is filtered by \"$1\" language."
2626
}

src/Category/ByLanguageCategoryPage.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ public function openShowCategory() {
5757
'div',
5858
array(
5959
'id' => 'sil-categorypage-languagefilter',
60-
'style' => 'font-style:italic' ),
61-
wfMessage( 'sil-categorypage-languagefilter-active' )->inLanguage( $this->getTitle()->getPageLanguage() )->text()
60+
'style' => 'font-style:italic'
61+
),
62+
wfMessage(
63+
'sil-categorypage-languagefilter-active',
64+
$this->getTitle()->getPageLanguage()->getCode() )->inLanguage( $this->getTitle()->getPageLanguage() )->text()
6265
);
6366

6467
$this->getContext()->getOutput()->addHTML( $html );
@@ -73,7 +76,9 @@ public function openShowCategory() {
7376
*/
7477
public function modifyCategoryView( &$page, InterlanguageLinksLookup $interlanguageLinksLookup ) {
7578

76-
if ( !$this->categoryFilterByLanguage || $this->getTitle()->getNamespace() !== NS_CATEGORY ) {
79+
if ( $this->getTitle()->getNamespace() !== NS_CATEGORY ||
80+
!$this->categoryFilterByLanguage ||
81+
!$interlanguageLinksLookup->hasSilAnnotationFor( $this->getTitle() ) ) {
7782
return null;
7883
}
7984

@@ -88,7 +93,9 @@ public function modifyCategoryView( &$page, InterlanguageLinksLookup $interlangu
8893
}
8994

9095
private function hasPageLanguageForTarget( Title $title ) {
91-
return $this->interlanguageLinksLookup !== null && $this->interlanguageLinksLookup->findPageLanguageForTarget( $title ) !== '';
96+
return $this->interlanguageLinksLookup !== null &&
97+
$this->interlanguageLinksLookup->findPageLanguageForTarget( $title ) !== '' &&
98+
$this->interlanguageLinksLookup->hasSilAnnotationFor( $title );
9299
}
93100

94101
}

src/Category/ByLanguageCategoryViewer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ private function canMatchCategoryLanguageToPageLanguage( $title ) {
6262
return true;
6363
}
6464

65+
if ( !$this->title->interlanguageLinksLookup->hasSilAnnotationFor( $title ) ) {
66+
return false;
67+
}
68+
6569
$categoryLanguageCode = $this->title->interlanguageLinksLookup->findPageLanguageForTarget( $this->title );
6670

6771
if ( $categoryLanguageCode === null || $categoryLanguageCode === '' ) {

src/InterlanguageLinksLookup.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,23 @@ public function findPageLanguageForTarget( Title $title ) {
164164
return $lookupLanguageCode;
165165
}
166166

167+
/**
168+
* @since 1.1
169+
*
170+
* @param Title $title
171+
*
172+
* @return boolean
173+
*/
174+
public function hasSilAnnotationFor( Title $title ) {
175+
176+
$propertyValues = $this->store->getPropertyValues(
177+
DIWikiPage::newFromTitle( $title ),
178+
new DIProperty( PropertyRegistry::SIL_CONTAINER )
179+
);
180+
181+
return $propertyValues !== array();
182+
}
183+
167184
/**
168185
* @since 1.0
169186
*

tests/phpunit/Unit/Category/ByLanguageCategoryPageTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public function testEnabledCategoryFilter() {
7474
->disableOriginalConstructor()
7575
->getMock();
7676

77+
$interlanguageLinksLookup->expects( $this->once() )
78+
->method( 'hasSilAnnotationFor' )
79+
->will( $this->returnValue( true ) );
80+
7781
$context = $this->getMockBuilder( '\IContextSource' )
7882
->disableOriginalConstructor()
7983
->getMock();
@@ -106,6 +110,10 @@ public function testInfoMessageByOpenShowCategoryForEnabledLanguageFilter() {
106110
->disableOriginalConstructor()
107111
->getMock();
108112

113+
$interlanguageLinksLookup->expects( $this->atLeastOnce() )
114+
->method( 'hasSilAnnotationFor' )
115+
->will( $this->returnValue( true ) );
116+
109117
$interlanguageLinksLookup->expects( $this->exactly( 1 ) )
110118
->method( 'findPageLanguageForTarget' )
111119
->will( $this->returnValue( 'foo' ) );

tests/phpunit/Unit/Category/ByLanguageCategoryViewerTest.php

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public function testTryAddImageForNoLanguageMatch() {
9393
->disableOriginalConstructor()
9494
->getMock();
9595

96+
$interlanguageLinksLookup->expects( $this->atLeastOnce() )
97+
->method( 'hasSilAnnotationFor' )
98+
->will( $this->returnValue( true ) );
99+
96100
$interlanguageLinksLookup->expects( $this->at( 0 ) )
97101
->method( 'findPageLanguageForTarget' )
98102
->will( $this->returnValue( 'no' ) );
@@ -115,7 +119,7 @@ public function testTryAddImageForNoLanguageMatch() {
115119
);
116120
}
117121

118-
public function testTryAddSubcategoryForNoInterlanguageLinksLookup() {
122+
public function testAddSubcategoryForNoInterlanguageLinksLookup() {
119123

120124
$title = Title::newFromText( 'Foo', NS_CATEGORY );
121125

@@ -147,6 +151,10 @@ public function testTryAddSubcategoryForNoLanguageMatch() {
147151
->disableOriginalConstructor()
148152
->getMock();
149153

154+
$interlanguageLinksLookup->expects( $this->atLeastOnce() )
155+
->method( 'hasSilAnnotationFor' )
156+
->will( $this->returnValue( true ) );
157+
150158
$interlanguageLinksLookup->expects( $this->at( 0 ) )
151159
->method( 'findPageLanguageForTarget' )
152160
->will( $this->returnValue( 'no' ) );
@@ -186,6 +194,10 @@ public function testAddPageForEmptyLanguage() {
186194
->disableOriginalConstructor()
187195
->getMock();
188196

197+
$interlanguageLinksLookup->expects( $this->atLeastOnce() )
198+
->method( 'hasSilAnnotationFor' )
199+
->will( $this->returnValue( true ) );
200+
189201
$interlanguageLinksLookup->expects( $this->atLeastOnce() )
190202
->method( 'findPageLanguageForTarget' )
191203
->with( $this->equalTo( $title ) )
@@ -205,7 +217,7 @@ public function testAddPageForEmptyLanguage() {
205217
);
206218
}
207219

208-
public function testTryAddPageForLanguageMatch() {
220+
public function testAddPageForLanguageMatch() {
209221

210222
$title = Title::newFromText( 'Foo', NS_CATEGORY );
211223
$target = Title::newFromText( 'Bar' );
@@ -214,12 +226,16 @@ public function testTryAddPageForLanguageMatch() {
214226
->disableOriginalConstructor()
215227
->getMock();
216228

217-
$interlanguageLinksLookup->expects( $this->at( 0 ) )
229+
$interlanguageLinksLookup->expects( $this->atLeastOnce() )
230+
->method( 'hasSilAnnotationFor' )
231+
->will( $this->returnValue( true ) );
232+
233+
$interlanguageLinksLookup->expects( $this->at( 1 ) )
218234
->method( 'findPageLanguageForTarget' )
219235
->with( $this->equalTo( $title ) )
220236
->will( $this->returnValue( 'vi' ) );
221237

222-
$interlanguageLinksLookup->expects( $this->at( 1 ) )
238+
$interlanguageLinksLookup->expects( $this->at( 2 ) )
223239
->method( 'findPageLanguageForTarget' )
224240
->with( $this->equalTo( $target ) )
225241
->will( $this->returnValue( 'vi' ) );
@@ -247,12 +263,16 @@ public function testTryAddPageForNoLanguageMatch() {
247263
->disableOriginalConstructor()
248264
->getMock();
249265

250-
$interlanguageLinksLookup->expects( $this->at( 0 ) )
266+
$interlanguageLinksLookup->expects( $this->atLeastOnce() )
267+
->method( 'hasSilAnnotationFor' )
268+
->will( $this->returnValue( true ) );
269+
270+
$interlanguageLinksLookup->expects( $this->at( 1 ) )
251271
->method( 'findPageLanguageForTarget' )
252272
->with( $this->equalTo( $title ) )
253273
->will( $this->returnValue( 'vi' ) );
254274

255-
$interlanguageLinksLookup->expects( $this->at( 1 ) )
275+
$interlanguageLinksLookup->expects( $this->at( 2 ) )
256276
->method( 'findPageLanguageForTarget' )
257277
->with( $this->equalTo( $target ) )
258278
->will( $this->returnValue( 'en' ) );
@@ -271,4 +291,31 @@ public function testTryAddPageForNoLanguageMatch() {
271291
);
272292
}
273293

294+
public function testTryAddPageForNoAnnotationMatch() {
295+
296+
$title = Title::newFromText( 'Foo', NS_CATEGORY );
297+
$target = Title::newFromText( 'Bar' );
298+
299+
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' )
300+
->disableOriginalConstructor()
301+
->getMock();
302+
303+
$interlanguageLinksLookup->expects( $this->atLeastOnce() )
304+
->method( 'hasSilAnnotationFor' )
305+
->will( $this->returnValue( false ) );
306+
307+
$title->interlanguageLinksLookup = $interlanguageLinksLookup;
308+
309+
$instance = new ByLanguageCategoryViewer(
310+
$title,
311+
$this->context
312+
);
313+
314+
$instance->addPage( $target, 'B', '' );
315+
316+
$this->assertEmpty(
317+
$instance->articles
318+
);
319+
}
320+
274321
}

0 commit comments

Comments
 (0)