From: Gabriel Wicke Date: Mon, 10 May 2004 13:15:28 +0000 (+0000) Subject: * user css/js preview X-Git-Tag: 1.3.0beta1~103 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/%22%24ccApp/ecrire?a=commitdiff_plain;h=2da73a4a50ff12082aafd1813ff6c503e4dda5aa;p=lhc%2Fweb%2Fwiklou.git * user css/js preview * utility functions in title to test for user css/js, some weird php bug prevents those from working in most places though --- diff --git a/includes/Article.php b/includes/Article.php index 16101eca27..5d493bff39 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -503,6 +503,7 @@ class Article { $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()) diff --git a/includes/EditPage.php b/includes/EditPage.php index e10b30a22a..7e891a831a 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -106,12 +106,14 @@ class EditPage { { 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")); @@ -178,7 +180,7 @@ class EditPage { } 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; @@ -287,7 +289,7 @@ class EditPage { $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 { @@ -337,15 +339,27 @@ class EditPage { $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( "
\n" ); } - $wgOut->addHTML( "
\n" ); } # if this is a comment, show a subject line at the top, which is also the edit summary. diff --git a/includes/SkinPHPTal.php b/includes/SkinPHPTal.php index b5bf3436f8..63de6e3fc8 100644 --- a/includes/SkinPHPTal.php +++ b/includes/SkinPHPTal.php @@ -82,13 +82,9 @@ $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() ); @@ -138,7 +134,7 @@ $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(); @@ -543,6 +539,23 @@ 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 { diff --git a/includes/Title.php b/includes/Title.php index 7935679a63..c4d49739c2 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -486,19 +486,20 @@ class Title { # 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 ) ) ) { @@ -508,6 +509,22 @@ class Title { 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() { diff --git a/languages/Language.php b/languages/Language.php index 4520ec808f..c06e3ddb7f 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -779,6 +779,10 @@ If you are here by mistake, just click your browser's '''back''' button.", "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" => "Note: ", "previewnote" => "Remember that this is only a preview, and has not yet been saved!", diff --git a/templates/xhtml_slim.pt b/templates/xhtml_slim.pt index d7b20d52ac..773f99d3f4 100644 --- a/templates/xhtml_slim.pt +++ b/templates/xhtml_slim.pt @@ -13,8 +13,9 @@ - - + +