r96720 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96719‎ | r96720 | r96721 >
Date:12:12, 10 September 2011
Author:ialex
Status:deferred
Tags:
Comment:
* Removed usage of $wgTitle
* Use OutputPage::addExtensionStyle() and OutputPage::addScriptFile() instead of OutputPage::addLink() and OutputPage::addScript()
Modified paths:
  • /trunk/extensions/SelectCategory/SelectCategory_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SelectCategory/SelectCategory_body.php
@@ -26,30 +26,18 @@
2727 # check if we should do anything or sleep
2828 if ( self::checkConditions( $isUpload, $pageObj ) ) {
2929 # Register CSS file for our select box
30 - global $wgOut, $wgScriptPath, $wgUser, $wgTitle;
 30+ global $wgOut, $wgUser, $wgExtensionAssetsPath;
3131 global $wgSelectCategoryMaxLevel;
3232
33 - $wgOut->addLink(
34 - array(
35 - 'rel' => 'stylesheet',
36 - 'type' => 'text/css',
37 - 'href' => $wgScriptPath.'/extensions/SelectCategory/SelectCategory.css'
38 - )
39 - );
40 - $wgOut->addLink(
41 - array(
42 - 'rel' => 'stylesheet',
43 - 'type' => 'text/css',
44 - 'href' => $wgScriptPath.'/extensions/SelectCategory/jquery.treeview.css'
45 - )
46 - );
47 - $wgOut->addScript( '<script src="'.$wgScriptPath.'/extensions/SelectCategory/jquery.treeview.js" type="text/javascript"></script>' );
48 - $wgOut->addScript( '<script src="'.$wgScriptPath.'/extensions/SelectCategory/SelectCategory.js" type="text/javascript"></script>' );
 33+ $wgOut->addExtensionStyle( "{$wgExtensionAssetsPath}/SelectCategory/SelectCategory.css" );
 34+ $wgOut->addExtensionStyle( "{$wgExtensionAssetsPath}/SelectCategory/jquery.treeview.css" );
 35+ $wgOut->addScriptFile( "{$wgExtensionAssetsPath}/SelectCategory/jquery.treeview.js" );
 36+ $wgOut->addScriptFile( "{$wgExtensionAssetsPath}/SelectCategory/SelectCategory.js" );
4937
5038 $skin = $wgUser->getSkin();
5139
5240 # Get all categories from wiki
53 - $allCats = self::getAllCategories();
 41+ $allCats = self::getAllCategories( $isUpload ? NS_SPECIAL : $pageObj->mTitle->getNamespace() );
5442 # Load system messages
5543
5644 # Get the right member variables, depending on if we're on an upload form or not
@@ -115,7 +103,7 @@
116104 }
117105 # Clean names for text output
118106 $catName = str_replace( '_', ' ', $category );
119 - $title = $wgTitle->newFromText( $category, NS_CATEGORY );
 107+ $title = Title::newFromText( $category, NS_CATEGORY );
120108 # Output the actual checkboxes, indented
121109 $pageObj->$place .= '<li' . $open . '><input type="checkbox" name="SelectCategoryList[]" value="'.$category.'" class="checkbox" '.$checked.' />'.$skin->link( $title, $catName )."\n";
122110 # set id for next level
@@ -138,7 +126,6 @@
139127 ## Entry point for the hook and main function for saving the page
140128 public static function saveHook( $isUpload, $pageObj ) {
141129 global $wgContLang;
142 - global $wgTitle;
143130
144131 # check if we should do anything or sleep
145132 if ( self::checkConditions( $isUpload, $pageObj ) ) {
@@ -148,7 +135,7 @@
149136
150137 # default sort key is page name with stripped namespace name,
151138 # otherwise sorting is ugly.
152 - if( $wgTitle->getNamespace() == NS_MAIN ) {
 139+ if( !$isUpload && $pageObj->mTitle->getNamespace() == NS_MAIN ) {
153140 $default_sortkey = "";
154141 } else {
155142 $default_sortkey = "|{{PAGENAME}}";
@@ -181,12 +168,10 @@
182169 ## 'Name' => (int) Depth,
183170 ## ...
184171 ## )
185 - public static function getAllCategories() {
186 - global $wgTitle;
 172+ public static function getAllCategories( $namespace ) {
187173 global $wgSelectCategoryRoot;
188174
189175 # Get current namespace (save duplicate call of method)
190 - $namespace = $wgTitle->getNamespace();
191176 if( $namespace >= 0 && array_key_exists( $namespace, $wgSelectCategoryRoot ) && $wgSelectCategoryRoot[$namespace] ) {
192177 # Include root and step into the recursion
193178 $allCats = array_merge( array( $wgSelectCategoryRoot[$namespace] => 0 ),
@@ -307,7 +292,6 @@
308293 public static function checkConditions ($isUpload, $pageObj ) {
309294 global $wgSelectCategoryNamespaces;
310295 global $wgSelectCategoryEnableSubpages;
311 - global $wgTitle;
312296
313297
314298 # Run only if we are in an upload, an activated namespace or if page is
@@ -318,7 +302,7 @@
319303 return true;
320304 }
321305
322 - $ns = $wgTitle->getNamespace();
 306+ $ns = $pageObj->mTitle->getNamespace();
323307 if( array_key_exists( $ns, $wgSelectCategoryNamespaces ) ) {
324308 $enabledForNamespace = $wgSelectCategoryNamespaces[$ns];
325309 } else {
@@ -326,7 +310,7 @@
327311 }
328312
329313 # Check if page is subpage once to save method calls below
330 - $isSubpage = $wgTitle->isSubpage();
 314+ $isSubpage = $pageObj->mTitle->isSubpage();
331315
332316 if ($enabledForNamespace
333317 && (!$isSubpage

Sign-offs

UserFlagDate
Nikerabbitinspected15:42, 10 September 2011

Status & tagging log