Merge "CodeSniffer fixes"

This commit is contained in:
jenkins-bot 2016-09-26 22:27:32 +00:00 committed by Gerrit Code Review
commit 27c935f66c
4 changed files with 83 additions and 84 deletions

View file

@ -48,7 +48,7 @@ class ApiQueryExtracts extends ApiQueryBase {
/** /**
* @var array * @var array
*/ */
private $supportedContentModels = array( 'wikitext' ); private $supportedContentModels = [ 'wikitext' ];
public function __construct( $query, $moduleName, Config $conf ) { public function __construct( $query, $moduleName, Config $conf ) {
parent::__construct( $query, $moduleName, 'ex' ); parent::__construct( $query, $moduleName, 'ex' );
@ -91,9 +91,9 @@ class ApiQueryExtracts extends ApiQueryBase {
} }
if ( $isXml ) { if ( $isXml ) {
$fit = $result->addValue( array( 'query', 'pages', $id ), 'extract', array( '*' => $text ) ); $fit = $result->addValue( [ 'query', 'pages', $id ], 'extract', [ '*' => $text ] );
} else { } else {
$fit = $result->addValue( array( 'query', 'pages', $id ), 'extract', $text ); $fit = $result->addValue( [ 'query', 'pages', $id ], 'extract', $text );
} }
if ( !$fit ) { if ( !$fit ) {
$this->setContinueEnumParameter( 'continue', $continue + $count - 1 ); $this->setContinueEnumParameter( 'continue', $continue + $count - 1 );
@ -196,33 +196,33 @@ class ApiQueryExtracts extends ApiQueryBase {
return $text; return $text;
} }
} }
$request = array( $request = [
'action' => 'parse', 'action' => 'parse',
'page' => $page->getTitle()->getPrefixedText(), 'page' => $page->getTitle()->getPrefixedText(),
'prop' => 'text' 'prop' => 'text'
); ];
if ( $this->params['intro'] ) { if ( $this->params['intro'] ) {
$request['section'] = 0; $request['section'] = 0;
} }
// in case of cache miss, render just the needed section // in case of cache miss, render just the needed section
$api = new ApiMain( new FauxRequest( $request ) ); $api = new ApiMain( new FauxRequest( $request ) );
try { try {
$api->execute(); $api->execute();
$data = $api->getResult()->getResultData( null, array( $data = $api->getResult()->getResultData( null, [
'BC' => array(), 'BC' => [],
'Types' => array(), 'Types' => [],
) ); ] );
} catch ( UsageException $e ) { } catch ( UsageException $e ) {
if ( $e->getCodeString() === 'nosuchsection' ) { if ( $e->getCodeString() === 'nosuchsection' ) {
// Looks like we tried to get the intro to a page without // Looks like we tried to get the intro to a page without
// sections! Lets just grab what we can get. // sections! Lets just grab what we can get.
unset( $request['section'] ); unset( $request['section'] );
$api = new ApiMain( new FauxRequest( $request ) ); $api = new ApiMain( new FauxRequest( $request ) );
$api->execute(); $api->execute();
$data = $api->getResult()->getResultData( null, array( $data = $api->getResult()->getResultData( null, [
'BC' => array(), 'BC' => [],
'Types' => array(), 'Types' => [],
) ); ] );
} else { } else {
// Some other unexpected error - lets just report it to the user // Some other unexpected error - lets just report it to the user
// on the off chance that is the right thing. // on the off chance that is the right thing.
@ -304,7 +304,7 @@ class ApiQueryExtracts extends ApiQueryBase {
*/ */
private function tidy( $text ) { private function tidy( $text ) {
if ( $this->getConfig()->get( 'UseTidy' ) && !$this->params['plaintext'] ) { if ( $this->getConfig()->get( 'UseTidy' ) && !$this->params['plaintext'] ) {
$text = trim ( MWTidy::tidy( $text ) ); $text = trim( MWTidy::tidy( $text ) );
} }
return $text; return $text;
} }
@ -312,7 +312,7 @@ class ApiQueryExtracts extends ApiQueryBase {
private function doSections( $text ) { private function doSections( $text ) {
$text = preg_replace_callback( $text = preg_replace_callback(
"/" . ExtractFormatter::SECTION_MARKER_START . '(\d)'. ExtractFormatter::SECTION_MARKER_END . "(.*?)$/m", "/" . ExtractFormatter::SECTION_MARKER_START . '(\d)'. ExtractFormatter::SECTION_MARKER_END . "(.*?)$/m",
array( $this, 'sectionCallback' ), [ $this, 'sectionCallback' ],
$text $text
); );
return $text; return $text;
@ -336,44 +336,44 @@ class ApiQueryExtracts extends ApiQueryBase {
} }
public function getAllowedParams() { public function getAllowedParams() {
return array( return [
'chars' => array( 'chars' => [
ApiBase::PARAM_TYPE => 'integer', ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MIN => 1,
), ],
'sentences' => array( 'sentences' => [
ApiBase::PARAM_TYPE => 'integer', ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MIN => 1,
ApiBase::PARAM_MAX => 10, ApiBase::PARAM_MAX => 10,
), ],
'limit' => array( 'limit' => [
ApiBase::PARAM_DFLT => 1, ApiBase::PARAM_DFLT => 1,
ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MIN => 1,
ApiBase::PARAM_MAX => 20, ApiBase::PARAM_MAX => 20,
ApiBase::PARAM_MAX2 => 20, ApiBase::PARAM_MAX2 => 20,
), ],
'intro' => false, 'intro' => false,
'plaintext' => false, 'plaintext' => false,
'sectionformat' => array( 'sectionformat' => [
ApiBase::PARAM_TYPE => array( 'plain', 'wiki', 'raw' ), ApiBase::PARAM_TYPE => [ 'plain', 'wiki', 'raw' ],
ApiBase::PARAM_DFLT => 'wiki', ApiBase::PARAM_DFLT => 'wiki',
), ],
'continue' => array( 'continue' => [
ApiBase::PARAM_TYPE => 'integer', ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
), ],
); ];
} }
/** /**
* @see ApiBase::getExamplesMessages() * @see ApiBase::getExamplesMessages()
*/ */
protected function getExamplesMessages() { protected function getExamplesMessages() {
return array( return [
'action=query&prop=extracts&exchars=175&titles=Therion' 'action=query&prop=extracts&exchars=175&titles=Therion'
=> 'apihelp-query+extracts-example-1', => 'apihelp-query+extracts-example-1',
); ];
} }
public function getHelpUrls() { public function getHelpUrls() {

View file

@ -45,7 +45,7 @@ class ExtractFormatter extends HtmlFormatter {
if ( $plainText ) { if ( $plainText ) {
$this->flattenAllTags(); $this->flattenAllTags();
} else { } else {
$this->flatten( array( 'a' ) ); $this->flatten( [ 'a' ] );
} }
} }
@ -64,7 +64,7 @@ class ExtractFormatter extends HtmlFormatter {
public function onHtmlReady( $html ) { public function onHtmlReady( $html ) {
if ( $this->plainText ) { if ( $this->plainText ) {
$html = preg_replace( '/\s*(<h([1-6])\b)/i', $html = preg_replace( '/\s*(<h([1-6])\b)/i',
"\n\n" . self::SECTION_MARKER_START . '$2' . self::SECTION_MARKER_END . '$1' , "\n\n" . self::SECTION_MARKER_START . '$2' . self::SECTION_MARKER_END . '$1',
$html $html
); );
} }
@ -80,21 +80,21 @@ class ExtractFormatter extends HtmlFormatter {
*/ */
public static function getFirstSentences( $text, $requestedSentenceCount ) { public static function getFirstSentences( $text, $requestedSentenceCount ) {
// Based on code from OpenSearchXml by Brion Vibber // Based on code from OpenSearchXml by Brion Vibber
$endchars = array( $endchars = [
'[^\p{Lu}]\.(?:[ \n]|$)', '[\!\?](?:[ \n]|$)', // regular ASCII '[^\p{Lu}]\.(?:[ \n]|$)', '[\!\?](?:[ \n]|$)', // regular ASCII
'。', // full-width ideographic full-stop '。', // full-width ideographic full-stop
'', '', '', // double-width roman forms '', '', '', // double-width roman forms
'。', // half-width ideographic full stop '。', // half-width ideographic full stop
); ];
$endgroup = implode( '|', $endchars ); $endgroup = implode( '|', $endchars );
$end = "(?:$endgroup)"; $end = "(?:$endgroup)";
$sentence = ".+?$end+"; $sentence = ".+?$end+";
$requestedSentenceCount = intval( $requestedSentenceCount ); $requestedSentenceCount = intval( $requestedSentenceCount );
$regexp = "/^($sentence){1,{$requestedSentenceCount}}/u"; $regexp = "/^($sentence){1,{$requestedSentenceCount}}/u";
$matches = array(); $matches = [];
$res = preg_match( $regexp, $text, $matches ); $res = preg_match( $regexp, $text, $matches );
if( $res ) { if ( $res ) {
$text = trim( $matches[0] ); $text = trim( $matches[0] );
} else { } else {
if ( $res === false ) { if ( $res === false ) {

View file

@ -2,7 +2,6 @@
namespace TextExtracts; namespace TextExtracts;
use ApiMain; use ApiMain;
use ApiResult; use ApiResult;
use ConfigFactory; use ConfigFactory;
@ -22,17 +21,17 @@ class Hooks {
} }
$pageIds = array_keys( $results ); $pageIds = array_keys( $results );
$api = new ApiMain( new FauxRequest( $api = new ApiMain( new FauxRequest(
array( [
'action' => 'query', 'action' => 'query',
'prop' => 'extracts', 'prop' => 'extracts',
'explaintext' => true, 'explaintext' => true,
'exintro' => true, 'exintro' => true,
'exlimit' => count( $results ), 'exlimit' => count( $results ),
'pageids' => implode( '|', $pageIds ), 'pageids' => implode( '|', $pageIds ),
) ) ] )
); );
$api->execute(); $api->execute();
$data = $api->getResult()->getResultData( array( 'query', 'pages' ) ); $data = $api->getResult()->getResultData( [ 'query', 'pages' ] );
foreach ( $pageIds as $id ) { foreach ( $pageIds as $id ) {
$contentKey = isset( $data[$id]['extract'][ApiResult::META_CONTENT] ) $contentKey = isset( $data[$id]['extract'][ApiResult::META_CONTENT] )
? $data[$id]['extract'][ApiResult::META_CONTENT] ? $data[$id]['extract'][ApiResult::META_CONTENT]

View file

@ -22,29 +22,29 @@ class ExtractFormatterTest extends MediaWikiTestCase {
public function provideExtracts() { public function provideExtracts() {
$dutch = '<b>Dutch</b> (<span class="unicode haudio" style="white-space:nowrap;"><span class="fn"><a href="/wiki/File:Nl-Nederlands.ogg" title="About this sound"><img alt="About this sound" src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Loudspeaker.svg/11px-Loudspeaker.svg.png" width="11" height="11" srcset="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Loudspeaker.svg/17px-Loudspeaker.svg.png 1.5x, https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Loudspeaker.svg/22px-Loudspeaker.svg.png 2x" /></a>&#160;<a href="https://upload.wikimedia.org/wikipedia/commons/d/db/Nl-Nederlands.ogg" class="internal" title="Nl-Nederlands.ogg"><i>Nederlands</i></a></span>&#160;<small class="metadata audiolinkinfo" style="cursor:help;">(<a href="/w/index.php?title=Wikipedia:Media_help&amp;action=edit&amp;redlink=1" class="new" title="Wikipedia:Media help (page does not exist)"><span style="cursor:help;">help</span></a>·<a href="/wiki/File:Nl-Nederlands.ogg" title="File:Nl-Nederlands.ogg"><span style="cursor:help;">info</span></a>)</small></span>) is a <a href="/w/index.php?title=West_Germanic_languages&amp;action=edit&amp;redlink=1" class="new" title="West Germanic languages (page does not exist)">West Germanic language</a> and the native language of most of the population of the <a href="/w/index.php?title=Netherlands&amp;action=edit&amp;redlink=1" class="new" title="Netherlands (page does not exist)">Netherlands</a>'; $dutch = '<b>Dutch</b> (<span class="unicode haudio" style="white-space:nowrap;"><span class="fn"><a href="/wiki/File:Nl-Nederlands.ogg" title="About this sound"><img alt="About this sound" src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Loudspeaker.svg/11px-Loudspeaker.svg.png" width="11" height="11" srcset="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Loudspeaker.svg/17px-Loudspeaker.svg.png 1.5x, https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Loudspeaker.svg/22px-Loudspeaker.svg.png 2x" /></a>&#160;<a href="https://upload.wikimedia.org/wikipedia/commons/d/db/Nl-Nederlands.ogg" class="internal" title="Nl-Nederlands.ogg"><i>Nederlands</i></a></span>&#160;<small class="metadata audiolinkinfo" style="cursor:help;">(<a href="/w/index.php?title=Wikipedia:Media_help&amp;action=edit&amp;redlink=1" class="new" title="Wikipedia:Media help (page does not exist)"><span style="cursor:help;">help</span></a>·<a href="/wiki/File:Nl-Nederlands.ogg" title="File:Nl-Nederlands.ogg"><span style="cursor:help;">info</span></a>)</small></span>) is a <a href="/w/index.php?title=West_Germanic_languages&amp;action=edit&amp;redlink=1" class="new" title="West Germanic languages (page does not exist)">West Germanic language</a> and the native language of most of the population of the <a href="/w/index.php?title=Netherlands&amp;action=edit&amp;redlink=1" class="new" title="Netherlands (page does not exist)">Netherlands</a>';
return array( return [
array( [
"Dutch ( Nederlands ) is a West Germanic language and the native language of most of the population of the Netherlands", "Dutch ( Nederlands ) is a West Germanic language and the native language of most of the population of the Netherlands",
$dutch, $dutch,
true, true,
), ],
array( [
"<span><span lang=\"baz\">qux</span></span>", "<span><span lang=\"baz\">qux</span></span>",
'<span class="foo"><span lang="baz">qux</span></span>', '<span class="foo"><span lang="baz">qux</span></span>',
false, false,
), ],
array( [
"<span><span lang=\"baz\">qux</span></span>", "<span><span lang=\"baz\">qux</span></span>",
'<span style="foo: bar;"><span lang="baz">qux</span></span>', '<span style="foo: bar;"><span lang="baz">qux</span></span>',
false, false,
), ],
array( [
"<span><span lang=\"qux\">quux</span></span>", "<span><span lang=\"qux\">quux</span></span>",
'<span class="foo"><span style="bar: baz;" lang="qux">quux</span></span>', '<span class="foo"><span style="bar: baz;" lang="qux">quux</span></span>',
false, false,
), ],
); ];
} }
/** /**
@ -58,68 +58,68 @@ class ExtractFormatterTest extends MediaWikiTestCase {
} }
public function provideGetFirstSentences() { public function provideGetFirstSentences() {
return array( return [
array( [
'Foo is a bar. Such a smart boy. But completely useless.', 'Foo is a bar. Such a smart boy. But completely useless.',
2, 2,
'Foo is a bar. Such a smart boy.', 'Foo is a bar. Such a smart boy.',
), ],
array( [
'Foo is a bar. Such a smart boy. But completely useless.', 'Foo is a bar. Such a smart boy. But completely useless.',
1, 1,
'Foo is a bar.', 'Foo is a bar.',
), ],
array( [
'Foo is a bar. Such a smart boy.', 'Foo is a bar. Such a smart boy.',
2, 2,
'Foo is a bar. Such a smart boy.', 'Foo is a bar. Such a smart boy.',
), ],
array( [
'Foo is a bar.', 'Foo is a bar.',
1, 1,
'Foo is a bar.', 'Foo is a bar.',
), ],
array( [
'Foo is a bar.', 'Foo is a bar.',
2, 2,
'Foo is a bar.', 'Foo is a bar.',
), ],
array( [
'', '',
1, 1,
'', '',
), ],
// Exclamation points too!!! // Exclamation points too!!!
array( [
'Foo is a bar! Such a smart boy! But completely useless!', 'Foo is a bar! Such a smart boy! But completely useless!',
1, 1,
'Foo is a bar!', 'Foo is a bar!',
), ],
// A tricky one // A tricky one
array( [
"Acid phosphatase (EC 3.1.3.2) is a chemical you don't want to mess with. Polyvinyl acetate, however, is another story.", "Acid phosphatase (EC 3.1.3.2) is a chemical you don't want to mess with. Polyvinyl acetate, however, is another story.",
1, 1,
"Acid phosphatase (EC 3.1.3.2) is a chemical you don't want to mess with.", "Acid phosphatase (EC 3.1.3.2) is a chemical you don't want to mess with.",
), ],
// Bug T118621 // Bug T118621
array( [
'Foo was born in 1977. He enjoys listening to Siouxsie and the Banshees.', 'Foo was born in 1977. He enjoys listening to Siouxsie and the Banshees.',
1, 1,
'Foo was born in 1977.', 'Foo was born in 1977.',
), ],
// Bug T115795 - Test no cropping after initials // Bug T115795 - Test no cropping after initials
array( [
'P.J. Harvey is a singer. She is awesome!', 'P.J. Harvey is a singer. She is awesome!',
1, 1,
'P.J. Harvey is a singer.', 'P.J. Harvey is a singer.',
), ],
// Bug T115817 - Non-breaking space is not a delimiter // Bug T115817 - Non-breaking space is not a delimiter
array( [
html_entity_decode( 'Pigeons (lat.&nbsp;Columbidae) are birds. They primarily feed on seeds.' ), html_entity_decode( 'Pigeons (lat.&nbsp;Columbidae) are birds. They primarily feed on seeds.' ),
1, 1,
html_entity_decode( 'Pigeons (lat.&nbsp;Columbidae) are birds.' ), html_entity_decode( 'Pigeons (lat.&nbsp;Columbidae) are birds.' ),
), ],
); ];
} }
/** /**
@ -134,13 +134,13 @@ class ExtractFormatterTest extends MediaWikiTestCase {
public function provideGetFirstChars() { public function provideGetFirstChars() {
$text = 'Lullzy lulz are lullzy!'; $text = 'Lullzy lulz are lullzy!';
return array( return [
//array( $text, 0, '' ), // [ $text, 0, '' ],
array( $text, 100, $text ), [ $text, 100, $text ],
array( $text, 1, 'Lullzy' ), [ $text, 1, 'Lullzy' ],
array( $text, 6, 'Lullzy' ), [ $text, 6, 'Lullzy' ],
//array( $text, 7, 'Lullzy' ), // [ $text, 7, 'Lullzy' ],
array( $text, 8, 'Lullzy lulz' ), [ $text, 8, 'Lullzy lulz' ],
); ];
} }
} }