return str_replace( array_keys( $replace ), array_values( $replace ), $id );
}
+ /**
+ * Given a value, escape it so that it can be used as a CSS class and
+ * return it.
+ *
+ * TODO: For extra validity, input should be validated UTF-8.
+ *
+ * @link http://www.w3.org/TR/CSS21/syndata.html Valid characters/format
+ *
+ * @param string $class
+ * @return string
+ */
+ static function escapeClass( $class ) {
+ // Convert ugly stuff to underscores and kill underscores in ugly places
+ return rtrim(preg_replace(
+ array('/(^[0-9\\-])|[\\x00-\\x20!"#$%&\'()*+,.\\/:;<=>?@[\\]^`{|}~]|\\xC2\\xA0/','/_+/'),
+ '_',
+ $class ), '_');
+ }
+
/**
* Regex replace callback for armoring links against further processing.
* @param array $matches
$a['onload'] .= 'setupRightClickEdit()';
}
$a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
- ' page-'.Sanitizer::escapeId( $wgTitle->getPrefixedText() );
+ ' '.Sanitizer::escapeId( 'page-'.$wgTitle->getPrefixedText() );
return $a;
}
$tpl->set( 'title', $wgOut->getPageTitle() );
$tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
$tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
- $tpl->set( 'pageclass', 'page-'.Sanitizer::escapeId( $wgTitle->getPrefixedText() ) );
+ $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() ) );
$nsname = @$wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ];
if ( $nsname === NULL ) $nsname = $this->mTitle->getNsText();