Improving extendibility of the sidebar improvements, css adding, and also JS variables.
authorDaniel Friesen <dantman@users.mediawiki.org>
Tue, 15 Jul 2008 11:03:04 +0000 (11:03 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Tue, 15 Jul 2008 11:03:04 +0000 (11:03 +0000)
* 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.

RELEASE-NOTES
docs/hooks.txt
includes/Skin.php
includes/SkinTemplate.php
skins/Modern.php
skins/MonoBook.php

index 72bb5be..1a71195 100644 (file)
@@ -181,7 +181,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 11732) Allow localisation of edit button images
 * Allow the search box, toolbox and languages box in the Monobook sidebar to be
   moved around arbitrarily using special sections in [[MediaWiki:Sidebar]]: 
-  SEARCH, TOOLBOX and LANGUAGES
+  SEARCH, TOOLBOX and LANGUAGES extensions may also add new custom boxes to the
+  sidebar by hooking into SkinSidebarSpecialBox to define the box and into
+  SkinSidebarOutputSpecialBox to output data for the box.
 * Add a new hook NormalizeMessageKey to allow extensions to replace messages before
   the database is potentially queried
 * (bug 9736) Redirects on Special:Fewestrevisions are now marked as such.
@@ -190,7 +192,12 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * HTML entities like &nbsp; now work (are not escaped) in edit summaries.
 * (bug 13815) In the comment for page moves, use the colon-separator message
   instead of a hardcoded colon.
+* Add a new hook SkinSetupSiteCss to allow extensions to define new stylesheets
+  to load site wide, or modify the list of stylesheets to load. This can be useful
+  for wiki farms who need a specific placement of the stylesheets to cascade right.
+* Add a new hook SkinGlobalVariables to allow extensions to add new global variables
+  to be exported for JavaScript code to make use of.
+
 === Bug fixes in 1.13 ===
 
 * (bug 10677) Add link to the file description page on the shared repository
index 64064b9..bf9c694 100644 (file)
@@ -1062,6 +1062,27 @@ $skin: Skin object
 &$text: bottomScripts Text
 Append to $text to add additional text/scripts after the stock bottom scripts.
 
+'SkinGlobalVariables': Allows modification of the JS global variables exported to the browser
+&$vars: The list of variables
+
+'SkinSetupSiteCss': Allows modification of the stylesheets and css imported into the skin
+&$stylesheets: The list of stylesheet urls for importing, keys allow for internal things to be
+unset or have query arguments appended
+&$rawcss: Raw css to be exported
+$msgQuery: Query containing caching and other params to use when adding a stylesheet url
+that comes from a MediaWiki: message page
+
+'SkinSidebarOutputSpecialBox': Allows for custom outputting of special sidebar boxes
+&$skin: Skin object
+$boxName: Name of the skin box to output
+$cont: Content array which may be used for options
+
+'SkinSidebarSpecialBox': Allows for extension definition of custom special sidebar boxes
+Set $cont to an array of initial data and return false to define a new sidebar box
+&$skin: Skin object
+$boxName: Name of the custom box to match
+&$cont: Content array
+
 'SkinSubPageSubtitle': At the beginning of Skin::subPageSubtitle()
 $skin: Skin object
 &$subpages: Subpage links HTML
index a9e44ab..2197469 100644 (file)
@@ -361,6 +361,8 @@ class Skin extends Linker {
                        }
                        $vars['wgAjaxWatch'] = $msgs;
                }
+               
+               wfRunHooks('SkinGlobalVariables', array(&$vars));
 
                return self::makeVariablesScript( $vars );
        }
