r83039 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83038‎ | r83039 | r83040 >
Date:19:25, 1 March 2011
Author:mah
Status:deferred (Comments)
Tags:
Comment:
Bug #27795 - Apply patch from Christian Boltz to make
$wgSelectCategoryMaxLeel of which he writes:

I updated to SelectCategory 0.8. The jQuery treeview is a very nice feature,
however all categories are collapsed by default. This means my users see only
the root category with a [+] sign.

I found $wgSelectCategoryMaxLevel in the code, but changing it didn't work.

Long story short: you need to set class='open' if a node should be open by
default.
Modified paths:
  • /trunk/extensions/SelectCategory/SelectCategoryFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SelectCategory/SelectCategoryFunctions.php
@@ -22,95 +22,100 @@
2323
2424 # check if we should do anything or sleep
2525 if ( fnSelectCategoryCheckConditions( $m_isUpload, $m_pageObj ) ) {
26 - # Register CSS file for our select box:
27 - global $wgOut, $wgScriptPath, $wgUser, $wgTitle;
28 - global $wgSelectCategoryMaxLevel;
 26+ # Register CSS file for our select box:
 27+ global $wgOut, $wgScriptPath, $wgUser, $wgTitle;
 28+ global $wgSelectCategoryMaxLevel;
2929
30 - $wgOut->addLink(
31 - array(
32 - 'rel' => 'stylesheet',
33 - 'type' => 'text/css',
34 - 'href' => $wgScriptPath.'/extensions/SelectCategory/SelectCategory.css'
35 - )
36 - );
37 - $wgOut->addLink(
38 - array(
39 - 'rel' => 'stylesheet',
40 - 'type' => 'text/css',
41 - 'href' => $wgScriptPath.'/extensions/SelectCategory/jquery.treeview.css'
42 - )
43 - );
44 - $wgOut->addScript( '<script src="'.$wgScriptPath.'/extensions/SelectCategory/jquery.treeview.js" type="text/javascript"></script>' );
45 - $wgOut->addScript( '<script src="'.$wgScriptPath.'/extensions/SelectCategory/SelectCategory.js" type="text/javascript"></script>' );
 30+ $wgOut->addLink(
 31+ array(
 32+ 'rel' => 'stylesheet',
 33+ 'type' => 'text/css',
 34+ 'href' => $wgScriptPath.'/extensions/SelectCategory/SelectCategory.css'
 35+ )
 36+ );
 37+ $wgOut->addLink(
 38+ array(
 39+ 'rel' => 'stylesheet',
 40+ 'type' => 'text/css',
 41+ 'href' => $wgScriptPath.'/extensions/SelectCategory/jquery.treeview.css'
 42+ )
 43+ );
 44+ $wgOut->addScript( '<script src="'.$wgScriptPath.'/extensions/SelectCategory/jquery.treeview.js" type="text/javascript"></script>' );
 45+ $wgOut->addScript( '<script src="'.$wgScriptPath.'/extensions/SelectCategory/SelectCategory.js" type="text/javascript"></script>' );
4646
47 - $m_skin =& $wgUser->getSkin();
 47+ $m_skin =& $wgUser->getSkin();
4848
49 - # Get all categories from wiki:
50 - $m_allCats = fnSelectCategoryGetAllCategories();
51 - # Load system messages:
52 - wfLoadExtensionMessages( 'SelectCategory' );
53 - # Get the right member variables, depending on if we're on an upload form or not:
54 - if( !$m_isUpload ) {
55 - # Extract all categorylinks from page:
56 - $m_pageCats = fnSelectCategoryGetPageCategories( $m_pageObj );
 49+ # Get all categories from wiki:
 50+ $m_allCats = fnSelectCategoryGetAllCategories();
 51+ # Load system messages:
 52+ wfLoadExtensionMessages( 'SelectCategory' );
 53+ # Get the right member variables, depending on if we're on an upload form or not:
 54+ if( !$m_isUpload ) {
 55+ # Extract all categorylinks from page:
 56+ $m_pageCats = fnSelectCategoryGetPageCategories( $m_pageObj );
5757
58 - # Never ever use editFormTextTop here as it resides outside
59 - # the <form> so we will never get contents
60 - $m_place = 'editFormTextAfterWarn';
61 - # Print the localised title for the select box:
62 - $m_textBefore = '<b>'. wfMsg( 'selectcategory-title' ) . '</b>:';
63 - } else {
64 - # No need to get categories:
65 - $m_pageCats = array();
 58+ # Never ever use editFormTextTop here as it resides outside
 59+ # the <form> so we will never get contents
 60+ $m_place = 'editFormTextAfterWarn';
 61+ # Print the localised title for the select box:
 62+ $m_textBefore = '<b>'. wfMsg( 'selectcategory-title' ) . '</b>:';
 63+ } else {
 64+ # No need to get categories:
 65+ $m_pageCats = array();
6666
67 - # Place output at the right place:
68 - $m_place = 'uploadFormTextAfterSummary';
69 - # Print the part of the table including the localised title for the select box:
70 - $m_textBefore = "\n</td></tr><tr><td align='right'><label for='wpSelectCategory'>" . wfMsg( 'selectcategory-title' ) .":</label></td><td align='left'>";
71 - }
72 - # Introduce the output:
73 - $m_pageObj->$m_place .= "<!-- SelectCategory begin -->\n";
74 - # Print the select box:
75 - $m_pageObj->$m_place .= "\n$m_textBefore";
 67+ # Place output at the right place:
 68+ $m_place = 'uploadFormTextAfterSummary';
 69+ # Print the part of the table including the localised title for the select box:
 70+ $m_textBefore = "\n</td></tr><tr><td align='right'><label for='wpSelectCategory'>" . wfMsg( 'selectcategory-title' ) .":</label></td><td align='left'>";
 71+ }
 72+ # Introduce the output:
 73+ $m_pageObj->$m_place .= "<!-- SelectCategory begin -->\n";
 74+ # Print the select box:
 75+ $m_pageObj->$m_place .= "\n$m_textBefore";
7676
77 - # Begin list output, use <div> to enable custom formatting
78 - $m_level = 0;
79 - $m_pageObj->$m_place .= '<ul id="SelectCategoryList">';
 77+ # Begin list output, use <div> to enable custom formatting
 78+ $m_level = 0;
 79+ $m_pageObj->$m_place .= '<ul id="SelectCategoryList">';
8080
81 - foreach( $m_allCats as $m_cat => $m_depth ) {
82 - $checked = '';
 81+ foreach( $m_allCats as $m_cat => $m_depth ) {
 82+ $checked = '';
8383
84 - # See if the category was already added, so check it
85 - if( isset( $m_pageCats[$m_cat] ) ) {
86 - $checked = 'checked="checked"';
87 - }
88 - # Clean HTML Output:
89 - $category = htmlspecialchars( $m_cat );
 84+ # See if the category was already added, so check it
 85+ if( isset( $m_pageCats[$m_cat] ) ) {
 86+ $checked = 'checked="checked"';
 87+ }
 88+ # Clean HTML Output:
 89+ $category = htmlspecialchars( $m_cat );
9090
91 - # iterate through levels and adjust divs accordingly
92 - while( $m_level < $m_depth ) {
93 - # Collapse subcategories after reaching the configured MaxLevel
94 - if( $m_level >= ( $wgSelectCategoryMaxLevel - 1 ) ) {
95 - $m_class = 'display:none;';
96 - } else {
97 - $m_class = 'display:block;';
98 - }
99 - $m_pageObj->$m_place .= '<ul style="'.$m_class.'">'."\n";
100 - $m_level++;
101 - }
102 - if( $m_level == $m_depth ) $m_pageObj->$m_place .= '</li>'."\n";
103 - while( $m_level > $m_depth ) {
104 - $m_pageObj->$m_place .= '</ul></li>'."\n";
105 - $m_level--;
106 - }
107 - # Clean names for text output
108 - $title = str_replace( '_', ' ', $category );
109 - $m_title = $wgTitle->newFromText( $category, NS_CATEGORY );
110 - # Output the actual checkboxes, indented
111 - $m_pageObj->$m_place .= '<li><input type="checkbox" name="SelectCategoryList[]" value="'.$category.'" class="checkbox" '.$checked.' />'.$m_skin->link( $m_title, $title )."\n";
112 - # set id for next level
113 - $m_level_id = 'sc_'.$m_cat;
114 - } # End walking through cats (foreach)
 91+ # default for root category - otherwise it will always be closed
 92+ $m_open = " class='open' ";
 93+
 94+ # iterate through levels and adjust divs accordingly
 95+ while( $m_level < $m_depth ) {
 96+ # Collapse subcategories after reaching the configured MaxLevel
 97+ if( $m_level >= ( $wgSelectCategoryMaxLevel - 1 ) ) {
 98+ $m_class = 'display:none;';
 99+ $m_open = " class='closed' ";
 100+ } else {
 101+ $m_class = 'display:block;';
 102+ $m_open = " class='open' ";
 103+ }
 104+ $m_pageObj->$m_place .= '<ul style="'.$m_class.'">'."\n";
 105+ $m_level++;
 106+ }
 107+ if( $m_level == $m_depth ) $m_pageObj->$m_place .= '</li>'."\n";
 108+ while( $m_level > $m_depth ) {
 109+ $m_pageObj->$m_place .= '</ul></li>'."\n";
 110+ $m_level--;
 111+ }
 112+ # Clean names for text output
 113+ $title = str_replace( '_', ' ', $category );
 114+ $m_title = $wgTitle->newFromText( $category, NS_CATEGORY );
 115+ # Output the actual checkboxes, indented
 116+ $m_pageObj->$m_place .= '<li' . $m_open . '><input type="checkbox" name="SelectCategoryList[]" value="'.$category.'" class="checkbox" '.$checked.' />'.$m_skin->link( $m_title, $title )."\n";
 117+ # set id for next level
 118+ $m_level_id = 'sc_'.$m_cat;
 119+ } # End walking through cats (foreach)
115120 # End of list output - close all remaining divs
116121 while( $m_level > -1 ) {
117122 $m_pageObj->$m_place .= '</li></ul>'."\n";

Comments

#Comment by MarkAHershberger (talk | contribs)   19:38, 1 March 2011

Sorry for the overwhelming amount of w/s changes. Tried to get rid of all of them separately, but failed. Try " svn diff -x-w -r83038:83039"

#Comment by Cboltz (talk | contribs)   13:45, 19 January 2012

... or just use the viewvc interface, which also skips whitespace changes: r1=83038&r2=83039 https://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SelectCategory/SelectCategoryFunctions.php?&pathrev=83039&r1=83038&r2=83039

Status & tagging log