}
/**
- * A query module to list all external URLs found on a given set of pages.
+ * A module that allows for editing and creating pages.
*
+ * Currently, this wraps around the EditPage class in an ugly way,
+ * EditPage.php should be rewritten to provide a cleaner interface
* @ingroup API
*/
class ApiEditPage extends ApiBase {
if($params['createonly'] && $titleObj->exists())
$this->dieUsageMsg(array('createonly-exists'));
+ if($params['nocreate'] && !$titleObj->exists())
+ $this->dieUsageMsg(array('nocreate-missing'));
// Now let's check whether we're even allowed to do this
$errors = $titleObj->getUserPermissionsErrors('edit', $wgUser);
$this->dieUsageMsg($errors[0]);
$articleObj = new Article($titleObj);
+ $toMD5 = $params['text'];
if(!is_null($params['appendtext']) || !is_null($params['prependtext']))
{
$content = $articleObj->getContent();
$params['text'] = $params['prependtext'] . $content . $params['appendtext'];
+ $toMD5 = $params['prependtext'] . $params['appendtext'];
}
# See if the MD5 hash checks out
if(isset($params['md5']))
- if(md5($params['text']) !== $params['md5'])
+ if(md5($toMD5) !== $params['md5'])
$this->dieUsageMsg(array('hashcheckfailed'));
$ep = new EditPage($articleObj);
case EditPage::AS_CONFLICT_DETECTED:
$this->dieUsageMsg(array('editconflict'));
#case EditPage::AS_SUMMARY_NEEDED: Can't happen since we set wpIgnoreBlankSummary
- #case EditPage::AS_TEXTBOX_EMPTY: Can't happen since we don't do sections
+ case EditPage::AS_TEXTBOX_EMPTY:
+ $this->dieUsageMsg(array('emptynewsection'));
case EditPage::AS_END:
# This usually means some kind of race condition
# or DB weirdness occurred. Throw an unknown error here.
- $this->dieUsageMsg(array('unknownerror', 'AS_END'));
+ $this->dieUsageMsg(array('unknownerror'));
case EditPage::AS_SUCCESS_NEW_ARTICLE:
$r['new'] = '';
case EditPage::AS_SUCCESS_UPDATE:
$r['result'] = "Success";
$r['pageid'] = $titleObj->getArticleID();
$r['title'] = $titleObj->getPrefixedText();
- $newRevId = $titleObj->getLatestRevId();
+ # HACK: We create a new Article object here because getRevIdFetched()
+ # refuses to be run twice, and because Title::getLatestRevId()
+ # won't fetch from the master unless we select for update, which we
+ # don't want to do.
+ $newArticle = new Article($titleObj);
+ $newRevId = $newArticle->getRevIdFetched();
if($newRevId == $oldRevId)
$r['nochange'] = '';
else
'basetimestamp' => null,
'recreate' => false,
'createonly' => false,
+ 'nocreate' => false,
'captchaword' => null,
'captchaid' => null,
'watch' => false,
'Used to detect edit conflicts; leave unset to ignore conflicts.'
),
'recreate' => 'Override any errors about the article having been deleted in the meantime',
- 'createonly' => 'Don\'t create the page if it exists already',
+ 'createonly' => 'Don\'t edit the page if it exists already',
+ 'nocreate' => 'Throw an error if the page doesn\'t exist',
'watch' => 'Add the page to your watchlist',
'unwatch' => 'Remove the page from your watchlist',
'captchaid' => 'CAPTCHA ID from previous request',
'captchaword' => 'Answer to the CAPTCHA',
- 'md5' => 'The MD5 hash of the new article text. If set, the edit won\'t be done unless the hash is correct',
+ 'md5' => array( 'The MD5 hash of the text parameter, or the prependtext and appendtext parameters concatenated.',
+ 'If set, the edit won\'t be done unless the hash is correct'),
'prependtext' => array( 'Add this text to the beginning of the page. Overrides text.',
'Don\'t use together with section: that won\'t do what you expect.'),
'appendtext' => 'Add this text to the end of the page. Overrides text',