https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112315

Revision: 112315
Author:   wikinaut
Date:     2012-02-24 11:47:26 +0000 (Fri, 24 Feb 2012)
Log Message:
-----------
improved code legibility function namespacePrefixedQuery

Modified Paths:
--------------
    trunk/extensions/RSS/RSSData.php

Modified: trunk/extensions/RSS/RSSData.php
===================================================================
--- trunk/extensions/RSS/RSSData.php    2012-02-24 11:37:35 UTC (rev 112314)
+++ trunk/extensions/RSS/RSSData.php    2012-02-24 11:47:26 UTC (rev 112315)
@@ -28,14 +28,12 @@
                        $defaultNS = "";
                }
 
-               $q = "/rss/channel/item";
-               $q = preg_replace( '#(::|/\s*|\A)(?![/@].+?|[a-z\-]+::)#', '$1' 
. $defaultNS . '$2', $q );
-               $items = $xpath->query( $q ); // is it an RSS feed ?
+               // is it an RSS feed ?
+               $items = $xpath->query( $this->namespacePrefixedQuery( 
"/rss/channel/item", $defaultNS ) ); 
 
                if ( $items->length === 0 ) {
-                       $q = "/feed/entry";
-                       $q = preg_replace( 
'#(::|/\s*|\A)(?![/@].+?|[a-z\-]+::)#', '$1' . $defaultNS . '$2', $q );
-                       $items = $xpath->query( $q ); // is it an ATOM feed ?
+                        // or is it an ATOM feed ?
+                       $items = $xpath->query( $this->namespacePrefixedQuery( 
"/feed/entry", $defaultNS ) );
                }
 
                if( $items->length !== 0 ) {
@@ -63,6 +61,14 @@
                }
        }
 
+       protected function namespacePrefixedQuery( $query, $namespace = "" ) {
+               if ( $namespace !== "" ) {
+                       $ret = preg_replace( 
'#(::|/\s*|\A)(?![/@].+?|[a-z\-]+::)#', '$1' . $namespace . '$2', $query );
+               } else {
+                       $ret = $query;
+               }
+               return $ret;
+       }
        /**
         * Return a string that will be used to map RSS elements that
         * contain similar data (e.g. dc:date, date, and pubDate) to the


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to