Changeset 726

Show
Ignore:
Timestamp:
08/19/2007 08:41:38 PM (3 years ago)
Author:
JavaWoman
Message:
  • fixes a number of notices that prevented a feed from being displayed directly in the browser, (or as an aggregated feed via the {{rss}} action)
  • some other small bugs fixed as well
  • added @todo and @@@ markers in the source for further issues to be resolved (see #552 a.o); see also remarks about usage of the $item->source attribute (currently used only in an RSS 1.0 feed as a dc:source element)
  • corrects @since tag in recentchanges.xml.php


refs #496,
refs #552

Location:
trunk/handlers
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/handlers/comments.xml/comments.xml.php

    r690 r726  
    1414 * @access      public 
    1515 * @since       1.1.7 
     16 * 
    1617 * @uses        FeedCreator 
    1718 * @uses        Config::$base_url 
     
    2223 * @uses        Wakka::LoadRecentComments() 
    2324 * @uses        Wakka::StaticHref() 
    24  *  
     25 * 
     26 * @input       string  $f      optional GET parameter: output format, can be any of the 
     27 *                                      following: RSS0.91, RSS1.0, RSS2.0, ATOM1.0 
     28 *                                      default: RSS2.0 
     29 *                                      the default can be overridden by providing a URL parameter 'f'. 
     30 * @output      feed for recent comments in the specified format. 
    2531 * @todo        move some defaults to wiki configuration files 
    2632 * @todo        add flexible filtering support 
     
    3036 * @todo        use stylesheet compatible with multiple feed formats 
    3137 * @todo        allow feed for one page only, e.g. Feed for comments on my userpage only. Perhaps by adding params in $_GET. 
    32  * 
    33  * @input       string  $f      optional: output format, can be any of the following:  
    34  *                              RSS0.91, RSS1.0, RSS2.0, ATOM1.0 
    35  *                              default: RSS2.0 
    36  *                              the default format can be overridden by providing a URL parameter 'f'. 
    37  * @output      feed for recently changed pages in the specified format. 
     38 * @todo        replace htmlspecialchars() in FeedCreator with our secure version (!) 
     39 * @todo        either do not escape a <link> in FeedCreator, or feed it a URL that 
     40 *                      does not already have '&' in a URL escaped (as Href() is doing!) 
     41 *                      because it gets "double-escaped" now; in fact, I think it should not 
     42 *                      be escaped at all in a feed, only in HTML 
     43 * @todo        review whether page, or actual comment, should be used for the item 
     44 *                      'source' attribute in RSS 1.0 
     45 * @todo        replace current feed image 'images/wikka_logo.jpg' by a more 
     46 *                      appropriate smaller feed image 
    3847 */ 
    3948 
     
    7887//get URL parameters 
    7988$formats = explode(",",FEED_VALID_FORMATS); 
    80 $f = (in_array($_GET['f'], $formats))? $_GET['f'] : FEED_DEFAULT_OUTPUT_FORMAT; 
     89#$f = (in_array($_GET['f'], $formats))? $_GET['f'] : FEED_DEFAULT_OUTPUT_FORMAT; 
     90$f = (isset($_GET['f']) && in_array($_GET['f'], $formats)) ? $_GET['f'] : FEED_DEFAULT_OUTPUT_FORMAT; 
    8191 
    8292//create object 
     
    97107$rss->descriptionTruncSize = FEED_DESCRIPTION_TRUNCATE_SIZE; 
    98108$rss->descriptionHtmlSyndicated = FEED_DESCRIPTION_HTML; 
    99 $rss->link = $this->Href('', $this->GetConfigValue('root_page'));       // just $this->Href() should do it! 
    100 $rss->syndicationURL = $this->Href($this->method,'','f='.$f); 
     109$rss->link = $this->Href('', $this->GetConfigValue('root_page')); 
     110$rss->syndicationURL = $this->Href($this->handler,'','f='.$f); 
    101111 
    102112//create feed image 
     
    105115$image->title = FEED_IMAGE_TITLE; 
    106116$image->url = FEED_IMAGE_URL; 
    107 $image->link = $this->Href('', $this->GetConfigValue('root_page'));     // just $this->Href() should do it! 
     117$image->link = $this->Href('', $this->GetConfigValue('root_page')); 
    108118$image->description = FEED_IMAGE_DESCRIPTION; 
    109119$image->descriptionTruncSize = FEED_DESCRIPTION_TRUNCATE_SIZE; 
     
    114124$n = (int) $n; 
    115125// get feed items 
    116 // To optimize memory usage, we should load the minimum items. But, we must load  
     126// To optimize memory usage, we should load the minimum items. But, we must load 
    117127// more than what we need, because we may have no rights on some items. 
    118128// Twice the number we need is just an arbitrary value!!! (2*$n) 
     
    131141                $item->title = $comment['page_tag'];  
    132142                $item->link = $this->Href('', $comment['page_tag'], 'show_comments=1').'#comment_'.$comment['id']; 
     143                // @@@ ^ uses &amp;amp; in all formats - this is FC escaping the &amp; that Href() outputs 
     144                // WARNING: the double escape comes from the use of htmlspecialchars() 
     145                // see also recentchanges.xml.php 
    133146                $item->date = date('r', strtotime($comment['time']));  
    134147                $item->description = 'By '.$comment['user'].': '.$comment['comment']."\n"; 
    135148                #$item->source = $this->GetConfigValue('base_url'); 
    136                 $item->source = $this->base_url;        // @@@ JW: should link to actual comment, I think 
    137                 if ($f == 'ATOM1.0' || $f == 'RSS1.0')  
     149                #$item->source = $this->base_url;       // home page 
     150                // @@@ ^ JW: should link to actual comment, or (maybe) the page that has the comment 
     151/* 
     152http://dublincore.org/documents/1999/07/02/dces/ 
     153Element: Source 
     154 
     155  Name:        Source 
     156  Identifier:  Source 
     157  Definition:  A Reference to a resource from which the present resource 
     158               is derived. 
     159  Comment:     The present resource may be derived from the Source resource 
     160               in whole or in part.  Recommended best practice is to reference  
     161               the resource by means of a string or number conforming to a  
     162               formal identification system. 
     163*/ 
     164                if ('RSS1.0' == $f)             // dc:source used only here 
     165                { 
     166                        $item->source = $this->Href('', $comment['page_tag']);  // use page, rather than comment, for now 
     167                } 
     168                #if ($f == 'ATOM1.0' || $f == 'RSS1.0') 
     169                if (('ATOM1.0' == $f || 'RSS1.0' == $f) && $this->existsUser($comment['user'])) // check for existence of user 
    138170                { 
    139171                        $item->author = $comment['user']; # RSS0.91 and RSS2.0 require authorEmail 
    140172                } 
    141                 $rss->addItem($item);  
     173                $rss->addItem($item); 
     174 
    142175                if ($c == $n)                                   // enough! 
    143176                { 
  • trunk/handlers/recentchanges.xml/recentchanges.xml.php

    r701 r726  
    77 * 
    88 * @package             Handlers 
    9  * @author              {@link http://wikkawiki.org/DarTar Dario Taraborelli} 
     9 * @author              {@link http://wikkawiki.org/DarTar Dario Taraborelli} (rewrite using FeedCreator) 
    1010 * @version             $Id$ 
    11  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
     11 * @license             http://www.gnu.org/copyleft/gpl.html GNU General Public License 
    1212 * @filesource 
    1313 * 
    1414 * @access      public 
    15  * @since       1.1.7 
     15 * @since       1.0.0 
     16 * 
    1617 * @uses        FeedCreator 
    1718 * @uses        Config::$base_url 
     
    3334 * @todo        use stylesheet compatible with multiple feed formats 
    3435 * 
    35  * @input       string  $f      optional: output format, can be any of the following:  
    36  *                              RSS0.91, RSS1.0, RSS2.0, ATOM1.0 
    37  *                              default: RSS2.0 
    38  *                              the default format can be overridden by providing a URL parameter 'f'. 
     36 * @input       string  $f      optional GET parameter: output format, can be any of the 
     37 *                                      following: RSS0.91, RSS1.0, RSS2.0, ATOM1.0 
     38 *                                      default: RSS2.0 
     39 *                                      the default can be overridden by providing a URL parameter 'f'. 
    3940 * @output      feed for recently changed pages in the specified format. 
     41 * @todo        replace htmlspecialchars() in FeedCreator with our secure version (!) 
     42 * @todo        either do not escape a <link> in FeedCreator, or feed it a URL that 
     43 *                      does not already have '&' in a URL escaped (as Href() is doing!) 
     44 *                      because it gets "double-escaped" now; in fact, I think it should not 
     45 *                      be escaped at all in a feed, only in HTML 
     46 * @todo        replace current feed image 'images/wikka_logo.jpg' by a more 
     47 *                      appropriate smaller feed image 
    4048 */ 
    4149 
     
    6169 * Logo image to be used. 
    6270 */ 
    63 if (!defined('FEED_IMAGE_PATH')) define('FEED_IMAGE_PATH', $this->StaticHref('images/wikka_logo.jpg')); 
     71if (!defined('FEED_IMAGE_URL')) define('FEED_IMAGE_URL', $this->StaticHref('images/wikka_logo.jpg')); 
    6472 
    6573/**#@+ 
     
    8593//get URL parameters 
    8694$formats = explode(',',FEED_VALID_FORMATS); 
    87 $f = (in_array($_GET['f'], $formats))? $_GET['f'] : FEED_DEFAULT_OUTPUT_FORMAT; 
     95#$f = (in_array($_GET['f'], $formats))? $_GET['f'] : FEED_DEFAULT_OUTPUT_FORMAT; 
     96$f = (isset($_GET['f']) && in_array($_GET['f'], $formats)) ? $_GET['f'] : FEED_DEFAULT_OUTPUT_FORMAT; 
    8897 
    8998//create object 
     
    104113$rss->descriptionTruncSize = FEED_DESCRIPTION_TRUNCATE_SIZE; 
    105114$rss->descriptionHtmlSyndicated = FEED_DESCRIPTION_HTML; 
    106 $rss->link = $this->Href('', $this->GetConfigValue('root_page'));       // just $this->Href() should do it! 
    107 $rss->syndicationURL = $this->Href($this->method,'','f='.$f);  
     115$rss->link = $this->Href('', $this->GetConfigValue('root_page')); 
     116$rss->syndicationURL = $this->Href($this->handler,'','f='.$f);  
    108117 
    109118//create feed image 
     
    111120$image = instantiate('FeedImage'); 
    112121$image->title = FEED_IMAGE_TITLE; 
    113 $image->url = $PHP_SELF.FEED_IMAGE_PATH; 
    114 $image->link = $this->Href('', $this->GetConfigValue('root_page'));     // just $this->Href() should do it! 
     122$image->url = FEED_IMAGE_URL; 
     123$image->link = $this->Href('', $this->GetConfigValue('root_page')); 
    115124$image->description = FEED_IMAGE_DESCRIPTION; 
    116125$image->descriptionTruncSize = FEED_DESCRIPTION_TRUNCATE_SIZE; 
     
    130139                        #$item = new FeedItem(); 
    131140                        $item = instantiate('FeedItem'); 
    132                         $item->title = $page['tag'];  
    133                         $item->link = $this->Href('show', $page['tag'], 'time='.urlencode($page['time']));  
    134                         $item->date = date('r',strtotime($page['time']));  
     141                        $item->title = $page['tag']; 
     142                        #$item->link = $this->Href('show', $page['tag'], 'time='.urlencode($page['time']));  
     143                        $item->link = $this->Href('', $page['tag'], 'time='.urlencode($page['time'])); 
     144                        // @@@ ^ uses &amp;amp; in all formats - this is FC escaping the &amp; that Href() outputs 
     145                        // WARNING: the double escape comes from the use of htmlspecialchars() 
     146                        // 1. we need to replace this with our own secure version 
     147                        // 2. we should NOT use it on already-escaped links -OR- feed it 
     148                        //    links that that have & not escaped (yet) 
     149                        $item->date = date('r',strtotime($page['time']));       // RFC2822 
    135150                        $item->description = sprintf(FEED_ITEM_DESCRIPTION, $page['user']).($page['note'] ? ' ('.$page['note'].')' : '')."\n"; 
    136151                        #$item->source = $this->GetConfigValue('base_url'); 
    137                         $item->source = $this->base_url;        // home page    // @@@ JW: should link to actual page, I think 
    138                         #if (($f == 'ATOM1.0' || $f == 'RSS1.0') && $this->LoadUser($page['user']))// @@@ only check for existence of user here 
    139                         if (($f == 'ATOM1.0' || $f == 'RSS1.0') && $this->existsUser($page['user']))// @@@ only check for existence of user here 
     152                        #$item->source = $this->base_url;       // home page 
     153                        // @@@ JW: ^ should link to *actual* page not root 
     154/* 
     155http://dublincore.org/documents/1999/07/02/dces/ 
     156Element: Source 
     157 
     158  Name:        Source 
     159  Identifier:  Source 
     160  Definition:  A Reference to a resource from which the present resource 
     161               is derived. 
     162  Comment:     The present resource may be derived from the Source resource 
     163               in whole or in part.  Recommended best practice is to reference  
     164               the resource by means of a string or number conforming to a  
     165               formal identification system. 
     166*/ 
     167                        if ('RSS1.0' == $f)             // dc:source used only here 
     168                        { 
     169                                $item->source = $this->Href('', $page['tag']);  // correct, I think, but actually redundant -- JW 
     170                        } 
     171                        #if (($f == 'ATOM1.0' || $f == 'RSS1.0') && $this->LoadUser($page['user']))     //only check for existence of user here 
     172                        if (('ATOM1.0' == $f || 'RSS1.0' == $f) && $this->existsUser($page['user']))    // check for existence of user 
    140173                        { 
    141174                                $item->author = $page['user']; # RSS0.91 and RSS2.0 require authorEmail 
    142175                        } 
    143                         $rss->addItem($item);  
     176                        $rss->addItem($item); 
    144177                } 
    145178        } 
    146 }  
     179} 
    147180 
    148181//output feed