User:Sysy~metawiki/Scott Elcomb's RSS hack

Cached from

Please note that in order to authenticate, the users' name and password need to be sent to the script in plaintext... Using HTTPS (SSL, GET or POST) to access the feed generator is highly recommended.

Interrupted during Customizable MediaWiki/RSS Engine test - Temp Storage - Current time is 28minutesEdit

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use SAL::DBI;
# // Configuration
my $mediawiki_name = 'MyWiki';
my $mediawiki_url = 'http://localhost/mediawiki/index.php';
my $mediawiki_description = 'This is MyWiki';
# // Get parameters
my $q = new CGI;
my $self_url = $q->script_name();
my $user = $q->param('u');
my $pass = $q->param('p');
# // Setup database interface
my $dbo_factory = new SAL::DBI;
my $dbo_data = $dbo_factory->spawn_mysql('localhost','wikidbuser','wikidbpass','wikidb');
my $dbo_data2 = $dbo_factory->spawn_mysql('localhost','wikidbuser','wikidbpass','wikidb');
# // NOTE:  SAL stores SQL datasets as 2D arrays, accessible like so: $dbo_data->{data}->[$recordNum][$fieldNum]
# // Authenticate the user and password
my $SQL_auth_query = qq[SELECT count(user_id) FROM user WHERE (user_name='$user') AND (user_password = md5(concat(user_id,'-',md5('$pass'))))];
if ($dbo_data->{data}->[0][0] != 1) { die('Not Authorized!'); }
# // Get the user's watchlist
my $SQL_watchlist_query = qq[SELECT a.wl_title, a.wl_namespace FROM watchlist AS a, user AS b WHERE (a.wl_user=b.user_id) AND (b.user_name='$user')];
# // NOTE:  The SAL execute method returns the width and height of the dataset...
my ($w, $h) = $dbo_data->execute(qq[$SQL_watchlist_query]);
# // Start the RSS document
my $canvas = qq[<rss version="0.91">
# // Loop through the items
foreach my $i (0 .. $h) {
        my $mediawiki_item_title = $dbo_data->{data}->[$i][0];
        my $mediawiki_item_namespace = $dbo_data->{data}->[$i][1];
        my $SQL_item_query = '';
        if ($mediawiki_item_namespace == 0) {
                my $mediawiki_item_link = $mediawiki_url . '/' . $mediawiki_item_title;
                $SQL_item_query = qq[SELECT a.old_text FROM text AS a, page AS b WHERE (a.old_id = b.page_latest) AND (b.page_title='$mediawiki_item_title')];
                my $mediawiki_item_description = $dbo_data2->{data}[0][0];
                $canvas .= qq[    <item>
# // Close the RSS document
$canvas .= qq[  </channel>
# // And send it to the client
print "Content-type: text/xml\n\n" . $canvas;


<rss version="0.91">
    <description>This is MyWiki</description>
      <description>Wiki software successfully installed.
Please see [ documentation on customizing the interface]
and the [ User's Guide] for usage and configuration help.
Adding Edits</description>
      <description>This is a test
Now watching...</description>