problem with creation of bot for wiki

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
egomate
Forum Newbie
Posts: 3
Joined: Sun Jun 01, 2008 2:13 am

problem with creation of bot for wiki

Post by egomate »

I'm trying to make a bot (BSCBot) for a mediawiki wikipedia. I was trying to follow the directions here: http://wikisum.com/w/User:Adam/Creating ... ots_in_PHP
I downloaded Snoopy and BasicBot and put them on the server, in the /bot/ directory, with the .php files in /bot/BSCbot/ and as far as I know I did that part correctly. I keep on getting this error message: Warning: Invalid argument supplied for foreach() in .../html/bot/BSCbot/BasicBot.php on line 393 You are trying to update the links cache, but you passed no links.
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: problem with creation of bot for wiki

Post by vargadanis »

We need the +-5 lines of the foreach at least. Please post it. So lines 388-398. The info u gave us is simply not sufficient to any kind of response.
egomate
Forum Newbie
Posts: 3
Joined: Sun Jun 01, 2008 2:13 am

Re: problem with creation of bot for wiki

Post by egomate »

380 function HarvestSpecialLinks($title){
381 if (!$this->fetch( $this->wikiServer . PREFIX . '/index.php?title=' . $title ) )
382 return false;
383 // we want only the links in here: <ol start='1' class='special'> ... </ol>
384 preg_match( "|<ol[^>]*class=['\"]special['\"][^>]*>(.*)</ol[^>]*>|Usi",$this->results,$specialLinks );
385 if (!is_array($specialLinks))
386 return false;
387 $specialLinks = $specialLinks[0]; // the whole thing from <ol... to </ol>
388 $specialLinks = $this->_striplinks($specialLinks);
389 // Special pages use relative (not absolute) links. E.g. if ALTPREFIX is '/w', then you'll have things like '/w/Article_Title' in the special page's links.
390 // we want to reduce that to just the title--i.e. strip off the '/w/' part.
391 if (''!=ALTPREFIX){ $strlen = strlen(ALTPREFIX) + 1;} // the "+1" is for the slash after ALTPREFIX
392 else{ $strlen = 1;} // for the slash
393 foreach( $specialLinks as $key => $link )
394 $specialLinks[$key] = substr( $link, $strlen );
395 // now let's prepare to write the links to a temporary location
396 $cache = TEMP . 'harvest_' . gmdate("Ymd_his") . '.php';
397 $this->UpdateLinksCache($cache,$specialLinks);
398 return $cache; // we're returning the file path
399 }
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: problem with creation of bot for wiki

Post by vargadanis »

Maaaan, put the code in [ code ] tags!
I hate reading code as if it was text... Not indented
egomate
Forum Newbie
Posts: 3
Joined: Sun Jun 01, 2008 2:13 am

Re: problem with creation of bot for wiki

Post by egomate »

Code: Select all

 
    // analogous to wikiHarvestLinks, but for special pages. Special pages don't accept the ?action=raw trick we use in wikiHarvestLinks, so we use this method instead.
    // like wikiHarvestLinks, stores the harvested links to cache and returns the cache filename. Doesn't work on all types of special pages (must use <ol class="special">...</ol>)
    function HarvestSpecialLinks($title){
        if (!$this->fetch( $this->wikiServer . PREFIX . '/index.php?title=' . $title ) )
            return false;
        // we want only the links in here:  <ol start='1' class='special'> ... </ol>
        preg_match( "|<ol[^>]*class=['\"]special['\"][^>]*>(.*)</ol[^>]*>|Usi",$this->results,$specialLinks );
        if (!is_array($specialLinks))
            return false;
        $specialLinks = $specialLinks[0]; // the whole thing from <ol... to </ol>
        $specialLinks = $this->_striplinks($specialLinks);
        // Special pages use relative (not absolute) links. E.g. if ALTPREFIX is '/w', then you'll have things like '/w/Article_Title' in the special page's links.
        // we want to reduce that to just the title--i.e. strip off the '/w/' part.
        if (''!=ALTPREFIX){     $strlen = strlen(ALTPREFIX) + 1;}       // the "+1" is for the slash after ALTPREFIX
        else{                   $strlen = 1;}                           // for the slash
        foreach( $specialLinks as $key => $link )  // <----- 393 
            $specialLinks[$key] = substr( $link, $strlen );
        // now let's prepare to write the links to a temporary location
        $cache = TEMP . 'harvest_' . gmdate("Ymd_his") . '.php';
        $this->UpdateLinksCache($cache,$specialLinks);
        return $cache; // we're returning the file path
    }
 
like this ?
sorry
Post Reply