User:FlBot/Source
Appearance
(Redirected from User:AtyndallBot/Source)
The following is automatically generated by LoxyBot
opentasks.run.php (LoxyBot)
[edit]#!/usr/bin/php
<?php
/*********************************************************************\
* Opentasks script
*
* This file is part of LoxyBot, a bot created by User:Foxy Loxy
* at <http://en.wikipedia.org/wiki/User:LoxyBot>.
*
* LoxyBot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LoxyBot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LoxyBot. If not, see <http://www.gnu.org/licenses/>.
*
* This code is optimized to be run from the command line.
\*********************************************************************/
$OpenTasks_Version = '1.3.1';
/**
* = Files to include =
* pwiki.class.php; PHPediaWiki is the bot framework designed by Foxy Loxy (originally ported from SxWiki) for use with his bots.
**/
require_once "pwiki.class.php";
/**
* = Pwiki class stuff =
* This varible opens the Pwiki class for use.
* Make sure to call it with every Pwiki based command, e.g. $pw->getPage instead of getPage.
**/
$configurationfile = 'config.include.php';
$extensions = array(
'categorymanipulation.extends.php',
'loxybot.extends.php',
);
$verbosity = 4;
$logverbosity = 4;
$logfile = 'bot.log';
$logerrors = true;
$pw = new Pwiki($configurationfile,$extensions,$verbosity,$logverbosity,$logfile,$logerrors);
$username = $pw->username;
$owner = $pw->ownerusername;
/**
* = Configuration varibles =
* You can change these varibles to customise the program to suit your needs.
* $owner; Owner's en.Wikipedia username (if owner does not have en.wikipedia account, use interwiki, e.g. meta:Foxy Loxy).
* $stpage; The source code template page.
* $sourcecode; User:$username/Source page contents to write.
* $sourcepage; Page that sourcecode should be written to.
* $sourcesum; The edit summary used when dumping the source code.
* $ottemplate; The location of the template used when writing to open tasks (this template is just like the one you wish to write to only with information locations defined as $varibles).
* $otpage; The location of the open tasks page.
* $otsum; The edit summary used when updating the open tasks page.
* $findarr; This array contains the placeholder varibles used when using the open tasks template. Make sure not to replace the 'quotes' with "quotes".
* $amount; The number of articles to put in each section.
* $ns; The namespace number that the pages should be taken from. (0 = article space)
* $usecron; true = You want to use cron instead of looping this script endlessly. false = you want to use the traditional loop method.
* $sleep; The number of seconds to sleep for if $usecron is set to false.
* $executetimes;The number times the script should loop. Setting value to -1 means forever.
* NOTE: Other configuration varibles reside in pwiki.class.php and config.include.php.
**/
$stpage = "User:$username/SourceTemplate";
$sourcecode = str_replace(array("\$\$LoXyBoT\$\$","\$\$ExTeNsIoN\$\$"), array(file_get_contents(__FILE__),file_get_contents('loxybot.extends.php')), $pw->getPage($stpage));
$sourcepage = "User:$username/Source";
$sourcesum = "Writing source code. Script $OpenTasks_Version. Pwiki $Pwiki_Version.";
$ottemplate = "User:$username/Opentaskstemplate";
$otpage = 'Wikipedia:Community portal/Opentask';
$otsum = "Updating open tasks list";
$findarr = array('$wikify', // Needs to be wikified
'$cleanup', // Needs cleanup
'$stub', // Stubs
'$verify', // Needs verification
'$update', // Needs updating
'$npov', // Needs NPOV editing
'$copyedit', // Needs copyediting
'$merge', // Needs to be merged
'$style', // Needs its style fixed
'$expand', // Needs expanding
'$split', // Needs to be split
);
$amount = '6';
$ns = '0';
$usecron = false;
$sleep = '10800';
$executetimes = -1;
/**
* = Dumping the source code =
* This if statement checks checkrun() and then writes the sourcecode for this file, SxWiki.php
* and a sample of login.include.php to the predefined page on Wikipedia.
**/
if ($pw->getPage($sourcepage) != $sourcecode) {
$pw->_debug(0,"Source code different at User:$username/Source, writing.");
$pw->putPage($sourcepage,$sourcesum,$sourcecode);
}
/**
* = Category Arrays, Array Compression and Replace array function =
* This is the array that replaces the placeholders defined above with the real thing.
* These varibles call the wikifyarray function and compress the arrays, they also contain the category content required by the script.
* These varibles access the arrays above and are also used as the default varibles on the open tasks template.
* The getCat function accesses categories and fetches the 5 oldest mainspace posts.
* This is all combined into the generated page function which takes the open tasks template
* and generates the new open tasks page.
**/
function generatePage() {
/**
* = Category varibles =
* These varibles must point to the categories which contain ALL
* articles associated with that problem, not one with dated subcategories.
* DO NOT add Category: to the front of these.
**/
$wikifycat = 'All pages needing to be wikified';
$cleanupcat = 'All pages needing cleanup';
$stubcat = 'Stubs';
$verifycat = 'All pages needing factual verification';
$updatecat = 'Wikipedia articles in need of updating';
$npovcat = 'All NPOV disputes';
$copyeditcat = 'All articles needing copy edit';
$mergecat = 'All articles to be merged';
$stylecat = 'All articles needing style editing';
$expandcat = 'All articles to be expanded';
$splitcat = 'Articles to be split';
global $pw, $ns, $amount, $ottemplate, $findarr;
$result =
str_replace(
$findarr,
array(
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($wikifycat,$ns,$amount)
),
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($cleanupcat,$ns,$amount)
),
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($stubcat,$ns,$amount)
),
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($verifycat,$ns,$amount)
),
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($updatecat,$ns,$amount)
),
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($npovcat,$ns,$amount)
),
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($copyeditcat,$ns,$amount)
),
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($mergecat,$ns,$amount)
),
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($stylecat,$ns,$amount)
),
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($expandcat,$ns,$amount)
),
$pw->lb->wikifyimplodeArray(
$pw->cm->randCatMembers($splitcat,$ns,$amount)
),
),
$pw->getPage($ottemplate)
);
return $result;
}
if (!$usecron) {
$i = 0;
while ($i != $executetimes) {
$pw->putPage($otpage,$otsum,generatePage());
$i++;
$pw->_debug(2,"Sleeping for $sleep seconds. Loop run $i times.");
sleep($sleep);
$pw->_debug(2,"Awake now.");
};
} else {
$pw->putPage($otpage,$otsum,generatePage());
}
$pw->_exit("End of script.");
?>
loxybot.extends.php (Pwiki extension)
[edit]<?php
$name = 'LoxyBot';
$shortcut = 'lb';
$creator = 'en:User:Atyndall';
$licence = 'GNU GPL';
class LoxyBot extends Pwiki
{
function LoxyBot($verbosity=NULL, $logverbosity=NULL) {
if (isset($verbosity)) {
$this->verbosty = $verbosity;
}
if (isset($logverbosity)) {
$this->logverbosity = $logverbosity;
}
return NULL;
}
/*** TBU ***/
// See http://pwiki.sf.net/docs/Func:wikifyimplodeArray
public function wikifyimplodeArray($array, $after=', ') {
$this->_debug(4,"Public Function wikifyimplodeArray called.");
while (!isset($array)) {
$this->_debug(4,'$array was not set, returning NULL.');
return NULL;
}
foreach($array as $item){
$output .= "[[$item]]$after";
}
return $output;
}
}
?>
pwiki.class.php
[edit]LoxyBot now runs off the PHPediaWiki framework that I have ported from SxWiki and now develop myself. Pwiki can be downloaded from subversion at http://pwiki.svn.sourceforge.net/viewvc/pwiki/trunk/
config.include.php
[edit]See http://pwiki.sf.net/docs/Configuration_file
crontab
[edit]NOTE: crontab is not used on LoxyBot, but can be implemented if wanted.
# Runs script every three hours.
*/3 * * * * $HOME/bot/opentasks.run.php