r68552 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68551‎ | r68552 | r68553 >
Date:04:13, 25 June 2010
Author:juliano
Status:deferred
Tags:
Comment:
Wikilog feeds by namespace.
Modified paths:
  • /trunk/extensions/Wikilog/SpecialWikilog.php (modified) (history)
  • /trunk/extensions/Wikilog/Wikilog.i18n.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogFeed.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogQuery.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikilog/WikilogFeed.php
@@ -65,7 +65,7 @@
6666 * to this list means that feed caching should be revisited. Parameters
6767 * must be listed as keys.
6868 */
69 - public static $paramWhitelist = array( 'show' => true );
 69+ public static $paramWhitelist = array( 'wikilog' => true, 'show' => true );
7070
7171 /**
7272 * WikilogFeed constructor.
@@ -362,7 +362,6 @@
363363 if ( !$limit ) $limit = $wgWikilogNumArticles;
364364 parent::__construct( $title, $format, $query, $limit );
365365 $this->mSiteFeed = $this->mQuery->getWikilogTitle() === null;
366 -
367366 }
368367
369368 public function getIndexField() {
@@ -375,10 +374,12 @@
376375 }
377376
378377 public function getFeedObject() {
379 - if ( $this->mSiteFeed ) {
 378+ if ( $this->mQuery->getWikilogTitle() ) {
 379+ return $this->getWikilogFeedObject( $this->mQuery->getWikilogTitle() );
 380+ } elseif ( $this->mQuery->getNamespace() !== false ) {
 381+ return $this->getNamespaceFeedObject( $this->mQuery->getNamespace() );
 382+ } else {
380383 return $this->getSiteFeedObject();
381 - } else {
382 - return $this->getWikilogFeedObject( $this->mQuery->getWikilogTitle() );
383384 }
384385 }
385386
@@ -414,6 +415,47 @@
415416 }
416417
417418 /**
 419+ * Generates and populates a WlSyndicationFeed object for a given namespace.
 420+ *
 421+ * @param $ns Namespace.
 422+ * @return Feed object.
 423+ */
 424+ protected function getNamespaceFeedObject( $ns ) {
 425+ global $wgWikilogFeedClasses, $wgFavicon, $wgLogo;
 426+ global $wgContLang, $wgContLanguageCode;
 427+
 428+ $title = wfMsgForContent( 'wikilog-feed-ns-title', $wgContLang->getFormattedNsText( $ns ) );
 429+ $subtitle = wfMsgExt( 'wikilog-feed-description', array( 'parse', 'content' ) );
 430+
 431+ $updated = $this->mDb->selectField(
 432+ array( 'wikilog_wikilogs', 'page' ),
 433+ 'MAX(wlw_updated)',
 434+ array(
 435+ 'wlw_page = page_id',
 436+ 'page_namespace' => $ns
 437+ ),
 438+ __METHOD__
 439+ );
 440+ if ( !$updated ) $updated = wfTimestampNow();
 441+
 442+ $feed = new $wgWikilogFeedClasses[$this->mFormat](
 443+ $this->mTitle->getFullUrl(),
 444+ wfMsgForContent( 'wikilog-feed-title', $title, $wgContLanguageCode ),
 445+ $updated,
 446+ $this->mTitle->getFullUrl()
 447+ );
 448+ $feed->setSubtitle( new WlTextConstruct( 'html', $subtitle ) );
 449+ $feed->setLogo( wfExpandUrl( $wgLogo ) );
 450+ if ( $wgFavicon !== false ) {
 451+ $feed->setIcon( wfExpandUrl( $wgFavicon ) );
 452+ }
 453+ if ( $this->mCopyright ) {
 454+ $feed->setRights( new WlTextConstruct( 'html', $this->mCopyright ) );
 455+ }
 456+ return $feed;
 457+ }
 458+
 459+ /**
418460 * Generates and populates a WlSyndicationFeed object for the given
419461 * wikilog. Caches objects whenever possible.
420462 *
@@ -574,8 +616,13 @@
575617 * Returns the keys for the timestamp and feed output in the object cache.
576618 */
577619 public function getCacheKeys() {
578 - $title = $this->mQuery->getWikilogTitle();
579 - $id = $title ? 'id:' . $title->getArticleId() : 'site';
 620+ if ( ( $title = $this->mQuery->getWikilogTitle() ) ) {
 621+ $id = 'id:' . $title->getArticleId();
 622+ } elseif ( ( $ns = $this->mQuery->getNamespace() ) ) {
 623+ $id = 'ns:' . $ns;
 624+ } else {
 625+ $id = 'site';
 626+ }
580627 $ft = 'show:' . $this->mQuery->getPubStatus() .
581628 ':limit:' . $this->mLimit;
582629 return array(
Index: trunk/extensions/Wikilog/SpecialWikilog.php
@@ -119,7 +119,7 @@
120120 global $wgRequest, $wgFeedLimit;
121121
122122 $opts = $this->getDefaultOptions();
123 - $opts->fetchValuesFromRequest( $wgRequest, array( 'show', 'limit' ) );
 123+ $opts->fetchValuesFromRequest( $wgRequest, array( 'wikilog', 'show', 'limit' ) );
124124 $opts->validateIntBounds( 'limit', 0, $wgFeedLimit );
125125 return $opts;
126126 }
@@ -191,8 +191,8 @@
192192
193193 # Add feed links.
194194 $wgOut->setSyndicated();
195 - if ( isset( $qarr['show'] ) ) {
196 - $altquery = wfArrayToCGI( array_intersect_key( $qarr, WikilogItemFeed::$paramWhitelist ) );
 195+ $altquery = wfArrayToCGI( array_intersect_key( $qarr, WikilogItemFeed::$paramWhitelist ) );
 196+ if ( $altquery ) {
197197 $wgOut->setFeedAppendQuery( $altquery );
198198 }
199199
@@ -400,13 +400,20 @@
401401 * @return Wikilog query object.
402402 */
403403 public static function getQuery( $opts ) {
 404+ global $wgWikilogNamespaces;
 405+
404406 $query = new WikilogItemQuery();
405407 $query->setPubStatus( $opts['show'] );
406 - if ( $opts['wikilog'] && ( $t = Title::newFromText( $opts['wikilog'] ) ) ) {
407 - if ( $t->getText() == '*' ) {
408 - $query->setNamespace( $t->getNamespace() );
 408+ if ( $opts['wikilog'] ) {
 409+ $t = Title::newFromText( $opts['wikilog'] );
 410+ if ( $t && in_array( $t->getNamespace(), $wgWikilogNamespaces ) ) {
 411+ if ( $t->getText() == '*' ) {
 412+ $query->setNamespace( $t->getNamespace() );
 413+ } else {
 414+ $query->setWikilogTitle( $t );
 415+ }
409416 } else {
410 - $query->setWikilogTitle( $t );
 417+ $query->setEmpty();
411418 }
412419 }
413420 if ( ( $t = $opts['category'] ) ) {
Index: trunk/extensions/Wikilog/WikilogQuery.php
@@ -46,6 +46,12 @@
4747 protected $mDefaultOptions = array();
4848
4949 /**
 50+ * Whether the query should always return nothing (when invalid options
 51+ * are provided, for example).
 52+ */
 53+ protected $mEmpty = false;
 54+
 55+ /**
5056 * Constructor.
5157 */
5258 public function __construct() {
@@ -86,6 +92,12 @@
8793 }
8894
8995 /**
 96+ * Filter is always returns empty.
 97+ */
 98+ public function setEmpty( $empty = true ) { $this->mEmpty = $empty; }
 99+ public function getEmpty() { return $this->mEmpty; }
 100+
 101+ /**
90102 * Generate and return query information.
91103 * @param $db Database Database object used to encode table names, etc.
92104 * @param $opts mixed Misc query options.
@@ -312,10 +324,15 @@
313325 $q_options = array();
314326 $q_joins = $wlp_tables['join_conds'];
315327
 328+ # Invalid filter.
 329+ if ( $this->mEmpty ) {
 330+ $q_conds[] = '0=1';
 331+ }
 332+
316333 # Filter by wikilog name.
317334 if ( $this->mWikilogTitle !== null ) {
318335 $q_conds['wlp_parent'] = $this->mWikilogTitle->getArticleId();
319 - } elseif ( $this->mNamespace ) {
 336+ } elseif ( $this->mNamespace !== false ) {
320337 $q_conds['p.page_namespace'] = $this->mNamespace;
321338 }
322339
@@ -380,7 +397,7 @@
381398
382399 if ( $this->mNeedWikilogParam && $this->mWikilogTitle ) {
383400 $query['wikilog'] = $this->mWikilogTitle->getPrefixedDBKey();
384 - } elseif ( $this->mNamespace ) {
 401+ } elseif ( $this->mNamespace !== false ) {
385402 $query['wikilog'] = Title::makeTitle( $this->mNamespace, "*" )->getPrefixedDBKey();
386403 }
387404
@@ -525,7 +542,7 @@
526543 * precedence over this filter.
527544 * @param $ns Namespace to query for.
528545 */
529 - public function setNamespace ( $ns ) {
 546+ public function setNamespace( $ns ) {
530547 $this->mNamespace = $ns;
531548 }
532549
@@ -637,6 +654,11 @@
638655 $q_options = array();
639656 $q_joins = $wlc_tables['join_conds'];
640657
 658+ # Invalid filter.
 659+ if ( $this->mEmpty ) {
 660+ $q_conds[] = '0=1';
 661+ }
 662+
641663 # Filter by moderation status.
642664 if ( $this->mModStatus == self::MS_ACCEPTED ) {
643665 $q_conds['wlc_status'] = 'OK';
@@ -658,7 +680,7 @@
659681 } elseif ( $this->mWikilog !== null ) {
660682 $join_wlp = true;
661683 $q_conds['wlp_parent'] = $this->mWikilog->getArticleId();
662 - } elseif ( $this->mNamespace ) {
 684+ } elseif ( $this->mNamespace !== false ) {
663685 $q_conds['c.page_namespace'] = $this->mNamespace;
664686 }
665687
@@ -706,7 +728,7 @@
707729 $query['item'] = $this->mItem->mTitle->getPrefixedDBKey();
708730 } elseif ( $this->mWikilog ) {
709731 $query['wikilog'] = $this->mWikilog->getPrefixedDBKey();
710 - } elseif ( $this->mNamespace ) {
 732+ } elseif ( $this->mNamespace !== false ) {
711733 $query['wikilog'] = Title::makeTitle( $this->mNamespace, "*" )->getPrefixedDBKey();
712734 }
713735
Index: trunk/extensions/Wikilog/Wikilog.i18n.php
@@ -119,6 +119,7 @@
120120
121121 # Atom and RSS feeds
122122 'wikilog-feed-title' => '{{SITENAME}} - $1 [$2]', # $1 = title, $2 = content language
 123+ 'wikilog-feed-ns-title' => '$1 wikilog articles', # $1 = namespace name
123124 'wikilog-feed-description' => 'Read the most recent posts in this feed.',
124125 'wikilog-comment-feed-title1' => 'Comment by $2 (#$1)',
125126 'wikilog-comment-feed-title2' => 'Comment by $2 to $3 (#$1)',

Status & tagging log