Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php |
— | — | @@ -115,6 +115,10 @@ |
116 | 116 | /** |
117 | 117 | * Get the cached version of the feed if possible. |
118 | 118 | * Checks to see if the cached version is still valid. |
| 119 | + * |
| 120 | + * Note, this doesn't take into account changes to the keyword |
| 121 | + * mapping message (See getKeywords). I don't think that's a major issue. |
| 122 | + * |
119 | 123 | * @param $key String Cache key |
120 | 124 | * @param $invalidInfo String String to check if cache is clean from getCacheInvalidationInfo. |
121 | 125 | * @return Mixed String or Boolean: The cached feed, or false. |
— | — | @@ -509,42 +513,55 @@ |
510 | 514 | /** |
511 | 515 | * Given a title, figure out what keywords. Use the message googlenewssitemap_categorymap |
512 | 516 | * to map local categories to Google News Keywords. |
| 517 | + * |
| 518 | + * The format of this message is *Category name|What to map to |
| 519 | + * or *Category name|__MASK__ to hide the category completely. |
| 520 | + * |
513 | 521 | * @see http://www.google.com/support/news_pub/bin/answer.py?answer=116037 |
514 | 522 | * @param Title $title |
515 | | - * @return String Comma separated list of keywords |
| 523 | + * @return Array of String: list of keywords |
516 | 524 | */ |
517 | 525 | function getKeywords ( $title ) { |
518 | 526 | $cats = $title->getParentCategories(); |
519 | | - $str = ''; |
| 527 | + $res = array(); |
520 | 528 | |
521 | 529 | # the following code is based (stolen) from r56954 of flagged revs. |
522 | 530 | $catMap = array(); |
523 | 531 | $catMask = array(); |
524 | | - $msg = wfMsg( 'googlenewssitemap_categorymap' ); |
525 | 532 | if ( !wfEmptyMsg( 'googlenewssitemap_categorymap' ) ) { |
| 533 | + $msg = wfMsgForContent( 'googlenewssitemap_categorymap' ); |
526 | 534 | $list = explode( "\n*", "\n$msg" ); |
527 | 535 | foreach ( $list as $item ) { |
528 | 536 | $mapping = explode( '|', $item, 2 ); |
529 | 537 | if ( count( $mapping ) == 2 ) { |
530 | | - if ( trim( $mapping[1] ) == '__MASK__' ) { |
531 | | - $catMask[trim( $mapping[0] )] = true; |
| 538 | + |
| 539 | + $targetTitle = Title::newFromText( $mapping[0], NS_CATEGORY ); |
| 540 | + if ( !$targetTitle ) { |
| 541 | + continue; |
| 542 | + } |
| 543 | + $target = $targetTitle->getPrefixedDBkey(); |
| 544 | + $mapTo = trim( $mapping[1] ); |
| 545 | + |
| 546 | + if ( $mapTo === '__MASK__' ) { |
| 547 | + $catMask[$target] = true; |
532 | 548 | } else { |
533 | | - $catMap[trim( $mapping[0] )] = trim( $mapping[1] ); |
| 549 | + $catMap[$target] = $mapTo; |
534 | 550 | } |
535 | 551 | } |
536 | 552 | } |
537 | 553 | } |
538 | | - foreach ( $cats as $key => $val ) { |
539 | | - $cat = str_replace( '_', ' ', trim( substr( $key, strpos( $key, ':' ) + 1 ) ) ); |
540 | | - if ( !isset( $catMask[$cat] ) ) { |
541 | | - if ( isset( $catMap[$cat] ) ) { |
542 | | - $str .= ', ' . str_replace( '_', ' ', trim ( $catMap[$cat] ) ); |
543 | | - } else { |
544 | | - $str .= ', ' . $cat; |
545 | | - } |
| 554 | + foreach ( $cats as $cat => $val ) { |
| 555 | + if ( !isset( $catMask[$cat] ) ) { |
| 556 | + if ( isset( $catMap[$cat] ) ) { |
| 557 | + // Its mapped. |
| 558 | + $res[] = $catMap[$cat]; |
| 559 | + } else { |
| 560 | + // No mapping, so use just page name sans namespace. |
| 561 | + $cTitle = Title::newFromText( $cat ); |
| 562 | + $res[] = $cTitle->getText(); |
546 | 563 | } |
| 564 | + } |
547 | 565 | } |
548 | | - $str = substr( $str, 2 ); # to remove leading ', ' |
549 | | - return $str; |
| 566 | + return $res; |
550 | 567 | } |
551 | 568 | } |
Index: trunk/extensions/GoogleNewsSitemap/FeedSMItem.php |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | **/ |
10 | 10 | class FeedSMItem extends FeedItem { |
11 | 11 | |
12 | | - private $keywords = ''; |
| 12 | + private $keywords = array(); |
13 | 13 | |
14 | 14 | /** |
15 | 15 | * @var Title |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | /** |
20 | 20 | * @param Title $title Title object that this entry is for. |
21 | 21 | * @param String $pubDate Publish date formattable by wfTimestamp. |
22 | | - * @param String $keywords Comma separated list of keywords |
| 22 | + * @param Array $keywords list of (String) keywords |
23 | 23 | * @param Mixed Boolean or Integer. Namespace containing comments page for entry. |
24 | 24 | * True for the corresponding talk page of $title |
25 | 25 | * False for none |
— | — | @@ -72,7 +72,10 @@ |
73 | 73 | } |
74 | 74 | |
75 | 75 | public function getKeywords() { |
76 | | - return $this->xmlEncode( $this->keywords ); |
| 76 | + // Note, not using $wgContLang->commaList, as this is for |
| 77 | + // computers not humans, so we don't want to vary with |
| 78 | + // language conventions. |
| 79 | + return $this->xmlEncode( implode( ', ', $this->keywords ) ); |
77 | 80 | } |
78 | 81 | |
79 | 82 | /** |