Hi,
I´m developing a extension and I need to add an article to a category.
I only get the title of the article, so I try this:
$articleToAdd = new Article($title);
$context = $articleToAdd->getContext(); $resArticle = MediaWiki::articleFromTitle($title, $context);
$linksupdate = new LinksUpdate($resArticle->getTitle(), $resArticle->getParserOutput(), $f); $ps = $linksupdate->getParserOutput(); $categoriesLinks = $ps->getCategoryLinks();
..so I get all the categories for the article, but I need to add and remove a category. How can I do that ?
Thanks! Maurice.-
On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest mauricioet@gmail.com wrote:
Hi,
I´m developing a extension and I need to add an article to a category.
I only get the title of the article, so I try this:
$articleToAdd = new Article($title);
$context = $articleToAdd->getContext(); $resArticle = MediaWiki::articleFromTitle($title, $context);
$linksupdate = new LinksUpdate($resArticle->getTitle(), $resArticle->getParserOutput(), $f); $ps = $linksupdate->getParserOutput(); $categoriesLinks = $ps->getCategoryLinks();
..so I get all the categories for the article, but I need to add and remove a category. How can I do that ?
Thanks! Maurice.-
Firstly, don't use Article, use WikiPage.
We don't have an API to add/remove categories. So adding a category is nothing but appending category WikiText to the end of the page. And removing one is an ugly mess of using regexps to find some WikiText that looks like the category link you're looking for and erasing it.
On the other hand we DO have an api for things hooked into the parser to add categories that aren't marked up in the page (maintenance categories from tag extensions, etc...)
What exactly is the difference between Article and WikiPage? It seems like one is just an encapsulation of the other.
*--* *Tyler Romeo* Stevens Institute of Technology, Class of 2015 Major in Computer Science www.whizkidztech.com | tylerromeo@gmail.com
On Fri, Aug 17, 2012 at 12:03 PM, Daniel Friesen lists@nadir-seen-fire.comwrote:
On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest < mauricioet@gmail.com> wrote:
Hi,
I´m developing a extension and I need to add an article to a category.
I only get the title of the article, so I try this:
$articleToAdd = new Article($title);
$context = $articleToAdd->getContext(); $resArticle = MediaWiki::articleFromTitle($**title, $context);
$linksupdate = new LinksUpdate($resArticle->**getTitle(), $resArticle->getParserOutput()**, $f); $ps = $linksupdate->getParserOutput(**); $categoriesLinks = $ps->getCategoryLinks();
..so I get all the categories for the article, but I need to add and remove a category. How can I do that ?
Thanks! Maurice.-
Firstly, don't use Article, use WikiPage.
We don't have an API to add/remove categories. So adding a category is nothing but appending category WikiText to the end of the page. And removing one is an ugly mess of using regexps to find some WikiText that looks like the category link you're looking for and erasing it.
On the other hand we DO have an api for things hooked into the parser to add categories that aren't marked up in the page (maintenance categories from tag extensions, etc...)
-- ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]
______________________________**_________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/**mailman/listinfo/wikitech-lhttps://lists.wikimedia.org/mailman/listinfo/wikitech-l
Article is an ancient evil. A class in charge of the presentational logic to view a page from the front-end (and I'm not even sure it's ideal for that). Endowed with a public interface to act as a model for pages. It's PURE EVIL!!!
WikiPage the actual model for pages. Article inherits some WikiPage stuff for backwards compatibility but should never be used for that purpose.
Ideally one day we'll have a better system for outputting pages, actions, and special pages to the front-end and we'll eliminate the Article class in it's entirety.
Lol, good to know. I've wondered for the longest time what the difference.
*--* *Tyler Romeo* Stevens Institute of Technology, Class of 2015 Major in Computer Science www.whizkidztech.com | tylerromeo@gmail.com
On Fri, Aug 17, 2012 at 12:44 PM, Daniel Friesen lists@nadir-seen-fire.comwrote:
Article is an ancient evil. A class in charge of the presentational logic to view a page from the front-end (and I'm not even sure it's ideal for that). Endowed with a public interface to act as a model for pages. It's PURE EVIL!!!
WikiPage the actual model for pages. Article inherits some WikiPage stuff for backwards compatibility but should never be used for that purpose.
Ideally one day we'll have a better system for outputting pages, actions, and special pages to the front-end and we'll eliminate the Article class in it's entirety.
-- ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]
On Fri, 17 Aug 2012 09:35:02 -0700, Tyler Romeo tylerromeo@gmail.com wrote:
What exactly is the difference between Article and WikiPage? It seems like
one is just an encapsulation of the other.
*--* *Tyler Romeo*
Stevens Institute of Technology, Class of 2015 Major in Computer Science www.whizkidztech.com | tylerromeo@gmail.com
On Fri, Aug 17, 2012 at 12:03 PM, Daniel Friesen lists@nadir-seen-fire.com**wrote:
On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest <
mauricioet@gmail.com> wrote:
Hi,
I´m developing a extension and I need to add an article to a category.
I only get the title of the article, so I try this:
$articleToAdd = new Article($title);
$context = $articleToAdd->getContext(); $resArticle = MediaWiki::articleFromTitle($****title, $context);
$linksupdate = new LinksUpdate($resArticle->****getTitle(), $resArticle->getParserOutput()****, $f); $ps = $linksupdate->getParserOutput(****);
$categoriesLinks = $ps->getCategoryLinks();
..so I get all the categories for the article, but I need to add and remove a category. How can I do that ?
Thanks! Maurice.-
Firstly, don't use Article, use WikiPage.
We don't have an API to add/remove categories. So adding a category is nothing but appending category WikiText to the end of the page. And removing one is an ugly mess of using regexps to find some WikiText that looks like the category link you're looking for and erasing it.
On the other hand we DO have an api for things hooked into the parser to add categories that aren't marked up in the page (maintenance categories from tag extensions, etc...)
-- ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]
______________________________**_________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/**mailman/listinfo/wikitech-lhttps://lists.wikimedia.org/mailman/listinfo/wikitech-l
On 17/08/12 19:12, Tyler Romeo wrote:
Lol, good to know. I've wondered for the longest time what the difference.
*--* *Tyler Romeo* Stevens Institute of Technology, Class of 2015 Major in Computer Science www.whizkidztech.com | tylerromeo@gmail.com
Don't worry, I can't either. In the old days, it was too simple to know things that you were looking for were at Article :)
Thanks for answer..
I was working erasing the text, but the problem is when the word "category" is in other language.
How can I find all the translations of the word "category" to remove a categorization made in other language ?
Thanks.-
On Fri, Aug 17, 2012 at 6:05 PM, Platonides Platonides@gmail.com wrote:
On 17/08/12 19:12, Tyler Romeo wrote:
Lol, good to know. I've wondered for the longest time what the
difference.
*--* *Tyler Romeo* Stevens Institute of Technology, Class of 2015 Major in Computer Science www.whizkidztech.com | tylerromeo@gmail.com
Don't worry, I can't either. In the old days, it was too simple to know things that you were looking for were at Article :)
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On 08/18/2012 12:29 PM, Mauricio Etchevest wrote:
How can I find all the translations of the word "category" to remove a categorization made in other language ?
You mean the category namespace in MediaWiki? Here is how I found it:
$ grep NS_CATEGORY\ *.php | sed 's,.*=> *,,' | sort -u
That gives 132 translations.
Mark.
On 18/08/12 22:19, Mark A. Hershberger wrote:
On 08/18/2012 12:29 PM, Mauricio Etchevest wrote:
How can I find all the translations of the word "category" to remove a categorization made in other language ?
You mean the category namespace in MediaWiki? Here is how I found it:
$ grep NS_CATEGORY\ *.php | sed 's,.*=> *,,' | sort -u
That gives 132 translations.
Mark.
But he is only interested in the translations active for the content language of the wiki he is editing.
On 08/18/2012 05:16 PM, Platonides wrote:
But he is only interested in the translations active for the content language of the wiki he is editing.
Oh. Well, that is not as straightforward. Maybe he could use the side-bar links (inter-language links) on the category pages?
Mark.
Well, FWIW, you can use
$namespaces = $wgContLang->getNamespaces(); $categ = $namespaces[NS_CATEGORY];
to get the local name for the category namespace.
*--* *Tyler Romeo* Stevens Institute of Technology, Class of 2015 Major in Computer Science www.whizkidztech.com | tylerromeo@gmail.com
On Sun, Aug 19, 2012 at 3:17 PM, Mark A. Hershberger mah@everybody.orgwrote:
On 08/18/2012 05:16 PM, Platonides wrote:
But he is only interested in the translations active for the content language of the wiki he is editing.
Oh. Well, that is not as straightforward. Maybe he could use the side-bar links (inter-language links) on the category pages?
Mark.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
That only returns one possible namespace text.
We don't have a simple method to return all the strings that can be used to point to one namespace. You have to go through the canonical names and the aliases returned by Language.
wikitech-l@lists.wikimedia.org