Index: trunk/extensions/SelectCategory/SelectCategoryFunctions.php |
— | — | @@ -22,95 +22,100 @@ |
23 | 23 | |
24 | 24 | # check if we should do anything or sleep |
25 | 25 | 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; |
29 | 29 | |
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>' ); |
46 | 46 | |
47 | | - $m_skin =& $wgUser->getSkin(); |
| 47 | + $m_skin =& $wgUser->getSkin(); |
48 | 48 | |
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 ); |
57 | 57 | |
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(); |
66 | 66 | |
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"; |
76 | 76 | |
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">'; |
80 | 80 | |
81 | | - foreach( $m_allCats as $m_cat => $m_depth ) { |
82 | | - $checked = ''; |
| 81 | + foreach( $m_allCats as $m_cat => $m_depth ) { |
| 82 | + $checked = ''; |
83 | 83 | |
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 ); |
90 | 90 | |
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) |
115 | 120 | # End of list output - close all remaining divs |
116 | 121 | while( $m_level > -1 ) { |
117 | 122 | $m_pageObj->$m_place .= '</li></ul>'."\n"; |