Index: trunk/extensions/CategoryTree/CategoryPageSubclass.php |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | class CategoryTreeCategoryPage extends CategoryPage { |
5 | 5 | function closeShowCategory() { |
6 | 6 | global $wgOut, $wgRequest; |
| 7 | + |
7 | 8 | $from = $wgRequest->getVal( 'from' ); |
8 | 9 | $until = $wgRequest->getVal( 'until' ); |
9 | 10 | |
— | — | @@ -17,7 +18,7 @@ |
18 | 19 | function getCategoryTree() { |
19 | 20 | global $wgOut, $wgCategoryTreeCategoryPageOptions, $wgCategoryTreeForceHeaders; |
20 | 21 | |
21 | | - if ( ! isset($this->categorytree) ) { |
| 22 | + if ( ! isset( $this->categorytree ) ) { |
22 | 23 | if ( !$wgCategoryTreeForceHeaders ) CategoryTree::setHeaders( $wgOut ); |
23 | 24 | |
24 | 25 | $this->categorytree = new CategoryTree( $wgCategoryTreeCategoryPageOptions ); |
— | — | @@ -38,11 +39,6 @@ |
39 | 40 | return parent::addSubcategoryObject( $cat, $sortkey, $pageLength ); |
40 | 41 | } |
41 | 42 | |
42 | | - /*if ( ! $GLOBALS['wgCategoryTreeUnifiedView'] ) { |
43 | | - $this->child_cats[] = $cat; |
44 | | - return parent::addSubcategory( $cat, $sortkey, $pageLength ); |
45 | | - }*/ |
46 | | - |
47 | 43 | $tree = $this->getCategoryTree(); |
48 | 44 | |
49 | 45 | $this->children[] = $tree->renderNodeInfo( $title, $cat ); |
— | — | @@ -56,7 +52,7 @@ |
57 | 53 | } |
58 | 54 | |
59 | 55 | function finaliseCategoryState() { |
60 | | - if( $this->flip ) { |
| 56 | + if ( $this->flip ) { |
61 | 57 | $this->child_cats = array_reverse( $this->child_cats ); |
62 | 58 | } |
63 | 59 | parent::finaliseCategoryState(); |
Index: trunk/extensions/CategoryTree/CategoryTreePage.php |
— | — | @@ -9,13 +9,12 @@ |
10 | 10 | * @license GNU General Public Licence 2.0 or later |
11 | 11 | */ |
12 | 12 | |
13 | | -if( !defined( 'MEDIAWIKI' ) ) { |
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) { |
14 | 14 | echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" ); |
15 | 15 | die( 1 ); |
16 | 16 | } |
17 | 17 | |
18 | 18 | class CategoryTreePage extends SpecialPage { |
19 | | - |
20 | 19 | var $target = ''; |
21 | 20 | var $tree = null; |
22 | 21 | |
— | — | @@ -45,11 +44,11 @@ |
46 | 45 | $this->setHeaders(); |
47 | 46 | |
48 | 47 | if ( $par ) $this->target = $par; |
49 | | - else $this->target = $wgRequest->getVal( 'target', wfMsg( 'rootcategory') ); |
| 48 | + else $this->target = $wgRequest->getVal( 'target', wfMsg( 'rootcategory' ) ); |
50 | 49 | |
51 | 50 | $this->target = trim( $this->target ); |
52 | 51 | |
53 | | - #HACK for undefined root category |
| 52 | + # HACK for undefined root category |
54 | 53 | if ( $this->target == '<rootcategory>' || $this->target == '<rootcategory>' ) $this->target = null; |
55 | 54 | |
56 | 55 | $options = array(); |
— | — | @@ -68,7 +67,7 @@ |
69 | 68 | |
70 | 69 | $this->executeInputForm(); |
71 | 70 | |
72 | | - if( $this->target !== '' && $this->target !== null ) { |
| 71 | + if ( $this->target !== '' && $this->target !== null ) { |
73 | 72 | if ( !$wgCategoryTreeForceHeaders ) CategoryTree::setHeaders( $wgOut ); |
74 | 73 | |
75 | 74 | $title = CategoryTree::makeTitle( $this->target ); |
— | — | @@ -98,7 +97,6 @@ |
99 | 98 | $wgOut->addHTML( Xml::closeElement( 'div' ) ); |
100 | 99 | } |
101 | 100 | } |
102 | | - |
103 | 101 | } |
104 | 102 | |
105 | 103 | /** |
— | — | @@ -107,7 +105,7 @@ |
108 | 106 | function executeInputForm() { |
109 | 107 | global $wgScript, $wgOut; |
110 | 108 | $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() ); |
111 | | - $mode = $this->getOption('mode'); |
| 109 | + $mode = $this->getOption( 'mode' ); |
112 | 110 | |
113 | 111 | $wgOut->addHTML( Xml::openElement( 'form', array( 'name' => 'categorytree', 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-categorytree-form' ) ) ); |
114 | 112 | $wgOut->addHTML( Xml::openElement( 'fieldset' ) ); |
Index: trunk/extensions/CategoryTree/CategoryTree.i18n.php |
— | — | @@ -82,12 +82,12 @@ |
83 | 83 | {{Identical|All pages}}', |
84 | 84 | 'categorytree-collapse' => 'Tooltip for the "collapse" button', |
85 | 85 | 'categorytree-expand' => 'Tooltip for the "expand" button', |
86 | | - 'categorytree-member-counts' => 'Tooltip showing a detailed summary of subcategory member counts. Parameters: |
87 | | -* $1 = number of subcategories, |
88 | | -* $2 = number of pages (without subcategories and files), |
89 | | -* $3 = number of files, |
90 | | -* $4 = total number of members, |
91 | | -* $5 = members to be shown in the tree, depending on mode. |
| 86 | + 'categorytree-member-counts' => 'Tooltip showing a detailed summary of subcategory member counts. Parameters: |
| 87 | +* $1 = number of subcategories, |
| 88 | +* $2 = number of pages (without subcategories and files), |
| 89 | +* $3 = number of files, |
| 90 | +* $4 = total number of members, |
| 91 | +* $5 = members to be shown in the tree, depending on mode. |
92 | 92 | Use with { {PLURAL} }', |
93 | 93 | 'categorytree-load' => '{{Identical|Load}} |
94 | 94 | |
— | — | @@ -143,7 +143,7 @@ |
144 | 144 | 'categorytree' => 'የመደቦች ዛፍ', |
145 | 145 | 'categorytree-portlet' => 'መደቦች', |
146 | 146 | 'categorytree-legend' => 'የመደቦች ዛፍ ለማየት', |
147 | | - 'categorytree-header' => "[+] ተጭነው ንዑሱ-መደብ ይዘረጋል፣ [-] ተጭነው ደግሞ ይመልሳል። |
| 147 | + 'categorytree-header' => "[+] ተጭነው ንዑሱ-መደብ ይዘረጋል፣ [-] ተጭነው ደግሞ ይመልሳል። |
148 | 148 | |
149 | 149 | በግራ በኩል ባለው ሳጥን ውስጥ የመደቡን ስም ዝም ብለው መጻፍ ይችላሉ። (የዚሁ ዊኪ መደብ ስሞች ለመመልከት፣ [[Special:Mostlinkedcategories|እዚህ ይጫኑ]]።) ከዚያ፥ ምን ያሕል ንዑስ-መደቦች እንዳሉበት ለማየት «ዛፉ ይታይ» የሚለውን ይጫኑ። በቀኝ በኩል ካለው ሳጥን 'all pages' ከመረጡ፥ በየመደቡ ውስጥ ያሉት መጣጥፎች በተጨማሪ ይታያሉ። |
150 | 150 | |
— | — | @@ -516,7 +516,7 @@ |
517 | 517 | 'categorytree-portlet' => 'Rummadoù', |
518 | 518 | 'categorytree-legend' => 'Gwelet gwezennadur ar rummad', |
519 | 519 | 'categorytree-desc' => 'Furchal a ra ent dinamek [[Special:CategoryTree|framm ar rummadoù]]', |
520 | | - 'categorytree-header' => "Merkit anv ur rummad evit gwelet petra zo ennañ e stumm ur gwezennadur. |
| 520 | + 'categorytree-header' => "Merkit anv ur rummad evit gwelet petra zo ennañ e stumm ur gwezennadur. |
521 | 521 | Notit e rankit kaout an arc'hwelioù JavaScript araokaet anvet AJAX. |
522 | 522 | M'eo kozh-mat stumm ho merdeer pe m'eo diweredekaet JavaScript ganeoc'h, ne'z aio ket en-dro.", |
523 | 523 | 'categorytree-category' => 'Rummad :', |
— | — | @@ -693,8 +693,8 @@ |
694 | 694 | 'categorytree-portlet' => 'Categorïau', |
695 | 695 | 'categorytree-legend' => 'Dangos y goeden gategori', |
696 | 696 | 'categorytree-desc' => "Teclyn AJAX yn arddangos [[Special:CategoryTree|adeiledd categorïau]]'r wici", |
697 | | - 'categorytree-header' => "Teipiwch enw categori yn y blwch er mwyn gweld ei gynnwys ar lun coeden. |
698 | | -Sylwer bod yn rhaid defnyddio offer uwch Sgript Java o'r enw AJAX er mwyn gwneud hyn. |
| 697 | + 'categorytree-header' => "Teipiwch enw categori yn y blwch er mwyn gweld ei gynnwys ar lun coeden. |
| 698 | +Sylwer bod yn rhaid defnyddio offer uwch Sgript Java o'r enw AJAX er mwyn gwneud hyn. |
699 | 699 | Ni lwydda'r gofyniad os yw'ch porwr yn hen iawn neu os nad yw Sgript Java wedi ei alluogi.", |
700 | 700 | 'categorytree-category' => 'Categori:', |
701 | 701 | 'categorytree-go' => 'Dangos y Goeden', |
— | — | @@ -2137,7 +2137,7 @@ |
2138 | 2138 | 'categorytree-legend' => 'Weis Kategoriestruktur', |
2139 | 2139 | 'categorytree-desc' => "Gadget deen op Ajax opgebaut ass fir d'[[Special:CategoryTree|Kategorie-Struktur]] vun enger Wiki duerzestellen", |
2140 | 2140 | 'categorytree-header' => 'Gitt den Numm vun enger Kategorie an, fir hiren Inhalt als Bam-Struktur ze gesinn. |
2141 | | -Bedenkt, datt dës Fonctioun Java Script Funktioune benotzt, déi als AJAX bekannt sinn. |
| 2141 | +Bedenkt, datt dës Fonctioun Java Script Funktioune benotzt, déi als AJAX bekannt sinn. |
2142 | 2142 | Wann Dir ee ganz ale Browser hutt, oder wann Dir JavaScript ausgeschalt hutt, da fonktionnéiert dëst bei Iech net.', |
2143 | 2143 | 'categorytree-category' => 'Kategorie:', |
2144 | 2144 | 'categorytree-go' => 'Struktur weisen', |
— | — | @@ -2293,8 +2293,8 @@ |
2294 | 2294 | 'categorytree-portlet' => 'Kategorijas', |
2295 | 2295 | 'categorytree-legend' => 'Rādīt kategoriju koku', |
2296 | 2296 | 'categorytree-desc' => "AJAX bāzēts ''gadget'', kuru lieto lai attēlotu wiki [[Special:CategoryTree|kategoriju struktūru]]", |
2297 | | - 'categorytree-header' => 'Ievadi kategorijas nosaukumu lai apskatītos tās saturu kā koka struktūru. |
2298 | | -Tam ir nepieciešama JavaScript (AJAX) funkcionalitāte. |
| 2297 | + 'categorytree-header' => 'Ievadi kategorijas nosaukumu lai apskatītos tās saturu kā koka struktūru. |
| 2298 | +Tam ir nepieciešama JavaScript (AJAX) funkcionalitāte. |
2299 | 2299 | Ja tev ir veca interneta pārlūkprogramma, vai arī JavaScript ir atslēgts, šitas te nedarbosies.', |
2300 | 2300 | 'categorytree-category' => 'Kategorija:', |
2301 | 2301 | 'categorytree-go' => 'Parādīt koku', |
— | — | @@ -2547,7 +2547,7 @@ |
2548 | 2548 | 'categorytree-portlet' => 'Kattegerieën', |
2549 | 2549 | 'categorytree-legend' => 'Laot kattegerieboom zien', |
2550 | 2550 | 'categorytree-desc' => 'Dynamische navigasie veur de [[Special:CategoryTree|kattegeriestructuur]]', |
2551 | | - 'categorytree-header' => 'Voer een kattegerienaam in um de inhoud in boomstructuur te bekieken. |
| 2551 | + 'categorytree-header' => 'Voer een kattegerienaam in um de inhoud in boomstructuur te bekieken. |
2552 | 2552 | NB: Veur disse functie he-j de [[JavaScript]]functionaliteit, AJAX neudig. A-j een hele ouwe webkieker hemmen, of je JavaScript uut-eschakeld hemmen, dan zal disse functie neet warken.', |
2553 | 2553 | 'categorytree-category' => 'Kattegerie:', |
2554 | 2554 | 'categorytree-go' => 'Laojen', |
— | — | @@ -3646,8 +3646,8 @@ |
3647 | 3647 | 'categorytree-portlet' => 'Kategoriýalar', |
3648 | 3648 | 'categorytree-legend' => 'Kategoriýa agajyny görkez', |
3649 | 3649 | 'categorytree-desc' => '[[Special:CategoryTree|Kategoriýa gurluşyny]] dinamik ýagdaýda dolandyr', |
3650 | | - 'categorytree-header' => 'Kategoriýanyň adyny ýazyp, onuň mazmunyny agaç gurluşy hökmünde görüp bilersiňiz. |
3651 | | -Bu aýratynlyk AJAX ady bilen tanalýan ösen JavaScript bilen işleýändir. |
| 3650 | + 'categorytree-header' => 'Kategoriýanyň adyny ýazyp, onuň mazmunyny agaç gurluşy hökmünde görüp bilersiňiz. |
| 3651 | +Bu aýratynlyk AJAX ady bilen tanalýan ösen JavaScript bilen işleýändir. |
3652 | 3652 | Eger brauzeriňiz köne bolsa ýa-da JavaScript ýapyk bolsa, onda ol işlemez.', |
3653 | 3653 | 'categorytree-category' => 'Kategoriýa:', |
3654 | 3654 | 'categorytree-go' => 'Agajy görkez', |
— | — | @@ -3937,8 +3937,8 @@ |
3938 | 3938 | 'categorytree' => 'קאַטעגאריע בוים', |
3939 | 3939 | 'categorytree-portlet' => 'קאַטעגאריעס', |
3940 | 3940 | 'categorytree-legend' => 'ווײַזן קאַטעגאריע בוים', |
3941 | | - 'categorytree-header' => 'לייגט אריין א קאטעגאריע נאמען צו זען איר אינהאלט אלס א בוים סטרוקטור. |
3942 | | -באמערקט אז דאס פארלאנגט פארגעשריטענע JavaScript מעגליכקייטן, באקאנט אלס AJAX. |
| 3941 | + 'categorytree-header' => 'לייגט אריין א קאטעגאריע נאמען צו זען איר אינהאלט אלס א בוים סטרוקטור. |
| 3942 | +באמערקט אז דאס פארלאנגט פארגעשריטענע JavaScript מעגליכקייטן, באקאנט אלס AJAX. |
3943 | 3943 | אויב איר ניצט אן אלטן בלעטערער, אדער איר ערלויבט נישט קיין JavaScript, וועט דאס נישט ווירקן.', |
3944 | 3944 | 'categorytree-category' => 'קאטעגאריע:', |
3945 | 3945 | 'categorytree-go' => 'ווײַזן בוים', |
Index: trunk/extensions/CategoryTree/CategoryTree.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * Setup and Hooks for the CategoryTree extension, an AJAX based gadget |
6 | 5 | * to display the category structure of a wiki |
— | — | @@ -10,7 +9,7 @@ |
11 | 10 | * @license GNU General Public Licence 2.0 or later |
12 | 11 | */ |
13 | 12 | |
14 | | -if( !defined( 'MEDIAWIKI' ) ) { |
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) { |
15 | 14 | echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); |
16 | 15 | die( 1 ); |
17 | 16 | } |
— | — | @@ -19,19 +18,19 @@ |
20 | 19 | * Constants for use with the mode, |
21 | 20 | * defining what should be shown in the tree |
22 | 21 | */ |
23 | | -define('CT_MODE_CATEGORIES', 0); |
24 | | -define('CT_MODE_PAGES', 10); |
25 | | -define('CT_MODE_ALL', 20); |
26 | | -define('CT_MODE_PARENTS', 100); |
| 22 | +define( 'CT_MODE_CATEGORIES', 0 ); |
| 23 | +define( 'CT_MODE_PAGES', 10 ); |
| 24 | +define( 'CT_MODE_ALL', 20 ); |
| 25 | +define( 'CT_MODE_PARENTS', 100 ); |
27 | 26 | |
28 | 27 | /** |
29 | 28 | * Constants for use with the hideprefix option, |
30 | 29 | * defining when the namespace prefix should be hidden |
31 | 30 | */ |
32 | | -define('CT_HIDEPREFIX_NEVER', 0); |
33 | | -define('CT_HIDEPREFIX_ALWAYS', 10); |
34 | | -define('CT_HIDEPREFIX_CATEGORIES', 20); |
35 | | -define('CT_HIDEPREFIX_AUTO', 30); |
| 31 | +define( 'CT_HIDEPREFIX_NEVER', 0 ); |
| 32 | +define( 'CT_HIDEPREFIX_ALWAYS', 10 ); |
| 33 | +define( 'CT_HIDEPREFIX_CATEGORIES', 20 ); |
| 34 | +define( 'CT_HIDEPREFIX_AUTO', 30 ); |
36 | 35 | |
37 | 36 | /** |
38 | 37 | * Options: |
— | — | @@ -56,53 +55,53 @@ |
57 | 56 | $wgCategoryTreeDisableCache = true; |
58 | 57 | $wgCategoryTreeDynamicTag = false; |
59 | 58 | $wgCategoryTreeHTTPCache = false; |
60 | | -#$wgCategoryTreeUnifiedView = true; |
61 | | -$wgCategoryTreeMaxDepth = array(CT_MODE_PAGES => 1, CT_MODE_ALL => 1, CT_MODE_CATEGORIES => 2); |
| 59 | +# $wgCategoryTreeUnifiedView = true; |
| 60 | +$wgCategoryTreeMaxDepth = array( CT_MODE_PAGES => 1, CT_MODE_ALL => 1, CT_MODE_CATEGORIES => 2 ); |
62 | 61 | |
63 | | -# Set $wgCategoryTreeForceHeaders to true to force the JS and CSS headers for CategoryTree to be included on every page. |
| 62 | +# Set $wgCategoryTreeForceHeaders to true to force the JS and CSS headers for CategoryTree to be included on every page. |
64 | 63 | # May be usefull for using CategoryTree from within system messages, in the sidebar, or a custom skin. |
65 | | -$wgCategoryTreeForceHeaders = false; |
| 64 | +$wgCategoryTreeForceHeaders = false; |
66 | 65 | $wgCategoryTreeSidebarRoot = null; |
67 | 66 | $wgCategoryTreeHijackPageCategories = false; # EXPERIMENTAL! NOT YET FOR PRODUCTION USE! Main problem is general HTML/CSS layout cruftiness. |
68 | 67 | |
69 | 68 | $wgCategoryTreeExtPath = '/extensions/CategoryTree'; |
70 | | -$wgCategoryTreeVersion = '5'; #NOTE: bump this when you change the CSS or JS files! |
| 69 | +$wgCategoryTreeVersion = '5'; # NOTE: bump this when you change the CSS or JS files! |
71 | 70 | $wgCategoryTreeUseCategoryTable = version_compare( $wgVersion, "1.13", '>=' ); |
72 | 71 | |
73 | 72 | $wgCategoryTreeOmitNamespace = CT_HIDEPREFIX_CATEGORIES; |
74 | 73 | $wgCategoryTreeDefaultMode = CT_MODE_CATEGORIES; |
75 | | -$wgCategoryTreeDefaultOptions = array(); #Default values for most options. ADD NEW OPTIONS HERE! |
| 74 | +$wgCategoryTreeDefaultOptions = array(); # Default values for most options. ADD NEW OPTIONS HERE! |
76 | 75 | $wgCategoryTreeDefaultOptions['mode'] = null; # will be set to $wgCategoryTreeDefaultMode in efCategoryTree(); compatibility quirk |
77 | 76 | $wgCategoryTreeDefaultOptions['hideprefix'] = null; # will be set to $wgCategoryTreeDefaultMode in efCategoryTree(); compatibility quirk |
78 | 77 | $wgCategoryTreeDefaultOptions['showcount'] = false; |
79 | 78 | $wgCategoryTreeDefaultOptions['namespaces'] = false; # false means "no filter" |
80 | 79 | |
81 | 80 | $wgCategoryTreeCategoryPageMode = CT_MODE_CATEGORIES; |
82 | | -$wgCategoryTreeCategoryPageOptions = array(); #Options to be used for category pages |
| 81 | +$wgCategoryTreeCategoryPageOptions = array(); # Options to be used for category pages |
83 | 82 | $wgCategoryTreeCategoryPageOptions['mode'] = NULL; # will be set to $wgCategoryTreeDefaultMode in efCategoryTree(); compatibility quirk |
84 | 83 | $wgCategoryTreeCategoryPageOptions['showcount'] = true; |
85 | 84 | |
86 | | -$wgCategoryTreeSpecialPageOptions = array(); #Options to be used for Special:CategoryTree |
| 85 | +$wgCategoryTreeSpecialPageOptions = array(); # Options to be used for Special:CategoryTree |
87 | 86 | $wgCategoryTreeSpecialPageOptions['showcount'] = true; |
88 | 87 | |
89 | | -$wgCategoryTreeSidebarOptions = array(); #Options to be used in the sidebar (for use with $wgCategoryTreeSidebarRoot) |
| 88 | +$wgCategoryTreeSidebarOptions = array(); # Options to be used in the sidebar (for use with $wgCategoryTreeSidebarRoot) |
90 | 89 | $wgCategoryTreeSidebarOptions['mode'] = CT_MODE_CATEGORIES; |
91 | 90 | $wgCategoryTreeSidebarOptions['hideprefix'] = CT_HIDEPREFIX_CATEGORIES; |
92 | 91 | $wgCategoryTreeSidebarOptions['showcount'] = false; |
93 | 92 | $wgCategoryTreeSidebarOptions['hideroot'] = true; |
94 | | -$wgCategoryTreeSidebarOptions['namespaces'] = false; |
| 93 | +$wgCategoryTreeSidebarOptions['namespaces'] = false; |
95 | 94 | $wgCategoryTreeSidebarOptions['depth'] = 1; |
96 | 95 | |
97 | | -$wgCategoryTreePageCategoryOptions = array(); #Options to be used in the sidebar (for use with $wgCategoryTreePageCategories) |
| 96 | +$wgCategoryTreePageCategoryOptions = array(); # Options to be used in the sidebar (for use with $wgCategoryTreePageCategories) |
98 | 97 | $wgCategoryTreePageCategoryOptions['mode'] = CT_MODE_PARENTS; |
99 | 98 | $wgCategoryTreePageCategoryOptions['hideprefix'] = CT_HIDEPREFIX_CATEGORIES; |
100 | 99 | $wgCategoryTreePageCategoryOptions['showcount'] = false; |
101 | 100 | $wgCategoryTreePageCategoryOptions['hideroot'] = false; |
102 | 101 | $wgCategoryTreePageCategoryOptions['namespaces'] = false; |
103 | 102 | $wgCategoryTreePageCategoryOptions['depth'] = 0; |
104 | | -#$wgCategoryTreePageCategoryOptions['class'] = 'CategoryTreeInlineNode'; |
| 103 | +# $wgCategoryTreePageCategoryOptions['class'] = 'CategoryTreeInlineNode'; |
105 | 104 | |
106 | | -$wgExtensionAliasesFiles['CategoryTree'] = dirname(__FILE__) . '/CategoryTree.alias.php'; |
| 105 | +$wgExtensionAliasesFiles['CategoryTree'] = dirname( __FILE__ ) . '/CategoryTree.alias.php'; |
107 | 106 | |
108 | 107 | /** |
109 | 108 | * Register extension setup hook and credits |
— | — | @@ -127,7 +126,7 @@ |
128 | 127 | /** |
129 | 128 | * Register the special page |
130 | 129 | */ |
131 | | -$dir = dirname(__FILE__) . '/'; |
| 130 | +$dir = dirname( __FILE__ ) . '/'; |
132 | 131 | |
133 | 132 | if ( $wgUseAjax && $wgCategoryTreeAllowTag ) { |
134 | 133 | $wgExtensionMessagesFiles['CategoryTreeMagic'] = $dir . 'CategoryTree.i18n.magic.php'; |
— | — | @@ -139,7 +138,7 @@ |
140 | 139 | $wgAutoloadClasses['CategoryTreeCategoryPage'] = $dir . 'CategoryPageSubclass.php'; |
141 | 140 | $wgSpecialPages['CategoryTree'] = 'CategoryTreePage'; |
142 | 141 | $wgSpecialPageGroups['CategoryTree'] = 'pages'; |
143 | | -#$wgHooks['SkinTemplateTabs'][] = 'efCategoryTreeInstallTabs'; |
| 142 | +# $wgHooks['SkinTemplateTabs'][] = 'efCategoryTreeInstallTabs'; |
144 | 143 | $wgHooks['ArticleFromTitle'][] = 'efCategoryTreeArticleFromTitle'; |
145 | 144 | |
146 | 145 | /** |
— | — | @@ -173,7 +172,7 @@ |
174 | 173 | $wgHooks['SkinJoinCategoryLinks'][] = 'efCategoryTreeSkinJoinCategoryLinks'; |
175 | 174 | } |
176 | 175 | |
177 | | - if( $wgCategoryTreeAllowTag ) { |
| 176 | + if ( $wgCategoryTreeAllowTag ) { |
178 | 177 | $wgHooks['ParserFirstCallInit'][] = 'efCategoryTreeSetHooks'; |
179 | 178 | } |
180 | 179 | |
— | — | @@ -220,13 +219,13 @@ |
221 | 220 | $depth = isset( $options['depth'] ) ? (int)$options['depth'] : 1; |
222 | 221 | |
223 | 222 | $ct = new CategoryTree( $options, true ); |
224 | | - $depth = efCategoryTreeCapDepth( $ct->getOption('mode'), $depth ); |
| 223 | + $depth = efCategoryTreeCapDepth( $ct->getOption( 'mode' ), $depth ); |
225 | 224 | $response = $ct->ajax( $category, $depth ); |
226 | 225 | |
227 | 226 | if ( $wgCategoryTreeHTTPCache && $wgSquidMaxage && $wgUseSquid ) { |
228 | 227 | $response->setCacheDuration( $wgSquidMaxage ); |
229 | | - $response->setVary( 'Accept-Encoding, Cookie' ); #cache for anons only |
230 | | - #TODO: purge the squid cache when a category page is invalidated |
| 228 | + $response->setVary( 'Accept-Encoding, Cookie' ); # cache for anons only |
| 229 | + # TODO: purge the squid cache when a category page is invalidated |
231 | 230 | } |
232 | 231 | |
233 | 232 | return $response; |
— | — | @@ -239,20 +238,22 @@ |
240 | 239 | function efCategoryTreeCapDepth( $mode, $depth ) { |
241 | 240 | global $wgCategoryTreeMaxDepth; |
242 | 241 | |
243 | | - if (is_numeric($depth)) |
244 | | - $depth = intval($depth); |
245 | | - else return 1; |
| 242 | + if ( is_numeric( $depth ) ) { |
| 243 | + $depth = intval( $depth ); |
| 244 | + } else { |
| 245 | + return 1; |
| 246 | + } |
246 | 247 | |
247 | | - if (is_array($wgCategoryTreeMaxDepth)) { |
248 | | - $max = isset($wgCategoryTreeMaxDepth[$mode]) ? $wgCategoryTreeMaxDepth[$mode] : 1; |
249 | | - } elseif (is_numeric($wgCategoryTreeMaxDepth)) { |
| 248 | + if ( is_array( $wgCategoryTreeMaxDepth ) ) { |
| 249 | + $max = isset( $wgCategoryTreeMaxDepth[$mode] ) ? $wgCategoryTreeMaxDepth[$mode] : 1; |
| 250 | + } elseif ( is_numeric( $wgCategoryTreeMaxDepth ) ) { |
250 | 251 | $max = $wgCategoryTreeMaxDepth; |
251 | 252 | } else { |
252 | 253 | wfDebug( 'efCategoryTreeCapDepth: $wgCategoryTreeMaxDepth is invalid.' ); |
253 | 254 | $max = 1; |
254 | 255 | } |
255 | 256 | |
256 | | - return min($depth, $max); |
| 257 | + return min( $depth, $max ); |
257 | 258 | } |
258 | 259 | |
259 | 260 | /** |
— | — | @@ -261,28 +262,30 @@ |
262 | 263 | */ |
263 | 264 | function efCategoryTreeParserFunction( &$parser ) { |
264 | 265 | $params = func_get_args(); |
265 | | - array_shift( $params ); //first is &$parser, strip it |
| 266 | + array_shift( $params ); // first is &$parser, strip it |
266 | 267 | |
267 | | - //first user-supplied parameter must be category name |
268 | | - if ( !$params ) return ''; //no category specified, return nothing |
| 268 | + // first user-supplied parameter must be category name |
| 269 | + if ( !$params ) { |
| 270 | + return ''; // no category specified, return nothing |
| 271 | + } |
269 | 272 | $cat = array_shift( $params ); |
270 | 273 | |
271 | | - //build associative arguments from flat parameter list |
| 274 | + // build associative arguments from flat parameter list |
272 | 275 | $argv = array(); |
273 | 276 | foreach ( $params as $p ) { |
274 | | - if ( preg_match('/^\s*(\S.*?)\s*=\s*(.*?)\s*$/', $p, $m) ) { |
| 277 | + if ( preg_match( '/^\s*(\S.*?)\s*=\s*(.*?)\s*$/', $p, $m ) ) { |
275 | 278 | $k = $m[1]; |
276 | | - $v = preg_replace('/^"\s*(.*?)\s*"$/', '$1', $m[2]); //strip any quotes enclusing the value |
| 279 | + $v = preg_replace( '/^"\s*(.*?)\s*"$/', '$1', $m[2] ); // strip any quotes enclusing the value |
277 | 280 | } |
278 | 281 | else { |
279 | | - $k = trim($p); |
| 282 | + $k = trim( $p ); |
280 | 283 | $v = true; |
281 | 284 | } |
282 | 285 | |
283 | 286 | $argv[$k] = $v; |
284 | 287 | } |
285 | 288 | |
286 | | - //now handle just like a <categorytree> tag |
| 289 | + // now handle just like a <categorytree> tag |
287 | 290 | $html = efCategoryTreeParserHook( $cat, $argv, $parser ); |
288 | 291 | return array( $html, 'noparse' => true, 'isHTML' => true ); |
289 | 292 | } |
— | — | @@ -293,14 +296,15 @@ |
294 | 297 | */ |
295 | 298 | function efCategoryTreeSkinTemplateOutputPageBeforeExec( &$skin, &$tpl ) { |
296 | 299 | global $wgCategoryTreeSidebarRoot, $wgCategoryTreeSidebarOptions; |
297 | | - |
| 300 | + |
298 | 301 | $html = efCategoryTreeParserHook( $wgCategoryTreeSidebarRoot, $wgCategoryTreeSidebarOptions ); |
299 | | - if ( $html ) $tpl->data['sidebar']['categorytree-portlet'] = $html; //requires MW 1.13, r36917 |
| 302 | + if ( $html ) { |
| 303 | + $tpl->data['sidebar']['categorytree-portlet'] = $html; // requires MW 1.13, r36917 |
| 304 | + } |
300 | 305 | |
301 | 306 | return true; |
302 | 307 | } |
303 | 308 | |
304 | | - |
305 | 309 | /** |
306 | 310 | * Entry point for the <categorytree> tag parser hook. |
307 | 311 | * This loads CategoryTreeFunctions.php and calls CategoryTree::getTag() |
— | — | @@ -310,8 +314,7 @@ |
311 | 315 | |
312 | 316 | if ( $parser ) { |
313 | 317 | $parser->mOutput->mCategoryTreeTag = true; # flag for use by efCategoryTreeParserOutput |
314 | | - } |
315 | | - else { |
| 318 | + } else { |
316 | 319 | CategoryTree::setHeaders( $wgOut ); |
317 | 320 | } |
318 | 321 | |
— | — | @@ -324,7 +327,9 @@ |
325 | 328 | $depthArg = isset( $argv[ 'depth' ] ) ? (int)$argv[ 'depth' ] : null; |
326 | 329 | |
327 | 330 | $depth = efCategoryTreeCapDepth( $ct->getOption( 'mode' ), $depthArg ); |
328 | | - if ( $onlyroot ) $depth = 0; |
| 331 | + if ( $onlyroot ) { |
| 332 | + $depth = 0; |
| 333 | + } |
329 | 334 | |
330 | 335 | return $ct->getTag( $parser, $cat, $hideroot, $attr, $depth, $allowMissing ); |
331 | 336 | } |
— | — | @@ -365,13 +370,11 @@ |
366 | 371 | return false; |
367 | 372 | } |
368 | 373 | |
369 | | - |
370 | 374 | function efCategoryTreeSkinJoinCategoryLinks( &$skin, &$links, &$result ) { |
371 | 375 | $embed = '<div class="CategoryTreePretendInlineMSIE CategoryTreeCategoryBarItem">'; |
372 | 376 | $pop = '</div>'; |
373 | 377 | $sep = ' '; |
374 | 378 | |
375 | | -# $result = '<div class="CategoryTreeCatBarWrapper" style="border:1px solid blue">' . $embed . implode ( "{$pop} {$sep} {$embed}" , $links ) . $pop . '</div>'; |
376 | 379 | $result = $embed . implode ( "{$pop} {$sep} {$embed}" , $links ) . $pop; |
377 | 380 | |
378 | 381 | return false; |
Index: trunk/extensions/CategoryTree/CategoryTree.css |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | * @copyright © 2006 Daniel Kinzler |
10 | 10 | * @licence GNU General Public Licence 2.0 or later |
11 | 11 | * |
12 | | - * NOTE: if you change this, increment $wgCategoryTreeVersion |
| 12 | + * NOTE: if you change this, increment $wgCategoryTreeVersion |
13 | 13 | * in CategoryTree.php to avoid users getting stale copies from cache. |
14 | 14 | */ |
15 | 15 | |
Index: trunk/extensions/CategoryTree/CategoryTree.js |
— | — | @@ -8,155 +8,155 @@ |
9 | 9 | * @copyright © 2006 Daniel Kinzler |
10 | 10 | * @licence GNU General Public Licence 2.0 or later |
11 | 11 | * |
12 | | - * NOTE: if you change this, increment $wgCategoryTreeVersion |
| 12 | + * NOTE: if you change this, increment $wgCategoryTreeVersion |
13 | 13 | * in CategoryTree.php to avoid users getting stale copies from cache. |
14 | | -*/ |
| 14 | + */ |
15 | 15 | |
16 | 16 | // Default messages if new code loaded with old cached page |
17 | 17 | var categoryTreeErrorMsg = "Problem loading data."; |
18 | 18 | var categoryTreeRetryMsg = "Please wait a moment and try again."; |
19 | 19 | |
20 | | - function categoryTreeNextDiv(e) { |
21 | | - var n= e.nextSibling; |
22 | | - while ( n && ( n.nodeType != 1 || n.nodeName != 'DIV') ) { |
23 | | - //alert('nodeType: ' + n.nodeType + '; nodeName: ' + n.nodeName); |
24 | | - n= n.nextSibling; |
25 | | - } |
| 20 | +function categoryTreeNextDiv(e) { |
| 21 | + var n= e.nextSibling; |
| 22 | + while ( n && ( n.nodeType != 1 || n.nodeName != 'DIV') ) { |
| 23 | + //alert('nodeType: ' + n.nodeType + '; nodeName: ' + n.nodeName); |
| 24 | + n= n.nextSibling; |
| 25 | + } |
26 | 26 | |
27 | | - return n; |
28 | | - } |
| 27 | + return n; |
| 28 | +} |
29 | 29 | |
30 | | - function categoryTreeExpandNode(cat, options, lnk) { |
31 | | - var div= categoryTreeNextDiv( lnk.parentNode.parentNode ); |
| 30 | +function categoryTreeExpandNode(cat, options, lnk) { |
| 31 | + var div= categoryTreeNextDiv( lnk.parentNode.parentNode ); |
32 | 32 | |
33 | | - div.style.display= 'block'; |
34 | | - lnk.innerHTML= categoryTreeCollapseBulletMsg; |
35 | | - lnk.title= categoryTreeCollapseMsg; |
36 | | - lnk.onclick= function() { categoryTreeCollapseNode(cat, options, lnk) } |
| 33 | + div.style.display= 'block'; |
| 34 | + lnk.innerHTML= categoryTreeCollapseBulletMsg; |
| 35 | + lnk.title= categoryTreeCollapseMsg; |
| 36 | + lnk.onclick= function() { categoryTreeCollapseNode(cat, options, lnk) } |
37 | 37 | |
38 | | - if (!lnk.className.match(/(^| )CategoryTreeLoaded($| )/)) { |
39 | | - categoryTreeLoadNode(cat, options, lnk, div); |
40 | | - } |
41 | | - } |
| 38 | + if (!lnk.className.match(/(^| )CategoryTreeLoaded($| )/)) { |
| 39 | + categoryTreeLoadNode(cat, options, lnk, div); |
| 40 | + } |
| 41 | +} |
42 | 42 | |
43 | | - function categoryTreeCollapseNode(cat, options, lnk) { |
44 | | - var div= categoryTreeNextDiv( lnk.parentNode.parentNode ); |
| 43 | +function categoryTreeCollapseNode(cat, options, lnk) { |
| 44 | + var div= categoryTreeNextDiv( lnk.parentNode.parentNode ); |
45 | 45 | |
46 | | - div.style.display= 'none'; |
47 | | - lnk.innerHTML= categoryTreeExpandBulletMsg; |
48 | | - lnk.title= categoryTreeExpandMsg; |
49 | | - lnk.onclick= function() { categoryTreeExpandNode(cat, options, lnk) } |
50 | | - } |
| 46 | + div.style.display= 'none'; |
| 47 | + lnk.innerHTML= categoryTreeExpandBulletMsg; |
| 48 | + lnk.title= categoryTreeExpandMsg; |
| 49 | + lnk.onclick= function() { categoryTreeExpandNode(cat, options, lnk) } |
| 50 | +} |
51 | 51 | |
52 | | - function categoryTreeLoadNode(cat, options, lnk, div) { |
53 | | - div.style.display= 'block'; |
54 | | - lnk.className= 'CategoryTreeLoaded'; |
55 | | - lnk.innerHTML= categoryTreeCollapseBulletMsg; |
56 | | - lnk.title= categoryTreeCollapseMsg; |
57 | | - lnk.onclick= function() { categoryTreeCollapseNode(cat, options, lnk) } |
| 52 | +function categoryTreeLoadNode(cat, options, lnk, div) { |
| 53 | + div.style.display= 'block'; |
| 54 | + lnk.className= 'CategoryTreeLoaded'; |
| 55 | + lnk.innerHTML= categoryTreeCollapseBulletMsg; |
| 56 | + lnk.title= categoryTreeCollapseMsg; |
| 57 | + lnk.onclick= function() { categoryTreeCollapseNode(cat, options, lnk) } |
58 | 58 | |
59 | | - categoryTreeLoadChildren(cat, options, div) |
60 | | - } |
| 59 | + categoryTreeLoadChildren(cat, options, div) |
| 60 | +} |
61 | 61 | |
62 | | - // FIXME Why can't this just use uneval()? |
63 | | - function categoryTreeEncodeValue(value) { |
64 | | - switch (typeof value) { |
65 | | - case 'function': |
66 | | - throw new Error("categoryTreeEncodeValue encountered a function"); |
67 | | - break; |
| 62 | +// FIXME Why can't this just use uneval()? |
| 63 | +function categoryTreeEncodeValue(value) { |
| 64 | + switch (typeof value) { |
| 65 | + case 'function': |
| 66 | + throw new Error("categoryTreeEncodeValue encountered a function"); |
| 67 | + break; |
| 68 | + case 'string': |
| 69 | + s = '"' + value.replace(/([\\"'])/g, "\\$1") + '"'; |
| 70 | + break; |
| 71 | + case 'number': |
| 72 | + case 'boolean': |
| 73 | + case 'null': |
| 74 | + s = String(value); |
| 75 | + break; |
| 76 | + case 'object': |
| 77 | + if ( !value ) { |
| 78 | + s = 'null'; |
| 79 | + } else if (typeof value.length === 'number' && !(value.propertyIsEnumerable('length'))) { |
| 80 | + s = ''; |
| 81 | + for (i = 0; i<value.length; i++) { |
| 82 | + v = value[i]; |
| 83 | + if ( s!='' ) s += ', '; |
| 84 | + s += categoryTreeEncodeValue( v ); |
| 85 | + } |
| 86 | + s = '[' + s + ']'; |
| 87 | + } else { |
| 88 | + s = ''; |
| 89 | + for (k in value) { |
| 90 | + v = value[k]; |
| 91 | + if ( s!='' ) s += ', '; |
| 92 | + s += categoryTreeEncodeValue( k ); |
| 93 | + s += ': '; |
| 94 | + s += categoryTreeEncodeValue( v ); |
| 95 | + } |
| 96 | + s = '{' + s + '}'; |
| 97 | + } |
| 98 | + break; |
| 99 | + default: |
| 100 | + throw new Error("categoryTreeEncodeValue encountered strange variable type " + (typeof value)); |
| 101 | + } |
68 | 102 | |
69 | | - case 'string': |
70 | | - s = '"' + value.replace(/([\\"'])/g, "\\$1") + '"'; |
71 | | - break; |
| 103 | + return s; |
| 104 | +} |
72 | 105 | |
73 | | - case 'number': |
74 | | - case 'boolean': |
75 | | - case 'null': |
76 | | - s = String(value); |
77 | | - break; |
| 106 | +function categoryTreeLoadChildren(cat, options, div) { |
| 107 | + div.innerHTML= '<i class="CategoryTreeNotice">' + categoryTreeLoadingMsg + '</i>'; |
78 | 108 | |
79 | | - case 'object': |
80 | | - if ( !value ) { |
81 | | - s = 'null'; |
82 | | - } |
83 | | - else if (typeof value.length === 'number' && !(value.propertyIsEnumerable('length'))) { |
84 | | - s = ''; |
85 | | - for (i = 0; i<value.length; i++) { |
86 | | - v = value[i]; |
87 | | - if ( s!='' ) s += ', '; |
88 | | - s += categoryTreeEncodeValue( v ); |
89 | | - } |
90 | | - s = '[' + s + ']'; |
91 | | - } |
92 | | - else { |
93 | | - s = ''; |
94 | | - for (k in value) { |
95 | | - v = value[k]; |
96 | | - if ( s!='' ) s += ', '; |
97 | | - s += categoryTreeEncodeValue( k ); |
98 | | - s += ': '; |
99 | | - s += categoryTreeEncodeValue( v ); |
100 | | - } |
101 | | - s = '{' + s + '}'; |
102 | | - } |
103 | | - break; |
104 | | - default: |
105 | | - throw new Error("categoryTreeEncodeValue encountered strange variable type " + (typeof value)); |
106 | | - } |
| 109 | + if ( typeof options == "string" ) { //hack for backward compatibility |
| 110 | + options = { mode : options }; |
| 111 | + } |
107 | 112 | |
108 | | - return s; |
109 | | - } |
| 113 | + function f( request ) { |
| 114 | + if (request.status != 200) { |
| 115 | + div.innerHTML = '<i class="CategoryTreeNotice">' + categoryTreeErrorMsg + ' </i>'; |
| 116 | + var retryLink = document.createElement('a'); |
| 117 | + retryLink.innerHTML = categoryTreeRetryMsg; |
| 118 | + retryLink.onclick = function() { |
| 119 | + categoryTreeLoadChildren(cat, options, div, enc); |
| 120 | + } |
| 121 | + div.appendChild(retryLink); |
| 122 | + return; |
| 123 | + } |
110 | 124 | |
111 | | - function categoryTreeLoadChildren(cat, options, div) { |
112 | | - div.innerHTML= '<i class="CategoryTreeNotice">' + categoryTreeLoadingMsg + '</i>'; |
| 125 | + result= request.responseText; |
| 126 | + result= result.replace(/^\s+|\s+$/, ''); |
113 | 127 | |
114 | | - if ( typeof options == "string" ) { //hack for backward compatibility |
115 | | - options = { mode : options }; |
116 | | - } |
| 128 | + if ( result == '' ) { |
| 129 | + result= '<i class="CategoryTreeNotice">'; |
117 | 130 | |
118 | | - function f( request ) { |
119 | | - if (request.status != 200) { |
120 | | - div.innerHTML = '<i class="CategoryTreeNotice">' + categoryTreeErrorMsg + ' </i>'; |
121 | | - var retryLink = document.createElement('a'); |
122 | | - retryLink.innerHTML = categoryTreeRetryMsg; |
123 | | - retryLink.onclick = function() { |
124 | | - categoryTreeLoadChildren(cat, options, div, enc); |
125 | | - } |
126 | | - div.appendChild(retryLink); |
127 | | - return; |
128 | | - } |
| 131 | + if ( options.mode == 0 ) { |
| 132 | + result= categoryTreeNoSubcategoriesMsg; |
| 133 | + } else if ( options.mode == 10 ) { |
| 134 | + result= categoryTreeNoPagesMsg; |
| 135 | + } else if ( options.mode == 100 ) { |
| 136 | + result= categoryTreeNoParentCategoriesMsg; |
| 137 | + } else { |
| 138 | + result= categoryTreeNothingFoundMsg; |
| 139 | + } |
129 | 140 | |
130 | | - result= request.responseText; |
131 | | - result= result.replace(/^\s+|\s+$/, ''); |
| 141 | + result+= '</i>'; |
| 142 | + } |
132 | 143 | |
133 | | - if ( result == '' ) { |
134 | | - result= '<i class="CategoryTreeNotice">'; |
| 144 | + result = result.replace(/##LOAD##/g, categoryTreeExpandMsg); |
| 145 | + div.innerHTML= result; |
135 | 146 | |
136 | | - if ( options.mode == 0 ) result= categoryTreeNoSubcategoriesMsg; |
137 | | - else if ( options.mode == 10 ) result= categoryTreeNoPagesMsg; |
138 | | - else if ( options.mode == 100 ) result= categoryTreeNoParentCategoriesMsg; |
139 | | - else result= categoryTreeNothingFoundMsg; |
| 147 | + categoryTreeShowToggles(); |
| 148 | + } |
140 | 149 | |
141 | | - result+= '</i>'; |
142 | | - } |
| 150 | + var opt = categoryTreeEncodeValue(options); |
| 151 | + sajax_do_call( "efCategoryTreeAjaxWrapper", [cat, opt, 'json'] , f ); |
| 152 | +} |
143 | 153 | |
144 | | - result = result.replace(/##LOAD##/g, categoryTreeExpandMsg); |
145 | | - div.innerHTML= result; |
| 154 | +function categoryTreeShowToggles() { |
| 155 | + var toggles = getElementsByClassName( document, 'span', 'CategoryTreeToggle' ); |
146 | 156 | |
147 | | - categoryTreeShowToggles(); |
148 | | - } |
| 157 | + for( var i = 0; i<toggles.length; ++i ) { |
| 158 | + toggles[i].style.display = 'inline'; |
| 159 | + } |
| 160 | +} |
149 | 161 | |
150 | | - var opt = categoryTreeEncodeValue(options); |
151 | | - sajax_do_call( "efCategoryTreeAjaxWrapper", [cat, opt, 'json'] , f ); |
152 | | - } |
153 | | - |
154 | | - function categoryTreeShowToggles() { |
155 | | - var toggles = getElementsByClassName( document, 'span', 'CategoryTreeToggle' ); |
156 | | - |
157 | | - for( var i = 0; i<toggles.length; ++i ) { |
158 | | - toggles[i].style.display = 'inline'; |
159 | | - } |
160 | | - } |
161 | | - |
162 | | - // Re-show the CategoryTreeToggles |
163 | | - addOnloadHook(categoryTreeShowToggles); |
| 162 | +// Re-show the CategoryTreeToggles |
| 163 | +addOnloadHook(categoryTreeShowToggles); |
Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * Core functions for the CategoryTree extension, an AJAX based gadget |
6 | 5 | * to display the category structure of a wiki |
— | — | @@ -10,7 +9,7 @@ |
11 | 10 | * @license GNU General Public Licence 2.0 or later |
12 | 11 | */ |
13 | 12 | |
14 | | -if( !defined( 'MEDIAWIKI' ) ) { |
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) { |
15 | 14 | echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" ); |
16 | 15 | die( 1 ); |
17 | 16 | } |
— | — | @@ -24,16 +23,19 @@ |
25 | 24 | |
26 | 25 | $this->mIsAjaxRequest = $ajax; |
27 | 26 | |
28 | | - #ensure default values and order of options. Order may become important, it may influence the cache key! |
| 27 | + # ensure default values and order of options. Order may become important, it may influence the cache key! |
29 | 28 | foreach ( $wgCategoryTreeDefaultOptions as $option => $default ) { |
30 | | - if ( isset( $options[$option] ) && !is_null( $options[$option] ) ) $this->mOptions[$option] = $options[$option]; |
31 | | - else $this->mOptions[$option] = $default; |
| 29 | + if ( isset( $options[$option] ) && !is_null( $options[$option] ) ) { |
| 30 | + $this->mOptions[$option] = $options[$option]; |
| 31 | + } else { |
| 32 | + $this->mOptions[$option] = $default; |
| 33 | + } |
32 | 34 | } |
33 | 35 | |
34 | 36 | $this->mOptions['mode'] = self::decodeMode( $this->mOptions['mode'] ); |
35 | 37 | |
36 | 38 | if ( $this->mOptions['mode'] == CT_MODE_PARENTS ) { |
37 | | - $this->mOptions['namespaces'] = false; #namespace filter makes no sense with CT_MODE_PARENTS |
| 39 | + $this->mOptions['namespaces'] = false; # namespace filter makes no sense with CT_MODE_PARENTS |
38 | 40 | } |
39 | 41 | |
40 | 42 | $this->mOptions['hideprefix'] = self::decodeHidePrefix( $this->mOptions['hideprefix'] ); |
— | — | @@ -42,7 +44,7 @@ |
43 | 45 | |
44 | 46 | if ( $this->mOptions['namespaces'] ) { |
45 | 47 | # automatically adjust mode to match namespace filter |
46 | | - if ( sizeof( $this->mOptions['namespaces'] ) === 1 |
| 48 | + if ( sizeof( $this->mOptions['namespaces'] ) === 1 |
47 | 49 | && $this->mOptions['namespaces'][0] == NS_CATEGORY ) { |
48 | 50 | $this->mOptions['mode'] = CT_MODE_CATEGORIES; |
49 | 51 | } else if ( !in_array( NS_IMAGE, $this->mOptions['namespaces'] ) ) { |
— | — | @@ -58,7 +60,7 @@ |
59 | 61 | } |
60 | 62 | |
61 | 63 | function isInverse( ) { |
62 | | - return $this->getOption('mode') == CT_MODE_PARENTS; |
| 64 | + return $this->getOption( 'mode' ) == CT_MODE_PARENTS; |
63 | 65 | } |
64 | 66 | |
65 | 67 | static function decodeNamespaces( $nn ) { |
— | — | @@ -67,7 +69,7 @@ |
68 | 70 | if ( !$nn ) |
69 | 71 | return false; |
70 | 72 | |
71 | | - if ( !is_array($nn) ) |
| 73 | + if ( !is_array( $nn ) ) |
72 | 74 | $nn = preg_split( '![\s#:|]+!', $nn ); |
73 | 75 | |
74 | 76 | $namespaces = array(); |
— | — | @@ -79,10 +81,10 @@ |
80 | 82 | else { |
81 | 83 | $n = trim( $n ); |
82 | 84 | if ( $n === '' ) continue; |
83 | | - |
| 85 | + |
84 | 86 | $lower = strtolower( $n ); |
85 | | - |
86 | | - if ( is_numeric($n) ) $ns = (int)$n; |
| 87 | + |
| 88 | + if ( is_numeric( $n ) ) $ns = (int)$n; |
87 | 89 | elseif ( $n == '-' || $n == '_' || $n == '*' || $lower == 'main' ) $ns = NS_MAIN; |
88 | 90 | else $ns = $wgContLang->getNsIndex( $n ); |
89 | 91 | } |
— | — | @@ -145,7 +147,7 @@ |
146 | 148 | |
147 | 149 | if ( $value == 'yes' || $value == 'y' || $value == 'true' || $value == 't' || $value == 'on' ) return CT_HIDEPREFIX_ALWAYS; |
148 | 150 | else if ( $value == 'no' || $value == 'n' || $value == 'false' || $value == 'f' || $value == 'off' ) return CT_HIDEPREFIX_NEVER; |
149 | | - //else if ( $value == 'null' || $value == 'default' || $value == 'none' || $value == 'x' ) return $wgCategoryTreeDefaultOptions['hideprefix']; |
| 151 | + // else if ( $value == 'null' || $value == 'default' || $value == 'none' || $value == 'x' ) return $wgCategoryTreeDefaultOptions['hideprefix']; |
150 | 152 | else if ( $value == 'always' ) return CT_HIDEPREFIX_ALWAYS; |
151 | 153 | else if ( $value == 'never' ) return CT_HIDEPREFIX_NEVER; |
152 | 154 | else if ( $value == 'auto' ) return CT_HIDEPREFIX_AUTO; |
— | — | @@ -160,7 +162,6 @@ |
161 | 163 | static function setHeaders( &$outputPage ) { |
162 | 164 | global $wgJsMimeType, $wgScriptPath, $wgContLang; |
163 | 165 | global $wgCategoryTreeHijackPageCategories, $wgCategoryTreeExtPath, $wgCategoryTreeVersion; |
164 | | - self::init(); |
165 | 166 | |
166 | 167 | # Register css file for CategoryTree |
167 | 168 | $outputPage->addLink( |
— | — | @@ -180,7 +181,7 @@ |
181 | 182 | } |
182 | 183 | |
183 | 184 | # Register css RTL file for CategoryTree |
184 | | - if( $wgContLang->isRTL() ) { |
| 185 | + if ( $wgContLang->isRTL() ) { |
185 | 186 | $outputPage->addLink( |
186 | 187 | array( |
187 | 188 | 'rel' => 'stylesheet', |
— | — | @@ -199,27 +200,27 @@ |
200 | 201 | # Add messages |
201 | 202 | $outputPage->addScript( |
202 | 203 | " <script type=\"{$wgJsMimeType}\"> |
203 | | - var categoryTreeCollapseMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-collapse'))."\"; |
204 | | - var categoryTreeExpandMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-expand'))."\"; |
205 | | - var categoryTreeCollapseBulletMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-collapse-bullet'))."\"; |
206 | | - var categoryTreeExpandBulletMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-expand-bullet'))."\"; |
207 | | - var categoryTreeLoadMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-load'))."\"; |
208 | | - var categoryTreeLoadingMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-loading'))."\"; |
209 | | - var categoryTreeNothingFoundMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-nothing-found'))."\"; |
210 | | - var categoryTreeNoSubcategoriesMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-no-subcategories'))."\"; |
211 | | - var categoryTreeNoParentCategoriesMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-no-parent-categories'))."\"; |
212 | | - var categoryTreeNoPagesMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-no-pages'))."\"; |
213 | | - var categoryTreeErrorMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-error'))."\"; |
214 | | - var categoryTreeRetryMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-retry'))."\"; |
215 | | - </script>\n" |
| 204 | + var categoryTreeCollapseMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-collapse' ) ) . "\"; |
| 205 | + var categoryTreeExpandMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-expand' ) ) . "\"; |
| 206 | + var categoryTreeCollapseBulletMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-collapse-bullet' ) ) . "\"; |
| 207 | + var categoryTreeExpandBulletMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-expand-bullet' ) ) . "\"; |
| 208 | + var categoryTreeLoadMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-load' ) ) . "\"; |
| 209 | + var categoryTreeLoadingMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-loading' ) ) . "\"; |
| 210 | + var categoryTreeNothingFoundMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-nothing-found' ) ) . "\"; |
| 211 | + var categoryTreeNoSubcategoriesMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-no-subcategories' ) ) . "\"; |
| 212 | + var categoryTreeNoParentCategoriesMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-no-parent-categories' ) ) . "\"; |
| 213 | + var categoryTreeNoPagesMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-no-pages' ) ) . "\"; |
| 214 | + var categoryTreeErrorMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-error' ) ) . "\"; |
| 215 | + var categoryTreeRetryMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-retry' ) ) . "\"; |
| 216 | + </script>\n" |
216 | 217 | ); |
217 | 218 | } |
218 | 219 | |
219 | 220 | static function getJsonCodec() { |
220 | 221 | static $json = null; |
221 | 222 | |
222 | | - if (!$json) { |
223 | | - $json = new Services_JSON(); #recycle API's JSON codec implementation |
| 223 | + if ( !$json ) { |
| 224 | + $json = new Services_JSON(); # recycle API's JSON codec implementation |
224 | 225 | } |
225 | 226 | |
226 | 227 | return $json; |
— | — | @@ -227,9 +228,9 @@ |
228 | 229 | |
229 | 230 | static function encodeOptions( $options, $enc ) { |
230 | 231 | if ( $enc == 'mode' || $enc == '' ) { |
231 | | - $opt =$options['mode']; |
| 232 | + $opt = $options['mode']; |
232 | 233 | } elseif ( $enc == 'json' ) { |
233 | | - $json = self::getJsonCodec(); //XXX: this may be a bit heavy... |
| 234 | + $json = self::getJsonCodec(); // XXX: this may be a bit heavy... |
234 | 235 | $opt = $json->encode( $options ); |
235 | 236 | } else { |
236 | 237 | throw new MWException( 'Unknown encoding for CategoryTree options: ' . $enc ); |
— | — | @@ -242,21 +243,10 @@ |
243 | 244 | if ( $enc == 'mode' || $enc == '' ) { |
244 | 245 | $opt = array( "mode" => $options ); |
245 | 246 | } elseif ( $enc == 'json' ) { |
246 | | - $json = self::getJsonCodec(); //XXX: this may be a bit heavy... |
| 247 | + $json = self::getJsonCodec(); // XXX: this may be a bit heavy... |
247 | 248 | $opt = $json->decode( $options ); |
248 | 249 | $opt = get_object_vars( $opt ); |
249 | | - } /* elseif () { |
250 | | - foreach ( $oo as $o ) { |
251 | | - if ($o === "") continue; |
252 | | - |
253 | | - if ( preg_match( '!^(.*?)=(.*)$!', $o, $m ) { |
254 | | - $n = $m[1]; |
255 | | - $opt[$n] = $m[2]; |
256 | | - } else { |
257 | | - $opt[$o] = true; |
258 | | - } |
259 | | - } |
260 | | - } */ else { |
| 250 | + } else { |
261 | 251 | throw new MWException( 'Unknown encoding for CategoryTree options: ' . $enc ); |
262 | 252 | } |
263 | 253 | |
— | — | @@ -296,7 +286,7 @@ |
297 | 287 | |
298 | 288 | foreach ( $this->mOptions as $k => $v ) { |
299 | 289 | if ( $u != '' ) $u .= '&'; |
300 | | - $u .= $k . '=' . urlencode($v) ; |
| 290 | + $u .= $k . '=' . urlencode( $v ) ; |
301 | 291 | } |
302 | 292 | |
303 | 293 | return $u; |
— | — | @@ -310,7 +300,9 @@ |
311 | 301 | global $wgDBname, $wgUser; |
312 | 302 | $title = self::makeTitle( $category ); |
313 | 303 | |
314 | | - if ( ! $title ) return false; #TODO: error message? |
| 304 | + if ( ! $title ) { |
| 305 | + return false; # TODO: error message? |
| 306 | + } |
315 | 307 | |
316 | 308 | # configkey needed to take into account variant and secure options. |
317 | 309 | $configkey = $wgUser->getPageRenderingHash(); |
— | — | @@ -336,10 +328,13 @@ |
337 | 329 | return $response; |
338 | 330 | } |
339 | 331 | |
340 | | - $html = $this->renderChildren( $title, $depth ); |
| 332 | + $html = $this->renderChildren( $title, $depth ); |
341 | 333 | |
342 | | - if ( $html == '' ) $html = ' '; #HACK: Safari doesn't like empty responses. |
343 | | - #see Bug 7219 and http://bugzilla.opendarwin.org/show_bug.cgi?id=10716 |
| 334 | + if ( $html == '' ) { |
| 335 | + # HACK: Safari doesn't like empty responses. |
| 336 | + # see Bug 7219 and http://bugzilla.opendarwin.org/show_bug.cgi?id=10716 |
| 337 | + $html = ' '; |
| 338 | + } |
344 | 339 | |
345 | 340 | $response->addText( $html ); |
346 | 341 | |
— | — | @@ -352,7 +347,7 @@ |
353 | 348 | * Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to |
354 | 349 | * load CategoryTreeFunctions.php on demand. |
355 | 350 | */ |
356 | | - function getTag( $parser, $category, $hideroot = false, $attr, $depth=1, $allowMissing = false ) { |
| 351 | + function getTag( $parser, $category, $hideroot = false, $attr, $depth = 1, $allowMissing = false ) { |
357 | 352 | global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag; |
358 | 353 | static $uniq = 0; |
359 | 354 | |
— | — | @@ -360,24 +355,29 @@ |
361 | 356 | if ( $category === '' ) { |
362 | 357 | return false; |
363 | 358 | } |
| 359 | + |
364 | 360 | if ( $parser && $wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag ) { |
365 | 361 | $parser->disableCache(); |
366 | 362 | } |
| 363 | + |
367 | 364 | $title = self::makeTitle( $category ); |
368 | 365 | |
369 | | - if ( $title === false || $title === null ) return false; |
| 366 | + if ( $title === false || $title === null ) { |
| 367 | + return false; |
| 368 | + } |
370 | 369 | |
371 | | - if ( isset( $attr['class'] ) ) $attr['class'] .= ' CategoryTreeTag'; |
372 | | - else $attr['class'] = ' CategoryTreeTag'; |
| 370 | + if ( isset( $attr['class'] ) ) { |
| 371 | + $attr['class'] .= ' CategoryTreeTag'; |
| 372 | + } else { |
| 373 | + $attr['class'] = ' CategoryTreeTag'; |
| 374 | + } |
373 | 375 | |
374 | | - $this->init(); |
375 | | - |
376 | 376 | $html = ''; |
377 | 377 | $html .= Xml::openElement( 'div', $attr ); |
378 | 378 | |
379 | 379 | if ( !$allowMissing && !$title->getArticleID() ) { |
380 | 380 | $html .= Xml::openElement( 'span', array( 'class' => 'CategoryTreeNotice' ) ); |
381 | | - if( $parser ) { |
| 381 | + if ( $parser ) { |
382 | 382 | $html .= $parser->recursiveTagParse( wfMsgNoTrans( 'categorytree-not-found', $category ) ); |
383 | 383 | } else { |
384 | 384 | $html .= wfMsgExt( 'categorytree-not-found', 'parseinline', htmlspecialchars( $category ) ); |
— | — | @@ -385,9 +385,11 @@ |
386 | 386 | $html .= Xml::closeElement( 'span' ); |
387 | 387 | } |
388 | 388 | else { |
389 | | - if ( !$hideroot ) $html .= CategoryTree::renderNode( $title, $depth, $wgCategoryTreeDynamicTag ); |
390 | | - else if ( !$wgCategoryTreeDynamicTag ) $html .= $this->renderChildren( $title, $depth ); |
391 | | - else { |
| 389 | + if ( !$hideroot ) { |
| 390 | + $html .= CategoryTree::renderNode( $title, $depth, $wgCategoryTreeDynamicTag ); |
| 391 | + } else if ( !$wgCategoryTreeDynamicTag ) { |
| 392 | + $html .= $this->renderChildren( $title, $depth ); |
| 393 | + } else { |
392 | 394 | $uniq += 1; |
393 | 395 | $load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 ); |
394 | 396 | |
— | — | @@ -407,10 +409,10 @@ |
408 | 410 | * Returns a string with an HTML representation of the children of the given category. |
409 | 411 | * $title must be a Title object |
410 | 412 | */ |
411 | | - function renderChildren( &$title, $depth=1 ) { |
| 413 | + function renderChildren( &$title, $depth = 1 ) { |
412 | 414 | global $wgCategoryTreeMaxChildren, $wgCategoryTreeUseCategoryTable; |
413 | 415 | |
414 | | - if( $title->getNamespace() != NS_CATEGORY ) { |
| 416 | + if ( $title->getNamespace() != NS_CATEGORY ) { |
415 | 417 | // Non-categories can't have children. :) |
416 | 418 | return ''; |
417 | 419 | } |
— | — | @@ -418,8 +420,8 @@ |
419 | 421 | $dbr = wfGetDB( DB_SLAVE ); |
420 | 422 | |
421 | 423 | $inverse = $this->isInverse(); |
422 | | - $mode = $this->getOption('mode'); |
423 | | - $namespaces = $this->getOption('namespaces'); |
| 424 | + $mode = $this->getOption( 'mode' ); |
| 425 | + $namespaces = $this->getOption( 'namespaces' ); |
424 | 426 | |
425 | 427 | if ( $inverse ) { |
426 | 428 | $ctJoinCond = ' cl_to = cat.page_title AND cat.page_namespace = ' . NS_CATEGORY; |
— | — | @@ -432,20 +434,27 @@ |
433 | 435 | $ctWhere = ' cl_to = ' . $dbr->addQuotes( $title->getDBkey() ); |
434 | 436 | $ctJoin = ' JOIN '; |
435 | 437 | |
436 | | - #namespace filter. |
| 438 | + # namespace filter. |
437 | 439 | if ( $namespaces ) { |
438 | | - #NOTE: we assume that the $namespaces array contains only integers! decodeNamepsaces makes it so. |
439 | | - if ( sizeof( $namespaces ) === 1 ) $nsmatch = ' AND cat.page_namespace = ' . $namespaces[0] . ' '; |
440 | | - else $nsmatch = ' AND cat.page_namespace IN ( ' . implode( ', ', $namespaces ) . ') '; |
| 440 | + # NOTE: we assume that the $namespaces array contains only integers! decodeNamepsaces makes it so. |
| 441 | + if ( sizeof( $namespaces ) === 1 ) { |
| 442 | + $nsmatch = ' AND cat.page_namespace = ' . $namespaces[0] . ' '; |
| 443 | + } else { |
| 444 | + $nsmatch = ' AND cat.page_namespace IN ( ' . implode( ', ', $namespaces ) . ') '; |
| 445 | + } |
441 | 446 | } |
442 | 447 | else { |
443 | | - if ( $mode == CT_MODE_ALL ) $nsmatch = ''; |
444 | | - else if ( $mode == CT_MODE_PAGES ) $nsmatch = ' AND cat.page_namespace != ' . NS_IMAGE; |
445 | | - else $nsmatch = ' AND cat.page_namespace = ' . NS_CATEGORY; |
| 448 | + if ( $mode == CT_MODE_ALL ) { |
| 449 | + $nsmatch = ''; |
| 450 | + } else if ( $mode == CT_MODE_PAGES ) { |
| 451 | + $nsmatch = ' AND cat.page_namespace != ' . NS_IMAGE; |
| 452 | + } else { |
| 453 | + $nsmatch = ' AND cat.page_namespace = ' . NS_CATEGORY; |
| 454 | + } |
446 | 455 | } |
447 | 456 | } |
448 | 457 | |
449 | | - #additional stuff to be used if "transaltion" by interwiki-links is desired |
| 458 | + # additional stuff to be used if "transaltion" by interwiki-links is desired |
450 | 459 | $transFields = ''; |
451 | 460 | $transJoin = ''; |
452 | 461 | $transWhere = ''; |
— | — | @@ -475,25 +484,24 @@ |
476 | 485 | $countJoin |
477 | 486 | WHERE $ctWhere |
478 | 487 | $nsmatch |
479 | | - "./*AND cat.page_is_redirect = 0*/" |
| 488 | + " . /*AND cat.page_is_redirect = 0*/" |
480 | 489 | $transWhere |
481 | 490 | ORDER BY cl_sortkey"; |
482 | | - $sql = $dbr->limitResult($sql, (int)$wgCategoryTreeMaxChildren); |
483 | | - |
| 491 | + $sql = $dbr->limitResult( $sql, (int)$wgCategoryTreeMaxChildren ); |
| 492 | + |
484 | 493 | $res = $dbr->query( $sql, __METHOD__ ); |
485 | 494 | |
486 | | - #collect categories separately from other pages |
487 | | - $categories= ''; |
488 | | - $other= ''; |
| 495 | + # collect categories separately from other pages |
| 496 | + $categories = ''; |
| 497 | + $other = ''; |
489 | 498 | |
490 | 499 | while ( $row = $dbr->fetchObject( $res ) ) { |
491 | | - #NOTE: in inverse mode, the page record may be null, because we use a right join. |
| 500 | + # NOTE: in inverse mode, the page record may be null, because we use a right join. |
492 | 501 | # happens for categories with no category page (red cat links) |
493 | 502 | if ( $inverse && $row->page_title === null ) { |
494 | 503 | $t = Title::makeTitle( NS_CATEGORY, $row->cl_to ); |
495 | | - } |
496 | | - else { |
497 | | - #TODO: translation support; ideally added to Title object |
| 504 | + } else { |
| 505 | + # TODO: translation support; ideally added to Title object |
498 | 506 | $t = Title::newFromRow( $row ); |
499 | 507 | } |
500 | 508 | |
— | — | @@ -503,11 +511,14 @@ |
504 | 512 | $cat = Category::newFromRow( $row, $t ); |
505 | 513 | } |
506 | 514 | |
507 | | - $s = $this->renderNodeInfo( $t, $cat, $depth-1, false ); |
| 515 | + $s = $this->renderNodeInfo( $t, $cat, $depth -1, false ); |
508 | 516 | $s .= "\n\t\t"; |
509 | 517 | |
510 | | - if ($row->page_namespace == NS_CATEGORY) $categories .= $s; |
511 | | - else $other .= $s; |
| 518 | + if ( $row->page_namespace == NS_CATEGORY ) { |
| 519 | + $categories .= $s; |
| 520 | + } else { |
| 521 | + $other .= $s; |
| 522 | + } |
512 | 523 | } |
513 | 524 | |
514 | 525 | $dbr->freeResult( $res ); |
— | — | @@ -524,7 +535,7 @@ |
525 | 536 | |
526 | 537 | $dbr = wfGetDB( DB_SLAVE ); |
527 | 538 | |
528 | | - #additional stuff to be used if "transaltion" by interwiki-links is desired |
| 539 | + # additional stuff to be used if "transaltion" by interwiki-links is desired |
529 | 540 | $transFields = ''; |
530 | 541 | $transJoin = ''; |
531 | 542 | $transWhere = ''; |
— | — | @@ -537,23 +548,23 @@ |
538 | 549 | WHERE cl_from = " . $title->getArticleID() . " |
539 | 550 | $transWhere |
540 | 551 | ORDER BY cl_to"; |
541 | | - $sql = $dbr->limitResult($sql, (int)$wgCategoryTreeMaxChildren); |
| 552 | + $sql = $dbr->limitResult( $sql, (int)$wgCategoryTreeMaxChildren ); |
542 | 553 | |
543 | 554 | $res = $dbr->query( $sql, __METHOD__ ); |
544 | 555 | |
545 | 556 | $special = Title::makeTitle( NS_SPECIAL, 'CategoryTree' ); |
546 | 557 | |
547 | | - $s= ''; |
| 558 | + $s = ''; |
548 | 559 | |
549 | 560 | while ( $row = $dbr->fetchObject( $res ) ) { |
550 | | - #TODO: translation support; ideally added to Title object |
| 561 | + # TODO: translation support; ideally added to Title object |
551 | 562 | $t = Title::newFromRow( $row ); |
552 | 563 | |
553 | | - #$trans = $title->getLocalizedText(); |
554 | | - $trans = ''; #place holder for when translated titles are available |
| 564 | + # $trans = $title->getLocalizedText(); |
| 565 | + $trans = ''; # place holder for when translated titles are available |
555 | 566 | |
556 | 567 | $label = htmlspecialchars( $t->getText() ); |
557 | | - if ( $trans && $trans!=$label ) $label.= ' ' . Xml::element( 'i', array( 'class' => 'translation'), $trans ); |
| 568 | + if ( $trans && $trans != $label ) $label .= ' ' . Xml::element( 'i', array( 'class' => 'translation' ), $trans ); |
558 | 569 | |
559 | 570 | $wikiLink = $special->getLocalURL( 'target=' . $t->getPartialURL() . '&' . $this->getOptionsAsUrlParameters() ); |
560 | 571 | |
— | — | @@ -580,8 +591,9 @@ |
581 | 592 | |
582 | 593 | if ( $wgCategoryTreeUseCategoryTable && $title->getNamespace() == NS_CATEGORY && !$this->isInverse() ) { |
583 | 594 | $cat = Category::newFromTitle( $title ); |
| 595 | + } else { |
| 596 | + $cat = null; |
584 | 597 | } |
585 | | - else $cat = NULL; |
586 | 598 | |
587 | 599 | return $this->renderNodeInfo( $title, $cat, $children, $loadchildren ); |
588 | 600 | } |
— | — | @@ -593,9 +605,7 @@ |
594 | 606 | function renderNodeInfo( $title, $cat, $children = 0, $loadchildren = false ) { |
595 | 607 | static $uniq = 0; |
596 | 608 | |
597 | | - $this->init(); # initialize messages |
598 | | - |
599 | | - $mode = $this->getOption('mode'); |
| 609 | + $mode = $this->getOption( 'mode' ); |
600 | 610 | $load = false; |
601 | 611 | |
602 | 612 | if ( $children > 0 && $loadchildren ) { |
— | — | @@ -607,22 +617,32 @@ |
608 | 618 | $ns = $title->getNamespace(); |
609 | 619 | $key = $title->getDBkey(); |
610 | 620 | |
611 | | - #$trans = $title->getLocalizedText(); |
612 | | - $trans = ''; #place holder for when translated titles are available |
| 621 | + # $trans = $title->getLocalizedText(); |
| 622 | + $trans = ''; # place holder for when translated titles are available |
613 | 623 | |
614 | | - $hideprefix = $this->getOption('hideprefix'); |
| 624 | + $hideprefix = $this->getOption( 'hideprefix' ); |
615 | 625 | |
616 | | - if ( $hideprefix == CT_HIDEPREFIX_ALWAYS ) $hideprefix = true; |
617 | | - else if ( $hideprefix == CT_HIDEPREFIX_AUTO ) $hideprefix = ($mode == CT_MODE_CATEGORIES); |
618 | | - else if ( $hideprefix == CT_HIDEPREFIX_CATEGORIES ) $hideprefix = ($ns == NS_CATEGORY); |
619 | | - else $hideprefix = true; |
| 626 | + if ( $hideprefix == CT_HIDEPREFIX_ALWAYS ) { |
| 627 | + $hideprefix = true; |
| 628 | + } else if ( $hideprefix == CT_HIDEPREFIX_AUTO ) { |
| 629 | + $hideprefix = ( $mode == CT_MODE_CATEGORIES ); |
| 630 | + } else if ( $hideprefix == CT_HIDEPREFIX_CATEGORIES ) { |
| 631 | + $hideprefix = ( $ns == NS_CATEGORY ); |
| 632 | + } else { |
| 633 | + $hideprefix = true; |
| 634 | + } |
620 | 635 | |
621 | | - #when showing only categories, omit namespace in label unless we explicitely defined the configuration setting |
622 | | - #patch contributed by Manuel Schneider <manuel.schneider@wikimedia.ch>, Bug 8011 |
623 | | - if ( $hideprefix ) $label = htmlspecialchars( $title->getText() ); |
624 | | - else $label = htmlspecialchars( $title->getPrefixedText() ); |
| 636 | + # when showing only categories, omit namespace in label unless we explicitely defined the configuration setting |
| 637 | + # patch contributed by Manuel Schneider <manuel.schneider@wikimedia.ch>, Bug 8011 |
| 638 | + if ( $hideprefix ) { |
| 639 | + $label = htmlspecialchars( $title->getText() ); |
| 640 | + } else { |
| 641 | + $label = htmlspecialchars( $title->getPrefixedText() ); |
| 642 | + } |
625 | 643 | |
626 | | - if ( $trans && $trans!=$label ) $label.= ' ' . Xml::element( 'i', array( 'class' => 'translation'), $trans ); |
| 644 | + if ( $trans && $trans != $label ) { |
| 645 | + $label .= ' ' . Xml::element( 'i', array( 'class' => 'translation' ), $trans ); |
| 646 | + } |
627 | 647 | |
628 | 648 | $labelClass = 'CategoryTreeLabel ' . ' CategoryTreeLabelNs' . $ns; |
629 | 649 | |
— | — | @@ -639,12 +659,14 @@ |
640 | 660 | $labelClass .= ' CategoryTreeLabelPage'; |
641 | 661 | } |
642 | 662 | |
643 | | - if ( ( $ns % 2 ) > 0 ) $labelClass .= ' CategoryTreeLabelTalk'; |
| 663 | + if ( ( $ns % 2 ) > 0 ) { |
| 664 | + $labelClass .= ' CategoryTreeLabelTalk'; |
| 665 | + } |
644 | 666 | |
645 | 667 | $count = false; |
646 | 668 | $s = ''; |
647 | 669 | |
648 | | - #NOTE: things in CategoryTree.js rely on the exact order of tags! |
| 670 | + # NOTE: things in CategoryTree.js rely on the exact order of tags! |
649 | 671 | # Specifically, the CategoryTreeChildren div must be the first |
650 | 672 | # sibling with nodeName = DIV of the grandparent of the expland link. |
651 | 673 | |
— | — | @@ -656,39 +678,44 @@ |
657 | 679 | |
658 | 680 | if ( $ns == NS_CATEGORY ) { |
659 | 681 | if ( $cat ) { |
660 | | - if ( $mode == CT_MODE_CATEGORIES ) $count = $cat->getSubcatCount(); |
661 | | - else if ( $mode == CT_MODE_PAGES ) $count = $cat->getPageCount() - $cat->getFileCount(); |
662 | | - else $count = $cat->getPageCount(); |
| 682 | + if ( $mode == CT_MODE_CATEGORIES ) { |
| 683 | + $count = $cat->getSubcatCount(); |
| 684 | + } else if ( $mode == CT_MODE_PAGES ) { |
| 685 | + $count = $cat->getPageCount() - $cat->getFileCount(); |
| 686 | + } else { |
| 687 | + $count = $cat->getPageCount(); |
| 688 | + } |
663 | 689 | } |
664 | | - |
665 | | - $linkattr= array( ); |
666 | | - if ( $load ) $linkattr[ 'id' ] = $load; |
667 | 690 | |
| 691 | + $linkattr = array( ); |
| 692 | + if ( $load ) { |
| 693 | + $linkattr[ 'id' ] = $load; |
| 694 | + } |
| 695 | + |
668 | 696 | $linkattr[ 'class' ] = "CategoryTreeToggle"; |
669 | 697 | $linkattr['style'] = 'display: none;'; // Unhidden by JS |
670 | 698 | |
671 | | - /*if ( $count === 0 ) { |
672 | | - $tag = 'span'; |
673 | | - $txt = wfMsgNoTrans( 'categorytree-empty-bullet' ); |
674 | | - } |
675 | | - else*/ |
676 | 699 | if ( $children == 0 || $loadchildren ) { |
677 | 700 | $tag = 'span'; |
678 | | - if ( $count === 0 ) $txt = wfMsgNoTrans( 'categorytree-empty-bullet' ); |
679 | | - else $txt = wfMsgNoTrans( 'categorytree-expand-bullet' ); |
680 | | - $linkattr[ 'onclick' ] = "if (this.href) this.href='javascript:void(0)'; categoryTreeExpandNode('".Xml::escapeJsString($key)."',".$this->getOptionsAsJsStructure().",this);"; |
| 701 | + if ( $count === 0 ) { |
| 702 | + $txt = wfMsgNoTrans( 'categorytree-empty-bullet' ); |
| 703 | + } else { |
| 704 | + $txt = wfMsgNoTrans( 'categorytree-expand-bullet' ); |
| 705 | + } |
| 706 | + $linkattr[ 'onclick' ] = "if (this.href) this.href='javascript:void(0)'; categoryTreeExpandNode('" . Xml::escapeJsString( $key ) . "'," . $this->getOptionsAsJsStructure() . ",this);"; |
681 | 707 | # Don't load this message for ajax requests, so that we don't have to initialise $wgLang |
682 | | - $linkattr[ 'title' ] = $this->mIsAjaxRequest ? '##LOAD##' : wfMsgNoTrans('categorytree-expand'); |
683 | | - } |
684 | | - else { |
| 708 | + $linkattr[ 'title' ] = $this->mIsAjaxRequest ? '##LOAD##' : wfMsgNoTrans( 'categorytree-expand' ); |
| 709 | + } else { |
685 | 710 | $tag = 'span'; |
686 | 711 | $txt = wfMsgNoTrans( 'categorytree-collapse-bullet' ); |
687 | | - $linkattr[ 'onclick' ] = "if (this.href) this.href='javascript:void(0)'; categoryTreeCollapseNode('".Xml::escapeJsString($key)."',".$this->getOptionsAsJsStructure().",this);"; |
688 | | - $linkattr[ 'title' ] = wfMsgNoTrans('categorytree-collapse'); |
| 712 | + $linkattr[ 'onclick' ] = "if (this.href) this.href='javascript:void(0)'; categoryTreeCollapseNode('" . Xml::escapeJsString( $key ) . "'," . $this->getOptionsAsJsStructure() . ",this);"; |
| 713 | + $linkattr[ 'title' ] = wfMsgNoTrans( 'categorytree-collapse' ); |
689 | 714 | $linkattr[ 'class' ] .= ' CategoryTreeLoaded'; |
690 | 715 | } |
691 | 716 | |
692 | | - if ( $tag == 'a' ) $linkattr[ 'href' ] = $wikiLink; |
| 717 | + if ( $tag == 'a' ) { |
| 718 | + $linkattr[ 'href' ] = $wikiLink; |
| 719 | + } |
693 | 720 | $s .= Xml::openElement( $tag, $linkattr ) . $txt . Xml::closeElement( $tag ) . ' '; |
694 | 721 | } else { |
695 | 722 | $s .= wfMsgNoTrans( 'categorytree-page-bullet' ); |
— | — | @@ -720,15 +747,20 @@ |
721 | 748 | $s .= Xml::closeElement( 'div' ); |
722 | 749 | $s .= "\n\t\t"; |
723 | 750 | $s .= Xml::openElement( 'div', array( 'class' => 'CategoryTreeChildren', 'style' => $children > 0 ? "display:block" : "display:none" ) ); |
724 | | - |
725 | | - if ( $ns == NS_CATEGORY && $children > 0 && !$loadchildren) { |
| 751 | + |
| 752 | + if ( $ns == NS_CATEGORY && $children > 0 && !$loadchildren ) { |
726 | 753 | $children = $this->renderChildren( $title, $children ); |
727 | 754 | if ( $children == '' ) { |
728 | 755 | $s .= Xml::openElement( 'i', array( 'class' => 'CategoryTreeNotice' ) ); |
729 | | - if ( $mode == CT_MODE_CATEGORIES ) $s .= wfMsgExt( 'categorytree-no-subcategories', 'parsemag'); |
730 | | - else if ( $mode == CT_MODE_PAGES ) $s .= wfMsgExt( 'categorytree-no-pages', 'parsemag'); |
731 | | - else if ( $mode == CT_MODE_PARENTS ) $s .= wfMsgExt( 'categorytree-no-parent-categories', 'parsemag'); |
732 | | - else $s .= wfMsgExt( 'categorytree-nothing-found', 'parsemag'); |
| 756 | + if ( $mode == CT_MODE_CATEGORIES ) { |
| 757 | + $s .= wfMsgExt( 'categorytree-no-subcategories', 'parsemag' ); |
| 758 | + } else if ( $mode == CT_MODE_PAGES ) { |
| 759 | + $s .= wfMsgExt( 'categorytree-no-pages', 'parsemag' ); |
| 760 | + } else if ( $mode == CT_MODE_PARENTS ) { |
| 761 | + $s .= wfMsgExt( 'categorytree-no-parent-categories', 'parsemag' ); |
| 762 | + } else { |
| 763 | + $s .= wfMsgExt( 'categorytree-nothing-found', 'parsemag' ); |
| 764 | + } |
733 | 765 | $s .= Xml::closeElement( 'i' ); |
734 | 766 | } else { |
735 | 767 | $s .= $children; |
— | — | @@ -741,7 +773,7 @@ |
742 | 774 | if ( $load ) { |
743 | 775 | $s .= "\n\t\t"; |
744 | 776 | $s .= Xml::openElement( 'script', array( 'type' => 'text/javascript' ) ); |
745 | | - $s .= 'categoryTreeExpandNode("'.Xml::escapeJsString($key).'", '.$this->getOptionsAsJsStructure($children).', document.getElementById("'.$load.'"));'; |
| 777 | + $s .= 'categoryTreeExpandNode("' . Xml::escapeJsString( $key ) . '", ' . $this->getOptionsAsJsStructure( $children ) . ', document.getElementById("' . $load . '"));'; |
746 | 778 | $s .= Xml::closeElement( 'script' ); |
747 | 779 | } |
748 | 780 | |
— | — | @@ -756,7 +788,7 @@ |
757 | 789 | static function makeTitle( $title ) { |
758 | 790 | global $wgContLang, $wgCanonicalNamespaceNames; |
759 | 791 | |
760 | | - $title = trim($title); |
| 792 | + $title = trim( $title ); |
761 | 793 | |
762 | 794 | if ( $title === null || $title === '' || $title === false ) { |
763 | 795 | return null; |
— | — | @@ -771,18 +803,4 @@ |
772 | 804 | } |
773 | 805 | return $t; |
774 | 806 | } |
775 | | - |
776 | | - /** |
777 | | - * Initialize. Load messages, if not ajax request. |
778 | | - */ |
779 | | - static function init( ) { |
780 | | - static $initialized = false; |
781 | | - if ( $initialized ) return; |
782 | | - $initialized = true; |
783 | | - |
784 | | - #NOTE: don't load messages for ajax requests. Ajax requests are cachable and language-neutral. |
785 | | - # Messages used in JS are defined by setHeaders |
786 | | - if ( !isset( $this ) || !$this->mIsAjaxRequest ) |
787 | | - wfLoadExtensionMessages( 'CategoryTree' ); |
788 | | - } |
789 | 807 | } |
Index: trunk/extensions/CategoryTree/README |
— | — | @@ -16,4 +16,3 @@ |
17 | 17 | |
18 | 18 | Instructions on installing and using this extension are available at |
19 | 19 | <http://www.mediawiki.org/wiki/Extension:CategoryTree> |
20 | | - |