Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/88250
Change subject: Replace sajax with an API module
......................................................................
Replace sajax with an API module
Bug: 55396
Change-Id: I22163a53c482b964e59d56ebe1a3c61bb889bc83
---
A ApiSaveDrafts.php
M Drafts.php
2 files changed, 118 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Drafts
refs/changes/50/88250/1
diff --git a/ApiSaveDrafts.php b/ApiSaveDrafts.php
new file mode 100644
index 0000000..5c2b4bb
--- /dev/null
+++ b/ApiSaveDrafts.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * API module to save Drafts
+ *
+ * @file
+ * @ingroup API
+ * @author Kunal Mehta
+ */
+class ApiSaveDrafts extends ApiBase {
+ public function execute() {
+
+ if ( $this->getUser()->isAnon() ) {
+ $this->dieUsage( 'You must be logged in to save
drafts.', 'notloggedin' );
+ }
+
+ $params = $this->extractRequestParams();
+
+ $draft = Draft::newFromID( $params['id'] );
+ $draft->setToken( $params['drafttoken'] );
+ $draft->setTitle( Title::newFromText( $params['title'] ) );
+ $draft->setSection( $params['section'] == '' ? null :
$params['section'] );
+ $draft->setStartTime( $params['starttime'] );
+ $draft->setEditTime( $params['edittime'] );
+ $draft->setSaveTime( wfTimestampNow() );
+ $draft->setScrollTop( $params['scrolltop'] );
+ $draft->setText( $params['text'] );
+ $draft->setSummary( $params['summary'] );
+ $draft->setMinorEdit( $params['minoredit'] );
+ $draft->save();
+
+ $this->getResult()->addValue(
+ null,
+ $this->getModuleName(),
+ array( 'id' => $draft->getID() )
+ );
+
+ }
+
+ public function getDescription() {
+ return 'Save a draft';
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'id' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_REQUIRED => true
+ ),
+ 'title' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true
+ ),
+ 'section' => array(
+ ApiBase::PARAM_TYPE => 'integer'
+ ),
+ 'starttime' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'edittime' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'scrolltop' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'text' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true
+ ),
+ 'summary' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true
+ ),
+ 'minoredit' => array(
+ ApiBase::PARAM_TYPE => 'boolean',
+ ApiBase::PARAM_REQUIRED => true
+ ),
+ 'token' => null,
+ );
+ }
+
+ public function getPossibleErrors() {
+ return array(
+ array( 'notloggedin'),
+ );
+ }
+
+ public function getResultProperties() {
+ return array(
+ '' => array(
+ 'id' => 'integer',
+ )
+ );
+ }
+
+ public function mustBePosted() {
+ return true;
+ }
+
+
+ public function needsToken() {
+ return true;
+ }
+
+ public function getTokenSalt() {
+ return '';
+ }
+
+ public function isWriteMode() {
+ return true;
+ }
+
+}
diff --git a/Drafts.php b/Drafts.php
index ceb4724..2193b47 100644
--- a/Drafts.php
+++ b/Drafts.php
@@ -66,6 +66,11 @@
$wgAutoloadClasses['Draft'] = $dir . 'Drafts.classes.php';
$wgAutoloadClasses['DraftHooks'] = $dir . 'Drafts.hooks.php';
+// API module
+$wgAutoloadClasses['ApiSaveDrafts'] = "$dir/ApiSaveDrafts.php";
+$wgAPIModules['savedrafts'] = 'ApiSaveDrafts';
+
+
// Internationalization
$wgExtensionMessagesFiles['Drafts'] = $dir . 'Drafts.i18n.php';
$wgExtensionMessagesFiles['DraftsAlias'] = $dir . 'Drafts.alias.php';
@@ -95,9 +100,6 @@
// Register load hook
$wgHooks['EditPage::showEditForm:initial'][] = 'DraftHooks::loadForm';
-
-// Register ajax response hook
-$wgAjaxExportList[] = 'DraftHooks::save';
// Register JS / CSS
$wgResourceModules[ 'ext.Drafts' ] = array(
--
To view, visit https://gerrit.wikimedia.org/r/88250
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I22163a53c482b964e59d56ebe1a3c61bb889bc83
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Drafts
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits