Index: trunk/extensions/SelectCategory/SelectCategoryFunctions.php |
— | — | @@ -1,16 +1,14 @@ |
2 | 2 | <?php |
3 | | -/** |
4 | | - * Implementation of the SelectCategory extension, an extension of the |
5 | | - * edit box of MediaWiki to provide an easy way to add category links |
6 | | - * to a specific page. |
7 | | - * |
8 | | - * @file |
9 | | - * @ingroup Extensions |
10 | | - * @author Leon Weber <leon@leonweber.de> & Manuel Schneider <manuel.schneider@wikimedia.ch> |
11 | | - * @copyright © 2006 by Leon Weber & Manuel Schneider |
12 | | - * @licence GNU General Public Licence 2.0 or later |
13 | | - */ |
14 | 3 | |
| 4 | +# Implementation of the SelectCategory extension, an extension of the |
| 5 | +# edit box of MediaWiki to provide an easy way to add category links |
| 6 | +# to a specific page. |
| 7 | + |
| 8 | +# @addtogroup Extensions |
| 9 | +# @author Leon Weber <leon@leonweber.de> & Manuel Schneider <manuel.schneider@wikimedia.ch> |
| 10 | +# @copyright © 2006 by Leon Weber & Manuel Schneider |
| 11 | +# @licence GNU General Public Licence 2.0 or later |
| 12 | + |
15 | 13 | if( !defined( 'MEDIAWIKI' ) ) { |
16 | 14 | echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); |
17 | 15 | die(); |
— | — | @@ -22,7 +20,9 @@ |
23 | 21 | # check if we should do anything or sleep |
24 | 22 | if ( fnSelectCategoryCheckConditions( $m_isUpload, $m_pageObj ) ) { |
25 | 23 | # Register CSS file for our select box: |
26 | | - global $wgOut, $wgScriptPath; |
| 24 | + global $wgOut, $wgScriptPath, $wgUser, $wgTitle; |
| 25 | + global $wgSelectCategoryMaxLevel; |
| 26 | + |
27 | 27 | $wgOut->addLink( |
28 | 28 | array( |
29 | 29 | 'rel' => 'stylesheet', |
— | — | @@ -31,6 +31,8 @@ |
32 | 32 | ) |
33 | 33 | ); |
34 | 34 | |
| 35 | + $m_skin =& $wgUser->getSkin(); |
| 36 | + |
35 | 37 | # Get all categories from wiki: |
36 | 38 | $m_allCats = fnSelectCategoryGetAllCategories(); |
37 | 39 | # Load system messages: |
— | — | @@ -57,37 +59,51 @@ |
58 | 60 | $m_pageObj->$m_place .= "<!-- SelectCategory begin -->\n"; |
59 | 61 | # Print the select box: |
60 | 62 | $m_pageObj->$m_place .= "\n$m_textBefore"; |
61 | | -# # First come up with the JavaScript version of the select boxes: |
62 | | -# $m_pageObj->$m_place .= "<script type=\"text/javascript\" src=\"'/extensions/SelectCategory/SelectCategory.js\"></script>\n"; |
63 | | -# # Then the "old-style" select box for those without JavaScript: |
64 | | -# $m_pageObj->$m_place .= "<noscript>\n"; |
65 | | -# $m_pageObj->$m_place .= "</noscript>\n"; |
66 | 63 | |
67 | | - $m_pageObj->$m_place .= "<ul id='SelectCategoryList'>"; |
| 64 | + # Begin list output, use <div> to enable custom formatting |
| 65 | + $m_pageObj->$m_place .= '<div id="SelectCategoryList">'; |
68 | 66 | foreach( $m_allCats as $m_cat => $m_depth ) { |
69 | 67 | $checked = ''; |
70 | | - |
71 | | - if (isset($m_pageCats[$m_cat])) { |
72 | | - $checked = "checked='checked'"; |
| 68 | + # See if the category was already added, so check it |
| 69 | + if( isset( $m_pageCats[$m_cat] ) ) { |
| 70 | + $checked = 'checked="checked"'; |
73 | 71 | } |
74 | | - |
| 72 | + # Clean HTML Output: |
75 | 73 | $category = htmlspecialchars( $m_cat ); |
76 | 74 | |
77 | | - # Indent subcategories |
78 | | - $indention = ''; |
79 | | - for ($i = 0; $i < $m_depth; $i++) { |
80 | | - $indention .= '  '; |
| 75 | + # Calculate indention of subcategories |
| 76 | + $indention = 0; |
| 77 | + for( $i = 0; $i <= $m_depth; $i++ ) { |
| 78 | + $indention = 15 * $i; |
| 79 | + # Collapse subcategories after reaching the configured MaxLevel |
| 80 | + if( $i > $wgSelectCategoryMaxLevel ) { |
| 81 | + $display = 'display:none;'; |
| 82 | + } else { |
| 83 | + $display = ''; |
| 84 | + } |
| 85 | + # Check if we have reached the MaxLevel [-] or not [+] |
| 86 | + if( $i == $wgSelectCategoryMaxLevel ) { |
| 87 | + $sign = '[+]'; |
| 88 | + } else { |
| 89 | +# $sign = '[−]'; |
| 90 | + } |
| 91 | + # Check if there are more subcategories |
| 92 | +# if( $m_allCats[] > $m_depth ) |
81 | 93 | } |
| 94 | + # Clean names for text output |
| 95 | + $title = str_replace( '_', ' ', $category ); |
| 96 | + $m_title = $wgTitle->newFromText( $category, NS_CATEGORY ); |
| 97 | + # Output the actual checkboxes, indented |
| 98 | + $m_pageObj->$m_place .= ' |
| 99 | + <div id="sc_'.$category.'" style="'.$display.'"> |
| 100 | + <span style="padding-left:'.$indention.'px; width:10px; overflow:hidden;">'.$sign.'</span> |
| 101 | + <input type="checkbox" name="SelectCategoryList[]" value="'.$category.'" class="checkbox" '.$checked.' /> |
| 102 | + '.$m_skin->link( $m_title, $title ).' |
| 103 | + </div>'; |
| 104 | + } # End walking through cats (foreach) |
| 105 | + # End of list output |
| 106 | + $m_pageObj->$m_place .= '</div>'; |
82 | 107 | |
83 | | - $m_pageObj->$m_place .= " |
84 | | - <li> |
85 | | - $indention<input type='checkbox' name='SelectCategoryList[]' |
86 | | - value='$category' class='checkbox' $checked /> |
87 | | - $category |
88 | | - </li>"; |
89 | | - } |
90 | | - $m_pageObj->$m_place .= '</ul>'; |
91 | | - |
92 | 108 | # Print localised help string: |
93 | 109 | $m_pageObj->$m_place .= "<!-- SelectCategory end -->\n"; |
94 | 110 | } |
— | — | @@ -156,7 +172,7 @@ |
157 | 173 | $m_allCats = array(); |
158 | 174 | |
159 | 175 | # Get a database object: |
160 | | - $m_dbObj = wfGetDB( DB_SLAVE ); |
| 176 | + $m_dbObj =& wfGetDB( DB_SLAVE ); |
161 | 177 | # Get table names to access them in SQL query: |
162 | 178 | $m_tblCatLink = $m_dbObj->tableName( 'categorylinks' ); |
163 | 179 | $m_tblPage = $m_dbObj->tableName( 'page' ); |
— | — | @@ -187,16 +203,20 @@ |
188 | 204 | $m_allCats = array(); |
189 | 205 | |
190 | 206 | # Get a database object: |
191 | | - $m_dbObj = wfGetDB( DB_SLAVE ); |
| 207 | + $m_dbObj =& wfGetDB( DB_SLAVE ); |
192 | 208 | # Get table names to access them in SQL query: |
193 | 209 | $m_tblCatLink = $m_dbObj->tableName( 'categorylinks' ); |
194 | 210 | $m_tblPage = $m_dbObj->tableName( 'page' ); |
195 | 211 | |
196 | 212 | # The normal query to get all children of a given root category: |
197 | | - $m_sql = " SELECT tmpSelectCatPage.page_title AS title |
198 | | - FROM $m_tblCatLink AS tmpSelectCat |
199 | | - LEFT JOIN $m_tblPage AS tmpSelectCatPage ON tmpSelectCat.cl_from = tmpSelectCatPage.page_id |
200 | | - WHERE tmpSelectCat.cl_to LIKE " . $m_dbObj->addQuotes( $m_root ) . " AND tmpSelectCatPage.page_namespace = 14"; |
| 213 | + $m_sql = ' |
| 214 | + SELECT tmpSelectCatPage.page_title AS title |
| 215 | + FROM '.$m_tblCatLink.' AS tmpSelectCat |
| 216 | + LEFT JOIN '.$m_tblPage.' AS tmpSelectCatPage |
| 217 | + ON tmpSelectCat.cl_from = tmpSelectCatPage.page_id |
| 218 | + WHERE tmpSelectCat.cl_to LIKE '.$m_dbObj->addQuotes( $m_root ).' |
| 219 | + AND tmpSelectCatPage.page_namespace = 14 |
| 220 | + ORDER BY tmpSelectCatPage.page_title ASC;'; |
201 | 221 | # Run the query: |
202 | 222 | $m_res = $m_dbObj->query( $m_sql, __METHOD__ ); |
203 | 223 | # Process the resulting rows: |