How to get the article content?

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

How to get the article content?

Marcus Schäfer-3
Hi @all,

I used this line of code to get the content of an article within version 1.7.1

Now I did a upgrade to 1.11.0, and it doesn't work anymore?
Where's the problem?


_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: How to get the article content?

Rob Church
On 29/10/2007, demagggus <[hidden email]> wrote:
> Hi @all,
>
> I used this line of code to get the content of an article within version 1.7.1
>
> Now I did a upgrade to 1.11.0, and it doesn't work anymore?
> Where's the problem?

What line of code?


Rob Church

_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: How to get the article content?

Marcus Schäfer-3
In reply to this post by Marcus Schäfer-3
demagggus <magggus@...> writes:

>
> Hi @all,
>
> I used this line of code to get the content of an article within version 1.7.1
>
> Now I did a upgrade to 1.11.0, and it doesn't work anymore?
> Where's the problem?
>

Sorry, here the code...

$text = $wgArticle->getContent();


_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: How to get the article content?

Thomas Dalton
> $text = $wgArticle->getContent();

I've seen other people suggesting using the appropriate Revision to
get the text, rather than the Article, perhaps you could try that. (I
don't know enough about it to know why it would have stopped working,
though.)

_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: How to get the article content?

Bugzilla from andrew@epstone.net
In reply to this post by Marcus Schäfer-3
On 10/29/07, demagggus <[hidden email]> wrote:

> Now I did a upgrade to 1.11.0, and it doesn't work anymore?

Does it return nothing?
Does it throw an error?
Does it return the wrong text?
Is it working some of the time?
Is it not working at all?
Is it inserting bogus records into the database?
Is it sneaking off with your girlfriend when you're not looking?

"Doesn't work" isn't really a sufficient explanation of the problem
you're experiencing.

--
Andrew Garrett

_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: How to get the article content?

Marcus Schäfer-3

-------- Original-Nachricht --------
> Datum: Tue, 30 Oct 2007 18:04:19 +1100
> Von: "Andrew Garrett" <[hidden email]>
> An: "Wikimedia developers" <[hidden email]>
> Betreff: Re: [Wikitech-l] How to get the article content?

> On 10/29/07, demagggus <[hidden email]> wrote:
>
> > Now I did a upgrade to 1.11.0, and it doesn't work anymore?
>
> Does it return nothing?
> Does it throw an error?
> Does it return the wrong text?
> Is it working some of the time?
> Is it not working at all?
> Is it inserting bogus records into the database?
> Is it sneaking off with your girlfriend when you're not looking?
>
> "Doesn't work" isn't really a sufficient explanation of the problem
> you're experiencing.
>
> --
> Andrew Garrett
>

Sorry for the short and imprecisely description of my problem.
I forgot to activate display_errors so I didn't get any error message, just a blank page.

'$text = $wgArticle->getContent();'

If I try to use this line of code I get the following error-message:

"Fatal error: Call to a member function getContent() on a non-object"

--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: How to get the article content?

Bugzilla from andrew@epstone.net
On 10/30/07, "Marcus Schäfer" <[hidden email]> wrote:
> I forgot to activate display_errors so I didn't get any error message, just a blank page.
>
global $wgArticle;
> '$text = $wgArticle->getContent();'
>
> If I try to use this line of code I get the following error-message:
>
> "Fatal error: Call to a member function getContent() on a non-object"

Well then, the problem's pretty simple. See amended code above.

--
Andrew Garrett

_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: How to get the article content?

Marcus Schäfer-3

-------- Original-Nachricht --------
> Datum: Tue, 30 Oct 2007 20:41:56 +1100
> Von: "Andrew Garrett" <[hidden email]>
> An: "Wikimedia developers" <[hidden email]>
> Betreff: Re: [Wikitech-l] How to get the article content?

> On 10/30/07, "Marcus Schäfer" <[hidden email]> wrote:
> > I forgot to activate display_errors so I didn't get any error message,
> just a blank page.
> >
> global $wgArticle;
> > '$text = $wgArticle->getContent();'
> >
> > If I try to use this line of code I get the following error-message:
> >
> > "Fatal error: Call to a member function getContent() on a non-object"
>
> Well then, the problem's pretty simple. See amended code above.
>
> --
> Andrew Garrett


Even if I call the global $wgArticle variable the same error-message appears. For this reason I thought there were any changes in the code e.g. Because like I mentioned: it worked on older releases!?!
--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail

_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: How to get the article content?

Bugzilla from andrew@epstone.net
On 10/30/07, "Marcus Schäfer" <[hidden email]> wrote:
> Even if I call the global $wgArticle variable the same error-message appears. For this reason
> I thought there were any changes in the code e.g. Because like I mentioned: it worked on
> older releases!?!

Where are you calling it?

--
Andrew Garrett

_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: How to get the article content?

Marcus Schäfer-3

-------- Original-Nachricht --------
> Datum: Tue, 30 Oct 2007 21:08:53 +1100
> Von: "Andrew Garrett" <[hidden email]>
> An: "Wikimedia developers" <[hidden email]>
> Betreff: Re: [Wikitech-l] How to get the article content?

> On 10/30/07, "Marcus Schäfer" <[hidden email]> wrote:
> > Even if I call the global $wgArticle variable the same error-message
> appears. For this reason
> > I thought there were any changes in the code e.g. Because like I
> mentioned: it worked on
> > older releases!?!
>
> Where are you calling it?
>
> --
> Andrew Garrett
>

I call it within a parser function, like this:

function wfRenderArticleSectionCheck_Magic(&$parser) {
        global $wgArticle, $wgTitle, $wgParser, $wgLang, $wgLanguageCode;
       
        $lan = $wgLang->getCode();
        $text = $wgArticle->getContent();
 
        $regex = "'(<section lan=$lan>)(.*)(</section>)'";
       
        preg_match_all($regex, $text, $matches);
       
        for($i=0;$i<count($matches[0]);$i++) {
                $output = $parser->parse($matches[0][$i], $parser->mTitle, $parser->mOptions, true, false);
                return $output->getText();
                continue;
        }
        return true;
}
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: How to get the article content?

Rob Church
On 30/10/2007, "Marcus Schäfer" <[hidden email]> wrote:
> I call it within a parser function, like this:

Never, ever, ever refer to $wgArticle, $wgTitle or $wgParser within a
parser hook callback; the first two are not required to exist in order
to parse text - there might not be an actual saved article that
corresponds to the input (if parsing for the UI, for instance), or the
parsing might be taking place within a maintenance script or other
environment which hasn't been initialised for the web script.

Furthermore, use of $wgParser is technically incorrect - you're passed
a reference to the parent Parser object. While this might be a
reference to the same Parser instance as $wgParser (in most cases it
will be), you cannot guarantee that from within your extension.

If you need the Title of the wiki text being processed, then you can
obtain it from the parser, e.g. $parser->getTitle(), but be careful -
it's not necessarily the case that an actual article will exist.

Furthermore, be careful regarding $wgLanguageCode - its purpose
changes during initialisation. If in doubt, call Language::getCode()
[on the $wgLang and $wgContLang objects].


Rob Church
_______________________________________________
Wikitech-l mailing list
[hidden email]
http://lists.wikimedia.org/mailman/listinfo/wikitech-l