Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Wikitech

Add an article to a category

 

 

Wikipedia wikitech RSS feed   Index | Next | Previous | View Threaded


mauricioet at gmail

Aug 17, 2012, 8:02 AM

Post #1 of 12 (1317 views)
Permalink
Add an article to a category

Hi,

Im 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.-
_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


lists at nadir-seen-fire

Aug 17, 2012, 9:03 AM

Post #2 of 12 (1290 views)
Permalink
Re: Add an article to a category [In reply to]

On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest
<mauricioet [at] gmail> 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 [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


tylerromeo at gmail

Aug 17, 2012, 9:35 AM

Post #3 of 12 (1289 views)
Permalink
Re: Add an article to a category [In reply to]

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 [at] gmail



On Fri, Aug 17, 2012 at 12:03 PM, Daniel Friesen
<lists [at] nadir-seen-fire>wrote:

> On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest <
> mauricioet [at] gmail> 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 [at] lists
> https://lists.wikimedia.org/**mailman/listinfo/wikitech-l<https://lists.wikimedia.org/mailman/listinfo/wikitech-l>
>
_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


lists at nadir-seen-fire

Aug 17, 2012, 9:44 AM

Post #4 of 12 (1286 views)
Permalink
Re: Add an article to a category [In reply to]

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 [at] gmail>
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 [at] gmail
>
>
>
> On Fri, Aug 17, 2012 at 12:03 PM, Daniel Friesen
> <lists [at] nadir-seen-fire>wrote:
>
>> On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest <
>> mauricioet [at] gmail> 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 [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


tylerromeo at gmail

Aug 17, 2012, 10:12 AM

Post #5 of 12 (1286 views)
Permalink
Re: Add an article to a category [In reply to]

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 [at] gmail



On Fri, Aug 17, 2012 at 12:44 PM, Daniel Friesen
<lists [at] nadir-seen-fire>wrote:

> 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 [at] gmail>
> 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 [at] gmail
>>
>>
>>
>> On Fri, Aug 17, 2012 at 12:03 PM, Daniel Friesen
>> <lists [at] nadir-seen-fire>**wrote:
>>
>> On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest <
>>> mauricioet [at] gmail> 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 [at] lists
> https://lists.wikimedia.org/**mailman/listinfo/wikitech-l<https://lists.wikimedia.org/mailman/listinfo/wikitech-l>
>
_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


Platonides at gmail

Aug 17, 2012, 2:05 PM

Post #6 of 12 (1285 views)
Permalink
Re: Add an article to a category [In reply to]

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 [at] gmail

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 [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


mauricioet at gmail

Aug 18, 2012, 9:29 AM

Post #7 of 12 (1281 views)
Permalink
Re: Add an article to a category [In reply to]

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 [at] gmail> 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 [at] gmail
>
> 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 [at] lists
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


mah at everybody

Aug 18, 2012, 1:19 PM

Post #8 of 12 (1279 views)
Permalink
Re: Add an article to a category [In reply to]

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.

--
http://hexmode.com/

Human evil is not a problem. It is a mystery. It cannot be solved.
-- When Atheism Becomes a Religion, Chris Hedges

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


Platonides at gmail

Aug 18, 2012, 2:16 PM

Post #9 of 12 (1282 views)
Permalink
Re: Add an article to a category [In reply to]

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.


_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


mah at everybody

Aug 19, 2012, 12:17 PM

Post #10 of 12 (1269 views)
Permalink
Re: Add an article to a category [In reply to]

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 [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


tylerromeo at gmail

Aug 19, 2012, 1:22 PM

Post #11 of 12 (1274 views)
Permalink
Re: Add an article to a category [In reply to]

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 [at] gmail



On Sun, Aug 19, 2012 at 3:17 PM, Mark A. Hershberger <mah [at] everybody>wrote:

> 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 [at] lists
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


daniel at nadir-seen-fire

Aug 19, 2012, 3:24 PM

Post #12 of 12 (1273 views)
Permalink
Re: Add an article to a category [In reply to]

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.

--
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

On Sun, 19 Aug 2012 13:22:37 -0700, Tyler Romeo <tylerromeo [at] gmail>
wrote:

> 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 [at] gmail
>
>
>
> On Sun, Aug 19, 2012 at 3:17 PM, Mark A. Hershberger
> <mah [at] everybody>wrote:
>
>> 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 [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Wikipedia wikitech RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.