Tpt has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/401053 )
Change subject: Applies some coding standards
......................................................................
Applies some coding standards
* adds visibility to static function
* rename methods to be camlCased
* drops an unused static variable
* Replaces some "==" with "===" when it does not change semantics
* is_null -> "=== null"
Change-Id: I4dbf4deac88ae393cb9eac3161a7026fa299b807
---
M .phpcs.xml
M LabeledSectionTransclusion.class.php
2 files changed, 28 insertions(+), 80 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/LabeledSectionTransclusion
refs/changes/53/401053/1
diff --git a/.phpcs.xml b/.phpcs.xml
index 9b3fa34..53b90b0 100644
--- a/.phpcs.xml
+++ b/.phpcs.xml
@@ -3,9 +3,7 @@
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
<exclude
name="MediaWiki.Commenting.FunctionComment.MissingParamComment" />
<exclude name="MediaWiki.Files.ClassMatchesFilename.NotMatch" />
- <exclude
name="MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName" />
<exclude
name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" />
- <exclude name="Squiz.Scope.MethodScope.Missing" />
</rule>
<file>.</file>
<arg name="extensions" value="php,php5,inc" />
diff --git a/LabeledSectionTransclusion.class.php
b/LabeledSectionTransclusion.class.php
index 8a5eaeb..a119bb9 100644
--- a/LabeledSectionTransclusion.class.php
+++ b/LabeledSectionTransclusion.class.php
@@ -2,13 +2,11 @@
class LabeledSectionTransclusion {
- private static $loopCheck = [];
-
/**
* @param Parser $parser
* @return bool
*/
- static function setup( $parser ) {
+ public static function setup( $parser ) {
$parser->setHook( 'section', [ __CLASS__, 'noop' ] );
$parser->setFunctionHook( 'lst', [ __CLASS__, 'pfuncIncludeObj'
], Parser::SFH_OBJECT_ARGS );
$parser->setFunctionHook( 'lstx', [ __CLASS__,
'pfuncExcludeObj' ], Parser::SFH_OBJECT_ARGS );
@@ -24,7 +22,7 @@
* @param string $langCode
* @return bool
*/
- static function setupMagic( &$magicWords, $langCode ) {
+ public static function setupMagic( &$magicWords, $langCode ) {
global $wgParser, $wgLstLocal;
switch ( $langCode ) {
@@ -70,7 +68,7 @@
* @param string $part1
* @return bool
*/
- static function open_( $parser, $part1 ) {
+ private static function open( $parser, $part1 ) {
// Infinite loop test
if ( isset( $parser->mTemplatePath[$part1] ) ) {
wfDebug( __METHOD__ . ": template loop broken at
'$part1'\n" );
@@ -78,21 +76,6 @@
} else {
$parser->mTemplatePath[$part1] = 1;
return true;
- }
- }
-
- /**
- * Finish processing the function.
- * @param Parser $parser
- * @param string $part1
- * @return bool
- */
- static function close_( $parser, $part1 ) {
- // Infinite loop test
- if ( isset( $parser->mTemplatePath[$part1] ) ) {
- unset( $parser->mTemplatePath[$part1] );
- } else {
- wfDebug( __METHOD__ . ": close unopened template loop
at '$part1'\n" );
}
}
@@ -106,14 +89,13 @@
* @param int $skiphead Number of source string headers to skip for
numbering
* @return mixed string or magic array of bits
* @todo handle mixed-case </section>
- * @private
*/
- static function parse_( $parser, $title, $text, $part1, $skiphead = 0 )
{
+ private static function parse( $parser, $title, $text, $part1,
$skiphead = 0 ) {
// if someone tries something like<section begin=blah>lst
only</section>
// text, may as well do the right thing.
$text = str_replace( '</section>', '', $text );
- if ( self::open_( $parser, $part1 ) ) {
+ if ( self::open( $parser, $part1 ) ) {
// Try to get edit sections correct by munging around
the parser's guts.
return [ $text, 'title' => $title, 'replaceHeadings' =>
true,
'headingOffset' => $skiphead, 'noparse' =>
false, 'noargs' => false ];
@@ -136,36 +118,8 @@
* @param Parser $parser
* @return string HTML output
*/
- static function noop( $in, $assocArgs = [], $parser = null ) {
+ public static function noop( $in, $assocArgs = [], $parser = null ) {
return '';
- }
-
- /**
- * Generate a regex to match the section(s) we're interested in.
- * @param string $sec Name of target section
- * @param string $to Optional name of section to end with, if
transcluding
- * multiple sections in sequence. If blank, will
assume
- * same section name as started with.
- * @return string regex
- * @private
- */
- static function getPattern_( $sec, $to ) {
- global $wgLstLocal;
-
- $beginAttr = self::getAttrPattern_( $sec, 'begin' );
- if ( $to == '' ) {
- $endAttr = self::getAttrPattern_( $sec, 'end' );
- } else {
- $endAttr = self::getAttrPattern_( $to, 'end' );
- }
-
- if ( isset( $wgLstLocal ) ) {
- $section_re = "(?i:section|$wgLstLocal[section])";
- } else {
- $section_re = "(?i:section)";
- }
-
- return
"/<$section_re$beginAttr\/?>(.*?)\n?<$section_re$endAttr\/?>/s";
}
/**
@@ -174,18 +128,18 @@
* @param string $type Either "begin" or "end" depending on the type of
section tag to be matched
* @return string
*/
- static function getAttrPattern_( $sec, $type ) {
+ private static function getAttrPattern( $sec, $type ) {
global $wgLstLocal;
$sec = preg_quote( $sec, '/' );
$ws = "(?:\s+[^>]*)?"; // was like $ws="\s*"
if ( isset( $wgLstLocal ) ) {
- if ( $type == 'begin' ) {
+ if ( $type === 'begin' ) {
$attrName = "(?i:begin|{$wgLstLocal['begin']})";
} else {
$attrName = "(?i:end|{$wgLstLocal['end']})";
}
} else {
- if ( $type == 'begin' ) {
+ if ( $type === 'begin' ) {
$attrName = "(?i:begin)";
} else {
$attrName = "(?i:end)";
@@ -203,9 +157,8 @@
* @param string $text
* @param int $limit Cutoff point in the text to stop searching
* @return int Number of matches
- * @private
*/
- static function countHeadings_( $text, $limit ) {
+ private static function countHeadings( $text, $limit ) {
$pat = '^(={1,6}).+\1\s*$()';
$count = 0;
@@ -232,12 +185,11 @@
* @param Title &$title normalized title object
* @param string &$text wikitext output
* @return string bool true if returning text, false if target not found
- * @private
*/
- static function getTemplateText_( $parser, $page, &$title, &$text ) {
+ private static function getTemplateText( $parser, $page, &$title,
&$text ) {
$title = Title::newFromText( $page );
- if ( is_null( $title ) ) {
+ if ( $title === null ) {
$text = '';
return true;
} else {
@@ -265,7 +217,7 @@
* @param string $func
* @return array|string
*/
- static function setupPfunc12( $parser, $frame, $args, $func = 'lst' ) {
+ private static function setupPfunc12( $parser, $frame, $args, $func =
'lst' ) {
if ( !count( $args ) ) {
return '';
}
@@ -295,7 +247,7 @@
$begin = trim( $frame->expand( array_shift( $args ) ) );
- if ( $func == 'lstx' ) {
+ if ( $func === 'lstx' ) {
if ( !count( $args ) ) {
$repl = '';
} else {
@@ -309,9 +261,9 @@
$end = trim( $frame->expand( array_shift( $args ) ) );
}
- $beginAttr = self::getAttrPattern_( $begin, 'begin' );
+ $beginAttr = self::getAttrPattern( $begin, 'begin' );
$beginRegex = "/^$beginAttr$/s";
- $endAttr = self::getAttrPattern_( $end, 'end' );
+ $endAttr = self::getAttrPattern( $end, 'end' );
$endRegex = "/^$endAttr$/s";
return compact( 'dom', 'root', 'newFrame', 'repl',
'beginRegex', 'begin', 'endRegex' );
@@ -322,10 +274,10 @@
* @param string $name
* @return bool
*/
- static function isSection( $name ) {
+ private static function isSection( $name ) {
global $wgLstLocal;
$name = strtolower( $name );
- return $name == 'section'
+ return $name === 'section'
|| ( isset( $wgLstLocal['section'] ) && strtolower(
$wgLstLocal['section'] ) == $name );
}
@@ -336,7 +288,7 @@
* @param array $parts
* @return string
*/
- static function expandSectionNode( $parser, $frame, $parts ) {
+ private static function expandSectionNode( $parser, $frame, $parts ) {
if ( isset( $parts['inner'] ) ) {
return $parser->replaceVariables( $parts['inner'],
$frame );
} else {
@@ -350,7 +302,7 @@
* @param array $args
* @return array|string
*/
- static function pfuncIncludeObj( $parser, $frame, $args ) {
+ public static function pfuncIncludeObj( $parser, $frame, $args ) {
$setup = self::setupPfunc12( $parser, $frame, $args, 'lst' );
if ( !is_array( $setup ) ) {
return $setup;
@@ -370,7 +322,6 @@
$text = '';
$node = $root->getFirstChild();
- // @codingStandardsIgnoreStart
while ( $node ) {
// If the name of the begin node was specified, find it.
// Otherwise transclude everything from the beginning
of the page.
@@ -378,7 +329,7 @@
// Find the begin node
$found = false;
for ( ; $node; $node = $node->getNextSibling()
) {
- if ( $node->getName() != 'ext' ) {
+ if ( $node->getName() !== 'ext' ) {
continue;
}
$parts = $node->splitExt();
@@ -424,7 +375,6 @@
$node = $node->getNextSibling();
}
- // @codingStandardsIgnoreEnd
return $text;
}
@@ -434,7 +384,7 @@
* @param array $args
* @return array|string
*/
- static function pfuncExcludeObj( $parser, $frame, $args ) {
+ public static function pfuncExcludeObj( $parser, $frame, $args ) {
$setup = self::setupPfunc12( $parser, $frame, $args, 'lstx' );
if ( !is_array( $setup ) ) {
return $setup;
@@ -458,7 +408,7 @@
// Search for the start tag
$found = false;
for ( ; $node; $node = $node->getNextSibling() ) {
- if ( $node->getName() == 'ext' ) {
+ if ( $node->getName() === 'ext' ) {
$parts = $node->splitExt();
$parts = array_map( [ $newFrame,
'expand' ], $parts );
if ( self::isSection( $parts['name'] )
) {
@@ -484,7 +434,7 @@
// Search for the end tag
for ( ; $node; $node = $node->getNextSibling() ) {
- if ( $node->getName() == 'ext' ) {
+ if ( $node->getName() === 'ext' ) {
$parts = $node->splitExt( $node );
$parts = array_map( [ $newFrame,
'expand' ], $parts );
if ( self::isSection( $parts['name'] )
) {
@@ -514,8 +464,8 @@
* @param string $to
* @return mixed|string
*/
- static function pfuncIncludeHeading( $parser, $page = '', $sec = '',
$to = '' ) {
- if ( self::getTemplateText_( $parser, $page, $title, $text ) ==
false ) {
+ public static function pfuncIncludeHeading( $parser, $page = '', $sec =
'', $to = '' ) {
+ if ( self::getTemplateText( $parser, $page, $title, $text ) ==
false ) {
return $text;
}
@@ -551,7 +501,7 @@
}
}
- $nhead = self::countHeadings_( $text, $begin_off );
+ $nhead = self::countHeadings( $text, $begin_off );
if ( isset( $end_off ) ) {
$result = substr( $text, $begin_off, $end_off -
$begin_off );
@@ -565,6 +515,6 @@
$result = $frame->expand( $dom );
}
- return self::parse_( $parser, $title, $result,
"#lsth:${page}|${sec}", $nhead );
+ return self::parse( $parser, $title, $result,
"#lsth:${page}|${sec}", $nhead );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/401053
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4dbf4deac88ae393cb9eac3161a7026fa299b807
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/LabeledSectionTransclusion
Gerrit-Branch: master
Gerrit-Owner: Tpt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits