Extension talk:Hierarchy

Latest comment: 13 years ago by 82.207.110.66 in topic Questions

Unofficial Version 1.2.0

edit

I am (User:Cowtung). I have posted an unofficial version 1.2.0 here: Extension:Hierarchy/Hierarchy1.2.0.php. I added a root parameter to the <index> tag. This will remove whatever prefix you specify from all links generated. I needed this for my wiki, and decided to share.

Here is the new create table code. If you already have this table, you can just add the RootText and Deslash columns to that. If you drop the table and run this to create it again, you'll have to go through and save all your index pages again.

CREATE TABLE `hierarchy` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `IndexArticleId` int(10) unsigned NOT NULL,
  `TocLevel` int(10) unsigned NOT NULL,
  `TocNumber` varbinary(255) NOT NULL,
  `TocText` varbinary(255) NOT NULL,
  `Sequence` int(10) unsigned NOT NULL,
  `ArticleId` int(10) unsigned NOT NULL,
  `PreviousArticleId` int(10) unsigned NOT NULL,
  `NextArticleId` int(10) unsigned NOT NULL,
  `ParentArticleId` int(10) unsigned NOT NULL,
  `RootText` varbinary(255) NOT NULL,
  `Deslash` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`Id`),
  KEY `IndexArticle` USING BTREE (`IndexArticleId`,`Sequence`),
  KEY `ArticleId` (`ArticleId`)
) ENGINE=MyISAM DEFAULT CHARSET=binary;

To set the root param for the index...

<index root="Some_Book:Book_Title/" deslash="1">

I also...

  1. Added "deslash" param which tells the extension to remove all but the last element in forward slashed article hierarchies ("Some_Book:Book_Title/chapter1/subitem1/subitem2" -> "subitem2") for all links.
  2. Removed all trailing and leading carriage returns and hr tags (----).
  3. Added in the breadcrumbs (thanks to the guy who posted that).
  4. Reformatted some of the code to meet the standards of my company (no if statements without braces, etc.).

Removing carriage returns helps you format things exactly the way you want. I use this as my Template:Hierarchy_footer...