@@ -418,17 +420,25 @@ class Skin extends Linker {
        function getUserStylesheet() {
                global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
                $sheet = $this->getStylesheet();
-               $s = "@import \"$wgStylePath/common/shared.css?$wgStyleVersion\";\n";
-               $s .= "@import \"$wgStylePath/common/oldshared.css?$wgStyleVersion\";\n";
-               $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
-               if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
-
                $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
-               $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
-                       '@import "' . self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
-
-               $s .= $this->doGetUserStyles();
-               return $s."\n";
+               
+               $stylesheets = array();
+               $stylesheets['shared']    = "$wgStylePath/common/shared.css?$wgStyleVersion";
+               $stylesheets['oldshared'] = "$wgStylePath/common/oldshared.css?$wgStyleVersion";
+               $stylesheets['skin']      = "$wgStylePath/$sheet?$wgStyleVersion";
+               if($wgContLang->isRTL()) $stylesheets['rtl'] = "$wgStylePath/common/common_rtl.css?$wgStyleVersion";
+               $stylesheets['sitecommon'] = self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI );
+               $stylesheets['siteskin']  = self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI );
+               
+               $rawcss = $this->doGetUserStyles();
+               
+               wfRunHooks( 'SkinSetupSiteCss', array( &$stylesheets, &$rawcss, $query ) );
+               
+               $s = '';
+               foreach( $stylesheets as $link ) {
+                       $s .= "@import \"$link\";\n";
+               }
+               return "{$s}{$rawcss}\n";
        }
 
        /**
@@ -1672,19 +1682,35 @@ END;
                $bar = array();
                $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
                $heading = '';
+               $specialBox = false;
                foreach ($lines as $line) {
                        if (strpos($line, '*') !== 0)
                                continue;
                        if (strpos($line, '**') !== 0) {
                                $line = trim($line, '* ');
+                               
                                if ( $line == 'SEARCH' || $line == 'TOOLBOX' || $line == 'LANGUAGES' ) {
-                                       # Special box type
+                                       # Internal special box type
                                        $bar[$line] = array();
+                                       $specialBox = true;
                                } else {
-                                       $heading = $line;
+                                       $cont = null;
+                                       # Allow extensions to start a special box
+                                       if( !wfRunHooks( 'SkinSidebarSpecialBox', array( &$this, $line, &$cont ) ); ) {
+                                               # Extension special box type
+                                               $bar[$line] = $cont;
+                                               $specialBox = true;
+                                       } else {
+                                               # Normal box
+                                               $specialBox = false;
+                                       }
                                }
+                               $heading = $line;
                        } else {
-                               if (strpos($line, '|') !== false) { // sanity check
+                               if( $specialBox ) {
+                                       # Inside a special box, we just append the lines into the $cont
+                                       $bar[$heading][] = $line;
+                               } elseif (strpos($line, '|') !== false) { // sanity check
                                        $line = array_map('trim', explode( '|' , trim($line, '* '), 2 ) );
                                        $link = wfMsgForContent( $line[0] );
                                        if ($link == '-')
index c60cfb4..ae894cc 100644 (file)
@@ -964,54 +964,62 @@ class SkinTemplate extends Skin {
 
                global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
 
-               $sitecss = '';
-               $usercss = '';
+               $stylesheets = array();
+               $rawcss = '';
                $siteargs = '&maxage=' . $wgSquidMaxage;
+               $userPreview = false;
                if( $this->loggedin ) {
                        // Ensure that logged-in users' generated CSS isn't clobbered
                        // by anons' publicly cacheable generated CSS.
                        $siteargs .= '&smaxage=0';
-               }
-
-               # Add user-specific code if this is a user and we allow that kind of thing
-
-               if ( $wgAllowUserCss && $this->loggedin ) {
-                       $action = $wgRequest->getText('action');
-
-                       # if we're previewing the CSS page, use it
-                       if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
-                               $siteargs = "&smaxage=0&maxage=0";
-                               $usercss = $wgRequest->getText('wpTextbox1');
-                       } else {
-                               $usercss = '@import "' .
-                                 self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
-                                                                'action=raw&ctype=text/css') . '";' ."\n";
+                       
+                       // If we allow user-specific code append some arguments for it
+                       if( $wgAllowUserCss ) {
+                               $action = $wgRequest->getText('action');
+                               $userPreview = $this->mTitle->isCssSubpage() && $this->userCanPreview( $action );
+                               $siteargs .= '&ts=' . $wgUser->mTouched;
+                               if( $userPreview ) $siteargs = "&smaxage=0&maxage=0";
                        }
-
-                       $siteargs .= '&ts=' . $wgUser->mTouched;
                }
-
+               
                if( $wgContLang->isRTL() && in_array( 'rtl', $this->cssfiles ) ) {
                        global $wgStyleVersion;
-                       $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
+                       $stylesheets['skinrtl'] = "$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion";
                }
-
+               
                # If we use the site's dynamic CSS, throw that in, too
-               if ( $wgUseSiteCss ) {
+               if( $wgUseSiteCss ) {
                        $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
                        $skinquery = '';
                        if (($us = $wgRequest->getVal('useskin', '')) !== '')
                                $skinquery = "&useskin=$us";
-                       $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
-                       $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
-                       $sitecss .= '@import "' . self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
+                       $stylesheets['sitecommon'] = self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI);
+                       $stylesheets['siteskin']   = self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI );
+                       $stylesheets['gen']        = self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" );
                }
-
+               
+               # Add user-specific code if this is a user and we allow that kind of thing
+               if( $wgAllowUserCss && $this->loggedin ) {
+                       # if we're previewing the CSS page, use it
+                       if( $userPreview ) {
+                               $rawcss .= $wgRequest->getText('wpTextbox1');
+                       } else {
+                               $stylesheets['userskin'] = self::makeUrl(
+                                       $this->userpage . '/'.$this->skinname.'.css',
+                                       'action=raw&ctype=text/css');
+                       }
+               }
+               
+               wfRunHooks( 'SkinSetupSiteCss', array( &$stylesheets, &$rawcss, $query ) );
+               
                # If we use any dynamic CSS, make a little CDATA block out of it.
-
-               if ( !empty($sitecss) || !empty($usercss) ) {
-                       $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
+               $s = '';
+               foreach( $stylesheets as $link ) {
+                       $s .= "@import \"$link\";\n";
                }
+               $s .= $rawcss;
+               if( $s != '' ) $this->usercss = "/*<![CDATA[*/\n{$s}/*]]>*/";
+               
                wfProfileOut( __METHOD__ );
        }
 
