From a67f50cf39f4621417b8205fb874fcaec072f583 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Mon, 5 Aug 2013 11:26:49 -0400 Subject: [PATCH] API: DWIM for action=edit§ion=new&appendtext=... While it doesn't make a whole lot of sense to prepend or append with section=new, the user certainly doesn't intend to be copying the contents of section 0. In the spirit of "do what I mean", we should probably prepend/append to empty text in this situation. Bug: 52538 Change-Id: I9b03635906ca665a4f68b3bd35d05ae9108e2356 --- RELEASE-NOTES-1.22 | 2 ++ includes/api/ApiEditPage.php | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index a36d8cfa41..51ea25464f 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -293,6 +293,8 @@ production. with the content. * (bug 51342) prop=imageinfo iicontinue now contains the dbkey, not the text version of the title. +* (bug 52538) action=edit will now use empty text instead of the contents + of section 0 when passed prependtext or appendtext with section=new. === Languages updated in 1.22=== diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 22e4dedfe9..9c079da8f7 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -159,12 +159,17 @@ class ApiEditPage extends ApiBase { $this->dieUsage( "Sections are not supported for this content model: $modelName.", 'sectionsnotsupported' ); } - // Process the content for section edits - $section = intval( $params['section'] ); - $content = $content->getSection( $section ); + if ( $params['section'] == 'new' ) { + // DWIM if they're trying to prepend/append to a new section. + $content = null; + } else { + // Process the content for section edits + $section = intval( $params['section'] ); + $content = $content->getSection( $section ); - if ( !$content ) { - $this->dieUsage( "There is no section {$section}.", 'nosuchsection' ); + if ( !$content ) { + $this->dieUsage( "There is no section {$section}.", 'nosuchsection' ); + } } } -- 2.20.1