Show the source on preview for CSS and Javascript pages.
authorPlatonides <platonides@users.mediawiki.org>
Tue, 7 Dec 2010 14:53:36 +0000 (14:53 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Tue, 7 Dec 2010 14:53:36 +0000 (14:53 +0000)
Add pages in MediaWiki namespace into that group (bug 10871).
Only normal <pre> formatting is being used since ShowRawCssJs
hook directly sends things out to the output.

RELEASE-NOTES
includes/EditPage.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php

index 804ad86..aecca3d 100644 (file)
@@ -467,6 +467,8 @@ LocalSettings.php. The specific bugs are listed below in the general notes.
 * rebuildFileCache.php no longer creates inappropriate cache files for redirects
 * (bug 23119) WikiError class and subclasses are now marked as deprecated
 * (bug 18372) $wgFileExtensions will now override $wgFileBlacklist 
+* (bug 10871) Javascript and CSS pages in MediaWiki namespace are no longer treated
+  as wikitext on preview.
 
 === API changes in 1.17 ===
 * (bug 22738) Allow filtering by action type on query=logevent.
index b190237..e4d9321 100644 (file)
@@ -1878,17 +1878,28 @@ HTML
                }
 
                # don't parse user css/js, show message about preview
-               # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
+               # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago?
+
+               if ( $this->isCssJsSubpage || $this->mTitle->isCssOrJsPage() ) {
+                       $level = 'user';
+                       if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+                               $level = 'global';
+                       }
 
-               if ( $this->isCssJsSubpage ) {
                        if (preg_match( "/\\.css$/", $this->mTitle->getText() ) ) {
-                               $previewtext = "<div id='mw-usercsspreview'>\n" . wfMsg( 'usercsspreview' ) . "\n</div>";
-                       } else if (preg_match( "/\\.js$/", $this->mTitle->getText() ) ) {
-                               $previewtext = "<div id='mw-userjspreview'>\n" . wfMsg( 'userjspreview' ) . "\n</div>";
+                               $previewtext = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
+                               $class = "mw-code mw-js";
+                       } elseif (preg_match( "/\\.js$/", $this->mTitle->getText() ) ) {
+                               $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
+                               $class = "mw-code mw-js";
+                       } else {
+                               throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' );
                        }
+
                        $parserOptions->setTidy( true );
                        $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
                        $previewHTML = $parserOutput->mText;
+                       $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1 ) . "\n</pre>\n";
                } else {
                        $rt = Title::newFromRedirectArray( $this->textbox1 );
                        if ( $rt ) {
index 154cd5d..f767d6e 100644 (file)
@@ -1300,6 +1300,10 @@ The latest block log entry is provided below for reference:',
 '''It has not yet been saved!'''",
 'userjspreview'                    => "'''Remember that you are only testing/previewing your user JavaScript.'''
 '''It has not yet been saved!'''",
+'globalcsspreview'                   => "'''Remember that you are only previewing this global CSS.'''
+'''It has not yet been saved!'''",
+'globaljspreview'                    => "'''Remember that you are only previewing this global JavaScript code.'''
+'''It has not yet been saved!'''",
 'userinvalidcssjstitle'            => "'''Warning:''' There is no skin \"\$1\".
 Custom .css and .js pages use a lowercase title, e.g. {{ns:user}}:Foo/vector.css as opposed to {{ns:user}}:Foo/Vector.css.",
 'updated'                          => '(Updated)',
index bc43103..9c472f6 100644 (file)
@@ -838,6 +838,10 @@ See also {{msg-mw|Noarticletext-nopermission}}.',
 'clearyourcache'                   => 'Text at the top of .js/.css pages',
 'usercssyoucanpreview'             => "Text displayed on every css page. The 'Show preview' part should be the same as {{msg-mw|showpreview}} (or you can use <nowiki>{{int:showpreview}}</nowiki>).",
 'userjsyoucanpreview'              => 'Text displayed on every js page.',
+'usercsspreview'                   => 'Text displayed on preview of every user .css subpage',
+'userjspreview'                    => 'Text displayed on preview of every user .js subpage',
+'globalcsspreview'                 => 'Text displayed on preview of .css pages in MediaWiki namespace',
+'globaljspreview'                  => 'Text displayed on preview of .js pages in MediaWiki namespace',
 'updated'                          => '{{Identical|Updated}}',
 'previewnote'                      => 'Note displayed when clicking on Show preview',
 'editing'                          => "Shown as page title when editing a page. \$1 is the name of the page that is being edited. Example: \"''Editing Main Page''\".",