From: Brad Jorsch Date: Mon, 5 Aug 2013 15:26:49 +0000 (-0400) Subject: API: DWIM for action=edit§ion=new&appendtext=... X-Git-Tag: 1.31.0-rc.0~19037^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;h=a67f50cf39f4621417b8205fb874fcaec072f583;p=lhc%2Fweb%2Fwiklou.git 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 --- 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' ); + } } }