User:Gatoatigrado/sidebarhack

overview
This page is a quick hack to display a modified sidebar. It does not implement the more elegant solution of displaying user-defined toolbox items. Toolbox items (adding the horizontal line) is not complete yet; I would like Wikipedia's toolbox to add the cite item.


 * The very nice html output is thanks to Kwrite.


 * non-formatted pages at monobook and skin.


 * also a complete diff_version_1.8_2006-10-04.

input
* navigation ** mainpage|mainpage ** Wikipedia:Featured content|Featured content ** currentevents-url|currentevents ** Portal:Browse|Portals ** Wikipedia:Categorical index|Categories ** randompage-url|randompage * #searchbox * interact ** helppage|help ** portal-url|portal ** Wikipedia:Questions|Questions ** contact-url|Contact ** sitesupport-url|sitesupport

output

 * updated toolbox edits visible at http://wiki.ntung.com



skin.php
if the skin is set to monobook, the buildSidebar function will look for MediaWiki:monobooksidebar. It will handle the '#searchbox' header by assigning its value to "special:searchbox" instead of an array of list items. --gatoatigrado 17:09, 29 September 2006 (UTC)

&lt;?php /** 	 * Build an array that represents the sidebar(s), the navigation bar among them * 	 * @return array * @private */ 	 function buildSidebar  { global $wgDBname,  $parserMemc ,  $wgEnableSidebarCache ; global $wgLanguageCode,  $wgContLanguageCode ; // detect if monobook is set as the current skin // may be set to false if there is no MediaWiki:monobooksidebar $isMonobook = $this -&gt;skinname == "monobook" ; // run any hooks $fname = 'SkinTemplate::buildSidebar' ; wfProfileIn ( $fname  ); $cacheSidebar = $wgEnableSidebarCache &amp;&amp; ( $wgLanguageCode == $wgContLanguageCode ); // user has enabled sidebar cache if ( $cacheSidebar ) { 			 // if the user is using monobook if ( $isMonobook ) { 				 $key = " $wgDBname :monobooksidebar" ; // if the cache exists, return. if (( $cachedsidebar = $parserMemc -&gt;get ( $key )) !== false ) { 					wfProfileOut ( $fname ); return $cachedsidebar ; } 				 // if MediaWiki:monobooksidebar exists, parse, if it doesn't exist, try the other cache else if ( wfEmptyMsg ( 'monobooksidebar',  ( $monobooksidebar = wfMsgForContent ( 'monobooksidebar' )))) { 					 $isMonobook = false ; } 			}  			 if ( ! $isMonobook ) { 				 $key = " $wgDBname :sidebar" ; if (( $cachedsidebar = $parserMemc -&gt;get ( $key )) !== false ) { 					wfProfileOut ( $fname ); return $cachedsidebar ; } 			}  		}  		 // initialize output array $result = array ; // if the user disabled the sidebar cache, and $monobooksidebar was never saved if ( $isMonobook &amp;&amp; ! isset ( $monobooksidebar )) { $monobooksidebar = wfMsgForContent ( 'monobooksidebar' ); } if ( $isMonobook &amp;&amp; !wfEmptyMsg ( 'monobooksidebar', $monobooksidebar )) { $lines = explode ( " \n " ,  $monobooksidebar ); } else { $lines = explode ( " \n ", wfMsgForContent ( 'sidebar' )); } foreach ( $lines  as  $line ) { 			 if  ( strpos ( $line,  '*' ) !== 0 ) continue ; if ( strpos ( $line,  '**' ) !== 0 ) { 				 $line = trim ( $line,  '* ' ); $heading = $line ; if ( $heading == "#searchbox" ) { $result [ $heading ] = 'special:searchbox' ; } } 			 else  if  ( strpos ( $line,  '|' ) !== false ) { 				 $line = explode (  '|' ,  trim ( $line ,  '* ' ),  2  ); $link = wfMsgForContent ( $line [ 0 ]  ); if ( $link == '-' ) continue ; if ( wfEmptyMsg ( $line [ 1 ],  $text = wfMsg ( $line [ 1 ]))) $text = $line [ 1 ]; if ( wfEmptyMsg ( $line [ 0 ],  $link )) $link = $line [ 0 ]; $href = $this -&gt;makeInternalOrExternalUrl ( $link  ); if ( $heading == "#searchbox" ) { $result [ $heading ] = array ; } $result [ $heading ][] = array ( 					 'text' =&gt; $text,  					 'href' =&gt; $href ,  					 'id' =&gt; 'n-' . strtr ( $line [ 1 ],  ' ' ,  '-' ),  					 'active' =&gt; false  				 ); } 		}  		 if  ( $cacheSidebar ) $cachednotice = $parserMemc -&gt;set ( $key,  $result ,  86400  ); wfProfileOut ( $fname  ); return $result ; } ?&gt;

monobook.php
The only modifications to monobook will make an exception for the header equal to #searchbox with content type string and value "special:searchbox". The code for writing the searchbox was placed in another function. This function will be called when the header #searchbox is reached, or after the end of the foreach loop for all static sidebar headers. --gatoatigrado 17:05, 29 September 2006 (UTC)

The toolbox was cleaned up. It now displays a horizontal line between page content and usual toolbox links, such as "recent changes", "special pages", and "upload file". The line will not be present if there is no content above it. prior to cleanup. --gatoatigrado 20:33, 4 October 2006 (UTC)

&lt;?php /** * @todo document * @package MediaWiki * @subpackage Skins */ class MonoBookTemplate extends QuickTemplate { var $wrote_searchbox ; // write the searchbox function write_searchbox { if ( ! isset ( $this -&gt;wrote_searchbox )) { $this -&gt;wrote_searchbox = true ; } else { return ; } ?&gt; &lt;div id= "p-search" class= "portlet" &gt; &lt;h5&gt;&lt;label for= "searchInput" &gt;&lt;?php $this -&gt;msg ( 'search' )  ?&gt;&lt;/label&gt;&lt;/h5&gt; &lt;div id= "searchBody" class= "pBody" &gt; &lt;form action= " &lt;?php $this -&gt;text ( 'searchaction' )  ?&gt; " id= "searchform" &gt;&lt;div&gt; &lt;input id= "searchInput" name= "search" type= "text" &lt;?php if ( $this -&gt;haveMsg ( 'accesskey-search' )) { ?&gt; accesskey = " &lt;?php $this -&gt;msg ( 'accesskey-search' )  ?&gt; " &lt;?php } if ( isset (  $this -&gt;data [ 'search' ]  )  ) { ?&gt; value= " &lt;?php $this -&gt;text ( 'search' )  ?&gt; " &lt;?php } ?&gt;  /&gt; &lt;input type= 'submit' name= "go" class= "searchButton" id= "searchGoButton" 	value= " &lt;?php $this -&gt;msg ( 'go' )  ?&gt; "  /&gt; &amp;nbsp; &lt;input type= 'submit' name= "fulltext" class= "searchButton" value= " &lt;?php $this -&gt;msg ( 'search' )  ?&gt; "  /&gt; &lt;/div&gt;&lt;/form&gt; &lt;/div&gt; &lt;/div&gt;&lt;?php } /** 	 * Template filter callback for MonoBook skin. * Takes an associative array of data set from a SkinTemplate-based * class, and a wrapper for MediaWiki's localization database, and * outputs a formatted page. * 	 * @access private */ 	 function execute  { ?&gt; &lt;!-- ... --&gt; &lt;?php foreach ( $this -&gt;data [ 'sidebar' ]  as  $bar =&gt; $cont ) { if ( $bar == '#searchbox' &amp;&amp; $cont === 'special:searchbox' ) { 				 $this -&gt;write_searchbox ; continue ; } ?&gt; &lt;div class= 'portlet' id= 'p- &lt;?php echo  htmlspecialchars ( $bar )  ?&gt; ' &gt; &lt;h5&gt;&lt;?php $out = wfMsg (  $bar  );  if  ( wfEmptyMsg ( $bar,  $out ))  echo  $bar ;  else  echo  $out ;  ?&gt;&lt;/h5&gt; &lt;div class= 'pBody' &gt; &lt;ul&gt; &lt;?php 			 foreach ( $cont as  $key =&gt; $val ) { ?&gt; &lt;li id= " &lt;?php echo  htmlspecialchars ( $val [ 'id' ])  ?&gt; " &lt;?php if (  $val [ 'active' ]  ) { ?&gt; class= "active"  &lt;?php } ?&gt;&gt;&lt;a href= " &lt;?php echo  htmlspecialchars ( $val [ 'href' ])  ?&gt; " &gt;&lt;?php  echo  htmlspecialchars ( $val [ 'text' ])  ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php 			} ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php } $this -&gt;write_searchbox ; ?&gt; &lt;!-- ... --&gt; &lt;div class= "portlet" id= "p-tb" &gt; &lt;h5&gt;&lt;?php $this -&gt;msg ( 'toolbox' )  ?&gt;&lt;/h5&gt; &lt;div class= "pBody" &gt; &lt;ul&gt; &lt;?php $text_before_line = false ; if ( $this -&gt;data [ 'feeds' ]) { $text_before_line = true ;  ?&gt; &lt;li id= "feedlinks" &gt;&lt;?php foreach ( $this -&gt;data [ 'feeds' ]  as  $key =&gt; $feed ) { ?&gt;&lt;span id= "feed- &lt;?php echo  htmlspecialchars ( $key )  ?&gt; " &gt;&lt;a href= " &lt;?php  					 echo  htmlspecialchars ( $feed [ 'href' ])  ?&gt; " &gt;&lt;?php  echo  htmlspecialchars ( $feed [ 'text' ]) ?&gt;&lt;/a&gt; &amp;nbsp; &lt;/span&gt; &lt;?php } ?&gt;&lt;/li&gt;&lt;?php } 		 foreach (  array ( 'permalink',  'print' ,  'recentchangeslinked' ,  'whatlinkshere' , 'trackbacklink', 'contributions' ,  'blockip' ,  'emailuser' ,  '-' ,  'recentchanges' ,  'specialpages' ,  'upload' )  as  $special  ) { if ( $special == '-' &amp;&amp; $text_before_line ) { echo ( " \t\t\t &lt;/ul&gt; \n\t\t\t\t &lt;hr /&gt; \n\t\t\t &lt;ul&gt; \n " ); } else if ( $this -&gt;data [ 'nav_urls' ][ $special ]) { $text_before_line = true ; $link = $this -&gt;data [ 'nav_urls' ][ $special ][ 'href' ]; ?&gt; &lt;li id= "t- &lt;?php if ( $link ==    ) { echo  "is" ; } echo  $special  ?&gt; " &gt;&lt;?php  if ( $link !==    ) { ?&gt;&lt;a href= " &lt;?php  echo  htmlspecialchars ( $link )  				 ?&gt; " &gt;&lt;?php } ?&gt;&lt;?php  if ( $special == 'print' ) { $special = 'printableversion' ; } $this -&gt;msg ( $special )  ?&gt;&lt;?php  if ( $link !==  ''  ) { ?&gt;&lt;/a&gt;&lt;?php } ?&gt;&lt;/li&gt; &lt;?php 		} } 		wfRunHooks (  'MonoBookTemplateToolboxEnd',  array ( &amp; $this  )  ); ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt;

skintemplate.php
This adds a variable for the "recent changes" link in the toolbox.

&lt;?php function buildNavUrls { // ... 		 $nav_urls [ 'recentchanges' ] = array ( 'href' =&gt; $this -&gt;makeSpecialUrl ( 'Recentchanges' )); ?&gt;