Merge "Allow creation of empty MediaWiki: pages"
authorBrion VIBBER <brion@wikimedia.org>
Tue, 2 Jul 2013 17:01:37 +0000 (17:01 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 2 Jul 2013 17:01:37 +0000 (17:01 +0000)
includes/EditPage.php
tests/phpunit/includes/EditPageTest.php

index 84bb493..96cc908 100644 (file)
@@ -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;
index 00eba30..3544e5c 100644 (file)
@@ -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() {