diff --git a/src/Promote.php b/src/Promote.php index 139fda6..654d543 100644 --- a/src/Promote.php +++ b/src/Promote.php @@ -55,16 +55,22 @@ function getMainArticleTitle($topicBoxWikicode, $title) { /** There's 3 sources we can pick the topic name from: 1) main article's title, 2) |title= parameter, 3) /archive page's title. Per a conversation with Aza24, we will get it from #2: the |title= parameter. */ function getTopicTitle($topicBoxWikicode, $mainArticleTitle) { + assert($mainArticleTitle !== ''); // should not be blank. was checked in another step. + // search for |title= parameter preg_match("/\|\s*title\s*=\s*([^\|\}]+)\s*/is", $topicBoxWikicode, $matches); - // if not found, return $mainArticleTitle as topicTitle - if ( ! $matches ) { - return $mainArticleTitle; + if ( $matches ) { + $matches[1] = trim($matches[1]); + // get rid of apostrophes + $matches[1] = str_replace("'''", "", $matches[1]); + $matches[1] = str_replace("''", "", $matches[1]); + // if getting rid of apostrophes and trimming didn't delete the entire title, return that + if ( $matches[1] ) return $matches[1]; } - - // if found, return that as topicTitle - return trim($matches[1]); + + // else, return $mainArticleTitle as topicTitle + return $mainArticleTitle; } /** It's OK if this one isn't able to find anything. Not a critical error. It can return blank. */ diff --git a/tests/PromoteTest.php b/tests/PromoteTest.php index 63fd66d..7d8ccc4 100644 --- a/tests/PromoteTest.php +++ b/tests/PromoteTest.php @@ -849,6 +849,27 @@ function test_getTopicTitle_withTopic() { $this->assertSame('UEFA European Championship finals', $result); } + function test_getTopicTitle_withTopic_bold() { + $topicBoxWikicode = "{{Featured topic box |title='''UEFA European Championship finals''' |count=17}}"; + $mainArticleTitle = 'List of UEFA European Championship finals'; + $result = $this->p->getTopicTitle($topicBoxWikicode, $mainArticleTitle); + $this->assertSame('UEFA European Championship finals', $result); + } + + function test_getTopicTitle_withTopic_boldItalic() { + $topicBoxWikicode = "{{Featured topic box |title='''''UEFA European Championship finals''''' |count=17}}"; + $mainArticleTitle = 'List of UEFA European Championship finals'; + $result = $this->p->getTopicTitle($topicBoxWikicode, $mainArticleTitle); + $this->assertSame('UEFA European Championship finals', $result); + } + + function test_getTopicTitle_withTopic_italic() { + $topicBoxWikicode = "{{Featured topic box |title=''UEFA European Championship finals'' |count=17}}"; + $mainArticleTitle = 'List of UEFA European Championship finals'; + $result = $this->p->getTopicTitle($topicBoxWikicode, $mainArticleTitle); + $this->assertSame('UEFA European Championship finals', $result); + } + function test_getTopicTitle_noTopic() { $topicBoxWikicode = '{{Featured topic box |count=17 |image=Coupe Henri Delaunay 2017.jpg |imagesize=