Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -656,9 +656,14 @@ |
657 | 657 | Can be used to set custom CSS/JS |
658 | 658 | $out: OutputPage object |
659 | 659 | |
| 660 | +'ShowRawCssJs': When presenting raw CSS and JavaScript during page views |
| 661 | +&$text: Text being shown |
| 662 | +$title: Title of the custom script/stylesheet page |
| 663 | +$output: Current OutputPage object |
| 664 | + |
660 | 665 | 'AjaxAddScript': Called in output page just before the initialisation |
661 | 666 | of the javascript ajax engine. The hook is only called when ajax |
662 | 667 | is enabled ( $wgUseAjax = true; ). |
663 | 668 | |
664 | 669 | More hooks might be available but undocumented, you can execute |
665 | | -./maintenance/findhooks.php to find hidden one. |
| 670 | +./maintenance/findhooks.php to find hidden one. |
\ No newline at end of file |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -684,10 +684,12 @@ |
685 | 685 | } |
686 | 686 | |
687 | 687 | # Should the parser cache be used? |
688 | | - $pcache = $wgEnableParserCache && |
689 | | - intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 && |
690 | | - $this->exists() && |
691 | | - empty( $oldid ); |
| 688 | + $pcache = $wgEnableParserCache |
| 689 | + && intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 |
| 690 | + && $this->exists() |
| 691 | + && empty( $oldid ) |
| 692 | + && !$this->mTitle->isCssOrJsPage() |
| 693 | + && !$this->mTitle->isCssJsSubpage(); |
692 | 694 | wfDebug( 'Article::view using parser cache: ' . ($pcache ? 'yes' : 'no' ) . "\n" ); |
693 | 695 | if ( $wgUser->getOption( 'stubthreshold' ) ) { |
694 | 696 | wfIncrStats( 'pcache_miss_stub' ); |
— | — | @@ -777,21 +779,27 @@ |
778 | 780 | } |
779 | 781 | if( !$outputDone ) { |
780 | 782 | $wgOut->setRevisionId( $this->getRevIdFetched() ); |
781 | | - // Wrap site/user css/js in pre and don't parse. User pages need |
782 | | - // to be subpages, site pages just need to end in ".css" or ".js". |
783 | | - |
784 | | - // @todo: use $this->mTitle->isCssJsSubpage() when php is fixed/ |
785 | | - // a workaround is found. |
786 | | - if ( |
787 | | - ($ns == NS_USER and preg_match('#/\w+\.(css|js)$#',$this->mTitle->getDBkey(),$matches)) |
788 | | - or ($ns == NS_MEDIAWIKI and preg_match('/.(css|js)$/', $this->mTitle->getDBkey(), $matches)) |
789 | | - ) { |
790 | | - $wgOut->addWikiText( wfMsg('clearyourcache')); |
791 | | - $wgOut->addHTML( |
792 | | - "<pre class=\"mw-code mw-{$matches[1]}\" dir=\"ltr\">" |
793 | | - .htmlspecialchars($this->mContent)."\n</pre>" |
794 | | - ); |
795 | | - } else if ( $rt = Title::newFromRedirect( $text ) ) { |
| 783 | + |
| 784 | + // Pages containing custom CSS or JavaScript get special treatment |
| 785 | + if( $this->mTitle->isCssOrJsPage() || $this->mTitle->isCssJsSubpage() ) { |
| 786 | + $wgOut->addHtml( wfMsgExt( 'clearyourcache', 'parse' ) ); |
| 787 | + $text = $this->mContent; |
| 788 | + |
| 789 | + // Give hooks a chance to do formatting... |
| 790 | + if( wfRunHooks( 'ShowRawCssJs', array( &$text, $this->mTitle, $wgOut ) ) ) { |
| 791 | + // Wrap the whole lot in a <pre> and don't parse |
| 792 | + preg_match( '!\.(css|js)$!u', $this->mTitle->getText(), $m ); |
| 793 | + $wgOut->addHtml( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" ); |
| 794 | + $wgOut->addHtml( htmlspecialchars( $text ) ); |
| 795 | + $wgOut->addHtml( "\n</pre>\n" ); |
| 796 | + } else { |
| 797 | + // Wrap hook output in a <div> with the right direction attribute |
| 798 | + $wgOut->addHtml( "<div dir=\"ltr\">\n{$text}\n</div>" ); |
| 799 | + } |
| 800 | + |
| 801 | + } |
| 802 | + |
| 803 | + elseif ( $rt = Title::newFromRedirect( $text ) ) { |
796 | 804 | # Display redirect |
797 | 805 | $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr'; |
798 | 806 | $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png'; |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -1214,6 +1214,17 @@ |
1215 | 1215 | return false; |
1216 | 1216 | } |
1217 | 1217 | } |
| 1218 | + |
| 1219 | + /** |
| 1220 | + * Could this page contain custom CSS or JavaScript, based |
| 1221 | + * on the title? |
| 1222 | + * |
| 1223 | + * @return bool |
| 1224 | + */ |
| 1225 | + public function isCssOrJsPage() { |
| 1226 | + return $this->mNamespace == NS_MEDIAWIKI |
| 1227 | + && preg_match( '!\.(?:css|js)$!u', $this->mTextform ) > 0; |
| 1228 | + } |
1218 | 1229 | |
1219 | 1230 | /** |
1220 | 1231 | * Is this a .css or .js subpage of a user page? |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -112,8 +112,8 @@ |
113 | 113 | * Introduce 'UserEffectiveGroups' hook; see docs/hooks.txt for more information |
114 | 114 | * (bug 10387) Detect and handle '.php5' extension environments at install time |
115 | 115 | Patch by Edward Z. Yang. |
| 116 | +* Introduce 'ShowRawCssJs' hook; see docs/hooks.txt for more information |
116 | 117 | |
117 | | - |
118 | 118 | == Bugfixes since 1.10 == |
119 | 119 | |
120 | 120 | * (bug 9712) Use Arabic comma in date/time formats for Arabic and Farsi |
— | — | @@ -238,6 +238,8 @@ |
239 | 239 | Special:Confirmemail |
240 | 240 | * Fix read permission check for unreadable page titles which are numerically |
241 | 241 | equivalent to a whitelisted title |
| 242 | +* Don't use garbled parser cache output when viewing custom CSS or JavaScript |
| 243 | + pages |
242 | 244 | |
243 | 245 | == API changes since 1.10 == |
244 | 246 | |