From 83cbdc6f3636c2bd2df77334b2b06240d5b7045a Mon Sep 17 00:00:00 2001 From: MatmaRex Date: Mon, 1 Jul 2013 13:25:41 +0200 Subject: [PATCH] Allow creation of empty MediaWiki: pages This is useful now since it's possible to disable messages by blanking them (see bug 14176). Instead disallow creation of page contents equivalent to the default message to serve the same purpose as disallowing blanking did (prevent edits which wouldn't change anything anyway; the edit form is even prefilled with the default contents). Bug: 50124 Change-Id: I070036f341b866cda67eb928c5b74ad2ce6c527c --- includes/EditPage.php | 13 +++- tests/phpunit/includes/EditPageTest.php | 89 +++++++++++++++++++++++-- 2 files changed, 93 insertions(+), 9 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 84bb493855..96cc90858d 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1507,8 +1507,17 @@ class EditPage { return $status; } - # Don't save a new article if it's blank. - if ( $this->textbox1 == '' ) { + // Don't save a new page if it's blank or if it's a MediaWiki: + // message with content equivalent to default (allow empty pages + // in this case to disable messages, see bug 50124) + $defaultMessageText = $this->mTitle->getDefaultMessageText(); + if( $this->mTitle->getNamespace() === NS_MEDIAWIKI && $defaultMessageText !== false ) { + $defaultText = $defaultMessageText; + } else { + $defaultText = ''; + } + + if ( $this->textbox1 === $defaultText ) { $status->setResult( false, self::AS_BLANK_ARTICLE ); wfProfileOut( __METHOD__ ); return $status; diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index 00eba30a4e..3544e5c04f 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -173,15 +173,90 @@ class EditPageTest extends MediaWikiTestCase { } public function testCreatePage() { - $text = "Hello World!"; - $edit = array( - 'wpTextbox1' => $text, - 'wpSummary' => 'just testing', + $this->assertEdit( + 'EditPageTest_testCreatePage', + null, + null, + array( + 'wpTextbox1' => "Hello World!", + ), + EditPage::AS_SUCCESS_NEW_ARTICLE, + "Hello World!", + "expected article being created" + )->doDeleteArticleReal( 'EditPageTest_testCreatePage' ); + + $this->assertEdit( + 'EditPageTest_testCreatePage', + null, + null, + array( + 'wpTextbox1' => "", + ), + EditPage::AS_BLANK_ARTICLE, + null, + "expected article not being created if empty" + ); + + + $this->assertEdit( + 'MediaWiki:January', + null, + 'UTSysop', + array( + 'wpTextbox1' => "Not January", + ), + EditPage::AS_SUCCESS_NEW_ARTICLE, + "Not January", + "expected MediaWiki: page being created" + )->doDeleteArticleReal( 'EditPageTest_testCreatePage' ); + + $this->assertEdit( + 'MediaWiki:EditPageTest_testCreatePage', + null, + 'UTSysop', + array( + 'wpTextbox1' => "", + ), + EditPage::AS_BLANK_ARTICLE, + null, + "expected not-registered MediaWiki: page not being created if empty" ); - $this->assertEdit( 'EditPageTest_testCreatePafe', null, null, $edit, - EditPage::AS_SUCCESS_NEW_ARTICLE, $text, - "expected successfull creation with given text" ); + $this->assertEdit( + 'MediaWiki:January', + null, + 'UTSysop', + array( + 'wpTextbox1' => "", + ), + EditPage::AS_SUCCESS_NEW_ARTICLE, + "", + "expected registered MediaWiki: page being created even if empty" + )->doDeleteArticleReal( 'EditPageTest_testCreatePage' ); + + $this->assertEdit( + 'MediaWiki:Ipb-default-expiry', + null, + 'UTSysop', + array( + 'wpTextbox1' => "", + ), + EditPage::AS_BLANK_ARTICLE, + "", + "expected registered MediaWiki: page whose default content is empty not being created if empty" + ); + + $this->assertEdit( + 'MediaWiki:January', + null, + 'UTSysop', + array( + 'wpTextbox1' => "January", + ), + EditPage::AS_BLANK_ARTICLE, + null, + "expected MediaWiki: page not being created if text equals default message" + ); } public function testUpdatePage() { -- 2.20.1