r75957 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75956‎ | r75957 | r75958 >
Date:21:18, 3 November 2010
Author:80686
Status:deferred
Tags:
Comment:
import of latest changes
Modified paths:
  • /trunk/extensions/SelectCategory/SelectCategoryFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SelectCategory/SelectCategoryFunctions.php
@@ -1,16 +1,14 @@
22 <?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 - */
143
 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+
1513 if( !defined( 'MEDIAWIKI' ) ) {
1614 echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
1715 die();
@@ -22,7 +20,9 @@
2321 # check if we should do anything or sleep
2422 if ( fnSelectCategoryCheckConditions( $m_isUpload, $m_pageObj ) ) {
2523 # Register CSS file for our select box:
26 - global $wgOut, $wgScriptPath;
 24+ global $wgOut, $wgScriptPath, $wgUser, $wgTitle;
 25+ global $wgSelectCategoryMaxLevel;
 26+
2727 $wgOut->addLink(
2828 array(
2929 'rel' => 'stylesheet',
@@ -31,6 +31,8 @@
3232 )
3333 );
3434
 35+ $m_skin =& $wgUser->getSkin();
 36+
3537 # Get all categories from wiki:
3638 $m_allCats = fnSelectCategoryGetAllCategories();
3739 # Load system messages:
@@ -57,37 +59,51 @@
5860 $m_pageObj->$m_place .= "<!-- SelectCategory begin -->\n";
5961 # Print the select box:
6062 $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";
6663
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">';
6866 foreach( $m_allCats as $m_cat => $m_depth ) {
6967 $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"';
7371 }
74 -
 72+ # Clean HTML Output:
7573 $category = htmlspecialchars( $m_cat );
7674
77 - # Indent subcategories
78 - $indention = '';
79 - for ($i = 0; $i < $m_depth; $i++) {
80 - $indention .= '&#160;&#160;';
 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 )
8193 }
 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>';
82107
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 -
92108 # Print localised help string:
93109 $m_pageObj->$m_place .= "<!-- SelectCategory end -->\n";
94110 }
@@ -156,7 +172,7 @@
157173 $m_allCats = array();
158174
159175 # Get a database object:
160 - $m_dbObj = wfGetDB( DB_SLAVE );
 176+ $m_dbObj =& wfGetDB( DB_SLAVE );
161177 # Get table names to access them in SQL query:
162178 $m_tblCatLink = $m_dbObj->tableName( 'categorylinks' );
163179 $m_tblPage = $m_dbObj->tableName( 'page' );
@@ -187,16 +203,20 @@
188204 $m_allCats = array();
189205
190206 # Get a database object:
191 - $m_dbObj = wfGetDB( DB_SLAVE );
 207+ $m_dbObj =& wfGetDB( DB_SLAVE );
192208 # Get table names to access them in SQL query:
193209 $m_tblCatLink = $m_dbObj->tableName( 'categorylinks' );
194210 $m_tblPage = $m_dbObj->tableName( 'page' );
195211
196212 # 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;';
201221 # Run the query:
202222 $m_res = $m_dbObj->query( $m_sql, __METHOD__ );
203223 # Process the resulting rows:

Status & tagging log