Skip to content

Commit 84a2983

Browse files
author
Michał Chatłas
committed
PHPCS fixes
1 parent 49d119d commit 84a2983

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

src/UsingDataHooks.php

+47-14
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,28 @@
33
use MediaWiki\Linker\LinkTarget;
44
use MediaWiki\Revision\RevisionRecord;
55

6+
/**
7+
* Registers and defines parser functions for UsingData.
8+
*/
69
class UsingDataHooks {
10+
/**
11+
* @var UsingDataHooks Singleton instance
12+
*/
713
public static $instance = null;
814

15+
/**
16+
* @var UsingDataPPFrameDOM[] Data frames for each page
17+
*/
918
private $dataFrames = [];
1019

20+
/**
21+
* @var bool Whether we are currently searching for data
22+
*/
1123
private $searchingForData = false;
1224

25+
/**
26+
* @var array|null Arguments to override
27+
*/
1328
private static $phTitle = null;
1429

1530
public static function onParserFirstCallInit( Parser &$parser ) {
@@ -19,7 +34,11 @@ public static function onParserFirstCallInit( Parser &$parser ) {
1934
$parser->setFunctionHook( 'using', [ self::$instance, 'usingParserFunction' ], SFH_OBJECT_ARGS );
2035
$parser->setFunctionHook( 'usingarg', [ self::$instance, 'usingArgParserFunction' ], SFH_OBJECT_ARGS );
2136
$parser->setFunctionHook( 'data', [ self::$instance, 'dataParserFunction' ], SFH_OBJECT_ARGS );
22-
$parser->setFunctionHook( 'ancestorname', [ __CLASS__, 'ancestorNameFunction' ], SFH_OBJECT_ARGS | SFH_NO_HASH );
37+
$parser->setFunctionHook(
38+
'ancestorname',
39+
[ __CLASS__, 'ancestorNameFunction' ],
40+
SFH_OBJECT_ARGS | SFH_NO_HASH
41+
);
2342
$parser->setHook( 'using', [ self::$instance, 'usingTag' ] );
2443

2544
return true;
@@ -35,7 +54,8 @@ public static function onGetMagicVariableIDs( &$magicWords ) {
3554
$magicWords[] = 'selfname';
3655
}
3756

38-
/* Returns a UsingData frame for a given page
57+
/**
58+
* Returns a UsingData frame for a given page
3959
*/
4060
private function getDataFrame( $sourcePage, $title, &$parser, $frame ) {
4161
global $wgHooks;
@@ -71,7 +91,9 @@ private function getDataFrame( $sourcePage, $title, &$parser, $frame ) {
7191
return $this->dataFrames[$sourcePage];
7292
}
7393

74-
/* Returns the page title of the $depth ancestor of $frame; empty string if invalid */
94+
/**
95+
* Returns the page title of the $depth ancestor of $frame; empty string if invalid
96+
*/
7597
private static function ancestorNameHandler( $frame, $depth ) {
7698
while ( $depth-- && $frame != null ) {
7799
$frame = $frame->parent ?? null;
@@ -83,10 +105,15 @@ private static function ancestorNameHandler( $frame, $depth ) {
83105
/* Handles {{ANCESTORNAME:depth}} */
84106
public static function ancestorNameFunction( &$parser, $frame, $args ) {
85107
$arg = $frame->expand( $args[0] );
86-
return [ self::ancestorNameHandler( $frame, max( 0, is_numeric( $arg ) ? intval( $arg ) : 1 ) ), 'noparse' => true ];
108+
return [
109+
self::ancestorNameHandler( $frame, max( 0, is_numeric( $arg ) ? intval( $arg ) : 1 ) ),
110+
'noparse' => true
111+
];
87112
}
88113

89-
/* Handles {{PARENTNAME}}, {{SELFNAME}}, {{ANCESTORNAME}} */
114+
/**
115+
* Handles {{PARENTNAME}}, {{SELFNAME}}, {{ANCESTORNAME}}
116+
*/
90117
public static function ancestorNameVar( &$parser, &$varCache, &$index, &$ret, &$frame ) {
91118
if ( $index == 'parentname' ) {
92119
$ret = self::ancestorNameHandler( $frame, 1 );
@@ -97,7 +124,8 @@ public static function ancestorNameVar( &$parser, &$varCache, &$index, &$ret, &$
97124
return true;
98125
}
99126

100-
/* Parses common elements of #using syntax.
127+
/**
128+
* Parses common elements of #using syntax.
101129
*/
102130
private function usingParse( &$parser, $frame, $args ) {
103131
if ( $this->searchingForData ) {
@@ -132,7 +160,8 @@ private function usingParse( &$parser, $frame, $args ) {
132160
return [ $this->getDataFrame( $sourcePage, $title, $parser, $frame ), $sourceHash, $namedArgs, $one, $two ];
133161
}
134162

135-
/* {{#using:Page#Hash|Template|Default|...}} parses Template using #data from Page's Hash fragment; or Default
163+
/**
164+
* {{#using:Page#Hash|Template|Default|...}} parses Template using #data from Page's Hash fragment; or Default
136165
* if no data from Page can be found. Named arguments override those in the #data tag.
137166
*/
138167
public function usingParserFunction( &$parser, $frame, $args ) {
@@ -149,7 +178,9 @@ public function usingParserFunction( &$parser, $frame, $args ) {
149178
return $dframe->expandUsing( $frame, $title, $dom, $namedArgs, $fragment );
150179
}
151180

152-
/* {{#usingarg:Page#Hash|Arg|Default}} returns the value of Arg data field on Page's Hash fragment, Default if undefined.
181+
/**
182+
* {{#usingarg:Page#Hash|Arg|Default}} returns the value of Arg data field on Page's Hash fragment, Default if
183+
* undefined.
153184
*/
154185
public function usingArgParserFunction( &$parser, $frame, $args ) {
155186
$parse = $this->usingParse( $parser, $frame, $args );
@@ -167,12 +198,13 @@ public function usingArgParserFunction( &$parser, $frame, $args ) {
167198
return $ret !== false ? $ret : $frame->expand( $defaultValue );
168199
}
169200

170-
/* <using page="Page#Hash" default="Default">...</using>
201+
/**
202+
* <using page="Page#Hash" default="Default">...</using>
171203
* expands ... using the data from Page's Hash fragment; Default if undefined.
172204
* This tag relies on $parser->replaceVariables($text, $frame), which may prove fragile across MW versions.
173-
* Should it break, $parser->recursiveTagParse($text, $frame), in combination with either modifying the markerType, or using
174-
* insertStripItem directly, is a viable short-term alternative -- but one that call certain hooks prematurely,
175-
* potentially causing other extensions to misbehave slightly.
205+
* Should it break, $parser->recursiveTagParse($text, $frame), in combination with either modifying the markerType,
206+
* or using insertStripItem directly, is a viable short-term alternative -- but one that call certain hooks
207+
* prematurely, potentially causing other extensions to misbehave slightly.
176208
*/
177209
public function usingTag( $text, array $args, Parser $parser, PPFrame $frame ) {
178210
if ( $this->searchingForData ) {
@@ -206,7 +238,7 @@ public function usingTag( $text, array $args, Parser $parser, PPFrame $frame ) {
206238
];
207239
}
208240

209-
/* {{#data:Template#Hash|...}} specifies data-transcludable arguments for the page; may not be transcluded. */
241+
/** {{#data:Template#Hash|...}} specifies data-transcludable arguments for the page; may not be transcluded. */
210242
public function dataParserFunction( Parser &$parser, PPFrame $frame, $args ) {
211243
$templateTitle = trim( $frame->expand( $args[0] ) );
212244
$hostPage = $frame->title->getPrefixedText();
@@ -253,7 +285,8 @@ public function dataParserFunction( Parser &$parser, PPFrame $frame, $args ) {
253285
return $cframe->expand( $dom );
254286
}
255287

256-
/* Returns template text for transclusion.
288+
/**
289+
* Returns template text for transclusion.
257290
*/
258291
private function fetchTemplate( $parser, $template ) {
259292
global $wgNonincludableNamespaces;

src/UsingDataPPFrameDOM.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ public function getArgument( $index ) {
136136
case 'data-fragment':
137137
return $this->expansionFragment;
138138
case 'data-source-fragment':
139-
return $this->sourcePage . ( empty( $this->expansionFragment ) ? '' : ( '#' . $this->expansionFragment ) );
139+
return $this->sourcePage . (
140+
empty( $this->expansionFragment ) ?
141+
'' :
142+
( '#' . $this->expansionFragment )
143+
);
140144
default:
141145
if ( is_array( $this->overrideArgs ) && isset( $this->overrideArgs[$index] ) ) {
142146
if ( is_object( $this->overrideArgs[$index] ) ) {

0 commit comments

Comments
 (0)