Extension:SimpleUpdate
From MediaWiki.org
|
SimpleUpdate Release status: unknown |
|
|---|---|
| Implementation | Page action |
| Description | This extension allows updating page with just one URL hit. |
| Author(s) | Amir Szekely |
| Download | see below |
The SimpleUpdate extension allows updating pages with just one URL hit. It's ideal for automation scripts, such as software release scripts. It requires an extension on the server side, but it makes the client usage much simpler than existing solutions as it has no external library requirements.
To prevent abuse and vandalism, only sysops are allowed to update pages.
WARNING: always pass the password using POST and not GET method!
--Kichik 18:34, 24 November 2005 (UTC)
[edit] Python Client Code
WIKI_USER = 'kichik' WIKI_PASSWORD = 'xxx' WIKI_UPDATE_URL = 'http://my.wiki.org/Special:Simpleupdate?action=raw' def update_wiki_page(page, data, summary): import urllib post = 'su_user=' + urllib.quote(WIKI_USER) post += '&su_password=' + urllib.quote(WIKI_PASSWORD) post += '&su_title=' + urllib.quote(page) post += '&su_data=' + urllib.quote(data) post += '&su_summary=' + urllib.quote(summary) return urllib.urlopen(WIKI_UPDATE_URL, post).read() == 'success' update_wiki_page('Some Page', 'new content', 'summary of changes') update_wiki_page('Some other page', 'some other content', 'more sum')
[edit] Code for MediaWiki 1.5
<?php require_once( "SpecialPage.php" ); $wgExtensionFunctions[] = "wfSimpleUpdateSetup"; $wgExtensionCredits['other'][] = array( 'name' => 'Simple Update', 'description' => 'allows simple page updates using one URL', 'author' => 'Amir Szekely' ); function wfSimpleUpdateSetup() { global $wgMessageCache; $wgMessageCache->addMessages(array('simpleupdate' => 'Simple Update')); SpecialPage::addPage(new SpecialPage("Simpleupdate", '', false, 'wfSpecialSimpleUpdate', __FILE__)); } function wfSpecialSimpleUpdate() { global $wgOut, $wgRequest; $action = $wgRequest->getText('action'); $user = $wgRequest->getText('su_user'); $password = $wgRequest->getText('su_password'); $title = $wgRequest->getText('su_title'); $data = $wgRequest->getText('su_data'); $summary = $wgRequest->getText('su_summary'); if (wfSimpleUpdateLogin($user, $password)) { $title = Title::newFromText($title); $article = new Article($title); $article->updateArticle($data, $summary, false, $title->userIsWatching()); $result = 'success'; } else { $result = 'bad login'; } if ($action == 'raw') { $wgOut->disable(); header('Pragma: nocache'); echo $result; return; } $wgOut->addWikiText($result); } function wfSimpleUpdateLogin($user, $password) { // ripped from SpecialUserlogin.php $u = User::newFromName( $user ); if( is_null( $u ) ) { return false; } if ( 0 == $u->getID() ) { global $wgAuth; /** * If the external authentication plugin allows it, * automatically create a new account for users that * are externally defined but have not yet logged in. */ if ( $wgAuth->autoCreate() && $wgAuth->userExists( $u->getName() ) ) { if ( $wgAuth->authenticate( $u->getName(), $this->mPassword ) ) { $u =& $this->initUser( $u ); } else { return false; } } else { return false; } } else { $u->loadFromDatabase(); } if (!$u->checkPassword( $password )) { return false; } if (!$u->isSysop()) { return false; } // update logged on user global $wgUser; $wgUser = $u; return true; } ?>

