Autodiscovery <link> for RSS feed. Added helper functions for query stuff:
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 19 Mar 2004 08:05:36 +0000 (08:05 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 19 Mar 2004 08:05:36 +0000 (08:05 +0000)
appendQuery() and escapeAppendQuery() to WebRequest.

includes/OutputPage.php
includes/Skin.php
includes/SkinSmarty.php
includes/WebRequest.php

index 1ce3777..6552dd8 100644 (file)
@@ -43,7 +43,7 @@ class OutputPage {
        # To add an http-equiv meta tag, precede the name with "http:"
        function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
        function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
-       function addLink( $rel, $rev, $target ) { array_push( $this->mLinktags, array( $rel, $rev, $target ) ); }
+       function addLink( $rel, $rev, $target, $type="" ) { array_push( $this->mLinktags, array( $rel, $rev, $target, $type ) ); }
 
        # checkLastModified tells the client to use the client-cached page if
        # possible. If sucessful, the OutputPage is disabled so that
@@ -544,7 +544,7 @@ class OutputPage {
 
        /* private */ function headElement()
        {
-               global $wgDocType, $wgDTD, $wgUser, $wgLanguageCode, $wgOutputEncoding, $wgLang;
+               global $wgDocType, $wgDTD, $wgUser, $wgLanguageCode, $wgOutputEncoding, $wgLang, $wgRequest;
 
                $ret = "<!DOCTYPE HTML PUBLIC \"$wgDocType\"\n        \"$wgDTD\">\n";
 
@@ -575,8 +575,13 @@ class OutputPage {
                        $ret .= "<link ";
                        if ( "" != $tag[0] ) { $ret .= "rel=\"{$tag[0]}\" "; }
                        if ( "" != $tag[1] ) { $ret .= "rev=\"{$tag[1]}\" "; }
+                       if ( !empty( $tag[3] ) ) { $ret .= "type=\"{$tag[3]}\" "; }
                        $ret .= "href=\"{$tag[2]}\">\n";
                }
+               if( $this->isSyndicated() ) {
+                       $link = $wgRequest->escapeAppendQuery( "feed=rss" );
+                       $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS' href='$link'>\n";
+               }
                $sk = $wgUser->getSkin();
                $ret .= $sk->getHeadScripts();
                $ret .= $sk->getUserStyles();
index ffb671f..0b677fa 100644 (file)
@@ -479,7 +479,7 @@ class Skin {
 
        function printableLink()
        {
-               global $wgOut, $wgFeedClasses;
+               global $wgOut, $wgFeedClasses, $wgRequest;
 
                $baseurl = $_SERVER['REQUEST_URI'];
                if( strpos( "?", $baseurl ) == false ) {
@@ -488,11 +488,13 @@ class Skin {
                        $baseurl .= "&";
                }
                $baseurl = htmlspecialchars( $baseurl );
+               $printurl = $wgRequest->escapeAppendQuery( "printable=yes" );
                
-               $s = "<a href=\"{$baseurl}printable=yes\">" . wfMsg( "printableversion" ) . "</a>";
+               $s = "<a href=\"$printurl\">" . wfMsg( "printableversion" ) . "</a>";
                if( $wgOut->isSyndicated() ) {
                        foreach( $wgFeedClasses as $format => $class ) {
-                               $s .= " | <a href=\"{$baseurl}feed={$format}\">{$format}</a>";
+                               $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
+                               $s .= " | <a href=\"$feedurl\">{$format}</a>";
                        }
                }
                return $s;
index 8e2a3c4..54049e1 100644 (file)
@@ -1,4 +1,21 @@
 <?php
+# Copyright (C) 2003 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
 
 # And turn on $wgUseSmarty so this file gets included
 
index 4fc7f94..c75763e 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+# Deal with importing all those nasssty globals and things
+# 
+# Copyright (C) 2003 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
 
 # Hypothetically, we could use a WebRequest object to fake a
 # self-contained request.
@@ -6,7 +25,6 @@
 ## Enable this to debug total elimination of register_globals
 #define( "DEBUG_GLOBALS", 1 );
 
-# Deal with importing all those nasssty globals and things
 class WebRequest {
        function WebRequest() {
                if( defined('DEBUG_GLOBALS') ) error_reporting(E_ALL);
@@ -101,6 +119,35 @@ class WebRequest {
        function checkSessionCookie() {
                return isset( $_COOKIE[ini_get("session.name")] );
        }
+       
+       function getRequestURL() {
+               return $_SERVER['REQUEST_URI'];
+       }
+       
+       function getFullRequestURL() {
+               global $wgServer;
+               return $wgServer . $this->getRequestURL();
+       }
+       
+       # Take an arbitrary query and rewrite the present URL to include it
+       function appendQuery( $query ) {
+               global $wgTitle;
+               $basequery = "";
+               foreach( $_GET as $var => $val ) {
+                       if( $var == "title" ) continue;
+                       $basequery .= "&" . urlencode( $var ) . "=" . urlencode( $val );
+               }
+               $basequery .= "&" . $query;
+               
+               # Trim the extra &
+               $basequery = substr( $basequery, 1 );
+               return $wgTitle->getLocalURL( $basequery );
+       }
+       
+       function escapeAppendQuery( $query ) {
+               return htmlspecialchars( $this->appendQuery( $query ) );
+       }
+       
 }
 
 ?>
\ No newline at end of file