Merge "RCFilters: Actually apply proper classes to grouped pages"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 13 Sep 2017 17:34:49 +0000 (17:34 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 13 Sep 2017 17:34:49 +0000 (17:34 +0000)
includes/CommentStore.php
includes/CommentStoreComment.php
includes/Linker.php
includes/diff/DifferenceEngine.php
includes/filerepo/file/LocalFile.php
includes/page/ImageHistoryPseudoPager.php
includes/page/WikiPage.php
includes/skins/Skin.php
resources/Resources.php
resources/src/jquery/jquery.byteLength.js
resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js

index 2ed21d1..b8a31e6 100644 (file)
@@ -367,26 +367,7 @@ class CommentStore {
         * @return CommentStoreComment
         */
        public function createComment( IDatabase $dbw, $comment, array $data = null ) {
-               global $wgContLang;
-
-               if ( !$comment instanceof CommentStoreComment ) {
-                       if ( $data !== null ) {
-                               foreach ( $data as $k => $v ) {
-                                       if ( substr( $k, 0, 1 ) === '_' ) {
-                                               throw new InvalidArgumentException( 'Keys in $data beginning with "_" are reserved' );
-                                       }
-                               }
-                       }
-                       if ( $comment instanceof Message ) {
-                               $message = clone $comment;
-                               $text = $message->inLanguage( $wgContLang ) // Avoid $wgForceUIMsgAsContentMsg
-                                       ->setInterfaceMessageFlag( true )
-                                       ->text();
-                               $comment = new CommentStoreComment( null, $text, $message, $data );
-                       } else {
-                               $comment = new CommentStoreComment( null, $comment, null, $data );
-                       }
-               }
+               $comment = CommentStoreComment::newUnsavedComment( $comment, $data );
 
                # Truncate comment in a Unicode-sensitive manner
                $comment->text = $this->lang->truncate( $comment->text, self::MAX_COMMENT_LENGTH );
index afc1374..3920ba0 100644 (file)
@@ -42,7 +42,7 @@ class CommentStoreComment {
        public $data;
 
        /**
-        * @private For use by CommentStore only
+        * @private For use by CommentStore only. Use self::newUnsavedComment() instead.
         * @param int|null $id
         * @param string $text
         * @param Message|null $message
@@ -54,4 +54,39 @@ class CommentStoreComment {
                $this->message = $message ?: new RawMessage( '$1', [ $text ] );
                $this->data = $data;
        }
+
+       /**
+        * Create a new, unsaved CommentStoreComment
+        *
+        * @param string|Message|CommentStoreComment $comment Comment text or Message object.
+        *  A CommentStoreComment is also accepted here, in which case it is returned unchanged.
+        * @param array|null $data Structured data to store. Keys beginning with '_' are reserved.
+        *  Ignored if $comment is a CommentStoreComment.
+        * @return CommentStoreComment
+        */
+       public static function newUnsavedComment( $comment, array $data = null ) {
+               global $wgContLang;
+
+               if ( $comment instanceof CommentStoreComment ) {
+                       return $comment;
+               }
+
+               if ( $data !== null ) {
+                       foreach ( $data as $k => $v ) {
+                               if ( substr( $k, 0, 1 ) === '_' ) {
+                                       throw new InvalidArgumentException( 'Keys in $data beginning with "_" are reserved' );
+                               }
+                       }
+               }
+
+               if ( $comment instanceof Message ) {
+                       $message = clone $comment;
+                       $text = $message->inLanguage( $wgContLang ) // Avoid $wgForceUIMsgAsContentMsg
+                               ->setInterfaceMessageFlag( true )
+                               ->text();
+                       return new CommentStoreComment( null, $text, $message, $data );
+               } else {
+                       return new CommentStoreComment( null, $comment, null, $data );
+               }
+       }
 }
index dccd99c..c24ae41 100644 (file)
@@ -76,7 +76,7 @@ class Linker {
         * @since 1.18 Method exists since 1.16 as non-static, made static in 1.18.
         * @deprecated since 1.28, use MediaWiki\Linker\LinkRenderer instead
         *
-        * @param Title $target Can currently only be a Title, but this may
+        * @param LinkTarget $target Can currently only be a LinkTarget, but this may
         *   change to support Images, literal URLs, etc.
         * @param string $html The HTML contents of the <a> element, i.e.,
         *   the link text.  This is raw HTML and will not be escaped.  If null,
@@ -107,8 +107,8 @@ class Linker {
        public static function link(
                $target, $html = null, $customAttribs = [], $query = [], $options = []
        ) {
-               if ( !$target instanceof Title ) {
-                       wfWarn( __METHOD__ . ': Requires $target to be a Title object.', 2 );
+               if ( !$target instanceof LinkTarget ) {
+                       wfWarn( __METHOD__ . ': Requires $target to be a LinkTarget object.', 2 );
                        return "<!-- ERROR -->$html";
                }
 
@@ -1291,9 +1291,7 @@ class Linker {
                                                        if ( $target->getText() == '' && !$target->isExternal()
                                                                && !$local && $title
                                                        ) {
-                                                               $newTarget = clone $title;
-                                                               $newTarget->setFragment( '#' . $target->getFragment() );
-                                                               $target = $newTarget;
+                                                               $target = $title->createFragmentTarget( $target->getFragment() );
                                                        }
 
                                                        $thelink = Linker::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail;
@@ -1321,7 +1319,7 @@ class Linker {
         *
         * @note This is only public for technical reasons. It's not intended for use outside Linker.
         *
-        * @param Title $title
+        * @param LinkTarget $linkTarget
         * @param string $text
         * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
         *  as used by WikiMap.
@@ -1330,23 +1328,23 @@ class Linker {
         * @return string HTML link
         */
        public static function makeCommentLink(
-               Title $title, $text, $wikiId = null, $options = []
+               LinkTarget $linkTarget, $text, $wikiId = null, $options = []
        ) {
-               if ( $wikiId !== null && !$title->isExternal() ) {
+               if ( $wikiId !== null && !$linkTarget->isExternal() ) {
                        $link = self::makeExternalLink(
                                WikiMap::getForeignURL(
                                        $wikiId,
-                                       $title->getNamespace() === 0
-                                               ? $title->getDBkey()
-                                               : MWNamespace::getCanonicalName( $title->getNamespace() ) . ':'
-                                                       . $title->getDBkey(),
-                                       $title->getFragment()
+                                       $linkTarget->getNamespace() === 0
+                                               ? $linkTarget->getDBkey()
+                                               : MWNamespace::getCanonicalName( $linkTarget->getNamespace() ) . ':'
+                                                       . $linkTarget->getDBkey(),
+                                       $linkTarget->getFragment()
                                ),
                                $text,
                                /* escape = */ false // Already escaped
                        );
                } else {
-                       $link = self::link( $title, $text, [], [], $options );
+                       $link = self::link( $linkTarget, $text, [], [], $options );
                }
 
                return $link;
index 34f2852..ed8cbb4 100644 (file)
@@ -181,7 +181,8 @@ class DifferenceEngine extends ContextSource {
        public function deletedLink( $id ) {
                if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
                        $dbr = wfGetDB( DB_REPLICA );
-                       $row = $dbr->selectRow( 'archive', '*',
+                       $row = $dbr->selectRow( 'archive',
+                               Revision::selectArchiveFields(),
                                [ 'ar_rev_id' => $id ],
                                __METHOD__ );
                        if ( $row ) {
index 8aea7ab..96e7a7e 100644 (file)
@@ -1129,11 +1129,9 @@ class LocalFile extends File {
 
                if ( $this->historyLine == 0 ) { // called for the first time, return line from cur
                        $this->historyRes = $dbr->select( 'image',
-                               [
-                                       '*',
-                                       "'' AS oi_archive_name",
-                                       '0 as oi_deleted',
-                                       'img_sha1'
+                               self::selectFields() + [
+                                       'oi_archive_name' => $dbr->addQuotes( '' ),
+                                       'oi_deleted' => 0,
                                ],
                                [ 'img_name' => $this->title->getDBkey() ],
                                $fname
@@ -1145,7 +1143,9 @@ class LocalFile extends File {
                                return false;
                        }
                } elseif ( $this->historyLine == 1 ) {
-                       $this->historyRes = $dbr->select( 'oldimage', '*',
+                       $this->historyRes = $dbr->select(
+                               'oldimage',
+                               OldLocalFile::selectFields(),
                                [ 'oi_name' => $this->title->getDBkey() ],
                                $fname,
                                [ 'ORDER BY' => 'oi_timestamp DESC' ]
index 4785ef1..20bc614 100644 (file)
@@ -55,8 +55,7 @@ class ImageHistoryPseudoPager extends ReverseChronologicalPager {
        public function __construct( $imagePage ) {
                parent::__construct( $imagePage->getContext() );
                $this->mImagePage = $imagePage;
-               $this->mTitle = clone $imagePage->getTitle();
-               $this->mTitle->setFragment( '#filehistory' );
+               $this->mTitle = $imagePage->getTitle()->createFragmentTarget( 'filehistory' );
                $this->mImg = null;
                $this->mHist = [];
                $this->mRange = [ 0, 0 ]; // display range
index 6fc36f6..bbf22ba 100644 (file)
@@ -1921,10 +1921,10 @@ class WikiPage implements Page, IDBAccessObject {
                                        $wikiPage = $this;
                                        // Trigger post-create hook
                                        $params = [ &$wikiPage, &$user, $content, $summary,
-                                               $flags & EDIT_MINOR, null, null, &$flags, $revision ];
+                                                               $flags & EDIT_MINOR, null, null, &$flags, $revision ];
                                        Hooks::run( 'PageContentInsertComplete', $params );
                                        // Trigger post-save hook
-                                       $params = array_merge( $params, [ &$status, $meta['baseRevId'] ] );
+                                       $params = array_merge( $params, [ &$status, $meta['baseRevId'], 0 ] );
                                        Hooks::run( 'PageContentSaveComplete', $params );
                                }
                        ),
index df7a9ed..eaee0d2 100644 (file)
@@ -1611,7 +1611,7 @@ abstract class Skin extends ContextSource {
 
                $result .= implode(
                        '<span class="mw-editsection-divider">'
-                               . wfMessage( 'pipe-separator' )->inLanguage( $lang )->text()
+                               . wfMessage( 'pipe-separator' )->inLanguage( $lang )->escaped()
                                . '</span>',
                        $linksHtml
                );
index f0aa9ec..10786da 100644 (file)
@@ -1091,6 +1091,9 @@ return [
                'scripts' => [
                        'resources/src/mediawiki/htmlform/htmlform.Checker.js',
                ],
+               'dependencies' => [
+                       'jquery.throttle-debounce',
+               ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.htmlform.ooui' => [
@@ -1772,6 +1775,7 @@ return [
                        'resources/src/mediawiki.rcfilters/mw.rcfilters.UriProcessor.js',
                ],
                'dependencies' => [
+                       'jquery.byteLength',
                        'oojs',
                        'mediawiki.api',
                        'mediawiki.api.options',
index 7fe25ee..222f14a 100644 (file)
@@ -11,7 +11,7 @@
  * @static
  * @inheritable
  * @param {string} str
- * @return {string}
+ * @return {number}
  */
 jQuery.byteLength = function ( str ) {
        // This basically figures out how many bytes a UTF-16 string (which is what js sees)
index f37229f..ee74ac5 100644 (file)
                // Stringify state
                stringified = JSON.stringify( state );
 
-               if ( stringified.length > 65535 ) {
+               if ( $.byteLength( stringified ) > 65535 ) {
                        // Sanity check, since the preference can only hold that.
                        return;
                }