Allow creation of empty MediaWiki: pages
authorMatmaRex <matma.rex@gmail.com>
Mon, 1 Jul 2013 11:25:41 +0000 (13:25 +0200)
committerMatmaRex <matma.rex@gmail.com>
Tue, 2 Jul 2013 16:40:02 +0000 (18:40 +0200)
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
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() {