r23537 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23536‎ | r23537 | r23538 >
Date:04:31, 29 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Clean up handling of custom CSS and JavaScript pages in Article::view():

* Don't use parser cache, output is garbled
* Run 'ShowRawCssJs' hook
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -656,9 +656,14 @@
657657 Can be used to set custom CSS/JS
658658 $out: OutputPage object
659659
 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+
660665 'AjaxAddScript': Called in output page just before the initialisation
661666 of the javascript ajax engine. The hook is only called when ajax
662667 is enabled ( $wgUseAjax = true; ).
663668
664669 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 @@
685685 }
686686
687687 # 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();
692694 wfDebug( 'Article::view using parser cache: ' . ($pcache ? 'yes' : 'no' ) . "\n" );
693695 if ( $wgUser->getOption( 'stubthreshold' ) ) {
694696 wfIncrStats( 'pcache_miss_stub' );
@@ -777,21 +779,27 @@
778780 }
779781 if( !$outputDone ) {
780782 $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 ) ) {
796804 # Display redirect
797805 $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
798806 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
Index: trunk/phase3/includes/Title.php
@@ -1214,6 +1214,17 @@
12151215 return false;
12161216 }
12171217 }
 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+ }
12181229
12191230 /**
12201231 * Is this a .css or .js subpage of a user page?
Index: trunk/phase3/RELEASE-NOTES
@@ -112,8 +112,8 @@
113113 * Introduce 'UserEffectiveGroups' hook; see docs/hooks.txt for more information
114114 * (bug 10387) Detect and handle '.php5' extension environments at install time
115115 Patch by Edward Z. Yang.
 116+* Introduce 'ShowRawCssJs' hook; see docs/hooks.txt for more information
116117
117 -
118118 == Bugfixes since 1.10 ==
119119
120120 * (bug 9712) Use Arabic comma in date/time formats for Arabic and Farsi
@@ -238,6 +238,8 @@
239239 Special:Confirmemail
240240 * Fix read permission check for unreadable page titles which are numerically
241241 equivalent to a whitelisted title
 242+* Don't use garbled parser cache output when viewing custom CSS or JavaScript
 243+ pages
242244
243245 == API changes since 1.10 ==
244246

Follow-up revisions

RevisionCommit summaryAuthorDate
r23581Merged revisions 23406-23580 via svnmerge from...david04:50, 30 June 2007

Status & tagging log