index e75e4ae..bfbc0a8 100644 (file)
@@ -156,7 +156,7 @@ class ModernTemplate extends QuickTemplate {
                if ( !isset( $sidebar['SEARCH'] ) ) $sidebar['SEARCH'] = true;
                if ( !isset( $sidebar['TOOLBOX'] ) ) $sidebar['TOOLBOX'] = true;
                if ( !isset( $sidebar['LANGUAGES'] ) ) $sidebar['LANGUAGES'] = true;
-
+               
                foreach ($sidebar as $boxName => $cont) {
                        if ( $boxName == 'SEARCH' ) {
                                $this->searchBox();
@@ -165,7 +165,10 @@ class ModernTemplate extends QuickTemplate {
                        } elseif ( $boxName == 'LANGUAGES' ) {
                                $this->languageBox();
                        } else {
-                               $this->customBox( $boxName, $cont );
+                               if( wfRunHooks( 'SkinSidebarOutputSpecialBox', array( &$this, $boxName, $cont ) ) ) {
+                                       # If no hook returned false, then output a normal box
+                                       $this->customBox( $boxName, $cont );
+                               }
                        }
                }
        ?>
@@ -349,4 +352,5 @@ class ModernTemplate extends QuickTemplate {
        }
 
 } // end of class
-?>
+
+
index bfd94d5..6d3baf6 100644 (file)
@@ -158,6 +158,7 @@ class MonoBookTemplate extends QuickTemplate {
                if ( !isset( $sidebar['SEARCH'] ) ) $sidebar['SEARCH'] = true;
                if ( !isset( $sidebar['TOOLBOX'] ) ) $sidebar['TOOLBOX'] = true;
                if ( !isset( $sidebar['LANGUAGES'] ) ) $sidebar['LANGUAGES'] = true;
+               
                foreach ($sidebar as $boxName => $cont) {
                        if ( $boxName == 'SEARCH' ) {
                                $this->searchBox();
@@ -166,7 +167,10 @@ class MonoBookTemplate extends QuickTemplate {
                        } elseif ( $boxName == 'LANGUAGES' ) {
                                $this->languageBox();
                        } else {
-                               $this->customBox( $boxName, $cont );
+                               if( wfRunHooks( 'SkinSidebarOutputSpecialBox', array( &$this, $boxName, $cont ) ) ) {
+                                       # If no hook returned false, then output a normal box
+                                       $this->customBox( $boxName, $cont );
+                               }
                        }
                }
 ?>