r37686 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37685‎ | r37686 | r37687 >
Date:11:03, 15 July 2008
Author:dantman
Status:old
Tags:
Comment:
Improving extendibility of the sidebar improvements, css adding, and also JS variables.

* New hooks:
** SkinSidebarSpecialBox and SkinSidebarOutputSpecialBox to allow extensions to add new custom boxes to Tim's new Sidebar system
** SkinSetupSiteCss to allow extensions to modify and add new stylesheets to load into the page. This one allows for fine positioning and can be very useful for things like an extension providing global css for a wiki farm.
** SkinGlobalVariables to allow extensions to add new global variables to export to the JS variables in the page.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/skins/Modern.php (modified) (history)
  • /trunk/phase3/skins/MonoBook.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/MonoBook.php
@@ -158,6 +158,7 @@
159159 if ( !isset( $sidebar['SEARCH'] ) ) $sidebar['SEARCH'] = true;
160160 if ( !isset( $sidebar['TOOLBOX'] ) ) $sidebar['TOOLBOX'] = true;
161161 if ( !isset( $sidebar['LANGUAGES'] ) ) $sidebar['LANGUAGES'] = true;
 162+
162163 foreach ($sidebar as $boxName => $cont) {
163164 if ( $boxName == 'SEARCH' ) {
164165 $this->searchBox();
@@ -166,7 +167,10 @@
167168 } elseif ( $boxName == 'LANGUAGES' ) {
168169 $this->languageBox();
169170 } else {
170 - $this->customBox( $boxName, $cont );
 171+ if( wfRunHooks( 'SkinSidebarOutputSpecialBox', array( &$this, $boxName, $cont ) ) ) {
 172+ # If no hook returned false, then output a normal box
 173+ $this->customBox( $boxName, $cont );
 174+ }
171175 }
172176 }
173177 ?>
Index: trunk/phase3/skins/Modern.php
@@ -156,7 +156,7 @@
157157 if ( !isset( $sidebar['SEARCH'] ) ) $sidebar['SEARCH'] = true;
158158 if ( !isset( $sidebar['TOOLBOX'] ) ) $sidebar['TOOLBOX'] = true;
159159 if ( !isset( $sidebar['LANGUAGES'] ) ) $sidebar['LANGUAGES'] = true;
160 -
 160+
161161 foreach ($sidebar as $boxName => $cont) {
162162 if ( $boxName == 'SEARCH' ) {
163163 $this->searchBox();
@@ -165,7 +165,10 @@
166166 } elseif ( $boxName == 'LANGUAGES' ) {
167167 $this->languageBox();
168168 } else {
169 - $this->customBox( $boxName, $cont );
 169+ if( wfRunHooks( 'SkinSidebarOutputSpecialBox', array( &$this, $boxName, $cont ) ) ) {
 170+ # If no hook returned false, then output a normal box
 171+ $this->customBox( $boxName, $cont );
 172+ }
170173 }
171174 }
172175 ?>
@@ -349,4 +352,5 @@
350353 }
351354
352355 } // end of class
353 -?>
 356+
 357+
Index: trunk/phase3/docs/hooks.txt
@@ -1062,6 +1062,27 @@
10631063 &$text: bottomScripts Text
10641064 Append to $text to add additional text/scripts after the stock bottom scripts.
10651065
 1066+'SkinGlobalVariables': Allows modification of the JS global variables exported to the browser
 1067+&$vars: The list of variables
 1068+
 1069+'SkinSetupSiteCss': Allows modification of the stylesheets and css imported into the skin
 1070+&$stylesheets: The list of stylesheet urls for importing, keys allow for internal things to be
 1071+unset or have query arguments appended
 1072+&$rawcss: Raw css to be exported
 1073+$msgQuery: Query containing caching and other params to use when adding a stylesheet url
 1074+that comes from a MediaWiki: message page
 1075+
 1076+'SkinSidebarOutputSpecialBox': Allows for custom outputting of special sidebar boxes
 1077+&$skin: Skin object
 1078+$boxName: Name of the skin box to output
 1079+$cont: Content array which may be used for options
 1080+
 1081+'SkinSidebarSpecialBox': Allows for extension definition of custom special sidebar boxes
 1082+Set $cont to an array of initial data and return false to define a new sidebar box
 1083+&$skin: Skin object
 1084+$boxName: Name of the custom box to match
 1085+&$cont: Content array
 1086+
10661087 'SkinSubPageSubtitle': At the beginning of Skin::subPageSubtitle()
10671088 $skin: Skin object
10681089 &$subpages: Subpage links HTML
Index: trunk/phase3/includes/SkinTemplate.php
@@ -964,54 +964,62 @@
965965
966966 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
967967
968 - $sitecss = '';
969 - $usercss = '';
 968+ $stylesheets = array();
 969+ $rawcss = '';
