Index: trunk/extensions/SelectCategory/SelectCategoryFunctions.php |
— | — | @@ -13,32 +13,32 @@ |
14 | 14 | */ |
15 | 15 | |
16 | 16 | if( !defined( 'MEDIAWIKI' ) ) { |
17 | | - echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); |
18 | | - die(); |
| 17 | + echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); |
| 18 | + die(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | ## Entry point for the hook and main worker function for editing the page: |
22 | 22 | function fnSelectCategoryShowHook( $m_isUpload = false, $m_pageObj ) { |
23 | 23 | |
24 | | - # check if we should do anything or sleep |
25 | | - if ( fnSelectCategoryCheckConditions( $m_isUpload, $m_pageObj ) ) { |
| 24 | + # check if we should do anything or sleep |
| 25 | + if ( fnSelectCategoryCheckConditions( $m_isUpload, $m_pageObj ) ) { |
26 | 26 | # Register CSS file for our select box: |
27 | 27 | global $wgOut, $wgScriptPath, $wgUser, $wgTitle; |
28 | 28 | global $wgSelectCategoryMaxLevel; |
29 | 29 | |
30 | 30 | $wgOut->addLink( |
31 | | - array( |
32 | | - 'rel' => 'stylesheet', |
33 | | - 'type' => 'text/css', |
34 | | - 'href' => $wgScriptPath.'/extensions/SelectCategory/SelectCategory.css' |
35 | | - ) |
| 31 | + array( |
| 32 | + 'rel' => 'stylesheet', |
| 33 | + 'type' => 'text/css', |
| 34 | + 'href' => $wgScriptPath.'/extensions/SelectCategory/SelectCategory.css' |
| 35 | + ) |
36 | 36 | ); |
37 | 37 | $wgOut->addLink( |
38 | | - array( |
39 | | - 'rel' => 'stylesheet', |
40 | | - 'type' => 'text/css', |
41 | | - 'href' => $wgScriptPath.'/extensions/SelectCategory/jquery.treeview.css' |
42 | | - ) |
| 38 | + array( |
| 39 | + 'rel' => 'stylesheet', |
| 40 | + 'type' => 'text/css', |
| 41 | + 'href' => $wgScriptPath.'/extensions/SelectCategory/jquery.treeview.css' |
| 42 | + ) |
43 | 43 | ); |
44 | 44 | $wgOut->addScript( '<script src="'.$wgScriptPath.'/extensions/SelectCategory/jquery.treeview.js" type="text/javascript"></script>' ); |
45 | 45 | $wgOut->addScript( '<script src="'.$wgScriptPath.'/extensions/SelectCategory/SelectCategory.js" type="text/javascript"></script>' ); |
— | — | @@ -51,21 +51,22 @@ |
52 | 52 | wfLoadExtensionMessages( 'SelectCategory' ); |
53 | 53 | # Get the right member variables, depending on if we're on an upload form or not: |
54 | 54 | if( !$m_isUpload ) { |
55 | | - # Extract all categorylinks from page: |
56 | | - $m_pageCats = fnSelectCategoryGetPageCategories( $m_pageObj ); |
| 55 | + # Extract all categorylinks from page: |
| 56 | + $m_pageCats = fnSelectCategoryGetPageCategories( $m_pageObj ); |
57 | 57 | |
58 | | - # Never ever use editFormTextTop here as it resides outside the <form> so we will never get contents |
59 | | - $m_place = 'editFormTextAfterWarn'; |
60 | | - # Print the localised title for the select box: |
61 | | - $m_textBefore = '<b>'. wfMsg( 'selectcategory-title' ) . '</b>:'; |
| 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>:'; |
62 | 63 | } else { |
63 | | - # No need to get categories: |
64 | | - $m_pageCats = array(); |
| 64 | + # No need to get categories: |
| 65 | + $m_pageCats = array(); |
65 | 66 | |
66 | | - # Place output at the right place: |
67 | | - $m_place = 'uploadFormTextAfterSummary'; |
68 | | - # Print the part of the table including the localised title for the select box: |
69 | | - $m_textBefore = "\n</td></tr><tr><td align='right'><label for='wpSelectCategory'>" . wfMsg( 'selectcategory-title' ) .":</label></td><td align='left'>"; |
| 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'>"; |
70 | 71 | } |
71 | 72 | # Introduce the output: |
72 | 73 | $m_pageObj->$m_place .= "<!-- SelectCategory begin -->\n"; |
— | — | @@ -75,91 +76,93 @@ |
76 | 77 | # Begin list output, use <div> to enable custom formatting |
77 | 78 | $m_level = 0; |
78 | 79 | $m_pageObj->$m_place .= '<ul id="SelectCategoryList">'; |
| 80 | + |
79 | 81 | foreach( $m_allCats as $m_cat => $m_depth ) { |
80 | | - $checked = ''; |
81 | | - # See if the category was already added, so check it |
82 | | - if( isset( $m_pageCats[$m_cat] ) ) { |
83 | | - $checked = 'checked="checked"'; |
84 | | - } |
85 | | - # Clean HTML Output: |
86 | | - $category = htmlspecialchars( $m_cat ); |
| 82 | + $checked = ''; |
87 | 83 | |
88 | | - # iterate through levels and adjust divs accordingly |
89 | | - while( $m_level < $m_depth ) { |
90 | | - # Collapse subcategories after reaching the configured MaxLevel |
91 | | - if( $m_level >= ( $wgSelectCategoryMaxLevel - 1 ) ) { |
92 | | - $m_class = 'display:none;'; |
93 | | - } else { |
94 | | - $m_class = 'display:block;'; |
| 84 | + # See if the category was already added, so check it |
| 85 | + if( isset( $m_pageCats[$m_cat] ) ) { |
| 86 | + $checked = 'checked="checked"'; |
95 | 87 | } |
96 | | - $m_pageObj->$m_place .= '<ul style="'.$m_class.'">'."\n"; |
97 | | - $m_level++; |
98 | | - } |
99 | | - if( $m_level == $m_depth ) $m_pageObj->$m_place .= '</li>'."\n"; |
100 | | - while( $m_level > $m_depth ) { |
101 | | - $m_pageObj->$m_place .= '</ul></li>'."\n"; |
102 | | - $m_level--; |
103 | | - } |
104 | | - # Clean names for text output |
105 | | - $title = str_replace( '_', ' ', $category ); |
106 | | - $m_title = $wgTitle->newFromText( $category, NS_CATEGORY ); |
107 | | - # Output the actual checkboxes, indented |
108 | | - $m_pageObj->$m_place .= '<li><input type="checkbox" name="SelectCategoryList[]" value="'.$category.'" class="checkbox" '.$checked.' />'.$m_skin->link( $m_title, $title )."\n"; |
109 | | - # set id for next level |
110 | | - $m_level_id = 'sc_'.$m_cat; |
111 | | - } # End walking through cats (foreach) |
112 | | - # End of list output - close all remaining divs |
113 | | - while( $m_level > -1 ) { |
114 | | - $m_pageObj->$m_place .= '</li></ul>'."\n"; |
115 | | - $m_level--; |
| 88 | + # Clean HTML Output: |
| 89 | + $category = htmlspecialchars( $m_cat ); |
| 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) |
| 115 | + # End of list output - close all remaining divs |
| 116 | + while( $m_level > -1 ) { |
| 117 | + $m_pageObj->$m_place .= '</li></ul>'."\n"; |
| 118 | + $m_level--; |
| 119 | + } |
| 120 | + |
| 121 | + # Print localised help string: |
| 122 | + $m_pageObj->$m_place .= "<!-- SelectCategory end -->\n"; |
116 | 123 | } |
117 | 124 | |
118 | | - # Print localised help string: |
119 | | - $m_pageObj->$m_place .= "<!-- SelectCategory end -->\n"; |
120 | | - } |
121 | | - |
122 | | - # Return true to let the rest work: |
123 | | - return true; |
| 125 | + # Return true to let the rest work: |
| 126 | + return true; |
124 | 127 | } |
125 | 128 | |
126 | 129 | ## Entry point for the hook and main worker function for saving the page: |
127 | 130 | function fnSelectCategorySaveHook( $m_isUpload, $m_pageObj ) { |
128 | | - global $wgContLang; |
129 | | - global $wgTitle; |
| 131 | + global $wgContLang; |
| 132 | + global $wgTitle; |
130 | 133 | |
131 | | - # check if we should do anything or sleep |
132 | | - if ( fnSelectCategoryCheckConditions( $m_isUpload, $m_pageObj ) ) { |
| 134 | + # check if we should do anything or sleep |
| 135 | + if ( fnSelectCategoryCheckConditions( $m_isUpload, $m_pageObj ) ) { |
133 | 136 | |
134 | | - # Get localised namespace string: |
135 | | - $m_catString = $wgContLang->getNsText( NS_CATEGORY ); |
| 137 | + # Get localised namespace string: |
| 138 | + $m_catString = $wgContLang->getNsText( NS_CATEGORY ); |
136 | 139 | |
137 | | - # default sort key is page name with stripped namespace name, |
138 | | - # otherwise sorting is ugly. |
139 | | - if( $wgTitle->getNamespace() == NS_MAIN ) { |
140 | | - $default_sortkey = ""; |
141 | | - } else { |
142 | | - $default_sortkey = "|{{PAGENAME}}"; |
143 | | - } |
| 140 | + # default sort key is page name with stripped namespace name, |
| 141 | + # otherwise sorting is ugly. |
| 142 | + if( $wgTitle->getNamespace() == NS_MAIN ) { |
| 143 | + $default_sortkey = ""; |
| 144 | + } else { |
| 145 | + $default_sortkey = "|{{PAGENAME}}"; |
| 146 | + } |
144 | 147 | |
145 | | - # Get some distance from the rest of the content: |
146 | | - $m_text = "\n"; |
| 148 | + # Get some distance from the rest of the content: |
| 149 | + $m_text = "\n"; |
147 | 150 | |
148 | | - # Iterate through all selected category entries: |
149 | | - if (array_key_exists('SelectCategoryList', $_POST)) { |
150 | | - foreach( $_POST['SelectCategoryList'] as $m_cat ) { |
151 | | - $m_text .= "\n[[$m_catString:$m_cat$default_sortkey]]"; |
152 | | - } |
| 151 | + # Iterate through all selected category entries: |
| 152 | + if (array_key_exists('SelectCategoryList', $_POST)) { |
| 153 | + foreach( $_POST['SelectCategoryList'] as $m_cat ) { |
| 154 | + $m_text .= "\n[[$m_catString:$m_cat$default_sortkey]]"; |
| 155 | + } |
| 156 | + } |
| 157 | + # If it is an upload we have to call a different method: |
| 158 | + if ( $m_isUpload ) { |
| 159 | + $m_pageObj->mUploadDescription .= $m_text; |
| 160 | + } else { |
| 161 | + $m_pageObj->textbox1 .= $m_text; |
| 162 | + } |
153 | 163 | } |
154 | | - # If it is an upload we have to call a different method: |
155 | | - if ( $m_isUpload ) { |
156 | | - $m_pageObj->mUploadDescription .= $m_text; |
157 | | - } else{ |
158 | | - $m_pageObj->textbox1 .= $m_text; |
159 | | - } |
160 | | - } |
161 | 164 | |
162 | | - # Return to the let MediaWiki do the rest of the work: |
163 | | - return true; |
| 165 | + # Return to the let MediaWiki do the rest of the work: |
| 166 | + return true; |
164 | 167 | } |
165 | 168 | |
166 | 169 | ## Get all categories from the wiki - starting with a given root or otherwise detect root automagically (expensive) |
— | — | @@ -169,15 +172,47 @@ |
170 | 173 | ## ... |
171 | 174 | ## ) |
172 | 175 | function fnSelectCategoryGetAllCategories() { |
173 | | - global $wgTitle; |
174 | | - global $wgSelectCategoryRoot; |
| 176 | + global $wgTitle; |
| 177 | + global $wgSelectCategoryRoot; |
175 | 178 | |
176 | | - # Get current namespace (save duplicate call of method): |
177 | | - $m_namespace = $wgTitle->getNamespace(); |
178 | | - if( $m_namespace >= 0 && $wgSelectCategoryRoot[$m_namespace] ) { |
179 | | - # Include root and step into the recursion: |
180 | | - $m_allCats = array_merge( array( $wgSelectCategoryRoot[$m_namespace] => 0 ), fnSelectCategoryGetChildren( $wgSelectCategoryRoot[$m_namespace] ) ); |
181 | | - } else { |
| 179 | + # Get current namespace (save duplicate call of method): |
| 180 | + $m_namespace = $wgTitle->getNamespace(); |
| 181 | + if( $m_namespace >= 0 && $wgSelectCategoryRoot[$m_namespace] ) { |
| 182 | + # Include root and step into the recursion: |
| 183 | + $m_allCats = array_merge( array( $wgSelectCategoryRoot[$m_namespace] => 0 ), |
| 184 | + fnSelectCategoryGetChildren( $wgSelectCategoryRoot[$m_namespace] ) ); |
| 185 | + } else { |
| 186 | + # Initialize return value: |
| 187 | + $m_allCats = array(); |
| 188 | + |
| 189 | + # Get a database object: |
| 190 | + $m_dbObj = wfGetDB( DB_SLAVE ); |
| 191 | + # Get table names to access them in SQL query: |
| 192 | + $m_tblCatLink = $m_dbObj->tableName( 'categorylinks' ); |
| 193 | + $m_tblPage = $m_dbObj->tableName( 'page' ); |
| 194 | + |
| 195 | + # Automagically detect root categories: |
| 196 | + $m_sql = " SELECT tmpSelectCat1.cl_to AS title |
| 197 | + FROM $m_tblCatLink AS tmpSelectCat1 |
| 198 | + LEFT JOIN $m_tblPage AS tmpSelectCatPage ON (tmpSelectCat1.cl_to = tmpSelectCatPage.page_title AND tmpSelectCatPage.page_namespace = 14) |
| 199 | + LEFT JOIN $m_tblCatLink AS tmpSelectCat2 ON tmpSelectCatPage.page_id = tmpSelectCat2.cl_from |
| 200 | + WHERE tmpSelectCat2.cl_from IS NULL GROUP BY tmpSelectCat1.cl_to"; |
| 201 | + # Run the query: |
| 202 | + $m_res = $m_dbObj->query( $m_sql, __METHOD__ ); |
| 203 | + # Process the resulting rows: |
| 204 | + while ( $m_row = $m_dbObj->fetchRow( $m_res ) ) { |
| 205 | + $m_allCats += array( $m_row['title'] => 0 ); |
| 206 | + $m_allCats += fnSelectCategoryGetChildren( $m_row['title'] ); |
| 207 | + } |
| 208 | + # Free result: |
| 209 | + $m_dbObj->freeResult( $m_res ); |
| 210 | + } |
| 211 | + |
| 212 | + # Afterwards return the array to the caller: |
| 213 | + return $m_allCats; |
| 214 | +} |
| 215 | + |
| 216 | +function fnSelectCategoryGetChildren( $m_root, $m_depth = 1 ) { |
182 | 217 | # Initialize return value: |
183 | 218 | $m_allCats = array(); |
184 | 219 | |
— | — | @@ -187,39 +222,8 @@ |
188 | 223 | $m_tblCatLink = $m_dbObj->tableName( 'categorylinks' ); |
189 | 224 | $m_tblPage = $m_dbObj->tableName( 'page' ); |
190 | 225 | |
191 | | - # Automagically detect root categories: |
192 | | - $m_sql = " SELECT tmpSelectCat1.cl_to AS title |
193 | | - FROM $m_tblCatLink AS tmpSelectCat1 |
194 | | - LEFT JOIN $m_tblPage AS tmpSelectCatPage ON (tmpSelectCat1.cl_to = tmpSelectCatPage.page_title AND tmpSelectCatPage.page_namespace = 14) |
195 | | - LEFT JOIN $m_tblCatLink AS tmpSelectCat2 ON tmpSelectCatPage.page_id = tmpSelectCat2.cl_from |
196 | | - WHERE tmpSelectCat2.cl_from IS NULL GROUP BY tmpSelectCat1.cl_to"; |
197 | | - # Run the query: |
198 | | - $m_res = $m_dbObj->query( $m_sql, __METHOD__ ); |
199 | | - # Process the resulting rows: |
200 | | - while ( $m_row = $m_dbObj->fetchRow( $m_res ) ) { |
201 | | - $m_allCats += array( $m_row['title'] => 0 ); |
202 | | - $m_allCats += fnSelectCategoryGetChildren( $m_row['title'] ); |
203 | | - } |
204 | | - # Free result: |
205 | | - $m_dbObj->freeResult( $m_res ); |
206 | | - } |
207 | | - |
208 | | - # Afterwards return the array to the caller: |
209 | | - return $m_allCats; |
210 | | -} |
211 | | - |
212 | | -function fnSelectCategoryGetChildren( $m_root, $m_depth = 1 ) { |
213 | | - # Initialize return value: |
214 | | - $m_allCats = array(); |
215 | | - |
216 | | - # Get a database object: |
217 | | - $m_dbObj = wfGetDB( DB_SLAVE ); |
218 | | - # Get table names to access them in SQL query: |
219 | | - $m_tblCatLink = $m_dbObj->tableName( 'categorylinks' ); |
220 | | - $m_tblPage = $m_dbObj->tableName( 'page' ); |
221 | | - |
222 | | - # The normal query to get all children of a given root category: |
223 | | - $m_sql = ' |
| 226 | + # The normal query to get all children of a given root category: |
| 227 | + $m_sql = ' |
224 | 228 | SELECT tmpSelectCatPage.page_title AS title |
225 | 229 | FROM '.$m_tblCatLink.' AS tmpSelectCat |
226 | 230 | LEFT JOIN '.$m_tblPage.' AS tmpSelectCatPage |
— | — | @@ -227,98 +231,98 @@ |
228 | 232 | WHERE tmpSelectCat.cl_to LIKE '.$m_dbObj->addQuotes( $m_root ).' |
229 | 233 | AND tmpSelectCatPage.page_namespace = 14 |
230 | 234 | ORDER BY tmpSelectCatPage.page_title ASC;'; |
231 | | - # Run the query: |
232 | | - $m_res = $m_dbObj->query( $m_sql, __METHOD__ ); |
233 | | - # Process the resulting rows: |
234 | | - while ( $m_row = $m_dbObj->fetchRow( $m_res ) ) { |
235 | | - # Survive category link loops: |
236 | | - if( $m_root == $m_row['title'] ) { |
237 | | - continue; |
| 235 | + # Run the query: |
| 236 | + $m_res = $m_dbObj->query( $m_sql, __METHOD__ ); |
| 237 | + # Process the resulting rows: |
| 238 | + while ( $m_row = $m_dbObj->fetchRow( $m_res ) ) { |
| 239 | + # Survive category link loops: |
| 240 | + if( $m_root == $m_row['title'] ) { |
| 241 | + continue; |
| 242 | + } |
| 243 | + # Add current entry to array: |
| 244 | + $m_allCats += array( $m_row['title'] => $m_depth ); |
| 245 | + $m_allCats += fnSelectCategoryGetChildren( $m_row['title'], $m_depth + 1 ); |
238 | 246 | } |
239 | | - # Add current entry to array: |
240 | | - $m_allCats += array( $m_row['title'] => $m_depth ); |
241 | | - $m_allCats += fnSelectCategoryGetChildren( $m_row['title'], $m_depth + 1 ); |
242 | | - } |
243 | | - # Free result: |
244 | | - $m_dbObj->freeResult( $m_res ); |
| 247 | + # Free result: |
| 248 | + $m_dbObj->freeResult( $m_res ); |
245 | 249 | |
246 | | - # Afterwards return the array to the upper recursion level: |
247 | | - return $m_allCats; |
| 250 | + # Afterwards return the array to the upper recursion level: |
| 251 | + return $m_allCats; |
248 | 252 | } |
249 | 253 | |
250 | 254 | ## Returns an array with the categories the articles is in. |
251 | 255 | ## Also removes them from the text the user views in the editbox. |
252 | 256 | function fnSelectCategoryGetPageCategories( $m_pageObj ) { |
253 | 257 | |
254 | | - if (array_key_exists('SelectCategoryList', $_POST)) { |
255 | | - # We have already extracted the categories, return them instead |
256 | | - # of extracting zero categories from the page text. |
257 | | - $m_catLinks = array(); |
258 | | - foreach( $_POST['SelectCategoryList'] as $m_cat ) { |
259 | | - $m_catLinks[ $m_cat ] = true; |
| 258 | + if (array_key_exists('SelectCategoryList', $_POST)) { |
| 259 | + # We have already extracted the categories, return them instead |
| 260 | + # of extracting zero categories from the page text. |
| 261 | + $m_catLinks = array(); |
| 262 | + foreach( $_POST['SelectCategoryList'] as $m_cat ) { |
| 263 | + $m_catLinks[ $m_cat ] = true; |
| 264 | + } |
| 265 | + return $m_catLinks; |
260 | 266 | } |
261 | | - return $m_catLinks; |
262 | | - } |
263 | 267 | |
264 | | - global $wgContLang; |
| 268 | + global $wgContLang; |
265 | 269 | |
266 | | - # Get page contents: |
267 | | - $m_pageText = $m_pageObj->textbox1; |
268 | | - # Get localised namespace string: |
269 | | - $m_catString = strtolower( $wgContLang->getNsText( NS_CATEGORY ) ); |
270 | | - # The regular expression to find the category links: |
271 | | - $m_pattern = "\[\[({$m_catString}|category):([^\|\]]*)(\|{{PAGENAME}}|)\]\]"; |
272 | | - $m_replace = "$2"; |
273 | | - # The container to store all found category links: |
274 | | - $m_catLinks = array (); |
275 | | - # The container to store the processed text: |
276 | | - $m_cleanText = ''; |
| 270 | + # Get page contents: |
| 271 | + $m_pageText = $m_pageObj->textbox1; |
| 272 | + # Get localised namespace string: |
| 273 | + $m_catString = strtolower( $wgContLang->getNsText( NS_CATEGORY ) ); |
| 274 | + # The regular expression to find the category links: |
| 275 | + $m_pattern = "\[\[({$m_catString}|category):([^\|\]]*)(\|{{PAGENAME}}|)\]\]"; |
| 276 | + $m_replace = "$2"; |
| 277 | + # The container to store all found category links: |
| 278 | + $m_catLinks = array (); |
| 279 | + # The container to store the processed text: |
| 280 | + $m_cleanText = ''; |
277 | 281 | |
278 | | - # Check linewise for category links: |
279 | | - foreach( explode( "\n", $m_pageText ) as $m_textLine ) { |
280 | | - # Filter line through pattern and store the result: |
281 | | - $m_cleanText .= preg_replace( "/{$m_pattern}/i", "", $m_textLine ) . "\n"; |
282 | | - # Check if we have found a category, else proceed with next line: |
283 | | - if( !preg_match( "/{$m_pattern}/i", $m_textLine) ) continue; |
284 | | - # Get the category link from the original text and store it in our list: |
285 | | - $m_catLinks[ str_replace( ' ', '_', preg_replace( "/.*{$m_pattern}/i", $m_replace, $m_textLine ) ) ] = true; |
286 | | - } |
287 | | - # Place the cleaned text into the text box: |
288 | | - $m_pageObj->textbox1 = trim( $m_cleanText ); |
| 282 | + # Check linewise for category links: |
| 283 | + foreach( explode( "\n", $m_pageText ) as $m_textLine ) { |
| 284 | + # Filter line through pattern and store the result: |
| 285 | + $m_cleanText .= preg_replace( "/{$m_pattern}/i", "", $m_textLine ) . "\n"; |
| 286 | + # Check if we have found a category, else proceed with next line: |
| 287 | + if( !preg_match( "/{$m_pattern}/i", $m_textLine) ) continue; |
| 288 | + # Get the category link from the original text and store it in our list: |
| 289 | + $m_catLinks[ str_replace( ' ', '_', preg_replace( "/.*{$m_pattern}/i", $m_replace, $m_textLine ) ) ] = true; |
| 290 | + } |
| 291 | + # Place the cleaned text into the text box: |
| 292 | + $m_pageObj->textbox1 = trim( $m_cleanText ); |
289 | 293 | |
290 | | - # Return the list of categories as an array: |
291 | | - return $m_catLinks; |
| 294 | + # Return the list of categories as an array: |
| 295 | + return $m_catLinks; |
292 | 296 | } |
293 | 297 | |
294 | 298 | # Function that checks if we meet the run conditions of the extension |
295 | 299 | function fnSelectCategoryCheckConditions ($m_isUpload, $m_pageObj ) { |
296 | | - global $wgSelectCategoryNamespaces; |
297 | | - global $wgSelectCategoryEnableSubpages; |
298 | | - global $wgTitle; |
| 300 | + global $wgSelectCategoryNamespaces; |
| 301 | + global $wgSelectCategoryEnableSubpages; |
| 302 | + global $wgTitle; |
299 | 303 | |
300 | 304 | |
301 | | - # Run only if we are in an upload, an activated namespace or if page is |
302 | | - # a subpage and subpages are enabled (unfortunately we can't use |
303 | | - # implication in PHP) but not if we do a sectionedit: |
| 305 | + # Run only if we are in an upload, an activated namespace or if page is |
| 306 | + # a subpage and subpages are enabled (unfortunately we can't use |
| 307 | + # implication in PHP) but not if we do a sectionedit: |
304 | 308 | |
305 | | - if ($m_isUpload == true) { |
306 | | - return true; |
307 | | - } |
| 309 | + if ($m_isUpload == true) { |
| 310 | + return true; |
| 311 | + } |
308 | 312 | |
309 | | - $ns = $wgTitle->getNamespace(); |
310 | | - if( array_key_exists( $ns, $wgSelectCategoryNamespaces ) ) { |
311 | | - $enabledForNamespace = $wgSelectCategoryNamespaces[$ns]; |
312 | | - } else { |
313 | | - $enabledForNamespace = false; |
314 | | - } |
| 313 | + $ns = $wgTitle->getNamespace(); |
| 314 | + if( array_key_exists( $ns, $wgSelectCategoryNamespaces ) ) { |
| 315 | + $enabledForNamespace = $wgSelectCategoryNamespaces[$ns]; |
| 316 | + } else { |
| 317 | + $enabledForNamespace = false; |
| 318 | + } |
315 | 319 | |
316 | | - # Check if page is subpage once to save method calls below: |
317 | | - $m_isSubpage = $wgTitle->isSubpage(); |
| 320 | + # Check if page is subpage once to save method calls below: |
| 321 | + $m_isSubpage = $wgTitle->isSubpage(); |
318 | 322 | |
319 | | - if ($enabledForNamespace |
320 | | - && (!$m_isSubpage |
321 | | - || $m_isSubpage && $wgSelectCategoryEnableSubpage) |
322 | | - && $m_pageObj->section == false) { |
323 | | - return true; |
324 | | - } |
| 323 | + if ($enabledForNamespace |
| 324 | + && (!$m_isSubpage |
| 325 | + || $m_isSubpage && $wgSelectCategoryEnableSubpage) |
| 326 | + && $m_pageObj->section == false) { |
| 327 | + return true; |
| 328 | + } |
325 | 329 | } |