From: Brion Vibber Date: Wed, 2 Jul 2008 22:52:22 +0000 (+0000) Subject: Attempt to clean up some of the insanity in creating meta and link tags in the headers. X-Git-Tag: 1.31.0-rc.0~46790 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=f78f3ee864159f45b61e82da74b3660d3c8125fb;p=lhc%2Fweb%2Fwiklou.git Attempt to clean up some of the insanity in creating meta and link tags in the headers. Values are now escaped consistently, which should be a good thing. :) --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 99c752be27..8226cb2fbc 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1357,8 +1357,8 @@ class OutputPage { } $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n"; $ret .= "\n" . htmlspecialchars( $this->getHTMLTitle() ) . "\n"; - array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) ); - + $this->addMeta( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ); + $ret .= $this->getHeadLinks(); global $wgStylePath; if( $this->isPrintable() ) { @@ -1381,13 +1381,38 @@ class OutputPage { $ret .= "\n"; return $ret; } + + protected function addDefaultMeta() { + global $wgVersion; + $this->addMeta( "generator", "MediaWiki $wgVersion" ); + + $p = $this->mRobotpolicy; + if( $p !== '' && $p != 'index,follow' ) { + // http://www.robotstxt.org/wc/meta-user.html + // Only show if it's different from the default robots policy + $this->addMeta( 'robots', $p ); + } + + if ( count( $this->mKeywords ) > 0 ) { + $strip = array( + "/<.*?>/" => '', + "/_/" => ' ' + ); + $this->addMeta( 'keywords', preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ) ) ); + } + } /** * @return string HTML tag links to be put in the header. */ public function getHeadLinks() { - global $wgRequest, $wgFeed, $wgVersion; - $ret = "\n"; + global $wgRequest, $wgFeed; + + // Ideally this should happen earlier, somewhere. :P + $this->addDefaultMeta(); + + $tags = array(); + foreach ( $this->mMetatags as $tag ) { if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) { $a = 'http-equiv'; @@ -1395,30 +1420,13 @@ class OutputPage { } else { $a = 'name'; } - $ret .= "\n"; - } - - $p = $this->mRobotpolicy; - if( $p !== '' && $p != 'index,follow' ) { - // http://www.robotstxt.org/wc/meta-user.html - // Only show if it's different from the default robots policy - $ret .= "\n"; - } - - if ( count( $this->mKeywords ) > 0 ) { - $strip = array( - "/<.*?>/" => '', - "/_/" => ' ' - ); - $ret .= "\t\tmKeywords ))) . "\" />\n"; + $tags[] = Xml::element( 'meta', + array( + $a => $tag[0], + 'content' => $tag[1] ) ); } foreach ( $this->mLinktags as $tag ) { - $ret .= "\t\t $val ) { - $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\""; - } - $ret .= " />\n"; + $tags[] = Xml::element( 'link', $tag ); } if( $wgFeed ) { @@ -1429,7 +1437,7 @@ class OutputPage { # with having the same name for different feeds corresponding to # the same page, but we can't avoid that at this low a level. - $ret .= $this->feedLink( + $tags[] = $this->feedLink( $format, $link, wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) ); # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep) @@ -1444,18 +1452,18 @@ class OutputPage { if ( $wgTitle->getPrefixedText() != $rctitle->getPrefixedText() ) { global $wgSitename; - $ret .= $this->feedLink( + $tags[] = $this->feedLink( 'rss', $rctitle->getFullURL( 'feed=rss' ), wfMsg( 'site-rss-feed', $wgSitename ) ); - $ret .= $this->feedLink( + $tags[] = $this->feedLink( 'atom', $rctitle->getFullURL( 'feed=atom' ), wfMsg( 'site-atom-feed', $wgSitename ) ); } } - return $ret; + return implode( "\n\t\t", $tags ) . "\n"; } /** @@ -1488,7 +1496,7 @@ class OutputPage { 'rel' => 'alternate', 'type' => "application/$type+xml", 'title' => $text, - 'href' => $url ) ) . "\n"; + 'href' => $url ) ); } /**