r29751 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29750‎ | r29751 | r29752 >
Date:17:32, 14 January 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
Be more careful when building RSS-Link (avoid illegal title errors if there are problems)
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_RSSlink.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_RSSlink.php
@@ -13,6 +13,7 @@
1414 class SMWRSSResultPrinter extends SMWResultPrinter {
1515 protected $title = '';
1616 protected $description = '';
 17+ protected $rsslinktitle; // just a cache
1718
1819 protected function readParameters($params,$outputmode) {
1920 SMWResultPrinter::readParameters($params,$outputmode);
@@ -22,6 +23,7 @@
2324 if (array_key_exists('rssdescription', $this->m_params)) {
2425 $this->description = $this->m_params['rssdescription'];
2526 }
 27+ $this->rsslinktitle = '';
2628 }
2729
2830 public function getResult($results, $params, $outputmode) { // skip all checks, the result is never populated
@@ -38,7 +40,10 @@
3941 $label = wfMsgForContent('smw_rss_link');
4042 }
4143 $result .= $this->getRSSLink($outputmode, $res, $label);
42 - smwfRequireHeadItem('rss' . $smwgIQRunningNumber, '<link rel="alternate" type="application/rss+xml" title="' . $this->title . '" href="' . $this->getRSSURL($res) . '" />');
 44+ $rurl = $this->getRSSURL($res);
 45+ if ($rurl != false) {
 46+ smwfRequireHeadItem('rss' . $smwgIQRunningNumber, '<link rel="alternate" type="application/rss+xml" title="' . $this->title . '" href="' . $rurl . '" />');
 47+ }
4348 return $result;
4449 }
4550
@@ -51,11 +56,15 @@
5257
5358 protected function getRSSURL($res) {
5459 $title = Title::newFromText( $this->getRSSTitle($res) );
 60+ if ($title === NULL) return false; // this should not happen, but there can always be unexpected problems in user input strings
5561 return $title->getFullURL();
5662 }
5763
5864 protected function getRSSTitle($res) {
59 - $result = $res->getQueryTitle();
 65+ if ($this->rsslinktitle != '') {
 66+ return $this->rsslinktitle;
 67+ }
 68+ $this->rsslinktitle = $res->getQueryTitle();
6069 $params = array('rss=1');
6170 if (array_key_exists('limit', $this->m_params)) {
6271 $params[] = 'limit=' . $this->m_params['limit'];
@@ -68,9 +77,9 @@
6978 }
7079 foreach ($params as $p) {
7180 $p = str_replace(array('/','=','-','%'),array('-2F','-3D','-2D','-'), rawurlencode($p));
72 - $result .= '/' . $p;
 81+ $this->rsslinktitle .= '/' . $p;
7382 }
74 - return $result;
 83+ return $this->rsslinktitle;
7584 }
7685
7786 }

Status & tagging log