* utility functions in title to test for user css/js, some weird php bug prevents those from working in most places though
$wgLinkCache->preFill( $this->mTitle );
# wrap user css and user js in pre and don't parse
+ # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
if (
$this->mTitle->getNamespace() == Namespace::getUser() &&
preg_match("/\\/[\\w]+\\.(css|js)$/", $this->mTitle->getDBkey())
{
global $wgOut, $wgUser;
global $wgLang, $wgParser, $wgTitle;
- global $wgAllowAnonymousMinor;
- global $wgWhitelistEdit;
+ global $wgAllowAnonymousMinor;
+ global $wgWhitelistEdit;
global $wgSpamRegex;
$sk = $wgUser->getSkin();
$isConflict = false;
+ // css / js subpages of user pages get a special treatment
+ $isCssJsSubpage = Namespace::getUser() == $wgTitle->getNamespace() and preg_match("/\\.(css|js)$/", $wgTitle->getText() );
if(!$this->mTitle->getArticleID()) { # new article
$wgOut->addWikiText(wfmsg("newarticletext"));
} else {
# switch from section editing to normal editing in edit conflict
if($isConflict) {
- # Attempt merge
+ # Attempt merge
if( $this->mergeChangesInto( $text ) ){
// Successful merge! Maybe we should tell the user the good news?
$isConflict = false;
$copywarn = wfMsg( "copyrightwarning", $sk->makeKnownLink(
wfMsg( "copyrightpage" ) ) );
- if( $wgUser->getOption("showtoolbar") ) {
+ if( $wgUser->getOption("showtoolbar") and !$isCssJsSubpage ) {
# prepare toolbar for edit buttons
$toolbar = $sk->getEditToolbar();
} else {
$parserOptions->setUseCategoryMagic( false );
$parserOptions->setEditSection( false );
$parserOptions->setEditSectionOnRightClick( false );
- $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $previewtext ) ."\n\n",
+ # don't parse user css/js, show message about preview
+ # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
+ if ( $isCssJsSubpage ) {
+ if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
+ $previewtext = wfMsg('usercsspreview');
+ } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
+ $previewtext = wfMsg('userjspreview');
+ }
+ $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
+ $wgOut->addHTML( $parserOutput->mText );
+ } else {
+ $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $previewtext ) ."\n\n",
$wgTitle, $parserOptions );
- $previewHTML = $parserOutput->mText;
+ $previewHTML = $parserOutput->mText;
- if($wgUser->getOption("previewontop")) {
- $wgOut->addHTML($previewhead);
- $wgOut->addHTML($previewHTML);
+ if($wgUser->getOption("previewontop")) {
+ $wgOut->addHTML($previewhead);
+ $wgOut->addHTML($previewHTML);
+ }
+ $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
}
- $wgOut->addHTML( "<br clear=\"all\" />\n" );
}
# if this is a comment, show a subject line at the top, which is also the edit summary.
$this->userpage = $wgLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
$this->userpageurl = $this->makeUrl($this->userpage);
- if( $this->loggedin ) {
- $this->usercss = $this->makeUrl($this->userpage.'/'.$this->skinname.'.css', 'action=raw&ctype=text/css');
- $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript');
- $this->userjse = htmlspecialchars($this->userjs);
- } else {
- $this->usercss = $this->userjs = $this->userjse = false;
- }
+ $this->usercss = $this->userjs = $this->userjsprev = false;
+ if( $this->loggedin ) { $this->setupUserCssJs(); }
+
$this->titletxt = $wgTitle->getPrefixedText();
$tpl->set( "title", $wgOut->getPageTitle() );
$tpl->setRef( "userpageurl", &$this->userpageurl);
$tpl->setRef( "usercss", &$this->usercss);
$tpl->setRef( "userjs", &$this->userjs);
- $tpl->setRef( "userjse", &$this->userjse);
+ $tpl->setRef( "userjsprev", &$this->userjsprev);
if( $wgUser->getNewtalk() ) {
$usertitle = Title::newFromText( $this->userpage );
$usertalktitle = $usertitle->getTalkPage();
return wfMsg('nstab-main');
}
}
+ /* private */ function setupUserCssJs () {
+ global $wgRequest, $wgTitle;
+ $action = $wgRequest->getText('action');
+ if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
+ // css preview
+ $this->usercss = $wgRequest->getText('wpTextbox1');
+ } else {
+ $this->usercss = '@import url('.
+ $this->makeUrl($this->userpage.'/'.$this->skinname.'.css', 'action=raw&ctype=text/css').');';
+ }
+ if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
+ # XXX: additional security check/prompt?
+ $this->userjsprev = $wgRequest->getText('wpTextbox1');
+ } else {
+ $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript');
+ }
+ }
}
class SkinDaVinci extends SkinPHPTal {
# Can $wgUser edit this page?
function userCanEdit()
{
- global $wgUser;
if ( -1 == $this->mNamespace ) { return false; }
# if ( 0 == $this->getArticleID() ) { return false; }
if ( $this->mDbkeyform == "_" ) { return false; }
+ //if ( $this->isCssJsSubpage() and !$this->userCanEditCssJsSubpage() ) { return false; }
# protect css/js subpages of user pages
# XXX: this might be better using restrictions
+ # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
+ global $wgUser;
if( Namespace::getUser() == $this->mNamespace
and preg_match("/\\.(css|js)$/", $this->mTextform )
and !$wgUser->isSysop()
and !preg_match("/^".$wgUser->getName()."/", $this->mTextform) )
{ return false; }
-
$ur = $wgUser->getRights();
foreach ( $this->getRestrictions() as $r ) {
if ( "" != $r && ( ! in_array( $r, $ur ) ) ) {
return true;
}
+ function isCssJsSubpage() {
+ return ( Namespace::getUser() == $this->mNamespace and preg_match("/\\.(css|js)$/", $this->mTextform ) );
+ }
+ function isCssSubpage() {
+ return ( Namespace::getUser() == $this->mNamespace and preg_match("/\\.css$/", $this->mTextform ) );
+ }
+ function isJsSubpage() {
+ return ( Namespace::getUser() == $this->mNamespace and preg_match("/\\.js$/", $this->mTextform ) );
+ }
+ function userCanEditCssJsSubpage() {
+ # protect css/js subpages of user pages
+ # XXX: this might be better using restrictions
+ global $wgUser;
+ return ( $wgUser->isSysop() or preg_match("/^".$wgUser->getName()."/", $this->mTextform) );
+ }
+
# Accessor/initialisation for mRestrictions
function getRestrictions()
{
"anontalkpagetext" => "----''This is the discussion page for an anonymous user who has not created an account yet or who does not use it. We therefore have to use the numerical [[IP address]] to identify him/her. Such an IP address can be shared by several users. If you are an anonymous user and feel that irrelevant comments have been directed at you, please [[Special:Userlogin|create an account or log in]] to avoid future confusion with other anonymous users.'' ",
"noarticletext" => "(There is currently no text in this page)",
'usercssjs' => "'''Note:''' After saving, you have to tell your bowser to get the new version: '''Mozilla:''' click ''reload''(or ''ctrl-r''), '''IE / Opera:''' ''ctrl-f5'', '''Safari:''' ''cmd-r'', '''Konqueror''' ''ctrl-r''.",
+'usercsspreview' => "== Previewing your user css. ==
+'''Note:''' After saving, you have to tell your bowser to get the new version: '''Mozilla:''' click ''reload''(or ''ctrl-r''), '''IE / Opera:''' ''ctrl-f5'', '''Safari:''' ''cmd-r'', '''Konqueror''' ''ctrl-r''.",
+'userjspreview' => "== Previewing your user javascript. ==
+'''Note:''' After saving, you have to tell your bowser to get the new version: '''Mozilla:''' click ''reload''(or ''ctrl-r''), '''IE / Opera:''' ''ctrl-f5'', '''Safari:''' ''cmd-r'', '''Konqueror''' ''ctrl-r''.",
"updated" => "(Updated)",
"note" => "<strong>Note:</strong> ",
"previewnote" => "Remember that this is only a preview, and has not yet been saved!",
<script type="text/javascript" src="${stylepath}/wikibits.js"></script>
<script type="text/javascript"> /*<![CDATA[*/ if(addcss){addcss('${stylepath}/${skinname}/');} /*]]>*/</script>
<style tal:condition="rtl" type="text/css">/*<![CDATA[*/@import url(${stylepath}/${skinname}/rtl.css);/*]]>*/</style>
- <style tal:condition="usercss" type="text/css">/*<![CDATA[*/ @import url(${usercss}); /*]]>*/</style>
- <script tal:condition="userjs" type="text/javascript" tal:attributes="src userjs"></script>
+ <style tal:condition="usercss" type="text/css">/*<![CDATA[*/ ${usercss} /*]]>*/</style>
+ <script tal:condition="userjs" type="text/javascript" tal:attributes="src userjs"></script><script
+ tal:condition="userjsprev" type="text/javascript">/*<![CDATA[*/${userjsprev}/*]]>*/</script>
</head>
<body tal:attributes="ondblclick body-ondblclick|default">