Merge "Set parameter default to array() in WebResponse::setcookie()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 27 Mar 2015 16:33:18 +0000 (16:33 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 27 Mar 2015 16:33:18 +0000 (16:33 +0000)
includes/api/ApiParse.php
tests/phpunit/data/helpers/WellProtectedClass.php
tests/phpunit/includes/TestingAccessWrapper.php
tests/phpunit/includes/TestingAccessWrapperTest.php

index b621861..73bea83 100644 (file)
@@ -231,12 +231,11 @@ class ApiParse extends ApiBase {
                                        $result_array['wikitext'] = array();
                                        ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) );
                                }
-                               if ( !is_null( $params['summary'] ) ) {
+                               if ( !is_null( $params['summary'] ) ||
+                                       ( !is_null( $params['sectiontitle'] ) && $this->section === 'new' )
+                               ) {
                                        $result_array['parsedsummary'] = array();
-                                       ApiResult::setContent(
-                                               $result_array['parsedsummary'],
-                                               Linker::formatComment( $params['summary'], $titleObj )
-                                       );
+                                       ApiResult::setContent( $result_array['parsedsummary'], $this->formatSummary( $titleObj, $params ) );
                                }
 
                                $result->addValue( null, $this->getModuleName(), $result_array );
@@ -273,12 +272,11 @@ class ApiParse extends ApiBase {
                        ApiResult::setContent( $result_array['text'], $p_result->getText() );
                }
 
-               if ( !is_null( $params['summary'] ) ) {
+               if ( !is_null( $params['summary'] ) ||
+                       ( !is_null( $params['sectiontitle'] ) && $this->section === 'new' )
+               ) {
                        $result_array['parsedsummary'] = array();
-                       ApiResult::setContent(
-                               $result_array['parsedsummary'],
-                               Linker::formatComment( $params['summary'], $titleObj )
-                       );
+                       ApiResult::setContent( $result_array['parsedsummary'], $this->formatSummary( $titleObj, $params ) );
                }
 
                if ( isset( $prop['langlinks'] ) ) {
@@ -502,6 +500,30 @@ class ApiParse extends ApiBase {
                return $section;
        }
 
+       /**
+        * This mimicks the behavior of EditPage in formatting a summary
+        *
+        * @param Title $title of the page being parsed
+        * @param Array $params the API parameters of the request
+        * @return Content|bool
+        */
+       private function formatSummary( $title, $params ) {
+               global $wgParser;
+               $summary = !is_null( $params['summary'] ) ? $params['summary'] : '';
+               $sectionTitle = !is_null( $params['sectiontitle'] ) ? $params['sectiontitle'] : '';
+
+               if ( $this->section === 'new' && ( $sectionTitle === '' || $summary === '' ) ) {
+                       if( $sectionTitle !== '' ) {
+                               $summary = $params['sectiontitle'];
+                       }
+                       if ( $summary !== '' ) {
+                               $summary = wfMessage( 'newsectionsummary' )->rawParams( $wgParser->stripSectionName( $summary ) )
+                                       ->inContentLanguage()->text();
+                       }
+               }
+               return Linker::formatComment( $summary, $title, $this->section === 'new' );
+       }
+
        private function formatLangLinks( $links ) {
                $result = array();
                foreach ( $links as $link ) {
index 7114cc9..99c7f64 100644 (file)
@@ -14,4 +14,8 @@ class WellProtectedClass {
        public function getProperty() {
                return $this->property;
        }
+
+       protected function whatSecondArg( $a, $b = false ) {
+               return $b;
+       }
 }
index d4ad363..84c0f9b 100644 (file)
@@ -31,7 +31,7 @@ class TestingAccessWrapper {
                $classReflection = new ReflectionClass( $this->object );
                $methodReflection = $classReflection->getMethod( $method );
                $methodReflection->setAccessible( true );
-               return $methodReflection->invoke( $this->object, $args );
+               return $methodReflection->invokeArgs( $this->object, $args );
        }
 
        public function __set( $name, $value ) {
index 8da8e42..7e5b91a 100644 (file)
@@ -27,4 +27,8 @@ class TestingAccessWrapperTest extends MediaWikiTestCase {
                $this->assertSame( 2, $this->wrapped->property );
                $this->assertSame( 2, $this->raw->getProperty() );
        }
+
+       function testCallMethodTwoArgs() {
+               $this->assertSame( 'two', $this->wrapped->whatSecondArg( 'one', 'two' ) );
+       }
 }