Merge "Add userExpLevel filter in the RCFilters UI"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 5 Jan 2017 20:26:07 +0000 (20:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 5 Jan 2017 20:26:07 +0000 (20:26 +0000)
21 files changed:
Gemfile
Gemfile.lock
autoload.php
includes/Preferences.php
includes/WatchedItemQueryService.php
includes/api/ApiMain.php
includes/api/ApiSetPageLanguage.php [new file with mode: 0755]
includes/api/i18n/en.json
includes/api/i18n/qqq.json
includes/diff/DiffEngine.php
includes/json/FormatJson.php
includes/parser/Parser.php
includes/search/SearchHighlighter.php
includes/specialpage/LoginSignupSpecialPage.php
includes/specials/SpecialPageLanguage.php
languages/Language.php
languages/i18n/en.json
languages/i18n/qqq.json
languages/messages/MessagesRup.php [new file with mode: 0644]
maintenance/populateInterwiki.php
tests/phan/config.php

diff --git a/Gemfile b/Gemfile
index 8a349bf..8bbd00f 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -1,5 +1,5 @@
 source 'https://rubygems.org'
 
-gem 'mediawiki_selenium', '~> 1.7', '>= 1.7.2'
+gem 'mediawiki_selenium', '~> 1.7', '>= 1.7.4'
 gem 'rake', '~> 11.1', '>= 11.1.1'
 gem 'rubocop', '~> 0.32.1', require: false
index 982619a..8243874 100644 (file)
@@ -13,55 +13,58 @@ GEM
       gherkin (~> 2.12)
       multi_json (>= 1.7.5, < 2.0)
       multi_test (>= 0.1.2)
-    data_magic (0.22)
+    data_magic (1.0)
       faker (>= 1.1.2)
       yml_reader (>= 0.6)
     diff-lcs (1.2.5)
-    domain_name (0.5.20160615)
+    domain_name (0.5.20161129)
       unf (>= 0.0.5, < 1.0.0)
-    faker (1.6.6)
+    faker (1.7.1)
       i18n (~> 0.5)
-    faraday (0.9.2)
+    faraday (0.10.0)
       multipart-post (>= 1.2, < 3)
     faraday-cookie_jar (0.0.6)
       faraday (>= 0.7.4)
       http-cookie (~> 1.0.0)
-    faraday_middleware (0.10.0)
-      faraday (>= 0.7.4, < 0.10)
+    faraday_middleware (0.10.1)
+      faraday (>= 0.7.4, < 1.0)
     ffi (1.9.14)
     gherkin (2.12.2)
       multi_json (~> 1.3)
-    headless (2.2.3)
-    http-cookie (1.0.2)
+    headless (2.3.1)
+    http-cookie (1.0.3)
       domain_name (~> 0.5)
     i18n (0.7.0)
-    json (1.8.3)
+    json (2.0.2)
     mediawiki_api (0.7.0)
       faraday (~> 0.9, >= 0.9.0)
       faraday-cookie_jar (~> 0.0, >= 0.0.6)
       faraday_middleware (~> 0.10, >= 0.10.0)
-    mediawiki_selenium (1.7.2)
+    mediawiki_selenium (1.7.4)
       cucumber (~> 1.3, >= 1.3.20)
       headless (~> 2.0, >= 2.1.0)
-      json (~> 1.8, >= 1.8.1)
+      json (~> 2.0, >= 2.0.2)
       mediawiki_api (~> 0.7, >= 0.7.0)
       page-object (~> 1.0)
       rest-client (~> 1.6, >= 1.6.7)
       rspec-core (~> 2.14, >= 2.14.4)
       rspec-expectations (~> 2.14, >= 2.14.4)
+      selenium-webdriver (< 3)
       syntax (~> 1.2, >= 1.2.0)
       thor (~> 0.19, >= 0.19.1)
-    mime-types (2.99.2)
+    mime-types (2.99.3)
     multi_json (1.12.1)
     multi_test (0.1.2)
     multipart-post (2.0.0)
+    net-http-persistent (2.9.4)
     netrc (0.11.0)
-    page-object (1.2.0)
+    page-object (1.2.2)
+      net-http-persistent (~> 2.9.4)
       page_navigation (>= 0.9)
-      selenium-webdriver (>= 2.44.0)
-      watir-webdriver (>= 0.6.11)
-    page_navigation (0.9)
-      data_magic (>= 0.14)
+      selenium-webdriver (>= 2.53.0)
+      watir-webdriver (>= 0.6.11, < 0.9.9)
+    page_navigation (0.10)
+      data_magic (>= 0.22)
     parser (2.2.2.6)
       ast (>= 1.1, < 3.0)
     powerpack (0.1.1)
@@ -87,7 +90,7 @@ GEM
       rubyzip (~> 1.0)
       websocket (~> 1.0)
     syntax (1.2.1)
-    thor (0.19.1)
+    thor (0.19.4)
     unf (0.1.4)
       unf_ext
     unf_ext (0.0.7.2)
@@ -100,6 +103,9 @@ PLATFORMS
   ruby
 
 DEPENDENCIES
-  mediawiki_selenium (~> 1.7, >= 1.7.2)
+  mediawiki_selenium (~> 1.7, >= 1.7.4)
   rake (~> 11.1, >= 11.1.1)
   rubocop (~> 0.32.1)
+
+BUNDLED WITH
+   1.13.7
index cdbdf1f..a38fca2 100644 (file)
@@ -139,6 +139,7 @@ $wgAutoloadLocalClasses = [
        'ApiRsd' => __DIR__ . '/includes/api/ApiRsd.php',
        'ApiSerializable' => __DIR__ . '/includes/api/ApiSerializable.php',
        'ApiSetNotificationTimestamp' => __DIR__ . '/includes/api/ApiSetNotificationTimestamp.php',
+       'ApiSetPageLanguage' => __DIR__ . '/includes/api/ApiSetPageLanguage.php',
        'ApiStashEdit' => __DIR__ . '/includes/api/ApiStashEdit.php',
        'ApiTag' => __DIR__ . '/includes/api/ApiTag.php',
        'ApiTokens' => __DIR__ . '/includes/api/ApiTokens.php',
index cf8e7b8..263ff5b 100644 (file)
@@ -696,19 +696,23 @@ class Preferences {
                $tzOptions = self::getTimezoneOptions( $context );
 
                $tzSetting = $tzOffset;
-               if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
-                       $minDiff = $tz[1];
-                       $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 );
-               } elseif ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
+               if ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
                        !in_array( $tzOffset, HTMLFormField::flattenOptions( $tzOptions ) )
                ) {
-                       # Timezone offset can vary with DST
-                       $userTZ = timezone_open( $tz[2] );
-                       if ( $userTZ !== false ) {
-                               $minDiff = floor( timezone_offset_get( $userTZ, date_create( 'now' ) ) / 60 );
+                       // Timezone offset can vary with DST
+                       try {
+                               $userTZ = new DateTimeZone( $tz[2] );
+                               $minDiff = floor( $userTZ->getOffset( new DateTime( 'now' ) ) / 60 );
                                $tzSetting = "ZoneInfo|$minDiff|{$tz[2]}";
+                       } catch ( Exception $e ) {
+                               // User has an invalid time zone set. Fall back to just using the offset
+                               $tz[0] = 'Offset';
                        }
                }
+               if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
+                       $minDiff = $tz[1];
+                       $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 );
+               }
 
                $defaultPreferences['timecorrection'] = [
                        'class' => 'HTMLSelectOrOtherField',
@@ -1391,6 +1395,24 @@ class Preferences {
                $data = explode( '|', $tz, 3 );
                switch ( $data[0] ) {
                        case 'ZoneInfo':
+                               $valid = false;
+
+                               if ( count( $data ) === 3 ) {
+                                       // Make sure this timezone exists
+                                       try {
+                                               new DateTimeZone( $data[2] );
+                                               // If the constructor didn't throw, we know it's valid
+                                               $valid = true;
+                                       } catch ( Exception $e ) {
+                                               // Not a valid timezone
+                                       }
+                               }
+
+                               if ( !$valid ) {
+                                       // If the supplied timezone doesn't exist, fall back to the encoded offset
+                                       return 'Offset|' . intval( $tz[1] );
+                               }
+                               return $tz;
                        case 'System':
                                return $tz;
                        default:
@@ -1409,7 +1431,7 @@ class Preferences {
                                # Max is +14:00 and min is -12:00, see:
                                # https://en.wikipedia.org/wiki/Timezone
                                $minDiff = min( $minDiff, 840 );  # 14:00
-                               $minDiff = max( $minDiff, - 720 ); # -12:00
+                               $minDiff = max( $minDiff, -720 ); # -12:00
                                return 'Offset|' . $minDiff;
                }
        }
index cd78b49..c80e4a5 100644 (file)
@@ -471,7 +471,7 @@ class WatchedItemQueryService {
        }
 
        private function getStartEndConds( IDatabase $db, array $options ) {
-               if ( !isset( $options['start'] ) && ! isset( $options['end'] ) ) {
+               if ( !isset( $options['start'] ) && !isset( $options['end'] ) ) {
                        return [];
                }
 
index 4220fb8..52f1d95 100644 (file)
@@ -106,6 +106,7 @@ class ApiMain extends ApiBase {
                'managetags' => 'ApiManageTags',
                'tag' => 'ApiTag',
                'mergehistory' => 'ApiMergeHistory',
+               'setpagelanguage' => 'ApiSetPageLanguage',
        ];
 
        /**
diff --git a/includes/api/ApiSetPageLanguage.php b/includes/api/ApiSetPageLanguage.php
new file mode 100755 (executable)
index 0000000..3f03c02
--- /dev/null
@@ -0,0 +1,147 @@
+<?php
+/**
+ *
+ *
+ * Created on January 1, 2017
+ *
+ * Copyright © 2017 Justin Du "<justin.d128@gmail.com>"
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * API module that facilitates changing the language of a page.
+ * The API equivalent of SpecialPageLanguage.
+ * Requires API write mode to be enabled.
+ *
+ * @ingroup API
+ */
+class ApiSetPageLanguage extends ApiBase {
+       // Check if change language feature is enabled
+       protected function getDescriptionMessage() {
+               if ( !$this->getConfig()->get( 'PageLanguageUseDB' ) ) {
+                       return 'apihelp-setpagelanguage-description-disabled';
+               }
+               return parent::getDescriptionMessage();
+       }
+
+       /**
+        * Extracts the title and language from the request parameters and invokes
+        * the static SpecialPageLanguage::changePageLanguage() function with these as arguments.
+        * If the language change succeeds, the title, old language, and new language
+        * of the article changed, as well as the performer of the language change
+        * are added to the result object.
+        */
+       public function execute() {
+               // Check if change language feature is enabled
+               if ( !$this->getConfig()->get( 'PageLanguageUseDB' ) ) {
+                       $this->dieWithError( 'apierror-pagelang-disabled' );
+               }
+
+               // Check if the user has permissions
+               $this->checkUserRightsAny( 'pagelang' );
+
+               $this->useTransactionalTimeLimit();
+
+               $params = $this->extractRequestParams();
+
+               $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
+               if ( !$pageObj->exists() ) {
+                       $this->dieWithError( 'apierror-missingtitle' );
+               }
+
+               $titleObj = $pageObj->getTitle();
+               $user = $this->getUser();
+
+               // Check that the user is allowed to edit the page
+               $this->checkTitleUserPermissions( $titleObj, 'edit' );
+
+               // If change tagging was requested, check that the user is allowed to tag,
+               // and the tags are valid
+               if ( count( $params['tags'] ) ) {
+                       $tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
+                       if ( !$tagStatus->isOK() ) {
+                               $this->dieStatus( $tagStatus );
+                       }
+               }
+
+               $status = SpecialPageLanguage::changePageLanguage(
+                       $this,
+                       $titleObj,
+                       $params['lang'],
+                       $params['tags'] ?: []
+               );
+
+               if ( !$status->isOK() ) {
+                       $this->dieStatus( $status );
+               }
+
+               $r = [
+                       'title' => $titleObj->getPrefixedText(),
+                       'oldlanguage' => $status->value->oldLanguage,
+                       'newlanguage' => $status->value->newLanguage,
+                       'logid' => $status->value->logId
+               ];
+               $this->getResult()->addValue( null, $this->getModuleName(), $r );
+       }
+
+       public function mustBePosted() {
+               return true;
+       }
+
+       public function isWriteMode() {
+               return true;
+       }
+
+       public function getAllowedParams() {
+               return [
+                       'title' => null,
+                       'pageid' => [
+                               ApiBase::PARAM_TYPE => 'integer'
+                       ],
+                       'lang' => [
+                               ApiBase::PARAM_TYPE => array_merge(
+                                       [ 'default' ],
+                                       array_keys( Language::fetchLanguageNames( null, 'mwfile' ) )
+                               ),
+                               ApiBase::PARAM_REQUIRED => true,
+                       ],
+                       'tags' => [
+                               ApiBase::PARAM_TYPE => 'tags',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ],
+               ];
+       }
+
+       public function needsToken() {
+               return 'csrf';
+       }
+
+       protected function getExamplesMessages() {
+               return [
+                       'action=setpagelanguage&title=Main%20Page&lang=eu&token=123ABC'
+                               => 'apihelp-setpagelanguage-example-language',
+                       'action=setpagelanguage&pageid=123&lang=default&token=123ABC'
+                               => 'apihelp-setpagelanguage-example-default',
+               ];
+       }
+
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/API:SetPageLanguage';
+       }
+}
index bc9fbf6..79d0295 100644 (file)
        "apihelp-setnotificationtimestamp-example-pagetimestamp": "Set the notification timestamp for <kbd>Main page</kbd> so all edits since 1 January 2012 are unviewed.",
        "apihelp-setnotificationtimestamp-example-allpages": "Reset the notification status for pages in the <kbd>{{ns:user}}</kbd> namespace.",
 
+       "apihelp-setpagelanguage-description": "Change the language of a page.",
+       "apihelp-setpagelanguage-description-disabled": "Changing the language of a page is not allowed on this wiki.\n\nEnable <var>[[mw:Manual:$wgPageLanguageUseDB|$wgPageLanguageUseDB]]</var> to use this action.",
+       "apihelp-setpagelanguage-param-title": "Title of the page whose language you wish to change. Cannot be used together with <var>$1pageid</var>.",
+       "apihelp-setpagelanguage-param-pageid": "Page ID of the page whose language you wish to change. Cannot be used together with <var>$1title</var>.",
+       "apihelp-setpagelanguage-param-lang": "Language code of the language to change the page to. Use <kbd>default</kbd> to reset the page to the wiki's default content language.",
+       "apihelp-setpagelanguage-param-tags": "Change tags to apply to the log entry resulting from this action.",
+       "apihelp-setpagelanguage-example-language": "Change the language of <kbd>Main Page</kbd> to Basque.",
+       "apihelp-setpagelanguage-example-default": "Change the language of the page with ID 123 to the wiki's default content language.",
+
        "apihelp-stashedit-description": "Prepare an edit in shared cache.\n\nThis is intended to be used via AJAX from the edit form to improve the performance of the page save.",
        "apihelp-stashedit-param-title": "Title of the page being edited.",
        "apihelp-stashedit-param-section": "Section number. <kbd>0</kbd> for the top section, <kbd>new</kbd> for a new section.",
        "apierror-opensearch-json-warnings": "Warnings cannot be represented in OpenSearch JSON format.",
        "apierror-pagecannotexist": "Namespace doesn't allow actual pages.",
        "apierror-pagedeleted": "The page has been deleted since you fetched its timestamp.",
+       "apierror-pagelang-disabled": "Changing the language of a page is not allowed on this wiki.",
        "apierror-paramempty": "The parameter <var>$1</var> may not be empty.",
        "apierror-parsetree-notwikitext": "<kbd>prop=parsetree</kbd> is only supported for wikitext content.",
        "apierror-parsetree-notwikitext-title": "<kbd>prop=parsetree</kbd> is only supported for wikitext content. $1 uses content model $2.",
index 9d467cc..662020b 100644 (file)
        "apihelp-setnotificationtimestamp-example-page": "{{doc-apihelp-example|setnotificationtimestamp}}",
        "apihelp-setnotificationtimestamp-example-pagetimestamp": "{{doc-apihelp-example|setnotificationtimestamp}}",
        "apihelp-setnotificationtimestamp-example-allpages": "{{doc-apihelp-example|setnotificationtimestamp}}",
+       "apihelp-setpagelanguage-description": "{{doc-apihelp-description|setpagelanguage}}",
+       "apihelp-setpagelanguage-description-disabled": "{{doc-apihelp-description|setpagelanguage|info=This message is used when changing the language of a page is not allowed on the wiki because <var>[[mw:Manual:$wgPageLanguageUseDB|$wgPageLanguageUseDB]]</var> is not enabled.|seealso={{msg-mw|apihelp-setpagelanguage-description}}}}",
+       "apihelp-setpagelanguage-param-title": "{{doc-apihelp-param|setpagelanguage|title}}",
+       "apihelp-setpagelanguage-param-pageid": "{{doc-apihelp-param|setpagelanguage|pageid}}",
+       "apihelp-setpagelanguage-param-lang": "{{doc-apihelp-param|setpagelanguage|lang}}",
+       "apihelp-setpagelanguage-param-tags": "{{doc-apihelp-param|setpagelanguage|tags}}",
+       "apihelp-setpagelanguage-example-language": "{{doc-apihelp-example|setpagelanguage}}",
+       "apihelp-setpagelanguage-example-default": "{{doc-apihelp-example|setpagelanguage}}",
        "apihelp-stashedit-description": "{{doc-apihelp-description|stashedit}}",
        "apihelp-stashedit-param-title": "{{doc-apihelp-param|stashedit|title}}",
        "apihelp-stashedit-param-section": "{{doc-apihelp-param|stashedit|section}}",
        "apierror-opensearch-json-warnings": "{{doc-apierror}}",
        "apierror-pagecannotexist": "{{doc-apierror}}",
        "apierror-pagedeleted": "{{doc-apierror}}",
+       "apierror-pagelang-disabled": "{{doc-apierror}}",
        "apierror-paramempty": "{{doc-apierror}}\n\nParameters:\n* $1 - Parameter name.",
        "apierror-parsetree-notwikitext": "{{doc-apierror}}",
        "apierror-parsetree-notwikitext-title": "{{doc-apierror}}\n\nParameters:\n* $1 - Page title.\n* $2 - Content model.",
index babd00b..25d50d3 100644 (file)
@@ -182,7 +182,7 @@ class DiffEngine {
                        }
 
                        while ( $i < $len && !$changed[$i] ) {
-                               assert( $j < $other_len && ! $other_changed[$j] );
+                               assert( $j < $other_len && !$other_changed[$j] );
                                $i++;
                                $j++;
                                while ( $j < $other_len && $other_changed[$j] ) {
@@ -247,7 +247,7 @@ class DiffEngine {
                                                $i++;
                                        }
 
-                                       assert( $j < $other_len && ! $other_changed[$j] );
+                                       assert( $j < $other_len && !$other_changed[$j] );
                                        $j++;
                                        if ( $j < $other_len && $other_changed[$j] ) {
                                                $corresponding = $i;
index 41541ef..0c77a7b 100644 (file)
@@ -216,7 +216,7 @@ class FormatJson {
                        $count = 0;
                        $value =
                                preg_replace( '/,([ \t]*[}\]][^"\r\n]*([\r\n]|$)|[ \t]*[\r\n][ \t\r\n]*[}\]])/', '$1',
-                                       $value, - 1, $count );
+                                       $value, -1, $count );
                        if ( $count > 0 ) {
                                $result = json_decode( $value, $assoc );
                                if ( JSON_ERROR_NONE === json_last_error() ) {
index 1ca9dac..40a3755 100644 (file)
@@ -5258,7 +5258,7 @@ class Parser {
                                                case 'framed':
                                                case 'thumbnail':
                                                        // use first appearing option, discard others.
-                                                       $validated = ! $seenformat;
+                                                       $validated = !$seenformat;
                                                        $seenformat = true;
                                                        break;
                                                default:
index dd41a6e..d0e3a24 100644 (file)
@@ -75,10 +75,10 @@ class SearchHighlighter {
                        if ( preg_match( $spat, $text, $matches, PREG_OFFSET_CAPTURE, $start ) ) {
                                $epat = '';
                                foreach ( $matches as $key => $val ) {
-                                       if ( $key > 0 && $val[1] != - 1 ) {
+                                       if ( $key > 0 && $val[1] != -1 ) {
                                                if ( $key == 2 ) {
                                                        // see if this is an image link
-                                                       $ns = substr( $val[0], 2, - 1 );
+                                                       $ns = substr( $val[0], 2, -1 );
                                                        if ( $wgContLang->getNsIndex( $ns ) != NS_FILE ) {
                                                                break;
                                                        }
@@ -252,10 +252,10 @@ class SearchHighlighter {
 
                // $snippets = array_map( 'htmlspecialchars', $extended );
                $snippets = $extended;
-               $last = - 1;
+               $last = -1;
                $extract = '';
                foreach ( $snippets as $index => $line ) {
-                       if ( $last == - 1 ) {
+                       if ( $last == -1 ) {
                                $extract .= $line; // first line
                        } elseif ( $last + 1 == $index
                                && $offsets[$last] + strlen( $snippets[$last] ) >= strlen( $all[$last] )
index 540ce4b..c3ee321 100644 (file)
@@ -1088,13 +1088,13 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                        // B/C for old extensions that haven't been converted to AuthManager (or have been
                        // but somebody is using the old version) and still use templates via the
                        // UserCreateForm/UserLoginForm hook.
-                       // 'header' used by ConfirmEdit, CondfirmAccount, Persona, WikimediaIncubator, SemanticSignup
+                       // 'header' used by ConfirmEdit, ConfirmAccount, Persona, WikimediaIncubator, SemanticSignup
                        // 'formheader' used by MobileFrontend
                        $fieldDefinitions['header'] = [
                                'type' => 'info',
                                'raw' => true,
                                'default' => $template->get( 'header' ) ?: $template->get( 'formheader' ),
-                               'weight' => - 110,
+                               'weight' => -110,
                        ];
                }
                if ( $this->mEntryError ) {
index 61b6a8c..8546a08 100644 (file)
@@ -111,68 +111,102 @@ class SpecialPageLanguage extends FormSpecialPage {
        /**
         *
         * @param array $data
-        * @return bool
+        * @return Status
         */
        public function onSubmit( array $data ) {
-               $title = Title::newFromText( $data['pagename'] );
+               $pageName = $data['pagename'];
 
-               // Check if title is valid
-               if ( !$title ) {
-                       return false;
+               // Check if user wants to use default language
+               if ( $data['selectoptions'] == 1 ) {
+                       $newLanguage = 'default';
+               } else {
+                       $newLanguage = $data['language'];
+               }
+
+               try {
+                       $title = Title::newFromTextThrow( $pageName );
+               } catch ( MalformedTitleException $ex ) {
+                       return Status::newFatal( $ex->getMessageObject() );
                }
 
+               // Url to redirect to after the operation
+               $this->goToUrl = $title->getFullURL();
+
+               return self::changePageLanguage( $this->getContext(), $title, $newLanguage );
+       }
+
+       /**
+        * @param IContextSource $context
+        * @param Title $title
+        * @param string $newLanguage Language code
+        * @param array $tags Change tags to apply to the log entry
+        * @return Status
+        */
+       public static function changePageLanguage( IContextSource $context, Title $title,
+               $newLanguage, array $tags = [] ) {
                // Get the default language for the wiki
-               $defLang = $this->getConfig()->get( 'LanguageCode' );
+               $defLang = $context->getConfig()->get( 'LanguageCode' );
 
                $pageId = $title->getArticleID();
 
                // Check if article exists
                if ( !$pageId ) {
-                       return false;
+                       return Status::newFatal(
+                               'pagelang-nonexistent-page',
+                               wfEscapeWikiText( $title->getPrefixedText() )
+                       );
                }
 
                // Load the page language from DB
                $dbw = wfGetDB( DB_MASTER );
-               $langOld = $dbw->selectField(
+               $oldLanguage = $dbw->selectField(
                        'page',
                        'page_lang',
                        [ 'page_id' => $pageId ],
                        __METHOD__
                );
 
-               // Url to redirect to after the operation
-               $this->goToUrl = $title->getFullURL();
-
-               // Check if user wants to use default language
-               if ( $data['selectoptions'] == 1 ) {
-                       $langNew = null;
-               } else {
-                       $langNew = $data['language'];
+               // Check if user wants to use the default language
+               if ( $newLanguage === 'default' ) {
+                       $newLanguage = null;
                }
 
                // No change in language
-               if ( $langNew === $langOld ) {
-                       return false;
+               if ( $newLanguage === $oldLanguage ) {
+                       // Check if old language does not exist
+                       if ( !$oldLanguage ) {
+                               return Status::newFatal( ApiMessage::create(
+                                       [
+                                               'pagelang-unchanged-language-default',
+                                               wfEscapeWikiText( $title->getPrefixedText() )
+                                       ],
+                                       'pagelang-unchanged-language'
+                               ) );
+                       }
+                       return Status::newFatal(
+                               'pagelang-unchanged-language',
+                               wfEscapeWikiText( $title->getPrefixedText() ),
+                               $oldLanguage
+                       );
                }
 
                // Hardcoded [def] if the language is set to null
-               $logOld = $langOld ? $langOld : $defLang . '[def]';
-               $logNew = $langNew ? $langNew : $defLang . '[def]';
+               $logOld = $oldLanguage ? $oldLanguage : $defLang . '[def]';
+               $logNew = $newLanguage ? $newLanguage : $defLang . '[def]';
 
                // Writing new page language to database
-               $dbw = wfGetDB( DB_MASTER );
                $dbw->update(
                        'page',
-                       [ 'page_lang' => $langNew ],
+                       [ 'page_lang' => $newLanguage ],
                        [
                                'page_id' => $pageId,
-                               'page_lang' => $langOld
+                               'page_lang' => $oldLanguage
                        ],
                        __METHOD__
                );
 
                if ( !$dbw->affectedRows() ) {
-                       return false;
+                       return Status::newFatal( 'pagelang-db-failed' );
                }
 
                // Logging change of language
@@ -181,9 +215,10 @@ class SpecialPageLanguage extends FormSpecialPage {
                        '5::newlanguage' => $logNew
                ];
                $entry = new ManualLogEntry( 'pagelang', 'pagelang' );
-               $entry->setPerformer( $this->getUser() );
+               $entry->setPerformer( $context->getUser() );
                $entry->setTarget( $title );
                $entry->setParameters( $logParams );
+               $entry->setTags( $tags );
 
                $logid = $entry->insert();
                $entry->publish( $logid );
@@ -191,7 +226,11 @@ class SpecialPageLanguage extends FormSpecialPage {
                // Force re-render so that language-based content (parser functions etc.) gets updated
                $title->invalidateCache();
 
-               return true;
+               return Status::newGood( (object)[
+                       'oldLanguage' => $logOld,
+                       'newLanguage' => $logNew,
+                       'logId' => $logid,
+               ] );
        }
 
        public function onSuccess() {
index ac8d4cb..5bce76b 100644 (file)
@@ -2100,17 +2100,15 @@ class Language {
                $data = explode( '|', $tz, 3 );
 
                if ( $data[0] == 'ZoneInfo' ) {
-                       MediaWiki\suppressWarnings();
-                       $userTZ = timezone_open( $data[2] );
-                       MediaWiki\restoreWarnings();
-                       if ( $userTZ !== false ) {
-                               $date = date_create( $ts, timezone_open( 'UTC' ) );
-                               date_timezone_set( $date, $userTZ );
-                               $date = date_format( $date, 'YmdHis' );
-                               return $date;
+                       try {
+                               $userTZ = new DateTimeZone( $data[2] );
+                               $date = new DateTime( $ts, new DateTimeZone( 'UTC' ) );
+                               $date->setTimezone( $userTZ );
+                               return $date->format( 'YmdHis' );
+                       } catch ( Exception $e ) {
+                               // Unrecognized timezone, default to 'Offset' with the stored offset.
+                               $data[0] = 'Offset';
                        }
-                       # Unrecognized timezone, default to 'Offset' with the stored offset.
-                       $data[0] = 'Offset';
                }
 
                if ( $data[0] == 'System' || $tz == '' ) {
index 60dfb48..076ce40 100644 (file)
        "pagelang-use-default": "Use default language",
        "pagelang-select-lang": "Select language",
        "pagelang-submit": "Submit",
+       "pagelang-nonexistent-page": "The page $1 does not exist.",
+       "pagelang-unchanged-language": "The page $1 is already set to language $2.",
+       "pagelang-unchanged-language-default": "The page $1 is already set to the wiki's default content language.",
+       "pagelang-db-failed": "The database failed to change the page language.",
        "right-pagelang": "Change page language",
        "action-pagelang": "change the page language",
        "log-name-pagelang": "Language change log",
index 5184e53..d9f97fd 100644 (file)
        "pagelang-use-default": "Radio label for selector on Special:PageLanguage for default language",
        "pagelang-select-lang": "Radio label for selector on Special:PageLanguage for language selection\n{{Identical|Select language}}",
        "pagelang-submit": "Submit button label for Special:PageLanguage form\n{{Identical|Submit}}",
+       "pagelang-nonexistent-page": "Error message shown when the page the user is trying to change the language on does not exist.\n\nParameters:\n* $1 - the title of the nonexistent page",
+       "pagelang-unchanged-language": "Error message shown when the language the user is trying to change the page to and the current language the page is in are the same.\n\nParameters:\n* $1 - the title of the target page\n* $2 - the current language of the page",
+       "pagelang-unchanged-language-default": "Error message shown when the language the user is trying to set a page to fall back to the wiki's default content language, but the page is already set to do so.\n\nParameters:\n* $1 - the title of the target page",
+       "pagelang-db-failed": "Error message shown when the database fails to update the language of the page",
        "right-pagelang": "{{Doc-right|pagelang}}\nRight to change page language on Special:PageLanguage",
        "action-pagelang": "{{Doc-action|pagelang}}",
        "log-name-pagelang": "Display entry for log name for changes in page language in Special:Log.",
diff --git a/languages/messages/MessagesRup.php b/languages/messages/MessagesRup.php
new file mode 100644 (file)
index 0000000..041dc46
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+/** Aromanian (armãneashti)
+ *
+ * To improve a translation please visit https://translatewiki.net
+ *
+ * @ingroup Language
+ * @file
+ */
+
+$fallback = 'ro';
index 6c812bf..8f7a918 100644 (file)
@@ -129,7 +129,7 @@ TEXT
                                __METHOD__
                        );
 
-                       if ( ! $row ) {
+                       if ( !$row ) {
                                $dbw->insert(
                                        'interwiki',
                                        [
index 903d7cb..cef03ee 100644 (file)
@@ -167,7 +167,7 @@ return [
         */
        'analyze_signature_compatibility' => true,
 
-       // Emit all issues. They are then supressed via
+       // Emit all issues. They are then suppressed via
        // suppress_issue_types, rather than a minimum
        // severity.
        "minimum_severity" => 0,