Help:Creating a bot - Wikipedia

文章推薦指數: 80 %
投票人數:10人

Just like a human editor, a Wikipedia bot reads Wikipedia pages, and makes changes where it thinks changes need to be made. The difference is that, although ... Help:Creatingabot FromWikipedia,thefreeencyclopedia Jumptonavigation Jumptosearch Overview Dictionary Botpolicy BotApprovalsGroup Guide Noticeboard Newsletter BotRequests RequestsforApproval Adminbots {{BAGTools}} CreatingaBot Listofbots Botstatusreport Botactivitymonitor WikipediainformationpageThisisaninformationpage.ItisnotoneofWikipedia'spoliciesorguidelines,butratherintendstodescribesomeaspect(s)ofWikipedia'snorms,customs,technicalities,orpractices.Itmayreflectvaryinglevelsofconsensusandvetting.ShortcutsWP:CABWP:CREATEBOTWP:MKBOT RobotsorbotsareautomaticprocessesthatinteractwithWikipedia(andotherWikimediaprojects)asthoughtheywerehumaneditors.ThispageattemptstoexplainhowtocarryoutthedevelopmentofabotforuseonWikimediaprojectsandmuchofthisistransferabletootherwikisbasedonMediaWiki.Theexplanationisgearedmainlytowardsthosewhohavesomepriorprogrammingexperience,butareunsureofhowtoapplythisknowledgetocreatingaWikipediabot. Contents 1WhywouldIneedtocreateabot? 2Considerationsbeforecreatingabot 2.1Reuseexistingbots 2.2Reusecodebase 2.3Importantquestions 3HowdoesaWikipediabotwork? 3.1Overviewofoperation 3.2APIsforbots 3.3Loggingin 3.4Editing;edittokens 3.5Editconflicts 4Overviewoftheprocessofdevelopingabot 4.1Idea 4.2Specification 4.3Softwarearchitecture 4.4Implementation 4.5Testing 4.6Documentation 4.7Queries/Complaints 4.8Maintenance 5Generalguidelinesforrunningabot 5.1Botbestpractices 5.2Commonbotfeaturesyoushouldconsiderimplementing 5.2.1Manualassistance 5.2.2Disablingthebot 5.2.3Signature 5.2.4BotFlag 5.2.5Monitoringthebotstatus 6Open-sourcebots 7Programminglanguagesandlibraries 7.1Awk 7.2Perl 7.3PHP 7.4Python 7.5MATLAB 7.6Microsoft.NET 7.7Java 7.8Node.js 7.9Ruby 7.10CommonLisp 7.11Haskell 7.12VBScript 7.13Lua WhywouldIneedtocreateabot?[edit] Botscanautomatetasksandperformthemmuchfasterthanhumans.Ifyouhaveasimpletaskthatyouneedtoperformlotsoftimes(anexamplemightbetoaddatemplatetoallpagesinacategorywith1000pages),thenthisisataskbettersuitedtoabotthanahuman. Considerationsbeforecreatingabot[edit] Reuseexistingbots[edit] Itisoftenfarsimplertorequestabotjobfromanexistingbot.Ifyouhaveonlyperiodicrequestsorareuncomfortablewithprogramming,thisisusuallythebestsolution.TheserequestscanbemadeatWikipedia:Botrequests.Inaddition,thereareanumberoftoolsavailabletoanyone.MostofthesetaketheformofenhancedwebbrowserswithMediaWiki-specificfunctionality.ThemostpopularoftheseisAutoWikiBrowser(AWB),abrowserspecificallydesignedtoassistwitheditingonWikipediaandotherWikimediaprojects.AmostlycompletelistoftoolscanbefoundatWikipedia:Tools/Editingtools.Tools,suchasAWB,canoftenbeoperatedwithlittleornounderstandingofprogramming. Reusecodebase[edit] Ifyoudecideyouneedabotofyourownduetothefrequencyornoveltyofyourrequirements,youdon'tneedtowriteonefromscratch.TherearealreadyanumberofbotsrunningonWikipediaandmanyofthesebotspublishtheirsourcecode,whichcansometimesbereusedwithlittleadditionaldevelopmenttime.Therearealsoanumberofstandardbotframeworksavailable.Modifyinganexistingbotorusingaframeworkgreatlyspeedsdevelopmenttime.Also,becausethesecodebasesareincommonusageandaremaintainedcommunityprojects,itisfareasiertogetbotsbasedontheseframeworksapprovedforuse.ThemostpopularandcommonoftheseframeworksisPywikibot(PWB),abotframeworkwritteninPython.ItisthoroughlydocumentedandtestedandmanystandardizedPywikibotscripts(botinstructions)arealreadyavailable.Otherexamplesofbotframeworkscanbefoundbelow.Forsomeofthesebotframeworks,suchasPWB,ageneralfamiliaritywithscriptsisallthatisnecessarytorunthebotsuccessfully(itisimportanttoupdatetheseframeworksregularly). Importantquestions[edit] Writinganewbotrequiressignificantprogrammingability.Acompletelynewbotmustundergosubstantialtestingbeforeitwillbeapprovedforregularoperation.Towriteasuccessfulbot,planningiscrucial.Thefollowingconsiderationsareimportant: Willthebotbemanuallyassistedorfullyautomated? Willyoucreatethebotalone,orwiththehelpofotherprogrammers? Willthebot'srequests,edits,orotheractionsbelogged?Ifso,willthelogsbestoredonlocalmedia,oronwikipages? Willthebotruninsideawebbrowser(forexample,writteninJavaScript),orwillitbeastandaloneprogram? Ifthebotisastandaloneprogram,willitrunonyourlocalcomputer,oronaremoteserversuchastheToolforge? Ifthebotrunsonaremoteserver,willothereditorsbeabletooperatethebotorstartitrunning? HowdoesaWikipediabotwork?[edit] Overviewofoperation[edit] Justlikeahumaneditor,aWikipediabotreadsWikipediapages,andmakeschangeswhereitthinkschangesneedtobemade.Thedifferenceisthat,althoughbotsarefasterandlesspronetofatiguethanhumans,theyarenowherenearasbrightasweare.Botsaregoodatrepetitivetasksthathaveeasilydefinedpatterns,wherefewdecisionshavetobemade. Inthemosttypicalcase,abotlogsintoitsownaccountandrequestspagesfromWikipediainmuchthesamewayasabrowserdoes –althoughitdoesnotdisplaythepageonscreen,butworksonitinmemory –andthenprogrammaticallyexaminesthepagecodetoseeifanychangesneedtobemade.Itthenmakesandsubmitswhatevereditsitwasdesignedtodo,againinmuchthesamewayabrowserwould. Becausebotsaccesspagesthesamewaypeopledo,botscanexperiencethesamekindofdifficultiesthathumanusersdo.Theycangetcaughtineditconflicts,havepagetimeouts,orrunacrossotherunexpectedcomplicationswhilerequestingpagesormakingedits.Becausethevolumeofworkdonebyabotislargerthanthatdonebyaliveperson,thebotismorelikelytoencountertheseissues.Thus,itisimportanttoconsiderthesesituationswhenwritingabot. APIsforbots[edit] InordertomakechangestoWikipediapages,abotnecessarilyhastoretrievepagesfromWikipediaandsendeditsback.Thereareseveralapplicationprogramminginterfaces(APIs)availableforthatpurpose. MediaWikiAPI(api.php).Thislibrarywasspecificallywrittentopermitautomatedprocessessuchasbotstomakequeriesandpostchanges.DataisreturnedinJSONformat(seeoutputformatsformoredetails). Status:Built-infeatureofMediaWiki,availableonallWikimediaservers.Othernon-Wikimediawikismaydisableorrestrictwriteaccess. ThereisalsoanAPIsandboxforthosewantingtotestapi.php'sfeatures. Special:ExportcanbeusedtoobtainbulkexportofpagecontentinXMLform.SeeManual:ParameterstoSpecial:Exportforarguments; Status:Built-infeatureofMediaWiki,availableonallWikimediaservers. Raw(Wikitext)pageprocessing:sendingaaction=raworaaction=raw&templates=expandGETrequesttoindex.phpwillgivetheunprocessedwikitextsourcecodeofapage.Forexample:https://en.wikipedia.org/w/index.php?title=Help:Creating_a_bot&action=raw.AnAPIquerywithaction=query&prop=revisions&rvprop=contentoraction=query&prop=revisions&rvprop=content&rvexpandtemplates=1isroughlyequivalent,andallowsforretrievingadditionalinformation. Status:Built-infeatureofMediaWiki,availableonallWikimediaservers. SomeWikipediawebserversareconfiguredtograntrequestsforcompressed(GZIP)content.Thiscanbedonebyincludingaline"Accept-Encoding:gzip"intheHTTPrequestheader;iftheHTTPreplyheadercontains"Content-Encoding:gzip",thedocumentisinGZIPform,otherwise,itisintheregularuncompressedform.NotethatthisisspecifictothewebserverandnottotheMediaWikisoftware.OthersitesemployingMediaWikimaynothavethisfeature.Ifyouareusinganexistingbotframework,itshouldhandlelow-leveloperationslikethis. Loggingin[edit] Approvedbotsneedtobeloggedintomakeedits.Althoughabotcanmakereadrequestswithoutloggingin,botsthathavecompletedtestingshouldloginforallactivities.BotsloggedinfromanaccountwiththebotflagcanobtainmoreresultsperqueryfromtheMediaWikiAPI(api.php).Mostbotframeworksshouldhandleloginandcookiesautomatically,butifyouarenotusinganexistingframework,youwillneedtofollowthesesteps. Forsecurity,logindatamustbepassedusingtheHTTPPOSTmethod.BecauseparametersofHTTPGETrequestsareeasilyvisibleinURL,loginsviaGETaredisabled. TologabotinusingtheMediaWikiAPI,tworequestsareneeded: Request1–thisisaGETrequesttoobtainalogintoken URL:https://en.wikipedia.org/w/api.php?action=query&meta=tokens&type=login&format=xml Request2–thisisaPOSTtocompletethelogin URL:https://en.wikipedia.org/w/api.php?action=login&format=xml POSTparameters: lgname=BOTUSERNAME lgpassword=BOTPASSWORD lgtoken=TOKEN whereTOKENisthetokenfromthepreviousresult.TheHTTPcookiesfromthepreviousrequestmustalsobepassedwiththesecondrequest. AsuccessfulloginattemptwillresultintheWikimediaserversettingseveralHTTPcookies.Thebotmustsavethesecookiesandsendthembackeverytimeitmakesarequest(thisisparticularlycrucialforediting).OntheEnglishWikipedia,thefollowingcookiesshouldbeused:enwikiUserID,enwikiToken,andenwikiUserName.Theenwiki_sessioncookieisrequiredtoactuallysendaneditorcommitsomechange,otherwisetheMediaWiki:Sessionfailpreviewerrormessagewillbereturned. Main-accountloginvia"action=login"isdeprecatedandmaystopworkingwithoutwarning.Tocontinueloginwith"action=login",seeSpecial:BotPasswords. Editing;edittokens[edit] WikipediausesasystemofedittokensformakingeditstoWikipediapages,aswellasotheroperationsthatmodifyexistingcontentsuchasrollback.Thetokenlookslikealonghexadecimalnumberfollowedby'+\',forexample: d41d8cd98f00b204e9800998ecf8427e+\ Theroleofedittokensistoprevent"edithijacking",whereusersaretrickedintomakinganeditbyclickingasinglelink. TheeditingprocessinvolvestwoHTTPrequests.First,arequestforanedittokenmustbemade.Then,asecondHTTPrequestmustbemadethatsendsthenewcontentofthepagealongwiththeedittokenjustobtained.ItisnotpossibletomakeaneditinasingleHTTPrequest.Anedittokenremainsthesameforthedurationofalogged-insession,sotheedittokenneedstoberetrievedonlyonceandcanbeusedforallsubsequentedits. Toobtainanedittoken,followthesesteps: MediaWikiAPI(api.php).Makearequestwiththefollowingparameters(seemw:API:Edit-Create&Editpages). action=query meta=tokens Thetokenwillbereturnedinthecsrftokenattributeoftheresponse. Iftheedittokenthebotreceivesdoesnothavethehexadecimalstring(i.e.,theedittokenisjust'+\')thenthebotmostlikelyisnotloggedin.Thismightbeduetoanumberoffactors:failureinauthenticationwiththeserver,adroppedconnection,atimeoutofsomesort,oranerrorinstoringorreturningthecorrectcookies.Ifitisnotbecauseofaprogrammingerror,justloginagaintorefreshthelogincookies.Thebotsmustuseassertiontomakesurethattheyareloggedin. Editconflicts[edit] Editconflictsoccurwhenmultiple,overlappingeditattemptsaremadeonthesamepage.Almosteverybotwilleventuallygetcaughtinaneditconflictofonesortoranother,andshouldincludesomemechanismtotestforandaccommodatetheseissues. BotsthatusetheMediawikiAPI(api.php)shouldretrievetheedittoken,alongwiththestarttimestampandthelastrevision"base"timestamp,beforeloadingthepagetextinpreparationfortheedit;prop=info|revisionscanbeusedtoretrieveboththetokenandpagecontentsinonequery(example).Whensubmittingtheedit,setthestarttimestampandbasetimestampattributes,andchecktheserverresponsesforindicationsoferrors.Formoredetails,seemw:API:Edit-Create&Editpages. Generallyspeaking,ifaneditfailstocompletethebotshouldcheckthepageagainbeforetryingtomakeanewedit,tomakesuretheeditisstillappropriate.Further,ifabotrechecksapagetoresubmitachange,itshouldbecarefultoavoidanybehaviorthatcouldleadtoaninfiniteloopandanybehaviorthatcouldevenresembleeditwarring. Overviewoftheprocessofdevelopingabot[edit] Actually,codingorwritingabotisonlyonepartofdevelopingabot.YoushouldgenerallyfollowthedevelopmentcyclebelowtoensurethatyourbotfollowsWikipedia'sbotpolicy.FailuretocomplywiththepolicymayleadtoyourbotfailingtobeapprovedorbeingblockedfromeditingWikipedia. OverviewofWikipediabotdevelopmentcycle Idea[edit] ThefirsttaskincreatingaWikipediabotisextractingtherequirementsorcomingupwithanidea.Ifyoudon'thaveanideaofwhattowriteabotfor,youcouldpickupideasatrequestsforworktobedonebyabot. Makesureanexistingbotisn'talreadydoingwhatyouthinkyourbotshoulddo.Toseewhattasksarealreadybeingperformedbyabot,seethelistofcurrentlyoperatingbots. Specification[edit] Specificationisthetaskofpreciselydescribingthesoftwaretobewritten,possiblyinarigorousway.Youshouldcomeupwithadetailedproposalofwhatyouwantittodo.Trytodiscussthisproposalwithsomeeditorsandrefineitbasedonfeedback.Evenagreatideacanbemadebetterbyincorporatingideasfromothereditors. Inthemostbasicform,yourspecifiedbotmustmeetthefollowingcriteria: Thebotisharmless(itmustnotmakeeditsthatcouldbeconsidereddisruptivetothesmoothrunningoftheencyclopedia) Thebotisuseful(itprovidesausefulservicemoreeffectivelythanahumaneditorcould) Thebotdoesnotwasteserverresources. Softwarearchitecture[edit] Thinkabouthowyoumightcreateitandwhichprogramminglanguage(s)andtoolsyouwoulduse.Architectureisconcernedwithmakingsurethesoftwaresystemwillmeettherequirementsoftheproductaswellasensuringthatfuturerequirementscanbeaddressed.Certainprogramminglanguagesarebettersuitedtosometasksthanothers,formoredetailssee§ Programminglanguagesandlibraries. Implementation[edit] Implementation(orcoding)involvesturningdesignandplanningintocode.Itmaybethemostobviouspartofthesoftwareengineeringjob,butitisnotnecessarilythelargestportion.Intheimplementationstageyoushould: Createanaccountforyourbot.Clickherewhenloggedintocreatetheaccount,linkingittoyours.(Ifyoudonotcreatethebotaccountwhileloggedin,itislikelytobeblockedasapossiblesockpuppetorunauthorisedbotuntilyouverifyownership) Createauserpageforyourbot.Yourbot'seditsmustnotbemadeunderyourownaccount.Yourbotwillneeditsownaccountwithitsownusernameandpassword. Addthesameinformationtotheuserpageofthebot.Itwouldbeagoodideatoaddalinktotheapprovalpage(whetherapprovedornot)foreachfunction. Testing[edit] Agoodwayoftestingyourbotasyouaredevelopingistohaveitshowthechanges(ifany)itwouldhavemadetoapage,ratherthanactuallyeditingthelivewiki.Somebotframeworks(suchaspywikibot)havepre-codedmethodsforshowingdiffs.Duringtheapprovalsprocess,thebotwillmostlikelybegivenatrialperiod(usuallywitharestrictiononthenumberofeditsordaysitistorunfor)duringwhichitmayactuallyedittoenablefine-tuningandironoutanybugs.Attheendofthetrialperiod,ifeverythingwentaccordingtoplan,thebotshouldgetapprovalforfull-scaleoperation. Documentation[edit] Animportant(andoftenoverlooked)taskisdocumentingtheinternaldesignofyourbotforthepurposeoffuturemaintenanceandenhancement.Thisisespeciallyimportantifyouaregoingtoallowclonesofyourbot.Ideally,youshouldpostthesourcecodeofyourbotonitsuserpageorinarevisioncontrolsystem(see#Open-sourcebots)ifyouwantotherstobeabletorunclonesofit.Thiscodeshouldbewelldocumented(usuallyusingcomments)foreaseofuse. Queries/Complaints[edit] Youshouldbereadytorespondtoqueriesaboutorobjectionstoyourbotonyourusertalkpage,especiallyifitisoperatinginapotentiallysensitivearea,suchasfair-useimagecleanup. Maintenance[edit] Maintainingandenhancingyourbottocopewithnewlydiscoveredbugsornewrequirementscantakefarmoretimethantheinitialdevelopmentofthesoftware.Toeasemaintenance,documentyourcodefromthebeginning. Majorfunctionalitychangesofapprovedbotsmustbeapproved. Generalguidelinesforrunningabot[edit] Inadditiontotheofficialbotpolicy,whichcoversthemainpointstoconsiderwhendevelopingyourbot,thereareanumberofmoregeneraladvisorypointstoconsiderwhendevelopingyourbot. Botbestpractices[edit] SetacustomUser-Agentheaderforyourbot,pertheWikimediaUser-Agentpolicy.Ifyoudon't,yourbotmayencountererrorsandmayendupblockedbythetechnicalstaffattheserverlevel. Usethemaxlagparameterwithamaximumlagof5seconds.Thiswillenablethebottorunquicklywhenserverloadislow,andthrottlethebotwhenserverloadishigh. Ifwritingabotinaframeworkthatdoesnotsupportmaxlag,limitthetotalrequests(readandwriterequeststogether)tonomorethan10/minute. UsetheAPIwheneverpossible,andsetthequerylimitstothelargestvaluesthattheserverpermits,tominimizethetotalnumberofrequeststhatmustbemade. Edit(write)requestsaremoreexpensiveinservertimethanreadrequests.Beedit-lightanddesignyourcodetokeepeditstoaminimum. Trytoconsolidateedits.Onesinglelargeeditisbetterthan10smallerones. EnableHTTPpersistentconnectionsandcompressioninyourHTTPclientlibrary,ifpossible. Donotmakemulti-threadedrequests.Waitforoneserverrequesttocompletebeforebeginninganother. Backoffuponreceivingerrorsfromtheserver.Errorssuchassquidtimeoutsareoftenanindicationofheavyserverload.Useasequenceofincreasinglylongerdelaysbetweenrepeatedrequests. Makeuseofassertiontoensureyourbotisloggedin. Testyourcodethoroughlybeforemakinglargeautomatedruns.Individuallyexaminealleditsontrialrunstoverifytheyareperfect. Commonbotfeaturesyoushouldconsiderimplementing[edit] Manualassistance[edit] Ifyourbotisdoinganythingthatrequiresjudgmentorevaluationofcontext(e.g.,correctingspelling)thenyoushouldconsidermakingyourbotmanually-assisted,whichmeansthatahumanverifiesalleditsbeforetheyaresaved.Thissignificantlyreducesthebot'sspeed,butitalsosignificantlyreduceserrors. Disablingthebot[edit] Itshouldbeeasytoquicklydisableyourbot.Ifyourbotgoesbad,itisyourresponsibilitytocleanupafterit!Youcouldhavethebotrefusetorunifamessagehasbeenleftonitstalkpage,ontheassumptionthatthemessagemaybeacomplaintagainstitsactivities;thiscanbecheckedusingtheAPImeta=userinfoquery(example).Oryoucouldhaveapagethatwillturnthebotoffwhenchanged;thiscanbecheckedbyloadingthepagecontentsbeforeeachedit. Signature[edit] Justlikeahuman,ifyourbotmakeseditstoatalkpageonWikipedia,itshouldsignitspostwithfourtildes(~~~~).Signaturesbelongonlyontalknamespaceswiththeexceptionofprojectpagesusedfordiscussion(e.g.,articlesfordeletion). BotFlag[edit] Abot'seditswillbevisibleatSpecial:RecentChanges,unlesstheeditsaresettoindicateabot.Oncethebothasbeenapprovedandgivenitsbotflagpermission,onecanaddthe"bot-True"totheAPIcall-seemw:API:Edit#Parametersinordertohidethebot'seditsinSpecial:RecentChanges.InPython,usingeithermwclientorwikitools,thenaddingBot=Truetotheedit/savecommandwillsettheeditasabotedit-e.g.PageObject.edit(text=pagetext,bot=True,summary=pagesummary). Monitoringthebotstatus[edit] Ifthebotisfullyautomatedandperformsregularedits,youshouldperiodicallycheckitrunsasspecified,anditsbehaviourhasnotbeenalteredbysoftwarechanges.ConsideraddingittoWikipedia:Botactivitymonitortobenotifiedifthebotstopsworking. Open-sourcebots[edit] Manybotoperatorschoosetomaketheircodeopensource,andoccasionallyitmayberequiredbeforeapprovalforparticularlycomplexbots.Makingyourcodeopensourcehasseveraladvantages: Itallowsotherstoreviewyourcodeforpotentialbugs.Aswithprose,itisoftendifficultfortheauthorofcodetoadequatelyreviewit. Otherscanuseyourcodetobuildtheirownbots.Ausernewtobotwritingmaybeabletouseyourcodeasanexampleoratemplatefortheirownbots. Itencouragesgoodsecuritypractices,ratherthansecuritythroughobscurity. Ifyouabandontheproject,itallowsotheruserstorunyourbottaskswithouthavingtowritenewcode. Open-sourcecode,whilerarelyrequired,istypicallyencouragedinkeepingwiththeopenandtransparentnatureofWikipedia. Beforesharingcode,makesurethatsensitiveinformationsuchaspasswordsisseparatedintoafilethatisn'tmadepublic. Therearemanyoptionsavailableforuserswishingtomaketheircodeopen.Hostingthecodeinasubpageofthebot'suserspacecanbeahassletomaintainifnotautomatedandresultsinthecodebeingmulti-licensedunderWikipedia'slicensingtermsinadditiontoanyothertermsyoumayspecify.AbettersolutionistousearevisioncontrolsystemsuchasSVN,Git,orMercurial.Wikipediahasarticlescomparingthedifferentsoftwareoptionsandwebsitesforcodehosting,manyofwhichhavenocost. Programminglanguagesandlibraries[edit] Seealso:mw:API:Clientcodeandmw:Alternativeparsers Botscanbewritteninalmostanyprogramminglanguage.Thechoiceofalanguagedependsontheexperienceandpreferencesofthebotwriter,andontheavailabilityoflibrariesrelevanttobotdevelopment.Thefollowinglistincludessomelanguagescommonlyusedforbots: Awk[edit] GNUAwkisaneasylanguageforbotssmallandlarge,includingOAuth. Frameworkandlibraries:BotWikiAwk ExamplebotsintheGitHubaccountofUser:GreenCatGitHub Perl[edit] Iflocatedonawebserver,youcanstartyourprogramrunningandinterfacewithyourprogramwhileitisrunningviatheCommonGatewayInterfacefromyourbrowser.Ifyourinternetserviceproviderprovidesyouwithwebspace,thechancesaregoodthatyouhaveaccesstoaPerlbuildonthewebserverfromwhichyoucanrunyourPerlprograms. Libraries: MediaWiki::API –BasicinterfacetotheAPI,allowingscriptstoautomateeditingandextractionofdatafromMediaWikidrivensites. MediaWiki::Bot –AfairlycompleteMediaWikibotframeworkwritteninPerl.ProvidesahigherlevelofabstractionthanMediaWiki::API.Pluginsprovideadministratorandstewardfunctionality.Currentlyunsupported. PHP[edit] PHPcanalsobeusedforprogrammingbots.MediaWikidevelopersarealreadyfamiliarwithPHP,sincethatisthelanguageMediaWikianditsextensionsarewrittenin.PHPisanespeciallygoodchoiceifyouwishtoprovideawebform-basedinterfacetoyourbot.Forexample,supposeyouwantedtocreateabotforrenamingcategories.YoucouldcreateanHTMLformintowhichyouwilltypethecurrentanddesirednamesofacategory.Whentheformissubmitted,yourbotcouldreadtheseinputs,theneditallthearticlesinthecurrentcategoryandmovethemtothedesiredcategory.(Obviously,anybotwithaforminterfacewouldneedtobesecuredsomehowfromrandomwebsurfers.) ThePHPbotfunctionstablemayprovidesomeinsightintothecapabilitiesofthemajorbotframeworks. CurrentPHPbotframeworks Keypeople[php1] Name PHPversion Lastupdate UsesAPI[php2] Exclusioncompliant Adminfunctions Plugins Repository Notes User:Cyberpower678,User:Addshore,andUser:Jarry1250 Peachy 5.2.1 2017 Yes Yes Yes Yes GitHub Largeframework,currentlyundergoingrewrite.Documentationcurrentlynon-existent,sopokeUser:Cyberpower678forhelp. User:Addshore mediawiki-api-base 5.3–7 2018 Yes N/A N/A extralibs GitHub Baselibraryforinteractionwiththemediawikiapi,providesyouwithwaystohandleloggingin,outandhandlingtokensaswellaseasilygettingandpostingrequests. User:Addshore mediawiki-api 5.3 2019 Yes No some extralibs GitHub Builtontopofmediawiki-api-basethisaddsmoreadvancedservicesfortheapisuchasRevisionGetter,UserGetter,PageDeleter,RevisionPatroller,RevisionSaveretc.Supportschunkeduploading. User:nzhamstarandUser:Xymph Wikimate 5.3.2 2021 Yes No No No GitHub Supportsmainarticleandfilestuff.Authentication,checkingifpagesexist,readingandeditingpages/sections.Gettingfileinformation,downloadinganduploadingfiles.Testedandworking.Aimstobeeasytouse. ГригорГачев Apibot 5.1 2015 Yes Yes Yes Yes onwiki FullAPIsupportuptoMW1.21incl.,persistentconnections,gzippedxfers,HTTPS,HTTPauth,GETsorting,autosite/user/paraminfocachingandusage,pagebotexclusioncompliance,closeto1000functions,DBsupport,etcetc.Easilyextendablemodularstructure.AnUNIX-likeoverlayed'assemblyline'framework.AGPL3.0orlater. ChrisG,wbm1058 botclasses.phpbotclasses.php 7.4 20212019 Yes Yes Yes No onwiki(2021),GitHub(2019) Forkofolderwikibot.classes(usedbyClueBotandSoxBot).Updatedfor2010and2015APIchanges.Supportsfileuploading. ^Doesnotincludethosewhoworkedonframeworksforkedtocreatelistedframework. ^Wherepossible.ExcludesuploadingimagesandothersuchtaskswhicharenotcurrentlysupportedbytheAPI. Python[edit] Libraries: Pywikibot –Probablythemostusedbotframework. ceterach –AninterfaceforinteractingwithMediaWiki wikitools –APython-2onlylightweightbotframeworkthatusestheMediaWikiAPIexclusivelyforgettingdataandediting,usedandmaintainedbyMr.Z-man(downloads) mwclient –AnAPI-basedframeworkmaintainedbyBryan mwparserfromhell –Awikitextparser,maintainedbyTheEarwig pymediawiki –Aread-onlyMediaWikiAPIwrapperinPython,whichissimpletouse. MATLAB[edit] MatWiki –apreliminary(asofFeb2019)MATLABR2016b(9.1.x)clientsupportingjustbot-logins&semantic#askqueries. Microsoft.NET[edit] Microsoft.NETisasetoflanguagesincludingC#,C++/CLI,VisualBasic.NET,J#,JScript.NET,IronPython,andWindowsPowerShell.UsingMonoProject,.NETprogramscanalsorunonLinux,Unix,BSD,SolarisandmacOSaswellasunderWindows. Libraries: DotNetWikiBotFramework –afull-featuredclientAPIon.NET,thatallowstobuildprogramsandwebrobotseasilytomanageinformationonMediaWiki-poweredsites.Nowtranslatedtoseverallanguages.DetailedcompileddocumentationisavailableinEnglish. WikiFunctions.NETlibrary –BundledwithAWB,isalibraryofstuffusefulforbots,suchasgeneratinglists,loading/editingarticles,connectingtotherecentchangesIRCchannelandmore. Java[edit] Libraries: JavaWikiBotFramework –AJavawikibotframework wiki-java –AJavawikibotframeworkthatisonlyonefile WPCleaner –ThelibraryusedbytheWPCleanertool jwiki –Asimpleandeasy-to-useJavawikibotframework Node.js[edit] Libraries: mwn –AlibraryactivelymaintainedandwritteninmodernES6usingpromises(supportingasync–await).Thisisalargelibrary,andhasclassesforconvenientlyworkingwithpagetitlesandwikitext(includinglimitedwikitextparsingcapabilities).AlsosupportsTypeScript.SeemwnonGitHub. mock-mediawiki –AnimplementationoftheMediaWikiJSinterfaceinNode.js.Seemock-mediawikionGitHub. wikiapi –AsimplewaytoaccessMediaWikiAPIviaJavaScriptwithsimplewikitextparser,usingCeJSMediaWikimodule.SeeWikipediabotexamplesonGitHub. Ruby[edit] Libraries: MediaWiki::Butt –APIclient.Activelymaintained.Seeevaluation mediawiki/ruby/api –APIclientbyWikimediaReleaseEngineeringTeam.LastupdatedDecember2017,nolongermaintained,butstillworks. wikipedia-client –APIclient.LastupdatedMarch2018.Unknownifstillworks. MediaWiki::Gateway –APIclient.LastupdatedJanuary2016.TesteduptoMediaWiki1.22,wasthencompatiblewithWikimediawikis.Unknownifstillworks. CommonLisp[edit] CL-MediaWiki –implementsMediaWikiAPIasaCommonLisppackage.IsplannedtouseJSONasaquerydataformat.Supportsmaxlagandassertion. Haskell[edit] http://hackage.haskell.org/package/mediawiki VBScript[edit] VBScriptisascriptinglanguagebasedontheVisualBasicprogramminglanguage.TherearenopublishedbotframeworksforVBScript,butsomeexamplesofbotsthatuseitcanbeseenbelow: User:Smallman12q/Scripts/cleanuplistingtowiki –Loginandgivepreviewofedit User:Smallman12q/VBS/Savewatchlist –Login,getrawwatchlist,savetofile,logout,closeIE Commons:User:Smallbot#Sources –SeveralscriptsshowingtheusageofVBScript(Javascript,XMLHTTP,MSHTML,XMLDOM,COM)forbatchuploads. Lua[edit] DuringtheLuaAnnualWorkshop2016,JimCarterandDfavrostarteddevelopingLua'sbotframeworkforWikimediaprojects.PleasecontactJimCarterontheirtalkpagetodiscussaboutthedevelopment. mwtestisanexampleusingLuatowriteawikibot,createdbyUser:AlexanderMisel,withsimpleAPI. vteWikipediatechnicalhelpGetpersonaltechnicalhelpattheTeahouse,Helpdesk,Villagepump(technical),talkpagesorIRC.Generaltechnicalhelp Browsernotes Bypasscache Keyboardshortcuts Editing CharInsert Editconflict Edittoolbar Reverting Howtocreateapage IRC Tutorial Mobileaccess Multilingualsupport Pagehistory Pageinformation Pagename Help Printing Softwarenotices Editnotice SpecialCharacters Entering Useraccesslevels VisualEditor Userguide Specialpage-related Specialpagehelp Editfilter Emailingusers Loggingin Resetpasswords Logs Movingapage Fixingcut-and-pastemoves Non-adminandadmin-onlypagemoves Notifications/Echo FAQ PageCuration Pageimport Pendingchanges Randompages Recentchanges Relatedchanges Searching Linksearch Tags Usercontributions Watchlist Whatlinkshere Wikitext Wikitext Cheatsheet Columns Line-breakhandling Lists Magicwords Forbeginners Conditionalexpressions Switchparserfunction Timefunction Redirects SectionsandTOCs Tables Introduction Basics Advancedtableformatting Collapsing Conditionaltables Sorting Usingcolours Linksanddiffs Links Interlanguage Interwiki Permanent Diffs Simplestdiffguide Simplediffandlinkguide Completediffandlinkguide Colontrick Linkcolor Pipetrick URLs Mediafiles:images,videosandsounds Mediahelp Files Creationandusage MovingfilestoCommons Images Introductiontoimages Picturetutorial Preparingimagesforupload Uploadingimages Optionstohideanimage Extendedimagesyntax SVGhelp Gallerytag Graphicstutorials Basicbitmapimageediting Howtoimproveimagequality GraphicsLabresources Soundfilemarkup Visualfilemarkup Othergraphics Familytrees Graphsandcharts Howtocreate Barcharts Toscalecharts Mathformulas Mathsymbols Musicalscores Musicalsymbols Timeline EasyTimelinesyntax WikiHierosyntax TemplatesandLuamodules Templates Advancedtemplatecoding Templatedocumentation Templateindex Templatelimits Templatesandboxandtestcases Citationtemplates Luahelp Luaproject Resources Todo Substitution Purge Jobqueue Transclusion Labeledsection Costsandbenefits GuidetoScribbling Datastructure Namespaces Main/Article Category Draft File Filedescriptionpage Help Portal Project/Wikipedia Talk Archiving Simple Template User Userpagedesign MediaWiki Bugreportsandfeaturerequests Systemmessage TimedMediaHandlerextension Module Special HTMLandCSS CascadingStyleSheets HTMLinwikitext CatalogueofCSSclasses Common.jsandcommon.css UserCSSformonospacedcodingfont Classesinmicroformats Markupvalidation Spantags Usefulstyles Customisationandtools Preferences Gadgets Skins Citationtools Cleaningupvandalismtools Customizingwatchlists Hidepages IRCScripts Userscripts Guide Techniques Userstyle Tools Alternativebrowsing Browsertools Editingtools Navigationshortcuts Optimumtoolset WikimediaCloudServices BetaFeaturesatMediaWiki Automatedediting AfChelperscript AutoWikiBrowser Bots Creating HotCat Huggle Navigationpopups RedWarn Twinkle WPCleaner Inactive igloo STiki Seealso:Category:Wikipediahow-to Category:WikipediainformationpagesFurthernavigationat:Helppages Administrators Accessibility Accounts Bots Referencing Citationmetadata Templates Userscripts Retrievedfrom"https://en.wikipedia.org/w/index.php?title=Help:Creating_a_bot&oldid=1063308987" Categories:WikipediainformationpagesWikipediabotsHiddencategories:Wikipediamove-protectedprojectpagesHelppageswithshortdescription Navigationmenu Personaltools NotloggedinTalkContributionsCreateaccountLogin Namespaces HelppageTalk English expanded collapsed Views ReadEditViewhistory More expanded collapsed Search Navigation MainpageContentsCurrenteventsRandomarticleAboutWikipediaContactusDonate Contribute HelpLearntoeditCommunityportalRecentchangesUploadfile Tools WhatlinkshereRelatedchangesUploadfileSpecialpagesPermanentlinkPageinformationWikidataitem Print/export DownloadasPDFPrintableversion Inotherprojects MediaWikiWikidata Languages العربيةAzərbaycancaЧӑвашлаEspañolفارسیFrançaisGalego한국어हिन्दीHrvatskiBahasaIndonesiaქართულიМакедонскиPortuguêsРусскийСрпски/srpskiТатарча/tatarçaతెలుగుTürkçeاردوTiếngViệt粵語中文 Editlinks



請為這篇文章評分?