Add an article to a category

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Add an article to a category

Mauricio Etchevest
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.-
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Daniel Friesen-4
On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest  
<[hidden email]> 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
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Tyler Romeo
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 | [hidden email]



On Fri, Aug 17, 2012 at 12:03 PM, Daniel Friesen
<[hidden email]>wrote:

> On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest <
> [hidden email]> 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
> [hidden email]
> https://lists.wikimedia.org/**mailman/listinfo/wikitech-l<https://lists.wikimedia.org/mailman/listinfo/wikitech-l>
>
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Daniel Friesen-4
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 <[hidden email]>  
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 | [hidden email]
>
>
>
> On Fri, Aug 17, 2012 at 12:03 PM, Daniel Friesen
> <[hidden email]>wrote:
>
>> On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest <
>> [hidden email]> 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
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Tyler Romeo
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 | [hidden email]



On Fri, Aug 17, 2012 at 12:44 PM, Daniel Friesen
<[hidden email]>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 <[hidden email]>
> 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 | [hidden email]
>>
>>
>>
>> On Fri, Aug 17, 2012 at 12:03 PM, Daniel Friesen
>> <[hidden email]>**wrote:
>>
>>  On Fri, 17 Aug 2012 08:02:23 -0700, Mauricio Etchevest <
>>> [hidden email]> 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
> [hidden email]
> https://lists.wikimedia.org/**mailman/listinfo/wikitech-l<https://lists.wikimedia.org/mailman/listinfo/wikitech-l>
>
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Platonides
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 | [hidden email]

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
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Mauricio Etchevest
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 <[hidden email]> 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 | [hidden email]
>
> 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
> [hidden email]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Mark A. Hershberger-2
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
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Platonides
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
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Mark A. Hershberger-2
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
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Tyler Romeo
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 | [hidden email]



On Sun, Aug 19, 2012 at 3:17 PM, Mark A. Hershberger <[hidden email]>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
> [hidden email]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Add an article to a category

Daniel Friesen-2
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 <[hidden email]>  
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 | [hidden email]
>
>
>
> On Sun, Aug 19, 2012 at 3:17 PM, Mark A. Hershberger  
> <[hidden email]>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
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l