Extension:SimpleUpdate

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
SimpleUpdate

Release status: unknown

Implementation Page action
Description This extension allows updating page with just one URL hit.
Author(s) Amir Szekely
License No license specified
Download see below

Check usage (experimental)

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.13

<?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)) {
    global $wgArticle;
    $title = Title::newFromText($title);
    $wgArticle = $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 (!$u->checkPassword( $password )) {
    return false;
  }
 
  if (!in_array('sysop', $u->getEffectiveGroups())) {
    return false;
  }
 
  // update logged on user
  global $wgUser;
  $wgUser = $u;
 
  return true;
}
 
?>
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox