Merge "Minor parameter documentation improvements on External Store classes"
authorIAlex <ialex.wiki@gmail.com>
Thu, 4 Oct 2012 04:41:46 +0000 (04:41 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 4 Oct 2012 04:41:46 +0000 (04:41 +0000)
RELEASE-NOTES-1.21
includes/api/ApiQueryExtLinksUsage.php
includes/api/ApiQueryExternalLinks.php
includes/filebackend/FileBackendStore.php
includes/parser/ParserOutput.php
includes/specials/SpecialActiveusers.php
includes/specials/SpecialListusers.php
tests/parser/parserTests.txt
tests/phpunit/includes/parser/ParserOutputTest.php [new file with mode: 0644]

index 0548946..50c3b2d 100644 (file)
@@ -20,6 +20,8 @@ production.
 * (bug 40352) fixDoubleRedirects.php should support interwiki redirects.
 * (bug 9237) SpecialBrokenRedirect should not list interwiki redirects.
 * (bug 34960) Drop unused fields rc_moved_to_ns and rc_moved_to_title from recentchanges table.
+* (bug 32951) Do not register internal externals with absolute protocol,
+  when server has relative protocol.
 
 === API changes in 1.21 ===
 * (bug 35693) ApiQueryImageInfo now suppresses errors when unserializing metadata.
index 42b398b..6081601 100644 (file)
@@ -121,8 +121,12 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                                        ApiQueryBase::addTitleInfo( $vals, $title );
                                }
                                if ( $fld_url ) {
-                                       // We *could* run this through wfExpandUrl() but I think it's better to output the link verbatim, even if it's protocol-relative --Roan
-                                       $vals['url'] = $row->el_to;
+                                       $to = $row->el_to;
+                                       // expand protocol-relative urls
+                                       if( $params['expandurl'] ) {
+                                               $to = wfExpandUrl( $to, PROTO_CANONICAL );
+                                       }
+                                       $vals['url'] = $to;
                                }
                                $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
                                if ( !$fit ) {
@@ -169,7 +173,8 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                                ApiBase::PARAM_MIN => 1,
                                ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
                                ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
-                       )
+                       ),
+                       'expandurl' => false,
                );
        }
 
@@ -218,7 +223,8 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                        ),
                        'query' => 'Search string without protocol. See [[Special:LinkSearch]]. Leave empty to list all external links',
                        'namespace' => 'The page namespace(s) to enumerate.',
-                       'limit' => 'How many pages to return.'
+                       'limit' => 'How many pages to return.',
+                       'expandurl' => 'Expand protocol-relative urls with the canonical protocol',
                );
 
                if ( $wgMiserMode ) {
index 9365a9b..1449a96 100644 (file)
@@ -86,8 +86,12 @@ class ApiQueryExternalLinks extends ApiQueryBase {
                                break;
                        }
                        $entry = array();
-                       // We *could* run this through wfExpandUrl() but I think it's better to output the link verbatim, even if it's protocol-relative --Roan
-                       ApiResult::setContent( $entry, $row->el_to );
+                       $to = $row->el_to;
+                       // expand protocol-relative urls
+                       if( $params['expandurl'] ) {
+                               $to = wfExpandUrl( $to, PROTO_CANONICAL );
+                       }
+                       ApiResult::setContent( $entry, $to );
                        $fit = $this->addPageSubItem( $row->el_from, $entry );
                        if ( !$fit ) {
                                $this->setContinueEnumParameter( 'offset', $offset + $count - 1 );
@@ -117,6 +121,7 @@ class ApiQueryExternalLinks extends ApiQueryBase {
                                ApiBase::PARAM_DFLT => '',
                        ),
                        'query' => null,
+                       'expandurl' => false,
                );
        }
 
@@ -130,6 +135,7 @@ class ApiQueryExternalLinks extends ApiQueryBase {
                                "Leave both this and {$p}query empty to list all external links"
                        ),
                        'query' => 'Search string without protocol. Useful for checking whether a certain page contains a certain external url',