970970 $siteargs = '&maxage=' . $wgSquidMaxage;
 971+ $userPreview = false;
971972 if( $this->loggedin ) {
972973 // Ensure that logged-in users' generated CSS isn't clobbered
973974 // by anons' publicly cacheable generated CSS.
974975 $siteargs .= '&smaxage=0';
975 - }
976 -
977 - # Add user-specific code if this is a user and we allow that kind of thing
978 -
979 - if ( $wgAllowUserCss && $this->loggedin ) {
980 - $action = $wgRequest->getText('action');
981 -
982 - # if we're previewing the CSS page, use it
983 - if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
984 - $siteargs = "&smaxage=0&maxage=0";
985 - $usercss = $wgRequest->getText('wpTextbox1');
986 - } else {
987 - $usercss = '@import "' .
988 - self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
989 - 'action=raw&ctype=text/css') . '";' ."\n";
 976+
 977+ // If we allow user-specific code append some arguments for it
 978+ if( $wgAllowUserCss ) {
 979+ $action = $wgRequest->getText('action');
 980+ $userPreview = $this->mTitle->isCssSubpage() && $this->userCanPreview( $action );
 981+ $siteargs .= '&ts=' . $wgUser->mTouched;
 982+ if( $userPreview ) $siteargs = "&smaxage=0&maxage=0";
990983 }
991 -
992 - $siteargs .= '&ts=' . $wgUser->mTouched;
993984 }
994 -
 985+
995986 if( $wgContLang->isRTL() && in_array( 'rtl', $this->cssfiles ) ) {
996987 global $wgStyleVersion;
997 - $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
 988+ $stylesheets['skinrtl'] = "$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion";
998989 }
999 -
 990+
1000991 # If we use the site's dynamic CSS, throw that in, too
1001 - if ( $wgUseSiteCss ) {
 992+ if( $wgUseSiteCss ) {
1002993 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
1003994 $skinquery = '';
1004995 if (($us = $wgRequest->getVal('useskin', '')) !== '')
1005996 $skinquery = "&useskin=$us";
1006 - $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
1007 - $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
1008 - $sitecss .= '@import "' . self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
 997+ $stylesheets['sitecommon'] = self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI);
 998+ $stylesheets['siteskin'] = self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI );
 999+ $stylesheets['gen'] = self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" );
10091000 }
1010 -
 1001+
 1002+ # Add user-specific code if this is a user and we allow that kind of thing
 1003+ if( $wgAllowUserCss && $this->loggedin ) {
 1004+ # if we're previewing the CSS page, use it
 1005+ if( $userPreview ) {
 1006+ $rawcss .= $wgRequest->getText('wpTextbox1');
 1007+ } else {
 1008+ $stylesheets['userskin'] = self::makeUrl(
 1009+ $this->userpage . '/'.$this->skinname.'.css',
 1010+ 'action=raw&ctype=text/css');
 1011+ }
 1012+ }
 1013+
 1014+ wfRunHooks( 'SkinSetupSiteCss', array( &$stylesheets, &$rawcss, $query ) );
 1015+
10111016 # If we use any dynamic CSS, make a little CDATA block out of it.
1012 -
1013 - if ( !empty($sitecss) || !empty($usercss) ) {
1014 - $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
 1017+ $s = '';
 1018+ foreach( $stylesheets as $link ) {
 1019+ $s .= "@import \"$link\";\n";
10151020 }
 1021+ $s .= $rawcss;
 1022+ if( $s != '' ) $this->usercss = "/*<![CDATA[*/\n{$s}/*]]>*/";
 1023+
10161024 wfProfileOut( __METHOD__ );
10171025 }
10181026
Index: trunk/phase3/includes/Skin.php
@@ -361,6 +361,8 @@
362362 }
363363 $vars['wgAjaxWatch'] = $msgs;
364364 }
 365+
 366+ wfRunHooks('SkinGlobalVariables', array(&$vars));