<includeonly><table width=100% style="padding: 0.0em; margin-left:0px; border: 1px solid #B8C7D9; background:#f5faff; font-size: 95%; margin: 1em auto 1em auto">
<tr><td width=40% align=left nowrap>{{#hierarchy-breadcrumb:}}</td>
<td align=center width=20% nowrap>{{#hierarchy-bottom:}}</td><td width=40%>&nbsp;</td></tr>
</table></includeonly><noinclude>This is the footer of a page that belongs to a hierarchy.</noinclude>

I didn't know where or how to post this unofficial version, and I didn't want to bother with creating a new extension. If anybody has any suggestions, I'll do my best to implement them. Thanks for a great extension which I hope I haven't damaged too much.  :)

Also, I'm not sure how well this works without the root tag. This code definitely could use some cleanup.

Feedback about version 1.0

edit

Instructions about templates

edit

I wanted to mention to you that it would be more clear in your instructions on the mediawiki site if you named the 'Template:Hierarchy header' 'Hierarchy header' because in your examples, you call {{Hierarchy header}}, not {{Template:Hierarchy header}}. Anyone messing around with this stuff should understand what transclusions are but I thought I would let you know the inconsistencies.

Questions

edit

Is there any site where this extension can be seen in action?

edit

No, sorry. But you can install it on a test site and follow the usage sample to try it out. --Fernando Correia 15:42, 1 February 2007 (UTC)Reply

Do you think this extension will work on MW 1.6.7?

edit

Regards, Aretai 11:04, 5 February 2007 (UTC)Reply

Well, it might. But I cannot verify that. My focus is to support the newest version. Only one way to find out... --Fernando Correia 11:31, 5 February 2007 (UTC)Reply

OK have had a try. Some minor problems with:

CREATE TABLE `mywikidb`.`hierarchy` (
  `Id` int( 10 ) unsigned NOT NULL AUTO_INCREMENT ,
  `IndexArticleId` int( 10 ) unsigned NOT NULL ,
  `TocLevel` int( 10 ) unsigned NOT NULL ,
  `TocNumber` varchar( 255 ) NOT NULL ,
  `TocText` varchar( 255 ) NOT NULL ,
  `Sequence` int( 10 ) unsigned NOT NULL ,
  `ArticleId` int( 10 ) unsigned NOT NULL ,
  `PreviousArticleId` int( 10 ) unsigned NOT NULL ,
  `NextArticleId` int( 10 ) unsigned NOT NULL ,
  `ParentArticleId` int( 10 ) unsigned NOT NULL ,
  PRIMARY KEY ( `Id` ) ,
  KEY `IndexArticle` USING BTREE(
    `IndexArticleId` ,
    `Sequence`
  ),
  KEY `ArticleId` ( `ArticleId` )
) ENGINE = MYISAM DEFAULT CHARSET = latin1;

Got an error 1064 - think some problems with KEY? What version of MySQL does your extension support? Aretai 14:41, 8 February 2007 (UTC)Reply

MySQL version 5. Take a look, you have to replace `mywikidb` for the name of your database. --Fernando Correia 15:35, 8 February 2007 (UTC)Reply

Yes I know:) I've already replaced it. Well will try again, however probably just need to update my software Aretai 09:45, 9 February 2007 (UTC)Reply

Probably this error is more related to MySQL than to MediaWiki. If at all possible try to update PHP, MySQL and MediaWiki. --Fernando Correia 10:40, 9 February 2007 (UTC)Reply

Id did have this Error 1064 on MySQL - 4.0.18, too. It appears to work when you avoid "USING BTREE". I hope this has no side effects (appart from performance ones). --Francesc Hervada-Sala, 217.95.231.1 08:44, 28 May 2007 (UTC)Reply

I cannot install the extension properly

edit

Thank you for this extension, I think it will be very useful to me. After copying all files and configuring the LocalSettings.php as indicated, I get this warning at every page of my wiki:

Warning: Cannot modify header information - headers already sent 
by (output started at .../extensions/Hierarchy.php:2) 
in .../includes/WebResponse.php on line 10

Does anyone know how to fix it? I use MediaWiki 1.10.0 --Francesc Hervada-Sala, 217.95.231.1 08:44, 28 May 2007 (UTC)Reply

I had the same error, following the instructions with Mediawiki 1.10.0. MAW

I also have this error for several extensions. Can anyone provide a solution? MW 1.11.

Try to save it without Unicod Signature (BOM) for example with Notepad2...

Also check for Hierarchy.php - it should be php script file but not a wiki page. It sounds stupid but first time I just click "Save As..." on link in Installation tutorial instead of open page and copy-paste a code itself

Getting error after setup

edit

Enabling produces the following error: Warning: Missing argument 2 for wfHierarchyParserFunction_Magic() in extensions/Hierarchy.php on line 381

This line in the code from the wiki is:

   function wfHierarchyParserFunction_Magic( &$magicWords, $langCode ) {
        # Add the magic word
        # The first array element is case sensitivity, in this case it is not case sensitive
        # All remaining elements are synonyms for our parser function
        $magicWords['hierarchy-top'] = array( 0, 'hierarchy-top' );
        $magicWords['hierarchy-bottom'] = array( 0, 'hierarchy-bottom' );
        # unless we return true, other parser functions extensions won't get loaded.
        return true;
   }

Can you let me know what the workaround might be?

Is it possible to include (the first N levels of) the hierarchy in the sidebar?

edit

--wimh 13:49, 8 May 2007 (UTC)Reply

previous and next buttons [images]

edit

the previous and next text works fine, but the arrows are merely images. as a textbook over caffeinated netizen, i usually aim for the largest thing that i can click on to get me where i am going, in this case the arrow, but alas, it is only an image.

is there a way to make the images links as well? basically back and forward buttons is what i am looking to do.

Zeefreak 16:38, 23 April 2008 (UTC)Reply

Must charset be latin1?

edit

The last line in the code that creates the MySQL table is:

ENGINE = MYISAM DEFAULT CHARSET = latin1;

Could I substitute UTF-8 without harm?

Is there anyone willing to update this extension so it will work in MW 1.16.0/PHP 5.3.3?

edit

After installing the extension, I get the following error:

Detected bug in an extension! Hook fnHierarchySaveHook failed to return a value; should return true to continue hook processing or false to abort.

If anyone knows a fix for this or can update the extension, it'd be greatly appreciated. Unfortunately I don't have the necessary PHP skills or I'd do it myself.

Kwelsh2 20:04, 15 February 2011 (UTC)Reply


Hi, on my MW version 1.15 I worked this around with this:

# diff  Hierarchy.php Hierarchy.php.orig
93,94c93
< function renderHierarchyIndex( $input, $argv, $parser ) {
---
> function renderHierarchyIndex( $input, $argv, &$parser ) {
99,100c98
< function fnHierarchySaveHook(&$article, &$user, $text) {
---
> function fnHierarchySaveHook(&$article, &$user, &$text, &$summary, &$minoredit, &$watchthis, &$sectionanchor, &$flags) {

--82.207.110.66 13:22, 26 May 2011 (UTC)Reply

Feature requests

edit

Allow less than 4 items

edit

It would be nice to remove the limitation of at least 4 items in the index. This may lead to confusion when users try to build the index incrementally. Probably a _TOC_ used internally in the index function could do it. --Fernando Correia 13:24, 9 March 2007 (UTC)Reply

Subordinate pages in the navigation box (resolved)

edit

Great extension! It works fine for me. However, it would be great to have the subordinate pages listed in the navigation box as well, instead of them only being displayed in the footer. 130.83.196.179 16:44, 6 March 2007 (UTC)Reply

Thanks for the feedback. I agree that this would be a good idea. Probably showing as an indented bulleted list. There could be an option to have these pages on the footer, in the box, or both. --Fernando Correia 18:39, 6 March 2007 (UTC)Reply

I have hacked the extension so as to include subordinate pages in the navigation box, can send you the modified file if you are interested. 130.83.196.179 14:36, 7 March 2007 (UTC)Reply

Sure, please do! You can post it here or email it to me. --Fernando Correia 16:58, 7 March 2007 (UTC)Reply
Thank you for your contribution, Felix! Version 1.1.0 is released. --Fernando Correia 17:01, 8 March 2007 (UTC)Reply

Alternate text in index

edit

Nice extension which helps me a lot. One thing I'm missing is to use another text in the index than the link, something like Piped Links. When using ...

<index>
[[ Top Page ]
== [[Chapter1| Sample Chapter]] ==

... I get a link to Sample_Chapter, instead of Chapter1

Tried also this form [[a (b)|]] but this gives an error in $page_url = $title->escapeLocalURL(); Thanks for your help. --Daniel 11:26, 9 March 2007 (UTC)Reply

I agree. I've already had this need also. I think this can be allowed with a little tweaking in the parser. This form should be easy to allow:
== [[Chapter1|Sample Chapter]] ==
--Fernando Correia 11:11, 9 March 2007 (UTC)Reply

That was fast! You think you might adopt this? Knowing this, I could already start using this form in my pages. Thanks --Daniel 12:25, 9 March 2007 (UTC)Reply

Talk about fast. By the timestamps, it seems I'm answering them before you ask them! :-)
I'd definitely like to have this feature. Maybe I can take some time to take a look at it today. No promises, though. In the meantime you can create a page redirect to have an alternate name. --Fernando Correia 12:20, 9 March 2007 (U

Also wanted to add a "me too" - this would be VERY helpful. Any rough idea on timeframe when you think you might have this added? THANK AGAIN- Jon


Auto Header/Footer

edit

Is it possible to have each new page created on my wiki to have the Hierarchy Header and Hierarchy Footer includes (i.e. with the brackets) automatically put on each new page. In this way all that I'd have to do is add it to the index. BTW: Great extension - it's a HUGE help to me- thanks! Jon


Classic breadcrumbs

edit

A classic breadcrumb path, based on item hierarchy, can be easily achieved with the following additions to the extension source code:

// ADD THIS FUNCTION:
// Generte a breadcrumb path based on the hierarchy
function wfHierarchyBreadcrumbRender( &$parser ) {
    $item = wfHierarchyGetItem($parser);
    if ($item == NULL) return "";
    $ancestors = array();
    $tempItem = $item;
    while ($tempItem->mParentArticleId) {
      $ancestors[] = $tempItem->mParentArticleId;
      $tempItem = HierarchyItem::newFromArticleId($tempItem->mParentArticleId);
    }
    $breadcrumb = Title::newFromID($item->mArticleId);
    foreach ($ancestors as $ancestor) {
        $link = wfHierarchyArticleLink($ancestor);
        if (!empty($link)) {
            $breadcrumb = "$link &gt; " . $breadcrumb;
        }
    }
    return $breadcrumb . "\n----\n";
}

//...

function wfHierarchyParserFunction_Setup() {
    global $wgParser;
    # Set a function hook associating the magic word with our function
    $wgParser->setFunctionHook( 'hierarchy-top', 'wfHierarchyTopRender' );
    $wgParser->setFunctionHook( 'hierarchy-bottom', 'wfHierarchyBottomRender' );
    
    // ADD THIS LINE:
    $wgParser->setFunctionHook( 'hierarchy-breadcrumb', 'wfHierarchyBreadcrumbRender' );
}

// ...

function wfHierarchyParserFunction_Magic( &$magicWords, $langCode ) {
    # Add the magic word
    # The first array element is case sensitivity, in this case it is not case sensitive
    # All remaining elements are synonyms for our parser function
    $magicWords['hierarchy-top'] = array( 0, 'hierarchy-top' );
    $magicWords['hierarchy-bottom'] = array( 0, 'hierarchy-bottom' );
    
    // ADD THIS LINE:
    $magicWords['hierarchy-breadcrumb'] = array( 0, 'hierarchy-breadcrumb' );
    
    # unless we return true, other parser functions extensions won't get loaded.
    return true;
}

Having done this little coding, it takes just a template definition and insertion to start using breadcrumbs. The one-time step template definition (Template:Hierarchy breadcrumb or something like it) could be::

<includeonly>{{#hierarchy-breadcrumb:}}</includeonly><noinclude>
This is the breadcrumb of a page that belongs to a hierarchy.
</noinclude>

While for each page that will belong to the hierarchy, in which we want the breadcrumb to be displayed will be something like:

{{Hierarchy breadcrumb}}
{{Hierarchy header}}
This is a page that belongs to a hierarchy.
{{Hierarchy footer}}

Of course, the code can be improved in order to parametrize some aspects of behaviour and/or appereance. That is why I have included this little contribution here (in feature requests), so that the author may adapt or modify it as he considers to be the best way (sorry for my far-from-perfect english).

--Metagrama 11:42, 6 August 2008 (UTC)Reply

Transclude Child Pages for an Index Item

edit

It would be nice if we had a way to optionally transclude all child pages for a given index item in only one page. This would be great because some users want to see all the information on the same page instead of navigating teh index structure to see all the items.

What do you think?

- Gabriel (glajman AT gmail DOT com) - March 11, 2009

Bugs

edit

Table prefixes

edit

It seems the extension does not work when table prefixes are used. --Fernando Correia 18:47, 4 April 2007 (UTC)Reply

I haven't seen any problems using this extension and table prefixes so far (only tested on a very limited demo site), off course the CREATE TABLE statement should be altered so that the hierarchy-table has the same prefix as the other tables --wimh 13:46, 8 May 2007 (UTC)Reply

Mediawiki 1.10

edit

This extension is great, but it screws up the layout on Mediawiki 1.10 . The Writing is huge, and there are spaces between many elements, e.g. between The page and the tabs at the top, or around the logo. --91.3.112.102 12:05, 29 May 2007 (UTC) (Die_Backe)Reply

edit: I checked the html-code of the mainpage with and without the extension installed. Only commentarys (processing time, caching of the page) and pagefiews are different. And there is a space in the very first line. ("< !DOCTYPE" with, "<!DOCTYPE" without extension). Any idea? -- Die_Backe, 91.3.112.102 12:14, 29 May 2007 (UTC)Reply

Blank <index> page when user login

edit

When a user logs in to our wiki the <index> page is blank. When you are not logged in you can see the index page. One of my users had this problem on her machine but I could log in on my machine with her login and see the index. Now, today, I can't see the index page with her log in or my own sysops loggin. I don't know if this because of the prefixes on the table or not. It seems more like a cache issue because of how intermittant the viewing has been over the last few days.

Does anyone have any ideas? Thanks, Margaret

Back again, I think I figured out my issue. I protected the index page so no one but a sysop could edit the page and in return, it doesn't show the outline when a user is logged in. I hope this solution fixes this back and forth behavior.


Index fails with large index

edit

I have a large index (about 700 pages). The index fails at about 600 pages. After messing around with the code I found the problem at the find TOC pattern:

 $pattern = '@<table id="toc">(.*?)</table>@s'; 

It fails to find a match. Inspecting the HTML the table exists, but it may be too long? It just returns the html and it looks like a page full of headers.

Example:

 Problem Page

Any ideas?

--Greg 18:08, 28 October 2008 (UTC)Reply

Index kills wiki

edit

I am over our corporate wiki and we have all of our manuals online. Some of them are several hundred pages long. We run all of them using the Hierarchy plugin. We love this extension. We run all the books off of separate namespaces, but we can't figure out why some namespaces work well and others don't. We have two users manuals, a generic users manual and a mobile users manual. The generic one is about 3 times as long and works just fine. The mobile users manual continually fails to work. On the pages with problems the script actually dies/times out and you just see a white page.

Here is an example:

 Title Page Works
 Next Page Doesn't


I am really confused about what is happening. I have altered the extension a bit, but even if I remove my changes it still fails. Any Ideas?

--Greg 18:08, 28 October 2008 (UTC)Reply

I have done a bunch more debugging and I found that when the article parses into the hierarchy table it's parentID is the same as it's own id. Here is a print out of the HierarcyItem: HierarchyItem Object ( [mId] => [mIndexArticleId] => 1190 [mTocLevel] => 2 [mTocNumber] => 1.2 [mTocText] => Mobile_User_Manual:About_Fishbowl_Mobile_Warehouse [mSequence] => 3 [mArticleId] => 1153 [mPreviousArticleId] => 1154 [mNextArticleId] => 0 [mParentArticleId] => 1153 )

--Greg 05:29, 29 October 2008 (UTC)Reply

PhP 5.3 Reference Restrictions

edit

Since I upgraded to php 5.3 I started having the following errors:

Parameter 1 to Language::getMagic() expected to be a reference, value given in /usr/share/mediawiki/includes/StubObject.php on line 58

Warning: Parameter 3 to fnHierarchySaveHook() expected to be a reference, value given in /usr/share/mediawiki/includes/Hooks.php on line 117"

To fix it I had to edit Language.php.

-	function getMagic( &$mw ) {
+	function getMagic( $mw ) {

And the Hierarchy.php

-       function fnHierarchySaveHook(&$article, &$user, &$text, &$summary, &$minoredit, &$watchthis, &$sectionanchor, &$flags) {
+       function fnHierarchySaveHook(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, $flags) {

Worked for me, might help somebody out there

Issue with navigation box

edit

I had issues with navigation box, with multiple levels. With deeper levels the navigation box didnt show the other pages in the current level, also did show the parents. After looking into the code and changing the following line in SaveIndex function made it work.

- $pattern = '@<li class=\"toclevel-(.*?)\">@';
+ $pattern = '@<li class=\"toclevel-(.*?) tocsection-.*\">@';

By looking into the database, next and previous article information was saved correctly. By the parent article id was not updated.

Contributors

edit

Source code contributors:

Version history

edit

1.2.0 (unofficial by Cowtung)

edit

Release date: 2009-06-16

  • FEATURE: New "root" parameter for index tag, removes root from all generated links.
  • FEATURE: New "deslash" parameter for index tag, removes everything before last forward slash in links. "A:B/C/D/E" -> "E".
  • FEATURE: Breadcrumbs added.
  • CHANGE: Removed horizontal lines and carriage returns generated so customization is easier (just add them back into your templates if you wish).

1.1.0

edit

Release date: 2007-03-08

  • FEATURE: Full "breadcrumb" of superior pages in the navigation box.
  • FEATURE: Optional subordinate pages in the navigation box.
  • FEATURE: Optional embedded subordinate pages list.
  • FEATURE: Separating text between the page content and the embedded subordinate pages list.
  • FEATURE: Automatic adjustment of navigation box width.
  • FEATURE: German translation.

1.0.0

edit

Release date: 2007-02-01

  • Initial release.

Namespaces in the hierarchy

edit

If you have separate namespaces you have to use the full namespace name such as:

 <index>
 [[ Book:TOC | TOC ]]
 = Book:Chapter 1 =
 == Book:Page 1 ==
 == Book:Page 2 ==
 = Book:Chapter 2 =
 == etc ==
 </index>

Is there any way to hide the Book: namespace by just adding a variable? It's not so bad in the index, but on the individual pages it can get a bit long. --Greg 05:43, 12 April 2008 (UTC)Reply

Same page in multiple indcies

edit

One more thing... can you have pages that you want to use in multiple hierarchies? What is the best way to do this? Should you create a template that has the data and then pull that into the page? I take it the hierarchy can not tell how you got to that page... Just a thought.
Thanks for this extension. It's EXACTLY what I wanted.

--Greg 05:51, 12 April 2008 (UTC)Reply

Hierachy table tags are not XHTML Compliant

edit

The .php file generates non compliant XHTML table tag.
As shipped the script generates a width attribute of width="200px" rather than width="200" (note 200 is arbitary)
See line 477 in .php source.
--84.92.164.19 12:38, 10 November 2008 (UTC)Reply

Return to "Hierarchy" page.