Merge "Removed view event from $wgAutopromoteOnce"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 27 Mar 2015 16:38:02 +0000 (16:38 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 27 Mar 2015 16:38:02 +0000 (16:38 +0000)
includes/User.php
includes/WebResponse.php
includes/api/ApiParse.php
includes/templates/Usercreate.php
resources/src/mediawiki.action/mediawiki.action.edit.preview.js
tests/phpunit/data/helpers/WellProtectedClass.php
tests/phpunit/includes/TestingAccessWrapper.php
tests/phpunit/includes/TestingAccessWrapperTest.php
tests/phpunit/includes/content/ContentHandlerTest.php

index 2594dbc..78693c1 100644 (file)
@@ -1392,7 +1392,7 @@ class User implements IDBAccessObject {
                global $wgAutopromoteOnceLogInRC, $wgAuth;
 
                $toPromote = array();
-               if ( $this->getId() ) {
+               if ( !wfReadOnly() && $this->getId() ) {
                        $toPromote = Autopromote::getAutopromoteOnceGroups( $this, $event );
                        if ( count( $toPromote ) ) {
                                $oldGroups = $this->getGroups(); // previous groups
@@ -1418,6 +1418,7 @@ class User implements IDBAccessObject {
                                }
                        }
                }
+
                return $toPromote;
        }
 
@@ -2308,7 +2309,9 @@ class User implements IDBAccessObject {
                        if ( $this->mQuickTouched === null ) {
                                $key = wfMemcKey( 'user-quicktouched', 'id', $this->mId );
                                $timestamp = $wgMemc->get( $key );
-                               if ( !$timestamp ) {
+                               if ( $timestamp ) {
+                                       $this->mQuickTouched = $timestamp;
+                               } else {
                                        # Set the timestamp to get HTTP 304 cache hits
                                        $this->touch();
                                }
index 83ac51a..ab34931 100644 (file)
@@ -60,7 +60,7 @@ class WebResponse {
         * @param int|null $expire Unix timestamp (in seconds) when the cookie should expire.
         *        0 (the default) causes it to expire $wgCookieExpiration seconds from now.
         *        null causes it to be a session cookie.
-        * @param array|null $options Assoc of additional cookie options:
+        * @param array $options Assoc of additional cookie options:
         *     prefix: string, name prefix ($wgCookiePrefix)
         *     domain: string, cookie domain ($wgCookieDomain)
         *     path: string, cookie path ($wgCookiePath)
@@ -72,7 +72,7 @@ class WebResponse {
         *   'prefix', 'domain', and 'secure'
         * @since 1.22 Replaced $prefix, $domain, and $forceSecure with $options
         */
-       public function setcookie( $name, $value, $expire = 0, $options = null ) {
+       public function setcookie( $name, $value, $expire = 0, $options = array() ) {
                global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
                global $wgCookieSecure, $wgCookieExpiration, $wgCookieHttpOnly;
 
@@ -188,9 +188,9 @@ class FauxResponse extends WebResponse {
         * @param string $name The name of the cookie.
         * @param string $value The value to be stored in the cookie.
         * @param int|null $expire Ignored in this faux subclass.
-        * @param array|null $options Ignored in this faux subclass.
+        * @param array $options Ignored in this faux subclass.
         */
-       public function setcookie( $name, $value, $expire = 0, $options = null ) {
+       public function setcookie( $name, $value, $expire = 0, $options = array() ) {
                $this->cookies[$name] = $value;
        }
 
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 dc9da63..f09b6bb 100644 (file)
@@ -261,7 +261,7 @@ class UsercreateTemplate extends BaseTemplate {
                                <?php
                                echo Html::submitButton(
                                        $this->getMsg( $this->data['loggedin'] ? 'createacct-another-submit' : 'createacct-submit' ),
-                                       $attrs = array(
+                                       array(
                                                'id' => 'wpCreateaccount',
                                                'name' => 'wpCreateaccount',
                                                'tabindex' => $tabIndex++
index 65ae0f0..4aa839c 100644 (file)
        $( function () {
                // Do not enable on user .js/.css pages, as there's no sane way of "previewing"
                // the scripts or styles without reloading the page.
-               // Do not enable for ProofreadPage Index page editors, which have no textbox
-               if ( $( '#mw-userjsyoucanpreview' ).length || $( '#mw-usercssyoucanpreview' ).length || $( '#wpTextbox1' ).length === 0 ) {
+               if ( $( '#mw-userjsyoucanpreview' ).length || $( '#mw-usercssyoucanpreview' ).length ) {
                        return;
                }
 
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' ) );
+       }
 }
index 1a90d6e..988a59e 100644 (file)
@@ -2,11 +2,6 @@
 
 /**
  * @group ContentHandler
- * @group Database
- *
- * @note Declare that we are using the database, because otherwise we'll fail in
- * the "databaseless" test run. This is because the LinkHolderArray used by the
- * parser needs database access.
  */
 class ContentHandlerTest extends MediaWikiTestCase {
 
@@ -36,6 +31,8 @@ class ContentHandlerTest extends MediaWikiTestCase {
                // Reset namespace cache
                MWNamespace::getCanonicalNamespaces( true );
                $wgContLang->resetNamespaces();
+               // And LinkCache
+               LinkCache::destroySingleton();
        }
 
        protected function tearDown() {
@@ -44,6 +41,8 @@ class ContentHandlerTest extends MediaWikiTestCase {
                // Reset namespace cache
                MWNamespace::getCanonicalNamespaces( true );
                $wgContLang->resetNamespaces();
+               // And LinkCache
+               LinkCache::destroySingleton();
 
                parent::tearDown();
        }
@@ -83,6 +82,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
         */
        public function testGetForTitle( $title, $expectedContentModel ) {
                $title = Title::newFromText( $title );
+               LinkCache::singleton()->addBadLinkObj( $title );
                $handler = ContentHandler::getForTitle( $title );
                $this->assertEquals( $expectedContentModel, $handler->getModelID() );
        }
@@ -139,6 +139,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
        public function testGetPageLanguage( $title, $expected ) {
                if ( is_string( $title ) ) {
                        $title = Title::newFromText( $title );
+                       LinkCache::singleton()->addBadLinkObj( $title );
                }
 
                $expected = wfGetLangObj( $expected );
@@ -292,7 +293,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
                $expectedModelId, $expectedNativeData, $shouldFail
        ) {
                $title = Title::newFromText( $title );
-
+               LinkCache::singleton()->addBadLinkObj( $title );
                try {
                        $content = ContentHandler::makeContent( $data, $title, $modelId, $format );