Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php |
— | — | @@ -147,7 +147,7 @@ |
148 | 148 | $this->pubDate = isset( $row->cl_timestamp ) ? $row->cl_timestamp : date( DATE_ATOM ); |
149 | 149 | $feedArticle = new Article( $title ); |
150 | 150 | |
151 | | - $feedItem = new feedSMItem( |
| 151 | + $feedItem = new FeedSMItem( |
152 | 152 | trim( $title->getFullURL() ), |
153 | 153 | wfTimeStamp( TS_ISO_8601, $this->pubDate ), |
154 | 154 | $this->getKeywords( $title ), |
— | — | @@ -385,130 +385,3 @@ |
386 | 386 | return $str; |
387 | 387 | } |
388 | 388 | } |
389 | | - |
390 | | -/** |
391 | | - * feedSMItem Class |
392 | | - ** |
393 | | - * Base class for basic SiteMap support, for building url containers. |
394 | | - **/ |
395 | | -class feedSMItem { |
396 | | - /** |
397 | | - * Var string |
398 | | - **/ |
399 | | - var $url = ''; |
400 | | - var $pubDate = ''; |
401 | | - var $keywords = ''; |
402 | | - var $lastMod = ''; |
403 | | - var $priority = ''; |
404 | | - |
405 | | - function __construct( $url, $pubDate, $keywords = '', $lastMod = '', $priority = '' ) { |
406 | | - $this->url = $url; |
407 | | - $this->pubDate = $pubDate; |
408 | | - $this->keywords = $keywords; |
409 | | - $this->lastMod = $lastMod; |
410 | | - $this->priority = $priority; |
411 | | - } |
412 | | - |
413 | | - public function xmlEncode( $string ) { |
414 | | - $string = str_replace( "\r\n", "\n", $string ); |
415 | | - $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string ); |
416 | | - return htmlspecialchars( $string ); |
417 | | - } |
418 | | - |
419 | | - public function getUrl() { |
420 | | - return $this->url; |
421 | | - } |
422 | | - |
423 | | - public function getPriority() { |
424 | | - return $this->priority; |
425 | | - } |
426 | | - |
427 | | - public function getLastMod() { |
428 | | - return $this->lastMod; |
429 | | - } |
430 | | - |
431 | | - public function getKeywords () { |
432 | | - return $this->xmlEncode( $this->keywords ); |
433 | | - } |
434 | | - |
435 | | - public function getPubDate() { |
436 | | - return $this->pubDate; |
437 | | - } |
438 | | - |
439 | | - function formatTime( $ts ) { |
440 | | - // need to use RFC 822 time format at least for rss2.0 |
441 | | - return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX, $ts ) ); |
442 | | - } |
443 | | -} |
444 | | - |
445 | | -class SitemapFeed extends feedSMItem { |
446 | | - private $writer; |
447 | | - |
448 | | - function __construct() { |
449 | | - global $wgOut; |
450 | | - $this->writer = new XMLWriter(); |
451 | | - $wgOut->disable(); |
452 | | - } |
453 | | - /** |
454 | | - * Output feed headers |
455 | | - **/ |
456 | | - function outHeader() { |
457 | | - global $wgOut; |
458 | | - global $wgRequest; |
459 | | - |
460 | | - // FIXME: Why can't we just pick one mime type and always send that? |
461 | | - $ctype = $wgRequest->getVal( 'ctype', 'application/xml' ); |
462 | | - $allowedctypes = array( 'application/xml', 'text/xml', 'application/rss+xml', 'application/atom+xml' ); |
463 | | - $mimetype = in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml'; |
464 | | - header( "Content-type: $mimetype; charset=UTF-8" ); |
465 | | - $wgOut->sendCacheControl(); |
466 | | - |
467 | | - $this->writer->openURI( 'php://output' ); |
468 | | - $this->writer->setIndent( true ); |
469 | | - $this->writer->startDocument( "1.0", "UTF-8" ); |
470 | | - $this->writer->startElement( "urlset" ); |
471 | | - $this->writer->writeAttribute( "xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9" ); |
472 | | - $this->writer->writeAttribute( "xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9" ); |
473 | | - $this->writer->flush(); |
474 | | - } |
475 | | - /** |
476 | | - * Output a SiteMap 0.9 item |
477 | | - * @param feedSMItem item to be output |
478 | | - **/ |
479 | | - function outItem( $item ) { |
480 | | - |
481 | | - $this->writer->startElement( "url" ); |
482 | | - $this->writer->startElement( "loc" ); |
483 | | - $this->writer->text( $item->getUrl() ); |
484 | | - $this->writer->endElement(); |
485 | | - $this->writer->startElement( "news:news" ); |
486 | | - $this->writer->startElement( "news:publication_date" ); |
487 | | - $this->writer->text( $item->getPubDate() ); |
488 | | - $this->writer->endElement(); |
489 | | - if ( $item->getKeywords() ) { |
490 | | - $this->writer->startElement( "news:keywords" ); |
491 | | - $this->writer->text( $item->getKeywords() ); |
492 | | - $this->writer->endElement(); |
493 | | - } |
494 | | - $this->writer->endElement(); // end news:news |
495 | | - if ( $item->getLastMod() ) { |
496 | | - $this->writer->startElement( "lastmod" ); |
497 | | - $this->writer->text( $item->getLastMod() ); |
498 | | - $this->writer->endElement(); |
499 | | - } |
500 | | - if ( $item->getPriority() ) { |
501 | | - $this->writer->startElement( "priority" ); |
502 | | - $this->writer->text( $item->getPriority() ); |
503 | | - $this->writer->endElement(); |
504 | | - } |
505 | | - $this->writer->endElement(); // end url |
506 | | - } |
507 | | - |
508 | | - /** |
509 | | - * Output SiteMap 0.9 footer |
510 | | - **/ |
511 | | - function outFooter() { |
512 | | - $this->writer->endDocument(); |
513 | | - $this->writer->flush(); |
514 | | - } |
515 | | -} |
Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.php |
— | — | @@ -66,4 +66,6 @@ |
67 | 67 | $wgExtensionMessagesFiles['GoogleNewsSitemap'] = $dir . 'GoogleNewsSitemap.i18n.php'; |
68 | 68 | $wgExtensionAliasesFiles['GoogleNewsSitemap'] = $dir . 'GoogleNewsSitemap.alias.php'; |
69 | 69 | $wgAutoloadClasses['GoogleNewsSitemap'] = $dir . 'GoogleNewsSitemap_body.php'; |
| 70 | +$wgAutoloadClasses['FeedSMItem'] = $dir . 'FeedSMItem.php'; |
| 71 | +$wgAutoloadClasses['SitemapFeed'] = $dir . 'SitemapFeed.php'; |
70 | 72 | $wgSpecialPages['GoogleNewsSitemap'] = 'GoogleNewsSitemap'; |
Index: trunk/extensions/GoogleNewsSitemap/FeedSMItem.php |
— | — | @@ -0,0 +1,57 @@ |
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 4 | + |
| 5 | +/** |
| 6 | + * FeedSMItem Class |
| 7 | + ** |
| 8 | + * Base class for basic SiteMap support, for building url containers. |
| 9 | + **/ |
| 10 | +class FeedSMItem { |
| 11 | + /** |
| 12 | + * Var string |
| 13 | + **/ |
| 14 | + var $url = ''; |
| 15 | + var $pubDate = ''; |
| 16 | + var $keywords = ''; |
| 17 | + var $lastMod = ''; |
| 18 | + var $priority = ''; |
| 19 | + |
| 20 | + function __construct( $url, $pubDate, $keywords = '', $lastMod = '', $priority = '' ) { |
| 21 | + $this->url = $url; |
| 22 | + $this->pubDate = $pubDate; |
| 23 | + $this->keywords = $keywords; |
| 24 | + $this->lastMod = $lastMod; |
| 25 | + $this->priority = $priority; |
| 26 | + } |
| 27 | + |
| 28 | + public function xmlEncode( $string ) { |
| 29 | + $string = str_replace( "\r\n", "\n", $string ); |
| 30 | + $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', '', $string ); |
| 31 | + return htmlspecialchars( $string ); |
| 32 | + } |
| 33 | + |
| 34 | + public function getUrl() { |
| 35 | + return $this->url; |
| 36 | + } |
| 37 | + |
| 38 | + public function getPriority() { |
| 39 | + return $this->priority; |
| 40 | + } |
| 41 | + |
| 42 | + public function getLastMod() { |
| 43 | + return $this->lastMod; |
| 44 | + } |
| 45 | + |
| 46 | + public function getKeywords () { |
| 47 | + return $this->xmlEncode( $this->keywords ); |
| 48 | + } |
| 49 | + |
| 50 | + public function getPubDate() { |
| 51 | + return $this->pubDate; |
| 52 | + } |
| 53 | + |
| 54 | + function formatTime( $ts ) { |
| 55 | + // need to use RFC 822 time format at least for rss2.0 |
| 56 | + return gmdate( 'Y-m-d\TH:i:s', wfTimestamp( TS_UNIX, $ts ) ); |
| 57 | + } |
| 58 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/GoogleNewsSitemap/FeedSMItem.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 59 | + native |
Index: trunk/extensions/GoogleNewsSitemap/SitemapFeed.php |
— | — | @@ -0,0 +1,74 @@ |
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 4 | + |
| 5 | +class SitemapFeed extends FeedSMItem { |
| 6 | + private $writer; |
| 7 | + |
| 8 | + function __construct() { |
| 9 | + global $wgOut; |
| 10 | + $this->writer = new XMLWriter(); |
| 11 | + $wgOut->disable(); |
| 12 | + } |
| 13 | + /** |
| 14 | + * Output feed headers |
| 15 | + **/ |
| 16 | + function outHeader() { |
| 17 | + global $wgOut; |
| 18 | + global $wgRequest; |
| 19 | + |
| 20 | + // FIXME: Why can't we just pick one mime type and always send that? |
| 21 | + $ctype = $wgRequest->getVal( 'ctype', 'application/xml' ); |
| 22 | + $allowedctypes = array( 'application/xml', 'text/xml', 'application/rss+xml', 'application/atom+xml' ); |
| 23 | + $mimetype = in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml'; |
| 24 | + header( "Content-type: $mimetype; charset=UTF-8" ); |
| 25 | + $wgOut->sendCacheControl(); |
| 26 | + |
| 27 | + $this->writer->openURI( 'php://output' ); |
| 28 | + $this->writer->setIndent( true ); |
| 29 | + $this->writer->startDocument( "1.0", "UTF-8" ); |
| 30 | + $this->writer->startElement( "urlset" ); |
| 31 | + $this->writer->writeAttribute( "xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9" ); |
| 32 | + $this->writer->writeAttribute( "xmlns:news", "http://www.google.com/schemas/sitemap-news/0.9" ); |
| 33 | + $this->writer->flush(); |
| 34 | + } |
| 35 | + /** |
| 36 | + * Output a SiteMap 0.9 item |
| 37 | + * @param FeedSMItem item to be output |
| 38 | + **/ |
| 39 | + function outItem( $item ) { |
| 40 | + |
| 41 | + $this->writer->startElement( "url" ); |
| 42 | + $this->writer->startElement( "loc" ); |
| 43 | + $this->writer->text( $item->getUrl() ); |
| 44 | + $this->writer->endElement(); |
| 45 | + $this->writer->startElement( "news:news" ); |
| 46 | + $this->writer->startElement( "news:publication_date" ); |
| 47 | + $this->writer->text( $item->getPubDate() ); |
| 48 | + $this->writer->endElement(); |
| 49 | + if ( $item->getKeywords() ) { |
| 50 | + $this->writer->startElement( "news:keywords" ); |
| 51 | + $this->writer->text( $item->getKeywords() ); |
| 52 | + $this->writer->endElement(); |
| 53 | + } |
| 54 | + $this->writer->endElement(); // end news:news |
| 55 | + if ( $item->getLastMod() ) { |
| 56 | + $this->writer->startElement( "lastmod" ); |
| 57 | + $this->writer->text( $item->getLastMod() ); |
| 58 | + $this->writer->endElement(); |
| 59 | + } |
| 60 | + if ( $item->getPriority() ) { |
| 61 | + $this->writer->startElement( "priority" ); |
| 62 | + $this->writer->text( $item->getPriority() ); |
| 63 | + $this->writer->endElement(); |
| 64 | + } |
| 65 | + $this->writer->endElement(); // end url |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Output SiteMap 0.9 footer |
| 70 | + **/ |
| 71 | + function outFooter() { |
| 72 | + $this->writer->endDocument(); |
| 73 | + $this->writer->flush(); |
| 74 | + } |
| 75 | +} |
Property changes on: trunk/extensions/GoogleNewsSitemap/SitemapFeed.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 76 | + native |