From 3d2a067e8c725d0ba16cabc6aeefff06f7e50571 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 3 Apr 2004 10:01:08 +0000 Subject: [PATCH] HTML tweaks inching towards XHTML-friendly output. To test: $wgMimeType = "text/xml"; $wgDocType = "-//W3C//DTD XHTML 1.0 Transitional//EN"; $wgDTD = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; Mozilla will spit out angry erorrs at all the well-formedness errors. --- includes/Article.php | 52 ++++++++++++++-------- includes/Database.php | 2 +- includes/DefaultSettings.php | 1 + includes/DifferenceEngine.php | 18 ++++---- includes/EditPage.php | 14 +++--- includes/ImagePage.php | 2 +- includes/Math.php | 4 +- includes/OutputPage.php | 38 +++++++++++----- includes/PageHistory.php | 2 +- includes/Parser.php | 6 +-- includes/Skin.php | 82 +++++++++++++++++------------------ languages/LanguageFr.php | 2 +- 12 files changed, 129 insertions(+), 94 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index a04ec9beb4..8305d3ae0b 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -790,8 +790,8 @@ class Article { $res = wfQuery( $sql, DB_READ, $fname ); if( ($old=wfFetchObject($res)) && !$confirm ) { $skin=$wgUser->getSkin(); - $wgOut->addHTML("".wfMsg("historywarning")); - $wgOut->addHTML( $skin->historyLink() ."

"); + $wgOut->addHTML("".wfMsg("historywarning")); + $wgOut->addHTML( $skin->historyLink() ."

"); } $sql="SELECT cur_text FROM cur WHERE cur_namespace=$ns and cur_title='$etitle'"; @@ -857,22 +857,40 @@ class Article { $formaction = $this->mTitle->escapeLocalURL( "action=delete" . $par ); - $confirm = wfMsg( "confirm" ); - $check = wfMsg( "confirmcheck" ); - $delcom = wfMsg( "deletecomment" ); + $confirm = htmlspecialchars( wfMsg( "confirm" ) ); + $check = htmlspecialchars( wfMsg( "confirmcheck" ) ); + $delcom = htmlspecialchars( wfMsg( "deletecomment" ) ); $wgOut->addHTML( " -

- - -
-{$delcom}: - -
 
- -
  - -
\n" ); +
+ + + + + + + + + + + + + + + + +
+ + + +
 
+ + + +
  + +
+
\n" ); $wgOut->returnToMain( false ); } @@ -1090,7 +1108,7 @@ class Article { $newcomment = wfMsg( "revertpage", $s->old_user_text, $from ); $wgOut->setPagetitle( wfMsg( "actioncomplete" ) ); $wgOut->setRobotpolicy( "noindex,nofollow" ); - $wgOut->addHTML( "

" . $newcomment . "

\n
\n" ); + $wgOut->addHTML( "

" . $newcomment . "

\n
\n" ); $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot ); Article::onArticleEdit( $this->mTitle ); $wgOut->returnToMain( false ); diff --git a/includes/Database.php b/includes/Database.php index 64cfbf11fa..d3ed827068 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -466,7 +466,7 @@ function wfEmergencyAbort( &$conn ) { $cache = new CacheManager( $t ); if( $cache->isFileCached() ) { - $msg = "

$msg
\n" . + $msg = "

$msg
\n" . wfMsgNoDB( "cachederror" ) . "

\n"; $tag = "
"; diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 5290a14db1..c0cc8a42c6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -90,6 +90,7 @@ $wgInterwikiMagic = true; # Treat language links as magic connectors, not inline $wgInputEncoding = "ISO-8859-1"; $wgOutputEncoding = "ISO-8859-1"; $wgEditEncoding = ""; +$wgMimeType = "text/html"; $wgDocType = "-//W3C//DTD HTML 4.01 Transitional//EN"; $wgDTD = "http://www.w3.org/TR/html4/loose.dtd"; $wgUseDynamicDates = false; # Enable to allow rewriting dates in page text diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index c33e95060d..4664515132 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -50,12 +50,12 @@ class DifferenceEngine { $rollback = ""; } - $oldHeader = "{$this->mOldtitle}
$oldUserLink ($oldUTLink | $oldContribs)"; - $newHeader = "{$this->mNewtitle}
$newUserLink ($newUTLink | $newContribs) $rollback"; + $oldHeader = "{$this->mOldtitle}
$oldUserLink ($oldUTLink | $oldContribs)"; + $newHeader = "{$this->mNewtitle}
$newUserLink ($newUTLink | $newContribs) $rollback"; DifferenceEngine::showDiff( $this->mOldtext, $this->mNewtext, $oldHeader, $newHeader ); - $wgOut->addHTML( "

{$this->mNewtitle}

\n" ); + $wgOut->addHTML( "

{$this->mNewtitle}

\n" ); $wgOut->addWikiText( $this->mNewtext ); } @@ -68,11 +68,11 @@ class DifferenceEngine { $nta = explode( "\n", str_replace( "\r\n", "\n", htmlspecialchars( $ntext ) ) ); - $wgOut->addHTML( " -\n
+ $wgOut->addHTML( " + -\n" ); @@ -1087,8 +1087,8 @@ class TableDiffFormatter extends DiffFormatter $l1 = wfMsg( "lineno", $xbeg ); $l2 = wfMsg( "lineno", $ybeg ); - $r = "\n" . - "\n"; + $r = "\n" . + "\n"; return $r; } diff --git a/includes/EditPage.php b/includes/EditPage.php index 058e73df35..8ce60faaaa 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -297,7 +297,7 @@ class EditPage { if ( 0 != $wgUser->getID() || $wgAllowAnonymousMinor ) { $minoredithtml = - "minoredit?" checked":"")." id='wpMinoredit'>". + "minoredit?" checked":"")." id='wpMinoredit' />". ""; } @@ -359,14 +359,14 @@ cols='{$cols}'{$ew} wrap=\"virtual\">" . htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) . " -
{$editsummary} +
{$editsummary} {$checkboxhtml} - - + +{$cancel} | {$edithelp} -

{$copywarn} -section ) . "\" name=\"wpSection\"> -edittime}\" name=\"wpEdittime\">\n" ); +

