gregdek ([info]gregdek) wrote,
@ 2009-03-23 15:39:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Entry tags:fedora

Dear Lazyweb...
...I'd love to keep some of my daily task info on my local machine, so that I can keep track of it all offline -- but then update corresponding pages on the Fedora wiki with a simple script. Can anyone point me to some dead easy scripts in Python/Perl/PHP that takes local content, logs into the wiki, and shoves that content into the right place?




(5 comments) - (Post a new comment)

Wikipedia People
[info]ricky.fedorapeople.org
2009-03-23 08:52 pm UTC (link)
I noticed that the people in #wikimedia-tech seem to have a IRC bot that does just that. Maybe the source of the bot could be useful in making something like this.

(Reply to this)

Horrible hack...
[info]ctyler
2009-03-24 04:01 am UTC (link)
I had to do something similar just the other day ... it's a horrible hack, but it works.
#
# pmw :: post to mediawiki
#
# CTyler 2009-02-23
#
# This script is used to push a file into a mediawiki page
#

# Variables
TMP=/var/tmp                                # tmp dir
NAME=wikibot                                # mediawiki account
PASSWD=foobarbaz                            # mediawiki password
FINALPAGELOG=${TMP}/${NAME}_result_page.log # file to store results in
COOKIEJAR=${TMP}/${NAME}_cookie_jar         # cookie file
COOKIEJAR2=${TMP}/${NAME}_cookie_jar2       # 2nd cookie file
EDITCACHE=${TMP}/${NAME}_edit_cache         # edit cache file
HOST='wiki.example.com'                     # host part of url
WIKIPATH='/wiki'                            # path on host
PAGETITLE='Important_Stuff"                 # page within wiki
CONTENTFILE='/home/chris/tos/planet/mediawiki-planet-page.txt' # to upload

# Login, saving the cookies in $COOKIEJAR
curl 	-c $COOKIEJAR	 			\
	-d "wpName=${NAME}" 			\
	-d "wpPassword=${PASSWD}" 		\
	-d "wpLoginattempt=Log+in" 		\
	"http://${HOST}${WIKIPATH}/index.php/Special:UserLogin" \
	-o /dev/null

# Edit the duration of the session-only cookie
sed 	-i "s/\t0\t/\t1299999999\t/" 		\
	${COOKIEJAR}

# Get the edit page, to get values for wpEditToken, wpStartime, wpEdittime, put cookies in $COOKIEJAR2
curl 	-b @${COOKIEJAR} 			\
	-c ${COOKIEJAR2}			\
	"http://${HOST}${WIKIPATH}/index.php?title=${PAGETITLE}&action=edit" \
	-o ${EDITCACHE}

# Edit the duration of the session-only cookie
sed 	-i "s/\t0\t/\t1299999999\t/" 		\
	${COOKIEJAR2}

# Get various values and save them in files (wpEditToken can't be passed on command line)
wpEditToken=$(sed -n '/wpEditToken/s/^.*value="\([^"]*\)".*$/\1/p' ${EDITCACHE}| tr -d "\012")
wpEdittime=$(sed -n '/wpStarttime/s/^.*value="\([^"]*\)".*$/\1/p'  ${EDITCACHE}| tr -d "\012")
wpStarttime=$(sed -n '/wpEdittime/s/^.*value="\([^"]*\)".*$/\1/p'  ${EDITCACHE}| tr -d "\012")
wpAutoSummary=$(tr ">" "\012" <${EDITCACHE}|sed -n '/wpAutoSummary/s/^.*value="\([^"]*\)".*$/\1/p'| tr -d "\012")

# URL for final step...
URL="http://${HOST}${WIKIPATH}/index.php?title=${PAGETITLE}&action=submit"

# Sleep so we don't post an instant edit
sleep 1

# Post the form data, and save the results
curl 	-b @${COOKIEJAR2}			\
	-F "wpMinoredit=" 			\
	-F "wpWatchthis=" 			\
	-F "wpSummary="				\
	-F "wpAutoSummary=${wpAutoSummary}"	\
	-F "wpStarttime=${wpStarttime}" 	\
	-F "wpEdittime=${wpEdittime}"		\
	-F "wpSection=" 			\
	-F "wpScrolltop=" 			\
	-F "wpTextbox1=<${CONTENTFILE}" 	\
	-F "wpEditToken=${wpEditToken}" 	\
	-F "wpSave=Save page" 			\
	${URL}					\
	-L					\
	-o ${FINALPAGELOG}

(Reply to this) (Thread)

Re: Horrible hack...
[info]ctyler
2009-03-24 04:04 am UTC (link)
Somehow dropped the bash shebang at the top.
#!/bin/bash

(Reply to this) (Parent)

API
[info]ianweller.myopenid.com
2009-03-24 04:20 am UTC (link)
This may interest you -- https://fedoraproject.org/w/api.php

(Reply to this)

pywikipedia
[info]kevin_kofler
2009-03-25 08:31 am UTC (link)
pywikipedia is a Python-based SDK allowing you to do all sorts of manipulations on MediaWiki wikis. There are some sample scripts for common operations which work almost out of the box, you just have to provide a small .cfg file for the fedoraproject.org wiki, and there's a Python API you can use to write your own scripts.

(Reply to this)


(5 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…