From dc8ac4172432261faae9bb157583ddccff0c42fe Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 19 Mar 2004 08:05:36 +0000 Subject: [PATCH] Autodiscovery for RSS feed. Added helper functions for query stuff: appendQuery() and escapeAppendQuery() to WebRequest. --- includes/OutputPage.php | 9 ++++++-- includes/Skin.php | 8 ++++--- includes/SkinSmarty.php | 17 ++++++++++++++ includes/WebRequest.php | 49 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 77 insertions(+), 6 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 1ce377778d..6552dd802c 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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 = "\n"; @@ -575,8 +575,13 @@ class OutputPage { $ret .= "\n"; } + if( $this->isSyndicated() ) { + $link = $wgRequest->escapeAppendQuery( "feed=rss" ); + $ret .= "\n"; + } $sk = $wgUser->getSkin(); $ret .= $sk->getHeadScripts(); $ret .= $sk->getUserStyles(); diff --git a/includes/Skin.php b/includes/Skin.php index ffb671f9bb..0b677fa6da 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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 = "" . wfMsg( "printableversion" ) . ""; + $s = "" . wfMsg( "printableversion" ) . ""; if( $wgOut->isSyndicated() ) { foreach( $wgFeedClasses as $format => $class ) { - $s .= " | {$format}"; + $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" ); + $s .= " | {$format}"; } } return $s; diff --git a/includes/SkinSmarty.php b/includes/SkinSmarty.php index 8e2a3c472b..54049e1fca 100644 --- a/includes/SkinSmarty.php +++ b/includes/SkinSmarty.php @@ -1,4 +1,21 @@ +# 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 diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 4fc7f9499e..c75763e971 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -1,4 +1,23 @@ +# 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 -- 2.20.1