{$copywarn} +section ) . "\" name=\"wpSection\" /> +edittime}\" name=\"wpEdittime\" />\n" ); if ( $isConflict ) { $wgOut->addHTML( "

" . wfMsg( "yourdiff" ) . "

\n" ); diff --git a/includes/ImagePage.php b/includes/ImagePage.php index dab95ac902..4ba864d7ef 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -38,7 +38,7 @@ class ImagePage extends Article { if ( $type != "" ) { # image - $s = "
"; + $s = "
"; } else { $s = "
".$sk->makeMediaLink($name,"")."
"; } diff --git a/includes/Math.php b/includes/Math.php index 798b569e56..4c24af53f7 100644 --- a/includes/Math.php +++ b/includes/Math.php @@ -3,7 +3,9 @@ function linkToMathImage ( $tex, $outputhash ) { global $wgMathPath; - return "\"".wfEscapeHTML($tex)."\""; + $url = htmlspecialchars( "$wgMathPath/$outputhash.png"; + $alt = htmlspecialchars( $tex ); + return "\"$alt\""; } function renderMath( $tex ) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 80f0496e3d..6ad71b33e3 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -239,7 +239,7 @@ class OutputPage { { global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration; global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode; - global $wgDebugRedirects; + global $wgDebugRedirects, $wgMimeType; if( $this->mDoNothing ){ return; } @@ -277,7 +277,7 @@ class OutputPage { $this->sendCacheControl(); - header( "Content-type: text/html; charset={$wgOutputEncoding}" ); + header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" ); header( "Content-language: {$wgLanguageCode}" ); $exp = time() + $wgCookieExpiration; @@ -572,16 +572,30 @@ class OutputPage { /* private */ function headElement() { - global $wgDocType, $wgDTD, $wgUser, $wgLanguageCode, $wgOutputEncoding, $wgLang, $wgRequest; + global $wgDocType, $wgDTD, $wgLanguageCode, $wgOutputEncoding, $wgMimeType; + global $wgUser, $wgLang, $wgRequest; - $ret = "\n"; + $xml = ($wgMimeType == 'text/xml'); + if( $xml ) { + $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n"; + } else { + $ret = ""; + } + + $ret .= "\n"; if ( "" == $this->mHTMLtitle ) { $this->mHTMLtitle = $this->mPagetitle; } + if( $xml ) { + $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\""; + } else { + $xmlbits = ""; + } $rtl = $wgLang->isRTL() ? " dir='RTL'" : ""; - $ret .= "{$this->mHTMLtitle}\n"; - array_push( $this->mMetatags, array( "http:Content-type", "text/html; charset={$wgOutputEncoding}" ) ); + $ret .= "\n"; + $ret .= "\n{$this->mHTMLtitle}\n"; + array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) ); foreach ( $this->mMetatags as $tag ) { if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) { $a = "http-equiv"; @@ -589,15 +603,15 @@ class OutputPage { } else { $a = "name"; } - $ret .= "\n"; + $ret .= "\n"; } $p = $this->mRobotpolicy; if ( "" == $p ) { $p = "index,follow"; } - $ret .= "\n"; + $ret .= "\n"; if ( count( $this->mKeywords ) > 0 ) { $ret .= "mKeywords ) . "\">\n"; + implode( ",", $this->mKeywords ) . "\" />\n"; } foreach ( $this->mLinktags as $tag ) { $ret .= "\n"; + $ret .= "href=\"{$tag[2]}\" />\n"; } if( $this->isSyndicated() ) { $link = $wgRequest->escapeAppendQuery( "feed=rss" ); - $ret .= "\n"; + $ret .= "\n"; } global $wgStyleSheetPath; if( $this->isPrintable() ) { @@ -618,7 +632,7 @@ class OutputPage { $media = "media='print'"; } $printsheet = htmlspecialchars( "$wgStyleSheetPath/wikiprintable.css" ); - $ret .= "\n"; + $ret .= "\n"; $sk = $wgUser->getSkin(); $ret .= $sk->getHeadScripts(); diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 6a001cd3ff..f01764e850 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -188,7 +188,7 @@ class PageHistory { } $arbitrary = ""; if( $this->linesonpage > 1) - $arbitrary = ""; + $arbitrary = ""; $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary . ."; $M = wfMsg( "minoreditletter" ); if ( $isminor ) { diff --git a/includes/Parser.php b/includes/Parser.php index 7fc503794a..b526d2d4d9 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -207,7 +207,7 @@ class Parser $ti = $this->mTitle->getText() ; $ti = explode ( ":" , $ti , 2 ) ; if ( $cat != $ti[0] ) return "" ; - $r = "
\n" ; + $r = "
\n" ; $articles = array() ; $parents = array () ; @@ -417,7 +417,7 @@ class Parser $text = $this->replaceVariables( $text ); # $text = preg_replace( "/(^|\n)-----*/", "\\1
", $text ); - $text = str_replace ( "
", "
", $text ); + $text = str_replace ( "
", "
", $text ); $text = $this->doHeadings( $text ); $text = $this->doBlockLevels( $text, $linestart ); @@ -682,7 +682,7 @@ class Parser $tagIsOpen = (count( $tokenStack ) != 0); break; case "----": - $txt = "\n
\n"; + $txt = "\n
\n"; break; case "'''": # This and the three next ones handle quotes diff --git a/includes/Skin.php b/includes/Skin.php index 429efdf849..13c345d3be 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -35,7 +35,7 @@ function getCategories () if ( !$wgOut->isArticle() ) return "" ; $sk = $wgUser->getSkin() ; $s = "" ; - $s .= "\n
\n"; + $s .= "\n
\n"; $s .= $sk->makeKnownLink ( "Special:Categories" , "Categories" , "article=".$wgTitle->getDBkey() ) ; $t = implode ( " | " , $wgOut->mCategoryLinks ) ; if ( $t != "" ) $s .= " : " ; @@ -122,7 +122,7 @@ class Skin { } $out->out( $this->beforeContent() ); - $out->out( $out->mBodytext ); + $out->out( $out->mBodytext . "\n" ); $out->out( $this->afterContent() ); @@ -142,12 +142,12 @@ class Skin { { global $wgOut, $wgStyleSheetPath; $sheet = $this->getStylesheet(); - $s = "\n"; + $s .= "\n"; return $s; } @@ -298,39 +298,39 @@ class Skin { $borderhack = "class='top'"; } - $s .= "\n
\n
" . - "
{$otitle} + {$ntitle}
{$l1}{$l2}
{$l1}{$l2}
"; + $s .= "\n
\n
\n" . + "
\n\n"; $shove = ($qb != 0); $left = ($qb == 1 || $qb == 3); if($wgLang->isRTL()) $left = !$left; if ( !$shove ) { - $s .= ""; } elseif( $left ) { $s .= $this->getQuickbarCompensator( $rows ); } $l = $wgLang->isRTL() ? "right" : "left"; - $s .= "\n\n"; + $s .= "\n
" . $this->searchForm() . ""; if ( $langlinks ) { - $s .= "\n"; + $s .= "\n\n\n"; } if ( $shove && !$left ) { # Right $s .= $this->getQuickbarCompensator( $rows ); } - $s .= "
" . + $s .= "\n" . $this->logoText() . ""; + $s .= "\n"; $s .= $this->topLinks() ; - $s .= "

" . $this->pageTitleLinks(); + $s .= "

" . $this->pageTitleLinks() . "

\n"; $r = $wgLang->isRTL() ? "left" : "right"; - $s .= "
"; + $s .= ""; $s .= $this->nameAndLogin(); - $s .= "\n
" . $this->searchForm() . "
$langlinks
$langlinks
\n\n"; - $s .= "\n
"; + $s .= "
\n
\n"; + $s .= "\n
\n"; $s .= $this->pageTitle(); $s .= $this->pageSubtitle() ; @@ -352,7 +352,7 @@ class Skin { global $wgUser, $wgOut, $wgServer; global $wgTitle, $wgLang; - $printfooter = "
" . $this->printFooter() . "
\n"; + $printfooter = "
\n" . $this->printFooter() . "
\n"; return $printfooter . $this->doAfterContent(); } @@ -370,9 +370,9 @@ class Skin { wfProfileIn( $fname ); wfProfileIn( "$fname-1" ); - $s = "\n

\n"; + $s = "\n
\n"; $s .= "\n