r37734 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37733‎ | r37734 | r37735 >
Date:00:58, 16 July 2008
Author:leon
Status:old
Tags:
Comment:
* Updated SelectCategory to work with the current MediaWiki core.
* Changed it to use checkboxes instead of scrolling lists for selecting.
* Some minor code reformatting.

Patch by Lambert Lum.
Modified paths:
  • /trunk/extensions/SelectCategory/SelectCategory.css (modified) (history)
  • /trunk/extensions/SelectCategory/SelectCategory.php (modified) (history)
  • /trunk/extensions/SelectCategory/SelectCategoryFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SelectCategory/SelectCategory.php
@@ -87,10 +87,6 @@
8888 $wgHooks['EditPage::attemptSave'][] = array( 'fnSelectCategorySaveHook', false );
8989 # Hook when saving the upload:
9090 $wgHooks['UploadForm:BeforeProcessing'][] = array( 'fnSelectCategorySaveHook', true );
91 -
92 - ## Infrastructure
93 - # Hook our own CSS:
94 - $wgHooks['OutputPageParserOutput'][] = 'fnSelectCategoryOutputHook';
9591 }
9692
9793 ## Load the file containing the hook functions:
Index: trunk/extensions/SelectCategory/SelectCategory.css
@@ -4,7 +4,7 @@
55 *
66 * @package MediaWiki
77 * @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>
99 * @copyright © 2006 by Leon Weber & Manuel Schneider
1010 * @licence GNU General Public Licence 2.0 or later
1111 */
@@ -13,3 +13,15 @@
1414 width: 100%;
1515 padding: .1em;
1616 }
 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 @@
66 # to a specific page.
77
88 # @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>
1010 # @copyright © 2006 by Leon Weber & Manuel Schneider
1111 # @licence GNU General Public Licence 2.0 or later
1212
@@ -19,6 +19,15 @@
2020
2121 # check if we should do anything or sleep
2222 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+ );
2332
2433 # Get all categories from wiki:
2534 $m_allCats = fnSelectCategoryGetAllCategories();
@@ -50,25 +59,25 @@
5160 # $m_pageObj->$m_place .= "<script type=\"text/javascript\" src=\"'/extensions/SelectCategory/SelectCategory.js\"></script>\n";
5261 # # Then the "old-style" select box for those without JavaScript:
5362 # $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 .= '&nbsp;&nbsp;';
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";
6863 # $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";
7264
 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";
7382 }
7483
7584 # Return true to let the rest work:
@@ -115,23 +124,6 @@
116125 return true;
117126 }
118127
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 -
136128 ## Get all categories from the wiki - starting with a given root or otherwise detect root automagically (expensive):
137129 function fnSelectCategoryGetAllCategories() {
138130 global $wgTitle;
@@ -139,7 +131,7 @@
140132
141133 # Get current namespace (save duplicate call of method):
142134 $m_namespace = $wgTitle->getNamespace();
143 - if( $wgSelectCategoryRoot[$m_namespace] ) {
 135+ if( $m_namespace >= 0 && $wgSelectCategoryRoot[$m_namespace] ) {
144136 # Include root and step into the recursion:
145137 $m_allCats = array_merge( array( $wgSelectCategoryRoot[$m_namespace] => 0 ), fnSelectCategoryGetChildren( $wgSelectCategoryRoot[$m_namespace] ) );
146138 } else {
@@ -259,9 +251,11 @@
260252 # Run only if we are in an upload, a activated namespace or if page is
261253 # a subpage and subpages are enabled (unfortunately we can't use
262254 # 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+ );
268262 }

Status & tagging log