r75963 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75962‎ | r75963 | r75964 >
Date:22:49, 3 November 2010
Author:80686
Status:deferred
Tags:
Comment:
merged changes from trunk to REL1_16
Modified paths:
  • /branches/REL1_16/extensions/SelectCategory/SelectCategoryFunctions.php (modified) (history)

Diff [purge]

Index: branches/REL1_16/extensions/SelectCategory/SelectCategoryFunctions.php
@@ -1,26 +1,31 @@
22 <?php
33
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.
 4+/**
 5+ * Implementation of the SelectCategory extension, an extension of the
 6+ * edit box of MediaWiki to provide an easy way to add category links
 7+ * to a specific page.
 8+ *
 9+ * @file
 10+ * @ingroup Extensions
 11+ * @author Leon Weber <leon@leonweber.de> & Manuel Schneider <manuel.schneider@wikimedia.ch>
 12+ * @copyright © 2006 by Leon Weber & Manuel Schneider
 13+ * @licence GNU General Public Licence 2.0 or later
 14+ */
715
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 -
1316 if( !defined( 'MEDIAWIKI' ) ) {
1417 echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
1518 die();
1619 }
1720
1821 ## Entry point for the hook and main worker function for editing the page:
19 -function fnSelectCategoryShowHook( $m_isUpload = false, &$m_pageObj ) {
 22+function fnSelectCategoryShowHook( $m_isUpload = false, $m_pageObj ) {
2023
2124 # check if we should do anything or sleep
2225 if ( fnSelectCategoryCheckConditions( $m_isUpload, $m_pageObj ) ) {
2326 # Register CSS file for our select box:
24 - global $wgOut, $wgScriptPath;
 27+ global $wgOut, $wgScriptPath, $wgUser, $wgTitle;
 28+ global $wgSelectCategoryMaxLevel;
 29+
2530 $wgOut->addLink(
2631 array(
2732 'rel' => 'stylesheet',
@@ -29,6 +34,8 @@
3035 )
3136 );
3237
 38+ $m_skin =& $wgUser->getSkin();
 39+
3340 # Get all categories from wiki:
3441 $m_allCats = fnSelectCategoryGetAllCategories();
3542 # Load system messages:
@@ -55,37 +62,51 @@
5663 $m_pageObj->$m_place .= "<!-- SelectCategory begin -->\n";
5764 # Print the select box:
5865 $m_pageObj->$m_place .= "\n$m_textBefore";
59 -# # First come up with the JavaScript version of the select boxes:
60 -# $m_pageObj->$m_place .= "<script type=\"text/javascript\" src=\"'/extensions/SelectCategory/SelectCategory.js\"></script>\n";
61 -# # Then the "old-style" select box for those without JavaScript:
62 -# $m_pageObj->$m_place .= "<noscript>\n";
63 -# $m_pageObj->$m_place .= "</noscript>\n";
6466
65 - $m_pageObj->$m_place .= "<ul id='SelectCategoryList'>";
 67+ # Begin list output, use <div> to enable custom formatting
 68+ $m_pageObj->$m_place .= '<div id="SelectCategoryList">';
6669 foreach( $m_allCats as $m_cat => $m_depth ) {
6770 $checked = '';
68 -
69 - if (isset($m_pageCats[$m_cat])) {
70 - $checked = "checked='checked'";
 71+ # See if the category was already added, so check it
 72+ if( isset( $m_pageCats[$m_cat] ) ) {
 73+ $checked = 'checked="checked"';
7174 }
72 -
 75+ # Clean HTML Output:
7376 $category = htmlspecialchars( $m_cat );
7477
75 - # Indent subcategories
76 - $indention = '';
77 - for ($i = 0; $i < $m_depth; $i++) {
78 - $indention .= '&nbsp;&nbsp;';
 78+ # Calculate indention of subcategories
 79+ $indention = 0;
 80+ for( $i = 0; $i <= $m_depth; $i++ ) {
 81+ $indention = 15 * $i;
 82+ # Collapse subcategories after reaching the configured MaxLevel
 83+ if( $i > $wgSelectCategoryMaxLevel ) {
 84+ $display = 'display:none;';
 85+ } else {
 86+ $display = '';
 87+ }
 88+ # Check if we have reached the MaxLevel [-] or not [+]
 89+ if( $i == $wgSelectCategoryMaxLevel ) {
 90+ $sign = '[+]';
 91+ } else {
 92+# $sign = '[−]';
 93+ }
 94+ # Check if there are more subcategories
 95+# if( $m_allCats[] > $m_depth )
7996 }
 97+ # Clean names for text output
 98+ $title = str_replace( '_', ' ', $category );
 99+ $m_title = $wgTitle->newFromText( $category, NS_CATEGORY );
 100+ # Output the actual checkboxes, indented
 101+ $m_pageObj->$m_place .= '
 102+ <div id="sc_'.$category.'" style="'.$display.'">
 103+ <span style="padding-left:'.$indention.'px; width:10px; overflow:hidden;">'.$sign.'</span>
 104+ <input type="checkbox" name="SelectCategoryList[]" value="'.$category.'" class="checkbox" '.$checked.' />
 105+ '.$m_skin->link( $m_title, $title ).'
 106+ </div>';
 107+ } # End walking through cats (foreach)
 108+ # End of list output
 109+ $m_pageObj->$m_place .= '</div>';
80110
81 - $m_pageObj->$m_place .= "
82 - <li>
83 - $indention<input type='checkbox' name='SelectCategoryList[]'
84 - value='$category' class='checkbox' $checked />
85 - $category
86 - </li>";
87 - }
88 - $m_pageObj->$m_place .= '</ul>';
89 -
90111 # Print localised help string:
91112 $m_pageObj->$m_place .= "<!-- SelectCategory end -->\n";
92113 }
@@ -95,7 +116,7 @@
96117 }
97118
98119 ## Entry point for the hook and main worker function for saving the page:
99 -function fnSelectCategorySaveHook( $m_isUpload, &$m_pageObj ) {
 120+function fnSelectCategorySaveHook( $m_isUpload, $m_pageObj ) {
100121 global $wgContLang;
101122 global $wgTitle;
102123
@@ -107,7 +128,7 @@
108129
109130 # default sort key is page name with stripped namespace name,
110131 # otherwise sorting is ugly.
111 - if ($wgTitle->getNamespace() == NS_MAIN) {
 132+ if( $wgTitle->getNamespace() == NS_MAIN ) {
112133 $default_sortkey = "";
113134 } else {
114135 $default_sortkey = "|{{PAGENAME}}";
@@ -191,10 +212,14 @@
192213 $m_tblPage = $m_dbObj->tableName( 'page' );
193214
194215 # The normal query to get all children of a given root category:
195 - $m_sql = " SELECT tmpSelectCatPage.page_title AS title
196 - FROM $m_tblCatLink AS tmpSelectCat
197 - LEFT JOIN $m_tblPage AS tmpSelectCatPage ON tmpSelectCat.cl_from = tmpSelectCatPage.page_id
198 - WHERE tmpSelectCat.cl_to LIKE " . $m_dbObj->addQuotes( $m_root ) . " AND tmpSelectCatPage.page_namespace = 14";
 216+ $m_sql = '
 217+ SELECT tmpSelectCatPage.page_title AS title
 218+ FROM '.$m_tblCatLink.' AS tmpSelectCat
 219+ LEFT JOIN '.$m_tblPage.' AS tmpSelectCatPage
 220+ ON tmpSelectCat.cl_from = tmpSelectCatPage.page_id
 221+ WHERE tmpSelectCat.cl_to LIKE '.$m_dbObj->addQuotes( $m_root ).'
 222+ AND tmpSelectCatPage.page_namespace = 14
 223+ ORDER BY tmpSelectCatPage.page_title ASC;';
199224 # Run the query:
200225 $m_res = $m_dbObj->query( $m_sql, __METHOD__ );
201226 # Process the resulting rows:
@@ -259,7 +284,7 @@
260285 }
261286
262287 # Function that checks if we meet the run conditions of the extension
263 -function fnSelectCategoryCheckConditions ($m_isUpload, &$m_pageObj ) {
 288+function fnSelectCategoryCheckConditions ($m_isUpload, $m_pageObj ) {
264289 global $wgSelectCategoryNamespaces;
265290 global $wgSelectCategoryEnableSubpages;
266291 global $wgTitle;
@@ -274,7 +299,7 @@
275300 }
276301
277302 $ns = $wgTitle->getNamespace();
278 - if (array_key_exists ($ns, $wgSelectCategoryNamespaces)) {
 303+ if( array_key_exists( $ns, $wgSelectCategoryNamespaces ) ) {
279304 $enabledForNamespace = $wgSelectCategoryNamespaces[$ns];
280305 } else {
281306 $enabledForNamespace = false;

Status & tagging log