Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php |
— | — | @@ -6,13 +6,13 @@ |
7 | 7 | ** |
8 | 8 | * Simple feed using Atom/RSS coupled to DynamicPageList category searching. |
9 | 9 | * |
10 | | - * To use: http://wiki.url/Special:GoogleNewsSitemap/[paramter=value][...] |
| 10 | + * To use: http://wiki.url/Special:GoogleNewsSitemap?[paramter=value][¶meter2=value]&... |
11 | 11 | * |
12 | 12 | * Implemented parameters are marked with an @ |
13 | 13 | ** |
14 | 14 | * Parameters |
15 | | - * * category = string ; default = Published |
16 | | - * * notcategory = string ; default = null |
| 15 | + * * categories = string ; default = Published |
| 16 | + * * notcategories = string ; default = null |
17 | 17 | * * namespace = string ; default = null |
18 | 18 | * * count = integer ; default = $wgDPLmaxResultCount = 50 |
19 | 19 | * * order = string ; default = descending |
— | — | @@ -27,11 +27,14 @@ |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Script default values - correctly spelt, naming standard. |
| 31 | + * @todo These should be configurable. Perhaps be $wg globals (?) |
31 | 32 | **/ |
32 | 33 | var $wgDPlminCategories = 1; // Minimum number of categories to look for |
33 | 34 | var $wgDPlmaxCategories = 6; // Maximum number of categories to look for |
34 | 35 | var $wgDPLmaxResultCount = 50; // Maximum number of results to allow |
35 | 36 | |
| 37 | + var $fallbackCategory = 'Published'; |
| 38 | + |
36 | 39 | /** |
37 | 40 | * @var array Parameters array |
38 | 41 | **/ |
— | — | @@ -62,15 +65,19 @@ |
63 | 66 | |
64 | 67 | // Check to make sure that feed type is supported. |
65 | 68 | if ( FeedUtils::checkFeedOutput( $this->params['feed'] ) ) { |
66 | | - // TODO: should feed title be a message. |
67 | 69 | $feed = new $wgFeedClasses[ $this->params['feed'] ]( |
68 | | - $wgSitename . " [$wgLanguageCode] " |
69 | | - . $wgContLang->uc( $this->params['feed'] ) . ' feed', |
| 70 | + wfMsgExt( 'googlenewssitemap_feedtitle', |
| 71 | + array( 'parsemag', 'content' ), |
| 72 | + $wgContLang->getLanguageName( $wgLanguageCode ), |
| 73 | + $wgContLang->uc( $this->params['feed'] ), |
| 74 | + $wgLanguageCode |
| 75 | + ), |
70 | 76 | wfMsgExt( 'tagline', 'parsemag' ), |
71 | 77 | Title::newMainPage()->getFullUrl() |
72 | 78 | ); |
73 | 79 | } else { |
74 | | - // Can't really do anything if wrong feed type. |
| 80 | + // FeedUtils outputs an error if wrong feed type. |
| 81 | + // So nothing else to do at this point |
75 | 82 | return; |
76 | 83 | } |
77 | 84 | |
— | — | @@ -170,28 +177,24 @@ |
171 | 178 | $currentTableNumber++; |
172 | 179 | } |
173 | 180 | |
174 | | - // exclusion categories disabled pending discussion on whether they are necessary |
175 | | - /* |
176 | 181 | for ( $i = 0; $i < $this->params['notCatCount']; $i++ ) { |
177 | | - // echo "notCategory parameter $i<br />\n"; |
178 | | - $sqlSelectFrom .= ' LEFT OUTER JOIN ' . $dbr->tableName( 'categorylinks' ); |
179 | | - $sqlSelectFrom .= ' AS c' . ( $currentTableNumber + 1 ) . ' ON page_id = c' . ( $currentTableNumber + 1 ); |
180 | | - $sqlSelectFrom .= '.cl_from AND c' . ( $currentTableNumber + 1 ); |
181 | | - $sqlSelectFrom .= '.cl_to=' . $dbr->addQuotes( $this->notCategories[$i]->getDBkey() ); |
182 | | - |
183 | | - $conditions .= ' AND c' . ( $currentTableNumber + 1 ) . '.cl_to IS NULL'; |
184 | | - |
| 182 | + $joins["$categorylinks AS c$currentTableNumber"] = array( 'LEFT OUTER JOIN', |
| 183 | + array( "page_id = c{$currentTableNumber}.cl_from", |
| 184 | + "c{$currentTableNumber}.cl_to={$dbr->addQuotes( $this->notCategories[$i]->getDBKey() ) }" |
| 185 | + ) |
| 186 | + ); |
| 187 | + $tables[] = "$categorylinks AS c$currentTableNumber"; |
| 188 | + $conditions[] = "c{$currentTableNumber}.cl_to IS NULL"; |
185 | 189 | $currentTableNumber++; |
186 | 190 | } |
187 | | - */ |
188 | 191 | |
189 | | - if ( 'descending' == $this->params['order'] ) { |
| 192 | + if ( $this->params['order'] === 'descending' ) { |
190 | 193 | $sortOrder = 'DESC'; |
191 | 194 | } else { |
192 | 195 | $sortOrder = 'ASC'; |
193 | 196 | } |
194 | 197 | |
195 | | - if ( 'lastedit' == $this->params['orderMethod'] ) { |
| 198 | + if ( $this->params['orderMethod'] === 'lastedit' ) { |
196 | 199 | $options['ORDER BY'] = 'page_touched ' . $sortOrder; |
197 | 200 | } else { |
198 | 201 | $options['ORDER BY'] = 'c1.cl_timestamp ' . $sortOrder; |
— | — | @@ -201,8 +204,7 @@ |
202 | 205 | // earlier validation logic ensures this is a reasonable number |
203 | 206 | $options['LIMIT'] = $this->params['count']; |
204 | 207 | |
205 | | - // return $dbr->query( $sqlSelectFrom . $conditions ); |
206 | | - return $dbr->select( $tables, $fields, $conditions, '', $options, $joins ); |
| 208 | + return $dbr->select( $tables, $fields, $conditions, __METHOD__, $options, $joins ); |
207 | 209 | } |
208 | 210 | |
209 | 211 | /** |
— | — | @@ -214,14 +216,8 @@ |
215 | 217 | |
216 | 218 | $this->params = array(); |
217 | 219 | |
218 | | - $category = $wgRequest->getText( 'category', 'Published' ); |
219 | | - $category = explode( "|", $category ); |
220 | | - foreach ( $category as $catName ) { |
221 | | - $catTitle = Title::newFromText( $catName, NS_CATEGORY ); |
222 | | - if ( $catTitle ) { |
223 | | - $this->categories[] = $catTitle; |
224 | | - } |
225 | | - } |
| 220 | + $this->categories = $this->getCatRequestArray( 'categories', $this->fallbackCategory, $this->wgDPlmaxCategories ); |
| 221 | + $this->notCategories = $this->getCatRequestArray( 'notcategories', '', $this->wgDPlmaxCategories ); |
226 | 222 | |
227 | 223 | // FIXME:notcats |
228 | 224 | // $this->notCategories[] = $wgRequest->getArray('notcategory'); |
— | — | @@ -246,11 +242,11 @@ |
247 | 243 | $totalCatCount = $this->params['catCount'] + $this->params['notCatCount']; |
248 | 244 | |
249 | 245 | if ( ( $this->params['catCount'] < 1 && !$this->params['nameSpace'] ) |
250 | | - || ( $totalCatCount < $this->wgDPlminCategories ) ) |
| 246 | + || ( $totalCatCount < 1 ) ) |
251 | 247 | { |
252 | | - $feed = Title::newFromText( 'Published', NS_CATEGORY ); |
253 | | - if ( is_object( $feed ) ) { |
254 | | - $this->categories[] = $feed; |
| 248 | + $fallBack = Title::newFromText( $this->fallbackCategory, NS_CATEGORY ); |
| 249 | + if ( $fallBack ) { |
| 250 | + $this->categories[] = $fallBack; |
255 | 251 | $this->params['catCount'] = count( $this->categories ); |
256 | 252 | } else { |
257 | 253 | throw new MWException( "Default fallback category is not a valid title!" ); |
— | — | @@ -269,8 +265,34 @@ |
270 | 266 | } |
271 | 267 | |
272 | 268 | /** |
| 269 | + * Turn a pipe-seperated list from a url parameter into an array. |
| 270 | + * Verifying each element would be a valid title in Category namespace. |
| 271 | + * @param String $name Parameter to retrieve from web reqeust. |
| 272 | + * @param String $default |
| 273 | + * @param Integer $max Maximuin size of resulting array. |
| 274 | + * @return Array of Title objects. The Titles passed in the parameter $name. |
| 275 | + */ |
| 276 | + private function getCatRequestArray( $name, $default, $max ) { |
| 277 | + global $wgRequest; |
| 278 | + |
| 279 | + $value = $wgRequest->getText( $name, $default ); |
| 280 | + $arr = explode( "|", $value, $max + 2 ); |
| 281 | + $res = array(); |
| 282 | + foreach ( $arr as $name ) { |
| 283 | + $catTitle = Title::newFromText( $name, NS_CATEGORY ); |
| 284 | + if ( $catTitle ) { |
| 285 | + $res[] = $catTitle; |
| 286 | + } |
| 287 | + } |
| 288 | + return $res; |
| 289 | + } |
| 290 | + |
| 291 | + /** |
| 292 | + * Given a title, figure out what keywords. Use the message googlenewssitemap_categorymap |
| 293 | + * to map local categories to Google News Keywords. |
| 294 | + * @see http://www.google.com/support/news_pub/bin/answer.py?answer=116037 |
273 | 295 | * @param Title $title |
274 | | - * @return string |
| 296 | + * @return string Comma seperated list of keywords |
275 | 297 | */ |
276 | 298 | function getKeywords ( $title ) { |
277 | 299 | $cats = $title->getParentCategories(); |
Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.i18n.php |
— | — | @@ -18,8 +18,7 @@ |
19 | 19 | 'googlenewssitemap-desc' => 'Outputs an Atom/RSS feed as a Google News Sitemap', |
20 | 20 | 'googlenewssitemap_categorymap' => '', # Default empty. List of categories to map to keywords. Do not translate. |
21 | 21 | 'googlenewssitemap_toomanycats' => 'Error: Too many categories!', |
22 | | - 'googlenewssitemap_toofewcats' => 'Error: Too few categories!', |
23 | | - 'googlenewssitemap_noincludecats' => 'Error: You need to include at least one category, or specify a namespace!', |
| 22 | + 'googlenewssitemap_feedtitle' => '$1 {{SITENAME}} $2 feed.' |
24 | 23 | ); |
25 | 24 | |
26 | 25 | /** Message documentation (Message documentation) |
— | — | @@ -28,7 +27,12 @@ |
29 | 28 | */ |
30 | 29 | $messages['qqq'] = array( |
31 | 30 | 'googlenewssitemap-desc' => '{{desc}}', |
| 31 | + 'googlenewssitemap_toomanycats' => 'Error given when maximum amount of categories specified is exceeded. Default max is 6.', |
32 | 32 | 'googlenewssitemap_badfeedobject' => '<code>$feed</code> is a variable, leave it unchanged.', |
| 33 | + 'googlenewssitemap_feedtitle' => 'Title for the RSS/ATOM feeds produced (does not appear in sitemap XML documents). |
| 34 | +*$1 is language name (like English) |
| 35 | +*$2 is feed type (RSS or ATOM) |
| 36 | +*$3 is language code (like en)' |
33 | 37 | ); |
34 | 38 | |
35 | 39 | /** Afrikaans (Afrikaans) |
Index: trunk/extensions/GoogleNewsSitemap/SitemapFeed.php |
— | — | @@ -3,11 +3,37 @@ |
4 | 4 | |
5 | 5 | class SitemapFeed extends ChannelFeed { |
6 | 6 | private $writer; |
| 7 | + private $publicationName; |
| 8 | + private $publicationLang; |
7 | 9 | |
8 | 10 | function __construct() { |
| 11 | + global $wgSitename, $wgLanguageCode; |
| 12 | + |
9 | 13 | $this->writer = new XMLWriter(); |
| 14 | + $this->publicationName = $wgSitename; |
| 15 | + $this->publicationLang = $wgLanguageCode; |
10 | 16 | } |
11 | 17 | |
| 18 | + /** |
| 19 | + * Set the publication language code. Only used if different from |
| 20 | + * $wgLanguageCode, which could happen if google disagrees with us |
| 21 | + * on say what code zh gets. |
| 22 | + * @param String $lang Language code (like en) |
| 23 | + */ |
| 24 | + function setPublicationLang( $lang ) { |
| 25 | + $this->publicationLang = $lang; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Set the publication name. Normally $wgSitename, but could |
| 30 | + * need to be changed, if Google gives the publication a different |
| 31 | + * name then $wgSitename. |
| 32 | + * @param String $name The name of the publication |
| 33 | + */ |
| 34 | + function setPublicationName( $name ) { |
| 35 | + $this->publicationName = $name; |
| 36 | + } |
| 37 | + |
12 | 38 | function contentType() { |
13 | 39 | return 'application/xml'; |
14 | 40 | } |
— | — | @@ -55,6 +81,15 @@ |
56 | 82 | $this->writer->text( $item->getTitle() ); |
57 | 83 | $this->writer->endElement(); |
58 | 84 | |
| 85 | + $this->writer->startElement( "news:publication" ); |
| 86 | + $this->writer->startElement( "news:name" ); |
| 87 | + $this->writer->text( $this->publicationName ); |
| 88 | + $this->writer->endElement(); |
| 89 | + $this->writer->startElement( "news:language" ); |
| 90 | + $this->writer->text( $this->publicationLang ); |
| 91 | + $this->writer->endElement(); |
| 92 | + $this->writer->endElement(); |
| 93 | + |
59 | 94 | if ( $item->getKeywords() ) { |
60 | 95 | $this->writer->startElement( "news:keywords" ); |
61 | 96 | $this->writer->text( $item->getKeywords() ); |