Some more RSS syndication work. <author> tags now included; Special:Newpages
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 19 Mar 2004 05:31:18 +0000 (05:31 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 19 Mar 2004 05:31:18 +0000 (05:31 +0000)
includes page text (incomplete); preliminary feed support for Recentchanges;
added RSS feed link next to printable link (incomplete).

includes/Feed.php
includes/OutputPage.php
includes/QueryPage.php
includes/Skin.php
includes/SpecialNewpages.php
includes/SpecialRecentchanges.php
languages/Language.php

index 248ba62..c7dd64c 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+# Basic support for outputting syndication feeds in RSS, other formats
+# 
+# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
+# http://www.mediawiki.org/
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or 
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# http://www.gnu.org/copyleft/gpl.html
 
 $wgFeedClasses = array(
        "rss" => "RSSFeed",
@@ -10,12 +29,14 @@ class FeedItem {
        var $Description = "";
        var $Url = "";
        var $Date = "";
+       var $Author = "";
        
-       function FeedItem( $Title, $Description, $Url, $Date = "" ) {
+       function FeedItem( $Title, $Description, $Url, $Date = "", $Author = "" ) {
                $this->Title = $Title;
                $this->Description = $Description;
                $this->Url = $Url;
                $this->Date = $Date;
+               $this->Author = $Author;
        }
        
        /* Static... */
@@ -43,6 +64,9 @@ class FeedItem {
        function getDate() {
                return $this->Date;
        }
+       function getAuthor() {
+               return $this->xmlEncode( $this->Author );
+       }
 }
 
 class ChannelFeed extends FeedItem {
@@ -66,6 +90,7 @@ class RSSFeed extends ChannelFeed {
        function outHeader() {
                global $wgVersion;
                
+               header( "Content-type: application/xml; charset=UTF-8" );
                print '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n";
                ?><rss version="2.0">
        <channel>
@@ -85,6 +110,7 @@ class RSSFeed extends ChannelFeed {
                        <link><?php print $item->getUrl() ?></link>
                        <description><?php print $item->getDescription() ?></description>
                        <?php if( $item->getDate() ) { ?><pubDate><?php print $this->formatTime( $item->getDate() ) ?></pubDate><?php } ?>
+                       <?php if( $item->getAuthor() ) { ?><author><?php print $item->getAuthor() ?></author><?php }?>
 
                </item>
 <?php
index dd2cfd6..1ce3777 100644 (file)
@@ -16,6 +16,7 @@ class OutputPage {
        var $mContainsOldMagic, $mContainsNewMagic; 
        var $mIsArticleRelated;
        var $mParserOptions;
+       var $mShowFeedLinks = false;
 
        function OutputPage()
        {
@@ -104,6 +105,8 @@ class OutputPage {
        function isArticle() { return $this->mIsarticle; }
        function setPrintable() { $this->mPrintable = true; }
        function isPrintable() { return $this->mPrintable; }
+       function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
+       function isSyndicated() { return $this->mShowFeedLinks; }
        function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
        function getOnloadHandler() { return $this->mOnloadHandler; }
        function disable() { $this->mDoNothing = true; }
index 62c5c7f..93a13bf 100644 (file)
@@ -42,14 +42,14 @@ class QueryPage {
        # real, honest-to-gosh query page.
 
        function doQuery( $offset, $limit ) {
-
                global $wgUser, $wgOut, $wgLang, $wgMiserMode;
 
                $sname = $this->getName();
                $fname = get_class($this) . "::doQuery";
 
+               $wgOut->setSyndicated( true );
+               
                if ( $this->isExpensive( ) ) {
-
                        $vsp = $wgLang->getValidSpecialPages();
                        $logpage = new LogPage( "!" . $vsp[$sname] );
                        $logpage->mUpdateRecentChanges = false;
@@ -141,23 +141,39 @@ class QueryPage {
                                $title->getText(),
                                $this->feedItemDesc( $row ),
                                $title->getFullURL(),
-                               $date);
+                               $date,
+                               $this->feedItemAuthor( $row ) );
                } else {
                        return NULL;
                }
        }
        
        function feedItemDesc( $row ) {
+               $text = "";
                if( isset( $row->cur_comment ) ) {
-                       return $row->cur_comment;
+                       $text = $row->cur_comment;
                } elseif( isset( $row->old_comment ) ) {
-                       return $row->old_comment;
+                       $text = $row->old_comment;
                } elseif( isset( $row->rc_comment ) ) {
-                       return $row->rc_comment;
+                       $text = $row->rc_comment;
+               }
+               $text = htmlspecialchars( $text );
+               
+               if( isset( $row->cur_text ) ) {
+                       $text = "<p>" . htmlspecialchars( wfMsg( "summary" ) ) . ": " . $text . "</p>\n<hr />\n<div>" .
+                               nl2br( $row->cur_text ) . "</div>";;
+               }
+               return $text;
+       }
+       
+       function feedItemAuthor( $row ) {
+               $fields = array( "cur_user_text", "old_user_text", "rc_user_text" );
+               foreach( $fields as $field ) {
+                       if( isset( $row->$field ) ) return $row->field;
                }
                return "";
        }
-
+       
        function feedTitle() {
                global $wgLanguageCode, $wgSitename, $wgLang;
                $pages = $wgLang->getValidSpecialPages();
index cd338b7..ffb671f 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+include_once( "Feed.php" );
+
 # See skin.doc
 
 # These are the INTERNAL names, which get mapped
@@ -422,7 +425,7 @@ class Skin {
 
        function pageTitleLinks()
        {
-               global $wgOut, $wgTitle, $oldid, $action, $diff, $wgUser, $wgLang, $wgUseApproval ;
+               global $wgOut, $wgTitle, $oldid, $action, $diff, $wgUser, $wgLang, $wgUseApproval;
 
                $s = $this->printableLink();
                if ( wfMsg ( "disclaimers" ) != "-" ) $s .= " | " . $this->makeKnownLink( wfMsg( "disclaimerpage" ), wfMsg( "disclaimers" ) ) ;
@@ -476,17 +479,22 @@ class Skin {
 
        function printableLink()
        {
-               global $wgOut, $wgTitle, $oldid, $action;
+               global $wgOut, $wgFeedClasses;
 
-               $q = "";
-               foreach( $_GET as $var => $val ) {
-                       if( $var != "title" && $var != "printable" )
-                               $q .= urlencode( $var ) . "=" . urlencode( $val );
+               $baseurl = $_SERVER['REQUEST_URI'];
+               if( strpos( "?", $baseurl ) == false ) {
+                       $baseurl .= "?";
+               } else {
+                       $baseurl .= "&";
                }
-               if( !empty( $q ) ) $q .= "&";
+               $baseurl = htmlspecialchars( $baseurl );
                
-               $s = $this->makeKnownLink( $wgTitle->getPrefixedText(),
-                 WfMsg( "printableversion" ), "{$q}printable=yes" );
+               $s = "<a href=\"{$baseurl}printable=yes\">" . wfMsg( "printableversion" ) . "</a>";
+               if( $wgOut->isSyndicated() ) {
+                       foreach( $wgFeedClasses as $format => $class ) {
+                               $s .= " | <a href=\"{$baseurl}feed={$format}\">{$format}</a>";
+                       }
+               }
                return $s;
        }
 
index f142a20..86f46d4 100644 (file)
@@ -14,7 +14,7 @@ class NewPagesPage extends QueryPage {
 
        function getSQL( $offset, $limit ) {
                return "SELECT rc_namespace AS cur_namespace, rc_title AS cur_title,rc_user AS cur_user,rc_user_text AS cur_user_text,rc_comment as cur_comment," .
-                 "rc_timestamp AS cur_timestamp,length(cur_text) as cur_length FROM recentchanges,cur " .
+                 "rc_timestamp AS cur_timestamp,length(cur_text) as cur_length,cur_text FROM recentchanges,cur " .
                  "WHERE rc_cur_id=cur_id AND rc_new=1 AND rc_namespace=0 AND cur_is_redirect=0 " .
                  "ORDER BY rc_timestamp DESC LIMIT {$offset}, {$limit}";
        }
index 732115a..46a5707 100644 (file)
@@ -1,11 +1,17 @@
 <?php
 
+include_once( "Feed.php" );
+
 function wfSpecialRecentchanges( $par )
 {
        global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname;
+       global $wgRequest, $wgSitename, $wgLanguageCode;
        global $days, $hideminor, $from, $hidebots, $hideliu; # From query string
        $fname = "wfSpecialRecentchanges";
-
+       
+       $feedFormat = $wgRequest->getVal( "feed" );
+       $feeding = ( $feedFormat == "rss" );
+       
        if( $par ) {
                $bits = preg_split( '/\s*,\s*/', trim( $par ) );
                if( in_array( "hidebots", $bits ) ) $hidebots = 1;
@@ -119,22 +125,43 @@ function wfSpecialRecentchanges( $par )
 
        $wgOut->addHTML( "{$note}\n" );
 
-       $s = $sk->beginRecentChangesList();
-       foreach( $rows as $obj ){
-               if( $limit == 0) {
-                       break; 
+       if( $feeding ) {
+               $wgOut->disable();
+               
+               $feed = new RSSFeed(
+                       $wgSitename . " - " . wfMsg( "recentchanges" ) . " [" . $wgLanguageCode . "]",
+                       htmlspecialchars( wfMsg( "recentchangestext" ) ),
+                       $wgTitle->getFullUrl() );
+               $feed->outHeader();
+               foreach( $rows as $obj ) {
+                       $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
+                       $item = new FeedItem(
+                               $title->getPrefixedText(),
+                               htmlspecialchars( $obj->rc_comment ),
+                               $title->getFullURL(),
+                               $obj->rc_timestamp,
+                               $obj->rc_user_text );
+                       $feed->outItem( $item );
                }
-
-               if ( ! ( $hideminor && $obj->rc_minor ) ) {
-                       $rc = RecentChange::newFromRow( $obj );
-                       $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user ) );
-                       --$limit;
+               $feed->outFooter();
+       } else {
+               $wgOut->setSyndicated( true );
+               $s = $sk->beginRecentChangesList();
+               foreach( $rows as $obj ){
+                       if( $limit == 0) {
+                               break; 
+                       }
+                       
+                       if ( ! ( $hideminor && $obj->rc_minor ) ) {
+                               $rc = RecentChange::newFromRow( $obj );
+                               $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user ) );
+                               --$limit;
+                       }
                }
+               $s .= $sk->endRecentChangesList();
+               $wgOut->addHTML( $s );
        }
-       $s .= $sk->endRecentChangesList();
-
        wfFreeResult( $res );
-       $wgOut->addHTML( $s );
 }
 
 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
index c580b14..ba4c587 100644 (file)
@@ -406,7 +406,8 @@ $wgLanguageNamesEn =& $wgLanguageNames;
        "Asksql"                => "Query the database",
        "Allmessages"   => "All system messages",
        "Undelete"              => "Restore deleted pages",
-       "Makesysop"             => "Turn a user into a sysop"
+       "Makesysop"             => "Turn a user into a sysop",
+       "Import"                => "Import a page with history",
 );
 
 /* private */ $wgDeveloperSpecialPagesEn = array(
@@ -1405,9 +1406,14 @@ amusement.",
 # Thumbnails
 
 "thumbnail-more"       => "Enlarge",
-"missingimage"         => "<b>Missing image</b><br><i>$1</i>\n"
-
-
+"missingimage"         => "<b>Missing image</b><br><i>$1</i>\n",
+
+# Special:Import
+"import"       => "Import pages",
+"importtext"   => "Blah blah blah",
+"importfailed" => "Import failed: $1",
+"importnotext" => "Empty or no text",
+"importsuccess"        => "Import succeeded!",
 );
 
 #--------------------------------------------------------------------------