+                       'expandurl' => 'Expand protocol-relative urls with the canonical protocol',
                );
        }
 
index 4271c4a..a29816f 100644 (file)
@@ -667,11 +667,11 @@ abstract class FileBackendStore extends FileBackend {
         */
        protected function doGetFileContentsMulti( array $params ) {
                $contents = array();
-               wfSuppressWarnings();
                foreach ( $this->doGetLocalReferenceMulti( $params ) as $path => $fsFile ) {
+                       wfSuppressWarnings();
                        $contents[$path] = $fsFile ? file_get_contents( $fsFile->getPath() ) : false;
+                       wfRestoreWarnings();
                }
-               wfRestoreWarnings();
                return $contents;
        }
 
index 41b4a38..be629d3 100644 (file)
@@ -150,11 +150,35 @@ class ParserOutput extends CacheTime {
                return (bool)$this->mNewSection;
        }
 
+       /**
+        * Checks, if a url is pointing to the own server
+        *
+        * @param $internal String the server to check against
+        * @param $url String the url to check
+        * @return bool
+        */
+       static function isLinkInternal( $internal, $url ) {
+               return (bool)preg_match( '/^' .
+                       # If server is proto relative, check also for http/https links
+                       ( substr( $internal, 0, 2 ) === '//' ? '(?:https?:)?' : '' ) .
+                       preg_quote( $internal, '/' ) .
+                       # check for query/path/anchor or end of link in each case
+                       '(?:[\?\/\#]|$)/i',
+                       $url
+               );
+       }
+
        function addExternalLink( $url ) {
                # We don't register links pointing to our own server, unless... :-)
                global $wgServer, $wgRegisterInternalExternals;
-               if( $wgRegisterInternalExternals or stripos($url,$wgServer.'/')!==0)
+
+               $registerExternalLink = true;
+               if( !$wgRegisterInternalExternals ) {
+                       $registerExternalLink = !self::isLinkInternal( $wgServer, $url );
+               }
+               if( $registerExternalLink ) {
                        $this->mExternalLinks[$url] = 1;
+               }
        }
 
        /**
index c5aa238..994365e 100644 (file)
@@ -93,7 +93,9 @@ class ActiveUsersPager extends UsersPager {
        function getQueryInfo() {
                $dbr = wfGetDB( DB_SLAVE );
                $conds = array( 'rc_user > 0' ); // Users - no anons
-               $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
+               if( !$this->getUser()->isAllowed( 'hideuser' ) ) {
+                       $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0'; // don't show hidden names
+               }
                $conds[] = 'rc_log_type IS NULL OR rc_log_type != ' . $dbr->addQuotes( 'newusers' );
                $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $dbr->timestamp( wfTimestamp( TS_UNIX ) - $this->RCMaxAge*24*3600 ) );
 
@@ -107,7 +109,7 @@ class ActiveUsersPager extends UsersPager {
                                'rc_user_text', // for Pager
                                'user_id',
                                'recentedits' => 'COUNT(*)',
-                               'blocked' => 'MAX(ipb_user)'
+                               'ipb_deleted' => 'MAX(ipb_deleted)'
                        ),
                        'options' => array(
                                'GROUP BY' => array( 'rc_user_text', 'user_id' ),
@@ -117,8 +119,7 @@ class ActiveUsersPager extends UsersPager {
                                'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
                                'ipblocks' => array( 'LEFT JOIN', array(
                                        'user_id=ipb_user',
-                                       'ipb_auto' => 0,
-                                       'ipb_deleted' => 1
+                                       'ipb_auto' => 0
                                )),
                        ),
                        'conds' => $conds
@@ -162,9 +163,12 @@ class ActiveUsersPager extends UsersPager {
                $groups = $lang->commaList( $list );
 
                $item = $lang->specialList( $ulinks, $groups );
+               if( $row->ipb_deleted ) {
+                       $item = "<span class=\"deleted\">$item</span>";
+               }
                $count = $this->msg( 'activeusers-count' )->numParams( $row->recentedits )
                        ->params( $userName )->numParams( $this->RCMaxAge )->escaped();
-               $blocked = $row->blocked ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
+               $blocked = !is_null( $row->ipb_deleted ) ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
 
                return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
        }
index 331a0e0..11d7f4d 100644 (file)
@@ -89,7 +89,7 @@ class UsersPager extends AlphabeticPager {
                $conds = array();
                // Don't show hidden names
                if( !$this->getUser()->isAllowed( 'hideuser' ) ) {
-                       $conds[] = 'ipb_deleted IS NULL';
+                       $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0';
                }
 
                $options = array();
@@ -129,7 +129,6 @@ class UsersPager extends AlphabeticPager {
                                'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ),
                                'ipblocks' => array( 'LEFT JOIN', array(
                                        'user_id=ipb_user',
-                                       'ipb_deleted' => 1,
                                        'ipb_auto' => 0
                                )),
                        ),
@@ -185,9 +184,10 @@ class UsersPager extends AlphabeticPager {
                        $created = $this->msg( 'usercreated', $d, $t, $row->user_name )->escaped();
                        $created = ' ' . $this->msg( 'parentheses' )->rawParams( $created )->escaped();
                }
+               $blocked = !is_null( $row->ipb_deleted ) ? ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : '';
 
                wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
-               return Html::rawElement( 'li', array(), "{$item}{$edits}{$created}" );
+               return Html::rawElement( 'li', array(), "{$item}{$edits}{$created}{$blocked}" );
        }
 
        function doBatchLookups() {
index f9c7f14..f555d4f 100644 (file)
@@ -968,6 +968,50 @@ bar
 </pre>
 !!end
 
+###
+### Parsoid-centric tests for testing RT edge cases
+### around comments and white-space inside pre blocks
+###
+
+!!test
+1a. Pre and Comments
+!!input
+ a
+<!--a-->
+c
+!!result
+<pre>a
+</pre>
+<p>c
+</p>
+!!end
+
+!!test
+1b. Pre and Comments
+!!input
+ a
+ <!--a-->
+c
+!!result
+<pre>a
+</pre>
+<p>c
+</p>
+!!end
+
+!!test
+1c. Pre and Comments
+!!input
+<!--a-->  a
+
+ <!--a--> a
+!!result
+<pre> a
+</pre>
+<pre> a
+</pre>
+!!end
+
 ###
 ### Definition lists
 ###
diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php
new file mode 100644 (file)
index 0000000..2244fdb
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+class ParserOutputTest extends MediaWikiTestCase {
+
+       function dataIsLinkInternal() {
+               return array(
+                       // Different domains
+                       array( false, 'http://example.org', 'http://mediawiki.org' ),
+                       // Same domains
+                       array( true, 'http://example.org', 'http://example.org' ),
+                       array( true, 'https://example.org', 'https://example.org' ),
+                       array( true, '//example.org', '//example.org' ),
+                       // Same domain different cases
+                       array( true, 'http://example.org', 'http://EXAMPLE.ORG' ),
+                       // Paths, queries, and fragments are not relevant
+                       array( true, 'http://example.org', 'http://example.org/wiki/Main_Page' ),
+                       array( true, 'http://example.org', 'http://example.org?my=query' ),
+                       array( true, 'http://example.org', 'http://example.org#its-a-fragment' ),
+                       // Different protocols
+                       array( false, 'http://example.org', 'https://example.org' ),
+                       array( false, 'https://example.org', 'http://example.org' ),
+                       // Protocol relative servers always match http and https links
+                       array( true, '//example.org', 'http://example.org' ),
+                       array( true, '//example.org', 'https://example.org' ),
+                       // But they don't match strange things like this
+                       array( false, '//example.org', 'irc://example.org' ),
+               );
+       }
+
+       /**
+        * Test to make sure ParserOutput::isLinkInternal behaves properly
+        * @dataProvider dataIsLinkInternal
+        */
+       function testIsLinkInternal( $shouldMatch, $server, $url ) {
+
+               $this->assertEquals( $shouldMatch, ParserOutput::isLinkInternal( $server, $url ) );
+       }
+}