Index: trunk/extensions/SelectCategory/SelectCategory.php |
— | — | @@ -87,10 +87,6 @@ |
88 | 88 | $wgHooks['EditPage::attemptSave'][] = array( 'fnSelectCategorySaveHook', false ); |
89 | 89 | # Hook when saving the upload: |
90 | 90 | $wgHooks['UploadForm:BeforeProcessing'][] = array( 'fnSelectCategorySaveHook', true ); |
91 | | - |
92 | | - ## Infrastructure |
93 | | - # Hook our own CSS: |
94 | | - $wgHooks['OutputPageParserOutput'][] = 'fnSelectCategoryOutputHook'; |
95 | 91 | } |
96 | 92 | |
97 | 93 | ## Load the file containing the hook functions: |
Index: trunk/extensions/SelectCategory/SelectCategory.css |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | * |
6 | 6 | * @package MediaWiki |
7 | 7 | * @subpackage Extensions |
8 | | - * @author Leon Weber <leon.weber@leonweber.de> & Manuel Schneider <manuel.schneider@wikimedia.ch> |
| 8 | + * @author Leon Weber <leon@leonweber.de> & Manuel Schneider <manuel.schneider@wikimedia.ch> |
9 | 9 | * @copyright © 2006 by Leon Weber & Manuel Schneider |
10 | 10 | * @licence GNU General Public Licence 2.0 or later |
11 | 11 | */ |
— | — | @@ -13,3 +13,15 @@ |
14 | 14 | width: 100%; |
15 | 15 | padding: .1em; |
16 | 16 | } |
| 17 | + |
| 18 | +ul#SelectCategoryList { |
| 19 | + list-style-image: none; |
| 20 | + list-style-type: none; |
| 21 | + float: left; |
| 22 | +} |
| 23 | + |
| 24 | +ul#SelectCategoryList li { |
| 25 | + float: left; |
| 26 | + width: 150px; |
| 27 | +} |
| 28 | + |
Index: trunk/extensions/SelectCategory/SelectCategoryFunctions.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | # to a specific page. |
7 | 7 | |
8 | 8 | # @addtogroup Extensions |
9 | | -# @author Leon Weber <leon.weber@leonweber.de> & Manuel Schneider <manuel.schneider@wikimedia.ch> |
| 9 | +# @author Leon Weber <leon@leonweber.de> & Manuel Schneider <manuel.schneider@wikimedia.ch> |
10 | 10 | # @copyright © 2006 by Leon Weber & Manuel Schneider |
11 | 11 | # @licence GNU General Public Licence 2.0 or later |
12 | 12 | |
— | — | @@ -19,6 +19,15 @@ |
20 | 20 | |
21 | 21 | # check if we should do anything or sleep |
22 | 22 | if ( fnSelectCategoryCheckConditions( $m_isUpload, &$m_pageObj ) ) { |
| 23 | + # Register CSS file for our select box: |
| 24 | + global $wgOut, $wgScriptPath; |
| 25 | + $wgOut->addLink( |
| 26 | + array( |
| 27 | + 'rel' => 'stylesheet', |
| 28 | + 'type' => 'text/css', |
| 29 | + 'href' => "$wgScriptPath/extensions/SelectCategory/SelectCategory.css" |
| 30 | + ) |
| 31 | + ); |
23 | 32 | |
24 | 33 | # Get all categories from wiki: |
25 | 34 | $m_allCats = fnSelectCategoryGetAllCategories(); |
— | — | @@ -50,25 +59,25 @@ |
51 | 60 | # $m_pageObj->$m_place .= "<script type=\"text/javascript\" src=\"'/extensions/SelectCategory/SelectCategory.js\"></script>\n"; |
52 | 61 | # # Then the "old-style" select box for those without JavaScript: |
53 | 62 | # $m_pageObj->$m_place .= "<noscript>\n"; |
54 | | - $m_pageObj->$m_place .= "<select id=\"SelectCategoryBox\" size=\"10\" name=\"SelectCategoryList[]\" multiple=\"multiple\">\n"; |
55 | | - # Populate box with categories: |
56 | | - foreach( $m_allCats as $m_cat => $m_prefix ) { |
57 | | - # Check if the category is in the list of category links on the page then select the entry: |
58 | | - if ( @$m_pageCats[ $m_cat ] ) $m_selected = 'selected="selected"'; |
59 | | - else $m_selected = ''; |
60 | | - # Print the entry: |
61 | | - $m_pageObj->$m_place .= "\t<option $m_selected value=\"". htmlspecialchars( $m_cat ) . "\">"; |
62 | | - for ( $m_i = 0; $m_i < $m_prefix; $m_i++ ) $m_pageObj->$m_place .= ' '; |
63 | | - $m_pageObj->$m_place .= htmlspecialchars( $m_cat ); |
64 | | - $m_pageObj->$m_place .= "</option>\n"; |
65 | | - } |
66 | | - # Close select box: |
67 | | - $m_pageObj->$m_place .= "</select>\n"; |
68 | 63 | # $m_pageObj->$m_place .= "</noscript>\n"; |
69 | | - # Print localised help string: |
70 | | - $m_pageObj->$m_place .= wfMsg( 'selectcategory-subtitle' ) . "<br />\n"; |
71 | | - $m_pageObj->$m_place .= "<!-- SelectCategory end -->\n"; |
72 | 64 | |
| 65 | + $m_pageObj->$m_place .= '<ul id="SelectCategoryList">'; |
| 66 | + foreach( $m_allCats as $m_cat => $m_prefix ) { |
| 67 | + $checked = ( @$m_pageCats[ $m_cat ] ) ? "checked=\"checked\"" : ''; |
| 68 | + $category = htmlspecialchars( $m_cat ); |
| 69 | + $m_pageObj->$m_place .= " |
| 70 | + <li> |
| 71 | + <label> |
| 72 | + <input type=\"checkbox\" name=\"SelectCategoryList[]\" |
| 73 | + value=\"$category\" class=\"checkbox\" $checked /> |
| 74 | + $category |
| 75 | + </label> |
| 76 | + </li>"; |
| 77 | + } |
| 78 | + $m_pageObj->$m_place .= '</ul>'; |
| 79 | + |
| 80 | + # Print localised help string: |
| 81 | + $m_pageObj->$m_place .= "<!-- SelectCategory end -->\n"; |
73 | 82 | } |
74 | 83 | |
75 | 84 | # Return true to let the rest work: |
— | — | @@ -115,23 +124,6 @@ |
116 | 125 | return true; |
117 | 126 | } |
118 | 127 | |
119 | | -## Entry point for the hook for printing the CSS: |
120 | | -function fnSelectCategoryOutputHook( &$m_pageObj, &$m_parserOutput ) { |
121 | | - global $wgScriptPath; |
122 | | - |
123 | | - # Register CSS file for our select box: |
124 | | - $m_pageObj->addLink( |
125 | | - array( |
126 | | - 'rel' => 'stylesheet', |
127 | | - 'type' => 'text/css', |
128 | | - 'href' => $wgScriptPath . '/extensions/SelectCategory/SelectCategory.css' |
129 | | - ) |
130 | | - ); |
131 | | - |
132 | | - # Be nice: |
133 | | - return true; |
134 | | -} |
135 | | - |
136 | 128 | ## Get all categories from the wiki - starting with a given root or otherwise detect root automagically (expensive): |
137 | 129 | function fnSelectCategoryGetAllCategories() { |
138 | 130 | global $wgTitle; |
— | — | @@ -139,7 +131,7 @@ |
140 | 132 | |
141 | 133 | # Get current namespace (save duplicate call of method): |
142 | 134 | $m_namespace = $wgTitle->getNamespace(); |
143 | | - if( $wgSelectCategoryRoot[$m_namespace] ) { |
| 135 | + if( $m_namespace >= 0 && $wgSelectCategoryRoot[$m_namespace] ) { |
144 | 136 | # Include root and step into the recursion: |
145 | 137 | $m_allCats = array_merge( array( $wgSelectCategoryRoot[$m_namespace] => 0 ), fnSelectCategoryGetChildren( $wgSelectCategoryRoot[$m_namespace] ) ); |
146 | 138 | } else { |
— | — | @@ -259,9 +251,11 @@ |
260 | 252 | # Run only if we are in an upload, a activated namespace or if page is |
261 | 253 | # a subpage and subpages are enabled (unfortunately we can't use |
262 | 254 | # implication in PHP) but not if we do a sectionedit: |
263 | | - if ( $m_isUpload || ( $wgSelectCategoryNamespaces[$wgTitle->getNamespace()] && ( !$m_isSubpage || ( $m_isSubpage && $wgSelectCategoryEnableSubpages ) ) ) && $m_pageObj->section == false ) { |
264 | | - return true; |
265 | | - } else { |
266 | | - return false; |
267 | | - } |
| 255 | + return ( |
| 256 | + $m_isUpload |
| 257 | + || ( $wgSelectCategoryNamespaces[$wgTitle->getNamespace()] |
| 258 | + && ( !$m_isSubpage |
| 259 | + || ( $m_isSubpage && $wgSelectCategoryEnableSubpages ) ) ) |
| 260 | + && $m_pageObj->section == false |
| 261 | + ); |
268 | 262 | } |