Hi, I am thinking about creating a hook extension that would display external content (i.e. a list of bookmarks from another site, e.g. Digg, Scuttle etc.) below the list of articles on an article page. Whenver a category page title corresponds to the description, tag or title of a bookmark, I want it to show up. So users can see all links to local pages in that category, but also some external bookmarks.
I have looked but don't seem to be able to find any hooks that would allow me to inject my content?
I could create a tag extension and display it on top of the page, but that isn't that intuitive for the user (why have external articles before local ones?).
Any help is appreciated!
Thanks, Andi
On 12/09/2007, Andreas Rindler mediawiki@jenandi.com wrote:
Hi, I am thinking about creating a hook extension that would display external content (i.e. a list of bookmarks from another site, e.g. Digg, Scuttle etc.) below the list of articles on an article page. Whenver a category page title corresponds to the description, tag or title of a bookmark, I want it to show up. So users can see all links to local pages in that category, but also some external bookmarks.
I have looked but don't seem to be able to find any hooks that would allow me to inject my content?
I also don't see any existing hooks. You can try and get a hook added to an appropriate place (submit a patch to bugzilla). Otherwise, I guess you could use a hook in the parser and just check to see if it's a category page somehow before doing anything.
I agree that the CategoryPage class could use some hooks. In the absence of hooks, you can also make your own CategoryPage class that exends CategoryPage and overrides (there's a technical term for this, but I forget what it is) just the methods you want to hook into.
When I did this for SplitCategoryPage.php, it worked, except that I never did figure out how to get CategoryPage.php to autoload the Article class (I assume this means I'm doing something incorrectly). I had to add require_once('Article.php') to CategoryPage.php. Not surprisingly, I forget about this and it breaks every time I upgrade.
Jim On Sep 12, 2007, at 5:54 AM, Andreas Rindler wrote:
Hi, I am thinking about creating a hook extension that would display external content (i.e. a list of bookmarks from another site, e.g. Digg, Scuttle etc.) below the list of articles on an article page. Whenver a category page title corresponds to the description, tag or title of a bookmark, I want it to show up. So users can see all links to local pages in that category, but also some external bookmarks.
I have looked but don't seem to be able to find any hooks that would allow me to inject my content?
I could create a tag extension and display it on top of the page, but that isn't that intuitive for the user (why have external articles before local ones?).
Any help is appreciated!
Thanks, Andi
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
===================================== Jim Hu Associate Professor Dept. of Biochemistry and Biophysics 2128 TAMU Texas A&M Univ. College Station, TX 77843-2128 979-862-4054
On 12/09/2007, Jim Hu jimhu@tamu.edu wrote:
I agree that the CategoryPage class could use some hooks. In the absence of hooks, you can also make your own CategoryPage class that exends CategoryPage and overrides (there's a technical term for this, but I forget what it is) just the methods you want to hook into.
Overloading. But wouldn't that require rewriting the code that calls CategoryPage to make it call the new class? If you're changing the core code like that, you may as well just add the code directly to CategoryPage.php and not worry about hooks.
When I did this for SplitCategoryPage.php, it worked, except that I never did figure out how to get CategoryPage.php to autoload the Article class (I assume this means I'm doing something incorrectly). I had to add require_once('Article.php') to CategoryPage.php. Not surprisingly, I forget about this and it breaks every time I upgrade.
If it extends Article (even indirectly, via CategoryPage), it should have all the methods and attributes from the Article class already... that's the whole point of inheritance...
On Sep 12, 2007, at 10:58 AM, Thomas Dalton wrote:
On 12/09/2007, Jim Hu jimhu@tamu.edu wrote:
I agree that the CategoryPage class could use some hooks. In the absence of hooks, you can also make your own CategoryPage class that exends CategoryPage and overrides (there's a technical term for this, but I forget what it is) just the methods you want to hook into.
Overloading.
Thanks! I knew it was "over"-something.
But wouldn't that require rewriting the code that calls CategoryPage to make it call the new class? If you're changing the core code like that, you may as well just add the code directly to CategoryPage.php and not worry about hooks.
There is a hook.
$wgHooks['CategoryPageView'][] = 'wfMyAlternativeCategoryPage';
When I did this for SplitCategoryPage.php, it worked, except that I never did figure out how to get CategoryPage.php to autoload the Article class (I assume this means I'm doing something incorrectly). I had to add require_once('Article.php') to CategoryPage.php. Not surprisingly, I forget about this and it breaks every time I upgrade.
If it extends Article (even indirectly, via CategoryPage), it should have all the methods and attributes from the Article class already... that's the whole point of inheritance...
Yup. And it does. But it has to load the parent classes first. Which it should do via autoloading in php 5.x. I'm getting inheritance. I'm not getting autoloading. I have no idea why, since I assume that the autoloader should have run earlier. But looking at it, I can put the require in the extension, so I can take care of the upgrade problem at least.
Jim
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
===================================== Jim Hu Associate Professor Dept. of Biochemistry and Biophysics 2128 TAMU Texas A&M Univ. College Station, TX 77843-2128 979-862-4054
But wouldn't that require rewriting the code that calls CategoryPage to make it call the new class? If you're changing the core code like that, you may as well just add the code directly to CategoryPage.php and not worry about hooks.
There is a hook.
$wgHooks['CategoryPageView'][] = 'wfMyAlternativeCategoryPage';
Good point, that hook would work.
Yup. And it does. But it has to load the parent classes first. Which it should do via autoloading in php 5.x. I'm getting inheritance. I'm not getting autoloading. I have no idea why, since I assume that the autoloader should have run earlier. But looking at it, I can put the require in the extension, so I can take care of the upgrade problem at least.
That's very odd... I know next to nothing about autoloading, so I can't help you.
On 12/09/2007, Thomas Dalton thomas.dalton@gmail.com wrote:
But wouldn't that require rewriting the code that calls CategoryPage to make it call the new class? If you're changing the core code like that, you may as well just add the code directly to CategoryPage.php and not worry about hooks.
There is a hook.
$wgHooks['CategoryPageView'][] = 'wfMyAlternativeCategoryPage';
Good point, that hook would work.
On the description page it says: Called before viewing a categorypage in CategoryPage::view
So that means I can just append my bit to the catpage that is passed in? or how do I control where my content shows up on the page?
On the description page it says: Called before viewing a categorypage in CategoryPage::view
So that means I can just append my bit to the catpage that is passed in? or how do I control where my content shows up on the page?
I think you would need to have your hook return false, stopping the processing of the normal category page. You would then have your own class extending CategoryPage which calls the appropriate methods from CategoryPage with your own code interspersed where required.
On 13/09/2007, Thomas Dalton thomas.dalton@gmail.com wrote:
On the description page it says: Called before viewing a categorypage in CategoryPage::view
So that means I can just append my bit to the catpage that is passed in? or how do I control where my content shows up on the page?
I think you would need to have your hook return false, stopping the processing of the normal category page. You would then have your own class extending CategoryPage which calls the appropriate methods from CategoryPage with your own code interspersed where required.
ok, that sounds like fun. i will try the simple thing first (bookmarks displayed above the articles) and then i will see to extend the solution to add the class.
thanks so far...
wikitech-l@lists.wikimedia.org