/i', $s ) ) { return preg_replace( '/\<\s*cross-domain-policy\s*\>/i', '', $s ); } else { return $s; } } /** * Add a Content-Length header if possible. This makes it cooperate with squid better. * * @param $length int */ function wfDoContentLength( $length ) { if ( !headers_sent() && isset( $_SERVER['SERVER_PROTOCOL'] ) && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0' ) { header( "Content-Length: $length" ); } } /** * Replace the output with an error if the HTML is not valid * * @param $s string * * @return string */ function wfHtmlValidationHandler( $s ) { $errors = ''; if ( MWTidy::checkErrors( $s, $errors ) ) { return $s; } header( 'Cache-Control: no-cache' ); $out = Html::element( 'h1', null, 'HTML validation error' ); $out .= Html::openElement( 'ul' ); $error = strtok( $errors, "\n" ); $badLines = array(); while ( $error !== false ) { if ( preg_match( '/^line (\d+)/', $error, $m ) ) { $lineNum = intval( $m[1] ); $badLines[$lineNum] = true; $out .= Html::rawElement( 'li', null, Html::element( 'a', array( 'href' => "#line-{$lineNum}" ), $error ) ) . "\n"; } $error = strtok( "\n" ); } $out .= Html::closeElement( 'ul' ); $out .= Html::element( 'pre', null, $errors ); $out .= Html::openElement( 'ol' ) . "\n"; $line = strtok( $s, "\n" ); $i = 1; while ( $line !== false ) { $attrs = array(); if ( isset( $badLines[$i] ) ) { $attrs['class'] = 'highlight'; $attrs['id'] = "line-$i"; } $out .= Html::element( 'li', $attrs, $line ) . "\n"; $line = strtok( "\n" ); $i++; } $out .= Html::closeElement( 'ol' ); $style = << 'en', 'dir' => 'ltr' ) ) . Html::rawElement( 'head', null, Html::element( 'title', null, 'HTML validation error' ) . Html::inlineStyle( $style ) ) . Html::rawElement( 'body', null, $out ) . Html::closeElement( 'html' ); return $out; }