365367
366368 return self::makeVariablesScript( $vars );
367369 }
@@ -418,17 +420,25 @@
419421 function getUserStylesheet() {
420422 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
421423 $sheet = $this->getStylesheet();
422 - $s = "@import \"$wgStylePath/common/shared.css?$wgStyleVersion\";\n";
423 - $s .= "@import \"$wgStylePath/common/oldshared.css?$wgStyleVersion\";\n";
424 - $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
425 - if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
426 -
427424 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
428 - $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
429 - '@import "' . self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
430 -
431 - $s .= $this->doGetUserStyles();
432 - return $s."\n";
 425+
 426+ $stylesheets = array();
 427+ $stylesheets['shared'] = "$wgStylePath/common/shared.css?$wgStyleVersion";
 428+ $stylesheets['oldshared'] = "$wgStylePath/common/oldshared.css?$wgStyleVersion";
 429+ $stylesheets['skin'] = "$wgStylePath/$sheet?$wgStyleVersion";
 430+ if($wgContLang->isRTL()) $stylesheets['rtl'] = "$wgStylePath/common/common_rtl.css?$wgStyleVersion";
 431+ $stylesheets['sitecommon'] = self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI );
 432+ $stylesheets['siteskin'] = self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI );
 433+
 434+ $rawcss = $this->doGetUserStyles();
 435+
 436+ wfRunHooks( 'SkinSetupSiteCss', array( &$stylesheets, &$rawcss, $query ) );
 437+
 438+ $s = '';
 439+ foreach( $stylesheets as $link ) {
 440+ $s .= "@import \"$link\";\n";
 441+ }
 442+ return "{$s}{$rawcss}\n";
433443 }
434444
435445 /**
@@ -1672,19 +1682,35 @@
16731683 $bar = array();
16741684 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
16751685 $heading = '';
 1686+ $specialBox = false;
16761687 foreach ($lines as $line) {
16771688 if (strpos($line, '*') !== 0)
16781689 continue;
16791690 if (strpos($line, '**') !== 0) {
16801691 $line = trim($line, '* ');
 1692+
16811693 if ( $line == 'SEARCH' || $line == 'TOOLBOX' || $line == 'LANGUAGES' ) {
1682 - # Special box type
 1694+ # Internal special box type
16831695 $bar[$line] = array();
 1696+ $specialBox = true;
16841697 } else {
1685 - $heading = $line;
 1698+ $cont = null;
 1699+ # Allow extensions to start a special box
 1700+ if( !wfRunHooks( 'SkinSidebarSpecialBox', array( &$this, $line, &$cont ) ); ) {
 1701+ # Extension special box type
 1702+ $bar[$line] = $cont;
 1703+ $specialBox = true;
 1704+ } else {
 1705+ # Normal box
 1706+ $specialBox = false;
 1707+ }
16861708 }
 1709+ $heading = $line;
16871710 } else {
1688 - if (strpos($line, '|') !== false) { // sanity check
 1711+ if( $specialBox ) {
 1712+ # Inside a special box, we just append the lines into the $cont
 1713+ $bar[$heading][] = $line;
 1714+ } elseif (strpos($line, '|') !== false) { // sanity check
16891715 $line = array_map('trim', explode( '|' , trim($line, '* '), 2 ) );
16901716 $link = wfMsgForContent( $line[0] );
16911717 if ($link == '-')
Index: trunk/phase3/RELEASE-NOTES
@@ -181,7 +181,9 @@
182182 * (bug 11732) Allow localisation of edit button images
183183 * Allow the search box, toolbox and languages box in the Monobook sidebar to be
184184 moved around arbitrarily using special sections in [[MediaWiki:Sidebar]]:
185 - SEARCH, TOOLBOX and LANGUAGES
 185+ SEARCH, TOOLBOX and LANGUAGES extensions may also add new custom boxes to the
 186+ sidebar by hooking into SkinSidebarSpecialBox to define the box and into
 187+ SkinSidebarOutputSpecialBox to output data for the box.
186188 * Add a new hook NormalizeMessageKey to allow extensions to replace messages before
187189 the database is potentially queried
188190 * (bug 9736) Redirects on Special:Fewestrevisions are now marked as such.
@@ -190,7 +192,12 @@
191193 * HTML entities like &nbsp; now work (are not escaped) in edit summaries.
192194 * (bug 13815) In the comment for page moves, use the colon-separator message
193195 instead of a hardcoded colon.
194 -
 196+* Add a new hook SkinSetupSiteCss to allow extensions to define new stylesheets
 197+ to load site wide, or modify the list of stylesheets to load. This can be useful
 198+ for wiki farms who need a specific placement of the stylesheets to cascade right.
 199+* Add a new hook SkinGlobalVariables to allow extensions to add new global variables
 200+ to be exported for JavaScript code to make use of.
 201+
195202 === Bug fixes in 1.13 ===
196203
197204 * (bug 10677) Add link to the file description page on the shared repository

Follow-up revisions

RevisionCommit summaryAuthorDate
r37719Revert r37686, 37687 for now:...brion21:35, 15 July 2008

Status & tagging log