r36956 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36955‎ | r36956 | r36957 >
Date:22:52, 2 July 2008
Author:brion
Status:old
Tags:
Comment:
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. :)
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -1357,8 +1357,8 @@
13581358 }
13591359 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
13601360 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1361 - array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1362 -
 1361+ $this->addMeta( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" );
 1362+
13631363 $ret .= $this->getHeadLinks();
13641364 global $wgStylePath;
13651365 if( $this->isPrintable() ) {
@@ -1381,13 +1381,38 @@
13821382 $ret .= "</head>\n";
13831383 return $ret;
13841384 }
 1385+
 1386+ protected function addDefaultMeta() {
 1387+ global $wgVersion;
 1388+ $this->addMeta( "generator", "MediaWiki $wgVersion" );
 1389+
 1390+ $p = $this->mRobotpolicy;
 1391+ if( $p !== '' && $p != 'index,follow' ) {
 1392+ // http://www.robotstxt.org/wc/meta-user.html
 1393+ // Only show if it's different from the default robots policy
 1394+ $this->addMeta( 'robots', $p );
 1395+ }
13851396
 1397+ if ( count( $this->mKeywords ) > 0 ) {
 1398+ $strip = array(
 1399+ "/<.*?>/" => '',
 1400+ "/_/" => ' '
 1401+ );
 1402+ $this->addMeta( 'keywords', preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ) ) );
 1403+ }
 1404+ }
 1405+
13861406 /**
13871407 * @return string HTML tag links to be put in the header.
13881408 */
13891409 public function getHeadLinks() {
1390 - global $wgRequest, $wgFeed, $wgVersion;
1391 - $ret = "<meta name=\"generator\" content=\"MediaWiki " . $wgVersion . "\" />\n";
 1410+ global $wgRequest, $wgFeed;
 1411+
 1412+ // Ideally this should happen earlier, somewhere. :P
 1413+ $this->addDefaultMeta();
 1414+
 1415+ $tags = array();
 1416+
13921417 foreach ( $this->mMetatags as $tag ) {
13931418 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
13941419 $a = 'http-equiv';
@@ -1395,30 +1420,13 @@
13961421 } else {
13971422 $a = 'name';
13981423 }
1399 - $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
 1424+ $tags[] = Xml::element( 'meta',
 1425+ array(
 1426+ $a => $tag[0],
 1427+ 'content' => $tag[1] ) );
14001428 }
1401 -
1402 - $p = $this->mRobotpolicy;
1403 - if( $p !== '' && $p != 'index,follow' ) {
1404 - // http://www.robotstxt.org/wc/meta-user.html
1405 - // Only show if it's different from the default robots policy
1406 - $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1407 - }
1408 -
1409 - if ( count( $this->mKeywords ) > 0 ) {
1410 - $strip = array(
1411 - "/<.*?>/" => '',
1412 - "/_/" => ' '
1413 - );
1414 - $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1415 - htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
1416 - }
14171429 foreach ( $this->mLinktags as $tag ) {
1418 - $ret .= "\t\t<link";
1419 - foreach( $tag as $attr => $val ) {
1420 - $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1421 - }
1422 - $ret .= " />\n";
 1430+ $tags[] = Xml::element( 'link', $tag );
14231431 }
14241432
14251433 if( $wgFeed ) {
@@ -1429,7 +1437,7 @@
14301438 # with having the same name for different feeds corresponding to
14311439 # the same page, but we can't avoid that at this low a level.
14321440
1433 - $ret .= $this->feedLink(
 1441+ $tags[] = $this->feedLink(
14341442 $format,
14351443 $link,
14361444 wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) ); # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
@@ -1444,18 +1452,18 @@
14451453 if ( $wgTitle->getPrefixedText() != $rctitle->getPrefixedText() ) {
14461454 global $wgSitename;
14471455
1448 - $ret .= $this->feedLink(
 1456+ $tags[] = $this->feedLink(
14491457 'rss',
14501458 $rctitle->getFullURL( 'feed=rss' ),
14511459 wfMsg( 'site-rss-feed', $wgSitename ) );
1452 - $ret .= $this->feedLink(
 1460+ $tags[] = $this->feedLink(
14531461 'atom',
14541462 $rctitle->getFullURL( 'feed=atom' ),
14551463 wfMsg( 'site-atom-feed', $wgSitename ) );
14561464 }
14571465 }
14581466
1459 - return $ret;
 1467+ return implode( "\n\t\t", $tags ) . "\n";
14601468 }
14611469
14621470 /**
@@ -1488,7 +1496,7 @@
14891497 'rel' => 'alternate',
14901498 'type' => "application/$type+xml",
14911499 'title' => $text,
1492 - 'href' => $url ) ) . "\n";
 1500+ 'href' => $url ) );
14931501 }
14941502
14951503 /**

Status & tagging log