| Conditions | 93 | 
| Paths | > 20000 | 
| Total Lines | 428 | 
| Code Lines | 269 | 
| Lines | 34 | 
| Ratio | 7.94 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 45 | 	public function execute() { | 
            ||
| 46 | // The data is hot but user-dependent, like page views, so we set vary cookies  | 
            ||
| 47 | $this->getMain()->setCacheMode( 'anon-public-user-private' );  | 
            ||
| 48 | |||
| 49 | // Get parameters  | 
            ||
| 50 | $params = $this->extractRequestParams();  | 
            ||
| 51 | $text = $params['text'];  | 
            ||
| 52 | $title = $params['title'];  | 
            ||
| 53 | 		if ( $title === null ) { | 
            ||
| 54 | $titleProvided = false;  | 
            ||
| 55 | // A title is needed for parsing, so arbitrarily choose one  | 
            ||
| 56 | $title = 'API';  | 
            ||
| 57 | 		} else { | 
            ||
| 58 | $titleProvided = true;  | 
            ||
| 59 | }  | 
            ||
| 60 | |||
| 61 | $page = $params['page'];  | 
            ||
| 62 | $pageid = $params['pageid'];  | 
            ||
| 63 | $oldid = $params['oldid'];  | 
            ||
| 64 | |||
| 65 | $model = $params['contentmodel'];  | 
            ||
| 66 | $format = $params['contentformat'];  | 
            ||
| 67 | |||
| 68 | 		if ( !is_null( $page ) && ( !is_null( $text ) || $titleProvided ) ) { | 
            ||
| 69 | $this->dieUsage(  | 
            ||
| 70 | 'The page parameter cannot be used together with the text and title parameters',  | 
            ||
| 71 | 'params'  | 
            ||
| 72 | );  | 
            ||
| 73 | }  | 
            ||
| 74 | |||
| 75 | $prop = array_flip( $params['prop'] );  | 
            ||
| 76 | |||
| 77 | 		if ( isset( $params['section'] ) ) { | 
            ||
| 78 | $this->section = $params['section'];  | 
            ||
| 79 | 			if ( !preg_match( '/^((T-)?\d+|new)$/', $this->section ) ) { | 
            ||
| 80 | $this->dieUsage(  | 
            ||
| 81 | 'The section parameter must be a valid section id or "new"', 'invalidsection'  | 
            ||
| 82 | );  | 
            ||
| 83 | }  | 
            ||
| 84 | 		} else { | 
            ||
| 85 | $this->section = false;  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 86 | }  | 
            ||
| 87 | |||
| 88 | // The parser needs $wgTitle to be set, apparently the  | 
            ||
| 89 | // $title parameter in Parser::parse isn't enough *sigh*  | 
            ||
| 90 | // TODO: Does this still need $wgTitle?  | 
            ||
| 91 | global $wgParser, $wgTitle;  | 
            ||
| 92 | |||
| 93 | $redirValues = null;  | 
            ||
| 94 | |||
| 95 | // Return result  | 
            ||
| 96 | $result = $this->getResult();  | 
            ||
| 97 | |||
| 98 | 		if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) { | 
            ||
| 99 | 			if ( $this->section === 'new' ) { | 
            ||
| 100 | $this->dieUsage(  | 
            ||
| 101 | 'section=new cannot be combined with oldid, pageid or page parameters. ' .  | 
            ||
| 102 | 'Please use text', 'params'  | 
            ||
| 103 | );  | 
            ||
| 104 | }  | 
            ||
| 105 | 			if ( !is_null( $oldid ) ) { | 
            ||
| 106 | // Don't use the parser cache  | 
            ||
| 107 | $rev = Revision::newFromId( $oldid );  | 
            ||
| 108 | 				if ( !$rev ) { | 
            ||
| 109 | $this->dieUsage( "There is no revision ID $oldid", 'missingrev' );  | 
            ||
| 110 | }  | 
            ||
| 111 | |||
| 112 | $this->checkReadPermissions( $rev->getTitle() );  | 
            ||
| 113 | 				if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) { | 
            ||
| 114 | $this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' );  | 
            ||
| 115 | }  | 
            ||
| 116 | |||
| 117 | $titleObj = $rev->getTitle();  | 
            ||
| 118 | $wgTitle = $titleObj;  | 
            ||
| 119 | $pageObj = WikiPage::factory( $titleObj );  | 
            ||
| 120 | list( $popts, $reset, $suppressCache ) = $this->makeParserOptions( $pageObj, $params );  | 
            ||
| 121 | |||
| 122 | // If for some reason the "oldid" is actually the current revision, it may be cached  | 
            ||
| 123 | // Deliberately comparing $pageObj->getLatest() with $rev->getId(), rather than  | 
            ||
| 124 | // checking $rev->isCurrent(), because $pageObj is what actually ends up being used,  | 
            ||
| 125 | // and if its ->getLatest() is outdated, $rev->isCurrent() won't tell us that.  | 
            ||
| 126 | 				if ( !$suppressCache && $rev->getId() == $pageObj->getLatest() ) { | 
            ||
| 127 | // May get from/save to parser cache  | 
            ||
| 128 | $p_result = $this->getParsedContent( $pageObj, $popts,  | 
            ||
| 129 | $pageid, isset( $prop['wikitext'] ) );  | 
            ||
| 130 | 				} else { // This is an old revision, so get the text differently | 
            ||
| 131 | $this->content = $rev->getContent( Revision::FOR_THIS_USER, $this->getUser() );  | 
            ||
| 132 | |||
| 133 | 					if ( $this->section !== false ) { | 
            ||
| 134 | $this->content = $this->getSectionContent( $this->content, 'r' . $rev->getId() );  | 
            ||
| 135 | }  | 
            ||
| 136 | |||
| 137 | // Should we save old revision parses to the parser cache?  | 
            ||
| 138 | $p_result = $this->content->getParserOutput( $titleObj, $rev->getId(), $popts );  | 
            ||
| 139 | }  | 
            ||
| 140 | 			} else { // Not $oldid, but $pageid or $page | 
            ||
| 141 | 				if ( $params['redirects'] ) { | 
            ||
| 142 | $reqParams = [  | 
            ||
| 143 | 'redirects' => '',  | 
            ||
| 144 | ];  | 
            ||
| 145 | 					if ( !is_null( $pageid ) ) { | 
            ||
| 146 | $reqParams['pageids'] = $pageid;  | 
            ||
| 147 | 					} else { // $page | 
            ||
| 148 | $reqParams['titles'] = $page;  | 
            ||
| 149 | }  | 
            ||
| 150 | $req = new FauxRequest( $reqParams );  | 
            ||
| 151 | $main = new ApiMain( $req );  | 
            ||
| 152 | $pageSet = new ApiPageSet( $main );  | 
            ||
| 153 | $pageSet->execute();  | 
            ||
| 154 | $redirValues = $pageSet->getRedirectTitlesAsResult( $this->getResult() );  | 
            ||
| 155 | |||
| 156 | $to = $page;  | 
            ||
| 157 | 					foreach ( $pageSet->getRedirectTitles() as $title ) { | 
            ||
| 158 | $to = $title->getFullText();  | 
            ||
| 159 | }  | 
            ||
| 160 | $pageParams = [ 'title' => $to ];  | 
            ||
| 161 | 				} elseif ( !is_null( $pageid ) ) { | 
            ||
| 162 | $pageParams = [ 'pageid' => $pageid ];  | 
            ||
| 163 | 				} else { // $page | 
            ||
| 164 | $pageParams = [ 'title' => $page ];  | 
            ||
| 165 | }  | 
            ||
| 166 | |||
| 167 | $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );  | 
            ||
| 168 | $titleObj = $pageObj->getTitle();  | 
            ||
| 169 | 				if ( !$titleObj || !$titleObj->exists() ) { | 
            ||
| 170 | $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );  | 
            ||
| 171 | }  | 
            ||
| 172 | |||
| 173 | $this->checkReadPermissions( $titleObj );  | 
            ||
| 174 | $wgTitle = $titleObj;  | 
            ||
| 175 | |||
| 176 | 				if ( isset( $prop['revid'] ) ) { | 
            ||
| 177 | $oldid = $pageObj->getLatest();  | 
            ||
| 178 | }  | 
            ||
| 179 | |||
| 180 | list( $popts, $reset, $suppressCache ) = $this->makeParserOptions( $pageObj, $params );  | 
            ||
| 181 | |||
| 182 | // Don't pollute the parser cache when setting options that aren't  | 
            ||
| 183 | // in ParserOptions::optionsHash()  | 
            ||
| 184 | /// @todo: This should be handled closer to the actual cache instead of here, see T110269  | 
            ||
| 185 | $suppressCache = $suppressCache ||  | 
            ||
| 186 | $params['disablepp'] ||  | 
            ||
| 187 | $params['disablelimitreport'] ||  | 
            ||
| 188 | $params['preview'] ||  | 
            ||
| 189 | $params['sectionpreview'] ||  | 
            ||
| 190 | $params['disabletidy'];  | 
            ||
| 191 | |||
| 192 | 				if ( $suppressCache ) { | 
            ||
| 193 | $this->content = $this->getContent( $pageObj, $pageid );  | 
            ||
| 194 | $p_result = $this->content->getParserOutput( $titleObj, null, $popts );  | 
            ||
| 195 | 				} else { | 
            ||
| 196 | // Potentially cached  | 
            ||
| 197 | $p_result = $this->getParsedContent( $pageObj, $popts, $pageid,  | 
            ||
| 198 | isset( $prop['wikitext'] ) );  | 
            ||
| 199 | }  | 
            ||
| 200 | }  | 
            ||
| 201 | 		} else { // Not $oldid, $pageid, $page. Hence based on $text | 
            ||
| 202 | $titleObj = Title::newFromText( $title );  | 
            ||
| 203 | 			if ( !$titleObj || $titleObj->isExternal() ) { | 
            ||
| 204 | $this->dieUsageMsg( [ 'invalidtitle', $title ] );  | 
            ||
| 205 | }  | 
            ||
| 206 | $wgTitle = $titleObj;  | 
            ||
| 207 | 			if ( $titleObj->canExist() ) { | 
            ||
| 208 | $pageObj = WikiPage::factory( $titleObj );  | 
            ||
| 209 | 			} else { | 
            ||
| 210 | // Do like MediaWiki::initializeArticle()  | 
            ||
| 211 | $article = Article::newFromTitle( $titleObj, $this->getContext() );  | 
            ||
| 212 | $pageObj = $article->getPage();  | 
            ||
| 213 | }  | 
            ||
| 214 | |||
| 215 | list( $popts, $reset ) = $this->makeParserOptions( $pageObj, $params );  | 
            ||
| 216 | $textProvided = !is_null( $text );  | 
            ||
| 217 | |||
| 218 | 			if ( !$textProvided ) { | 
            ||
| 219 | 				if ( $titleProvided && ( $prop || $params['generatexml'] ) ) { | 
            ||
| 220 | $this->setWarning(  | 
            ||
| 221 | "'title' used without 'text', and parsed page properties were requested " .  | 
            ||
| 222 | "(did you mean to use 'page' instead of 'title'?)"  | 
            ||
| 223 | );  | 
            ||
| 224 | }  | 
            ||
| 225 | // Prevent warning from ContentHandler::makeContent()  | 
            ||
| 226 | $text = '';  | 
            ||
| 227 | }  | 
            ||
| 228 | |||
| 229 | // If we are parsing text, do not use the content model of the default  | 
            ||
| 230 | // API title, but default to wikitext to keep BC.  | 
            ||
| 231 | 			if ( $textProvided && !$titleProvided && is_null( $model ) ) { | 
            ||
| 232 | $model = CONTENT_MODEL_WIKITEXT;  | 
            ||
| 233 | $this->setWarning( "No 'title' or 'contentmodel' was given, assuming $model." );  | 
            ||
| 234 | }  | 
            ||
| 235 | |||
| 236 | 			try { | 
            ||
| 237 | $this->content = ContentHandler::makeContent( $text, $titleObj, $model, $format );  | 
            ||
| 238 | 			} catch ( MWContentSerializationException $ex ) { | 
            ||
| 239 | $this->dieUsage( $ex->getMessage(), 'parseerror' );  | 
            ||
| 240 | }  | 
            ||
| 241 | |||
| 242 | 			if ( $this->section !== false ) { | 
            ||
| 243 | 				if ( $this->section === 'new' ) { | 
            ||
| 244 | // Insert the section title above the content.  | 
            ||
| 245 | 					if ( !is_null( $params['sectiontitle'] ) && $params['sectiontitle'] !== '' ) { | 
            ||
| 246 | $this->content = $this->content->addSectionHeader( $params['sectiontitle'] );  | 
            ||
| 247 | }  | 
            ||
| 248 | 				} else { | 
            ||
| 249 | $this->content = $this->getSectionContent( $this->content, $titleObj->getPrefixedText() );  | 
            ||
| 250 | }  | 
            ||
| 251 | }  | 
            ||
| 252 | |||
| 253 | 			if ( $params['pst'] || $params['onlypst'] ) { | 
            ||
| 254 | $this->pstContent = $this->content->preSaveTransform( $titleObj, $this->getUser(), $popts );  | 
            ||
| 255 | }  | 
            ||
| 256 | 			if ( $params['onlypst'] ) { | 
            ||
| 257 | // Build a result and bail out  | 
            ||
| 258 | $result_array = [];  | 
            ||
| 259 | $result_array['text'] = $this->pstContent->serialize( $format );  | 
            ||
| 260 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';  | 
            ||
| 261 | 				if ( isset( $prop['wikitext'] ) ) { | 
            ||
| 262 | $result_array['wikitext'] = $this->content->serialize( $format );  | 
            ||
| 263 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';  | 
            ||
| 264 | }  | 
            ||
| 265 | View Code Duplication | if ( !is_null( $params['summary'] ) ||  | 
            |
| 266 | ( !is_null( $params['sectiontitle'] ) && $this->section === 'new' )  | 
            ||
| 267 | 				) { | 
            ||
| 268 | $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );  | 
            ||
| 269 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';  | 
            ||
| 270 | }  | 
            ||
| 271 | |||
| 272 | $result->addValue( null, $this->getModuleName(), $result_array );  | 
            ||
| 273 | |||
| 274 | return;  | 
            ||
| 275 | }  | 
            ||
| 276 | |||
| 277 | // Not cached (save or load)  | 
            ||
| 278 | 			if ( $params['pst'] ) { | 
            ||
| 279 | $p_result = $this->pstContent->getParserOutput( $titleObj, null, $popts );  | 
            ||
| 280 | 			} else { | 
            ||
| 281 | $p_result = $this->content->getParserOutput( $titleObj, null, $popts );  | 
            ||
| 282 | }  | 
            ||
| 283 | }  | 
            ||
| 284 | |||
| 285 | $result_array = [];  | 
            ||
| 286 | |||
| 287 | $result_array['title'] = $titleObj->getPrefixedText();  | 
            ||
| 288 | $result_array['pageid'] = $pageid ?: $pageObj->getId();  | 
            ||
| 289 | |||
| 290 | 		if ( !is_null( $oldid ) ) { | 
            ||
| 291 | $result_array['revid'] = intval( $oldid );  | 
            ||
| 292 | }  | 
            ||
| 293 | |||
| 294 | 		if ( $params['redirects'] && !is_null( $redirValues ) ) { | 
            ||
| 295 | $result_array['redirects'] = $redirValues;  | 
            ||
| 296 | }  | 
            ||
| 297 | |||
| 298 | 		if ( $params['disabletoc'] ) { | 
            ||
| 299 | $p_result->setTOCEnabled( false );  | 
            ||
| 300 | }  | 
            ||
| 301 | |||
| 302 | 		if ( isset( $prop['text'] ) ) { | 
            ||
| 303 | $result_array['text'] = $p_result->getText();  | 
            ||
| 304 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';  | 
            ||
| 305 | }  | 
            ||
| 306 | |||
| 307 | View Code Duplication | if ( !is_null( $params['summary'] ) ||  | 
            |
| 308 | ( !is_null( $params['sectiontitle'] ) && $this->section === 'new' )  | 
            ||
| 309 | 		) { | 
            ||
| 310 | $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );  | 
            ||
| 311 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';  | 
            ||
| 312 | }  | 
            ||
| 313 | |||
| 314 | 		if ( isset( $prop['langlinks'] ) ) { | 
            ||
| 315 | $langlinks = $p_result->getLanguageLinks();  | 
            ||
| 316 | |||
| 317 | 			if ( $params['effectivelanglinks'] ) { | 
            ||
| 318 | // Link flags are ignored for now, but may in the future be  | 
            ||
| 319 | // included in the result.  | 
            ||
| 320 | $linkFlags = [];  | 
            ||
| 321 | Hooks::run( 'LanguageLinks', [ $titleObj, &$langlinks, &$linkFlags ] );  | 
            ||
| 322 | }  | 
            ||
| 323 | 		} else { | 
            ||
| 324 | $langlinks = false;  | 
            ||
| 325 | }  | 
            ||
| 326 | |||
| 327 | 		if ( isset( $prop['langlinks'] ) ) { | 
            ||
| 328 | $result_array['langlinks'] = $this->formatLangLinks( $langlinks );  | 
            ||
| 329 | }  | 
            ||
| 330 | 		if ( isset( $prop['categories'] ) ) { | 
            ||
| 331 | $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );  | 
            ||
| 332 | }  | 
            ||
| 333 | 		if ( isset( $prop['categorieshtml'] ) ) { | 
            ||
| 334 | $result_array['categorieshtml'] = $this->categoriesHtml( $p_result->getCategories() );  | 
            ||
| 335 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'categorieshtml';  | 
            ||
| 336 | }  | 
            ||
| 337 | 		if ( isset( $prop['links'] ) ) { | 
            ||
| 338 | $result_array['links'] = $this->formatLinks( $p_result->getLinks() );  | 
            ||
| 339 | }  | 
            ||
| 340 | 		if ( isset( $prop['templates'] ) ) { | 
            ||
| 341 | $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );  | 
            ||
| 342 | }  | 
            ||
| 343 | 		if ( isset( $prop['images'] ) ) { | 
            ||
| 344 | $result_array['images'] = array_keys( $p_result->getImages() );  | 
            ||
| 345 | }  | 
            ||
| 346 | 		if ( isset( $prop['externallinks'] ) ) { | 
            ||
| 347 | $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );  | 
            ||
| 348 | }  | 
            ||
| 349 | 		if ( isset( $prop['sections'] ) ) { | 
            ||
| 350 | $result_array['sections'] = $p_result->getSections();  | 
            ||
| 351 | }  | 
            ||
| 352 | |||
| 353 | 		if ( isset( $prop['displaytitle'] ) ) { | 
            ||
| 354 | $result_array['displaytitle'] = $p_result->getDisplayTitle() ?:  | 
            ||
| 355 | $titleObj->getPrefixedText();  | 
            ||
| 356 | }  | 
            ||
| 357 | |||
| 358 | 		if ( isset( $prop['headitems'] ) ) { | 
            ||
| 359 | $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() );  | 
            ||
| 360 | $this->logFeatureUsage( 'action=parse&prop=headitems' );  | 
            ||
| 361 | $this->setWarning( 'headitems is deprecated since MediaWiki 1.28. '  | 
            ||
| 362 | . 'Use prop=headhtml when creating new HTML documents, or '  | 
            ||
| 363 | . 'prop=modules|jsconfigvars when updating a document client-side.' );  | 
            ||
| 364 | }  | 
            ||
| 365 | |||
| 366 | 		if ( isset( $prop['headhtml'] ) ) { | 
            ||
| 367 | $context = new DerivativeContext( $this->getContext() );  | 
            ||
| 368 | $context->setTitle( $titleObj );  | 
            ||
| 369 | $context->setWikiPage( $pageObj );  | 
            ||
| 370 | |||
| 371 | // We need an OutputPage tied to $context, not to the  | 
            ||
| 372 | // RequestContext at the root of the stack.  | 
            ||
| 373 | $output = new OutputPage( $context );  | 
            ||
| 374 | $output->addParserOutputMetadata( $p_result );  | 
            ||
| 375 | |||
| 376 | $result_array['headhtml'] = $output->headElement( $context->getSkin() );  | 
            ||
| 377 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml';  | 
            ||
| 378 | }  | 
            ||
| 379 | |||
| 380 | View Code Duplication | 		if ( isset( $prop['modules'] ) ) { | 
            |
| 381 | $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) );  | 
            ||
| 382 | $result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) );  | 
            ||
| 383 | $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );  | 
            ||
| 384 | }  | 
            ||
| 385 | |||
| 386 | 		if ( isset( $prop['jsconfigvars'] ) ) { | 
            ||
| 387 | $result_array['jsconfigvars'] =  | 
            ||
| 388 | ApiResult::addMetadataToResultVars( $p_result->getJsConfigVars() );  | 
            ||
| 389 | }  | 
            ||
| 390 | |||
| 391 | View Code Duplication | 		if ( isset( $prop['encodedjsconfigvars'] ) ) { | 
            |
| 392 | $result_array['encodedjsconfigvars'] = FormatJson::encode(  | 
            ||
| 393 | $p_result->getJsConfigVars(), false, FormatJson::ALL_OK  | 
            ||
| 394 | );  | 
            ||
| 395 | $result_array[ApiResult::META_SUBELEMENTS][] = 'encodedjsconfigvars';  | 
            ||
| 396 | }  | 
            ||
| 397 | |||
| 398 | View Code Duplication | if ( isset( $prop['modules'] ) &&  | 
            |
| 399 | 			!isset( $prop['jsconfigvars'] ) && !isset( $prop['encodedjsconfigvars'] ) ) { | 
            ||
| 400 | $this->setWarning( 'Property "modules" was set but not "jsconfigvars" ' .  | 
            ||
| 401 | 'or "encodedjsconfigvars". Configuration variables are necessary ' .  | 
            ||
| 402 | 'for proper module usage.' );  | 
            ||
| 403 | }  | 
            ||
| 404 | |||
| 405 | 		if ( isset( $prop['indicators'] ) ) { | 
            ||
| 406 | $result_array['indicators'] = (array)$p_result->getIndicators();  | 
            ||
| 407 | ApiResult::setArrayType( $result_array['indicators'], 'BCkvp', 'name' );  | 
            ||
| 408 | }  | 
            ||
| 409 | |||
| 410 | 		if ( isset( $prop['iwlinks'] ) ) { | 
            ||
| 411 | $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );  | 
            ||
| 412 | }  | 
            ||
| 413 | |||
| 414 | 		if ( isset( $prop['wikitext'] ) ) { | 
            ||
| 415 | $result_array['wikitext'] = $this->content->serialize( $format );  | 
            ||
| 416 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';  | 
            ||
| 417 | 			if ( !is_null( $this->pstContent ) ) { | 
            ||
| 418 | $result_array['psttext'] = $this->pstContent->serialize( $format );  | 
            ||
| 419 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'psttext';  | 
            ||
| 420 | }  | 
            ||
| 421 | }  | 
            ||
| 422 | 		if ( isset( $prop['properties'] ) ) { | 
            ||
| 423 | $result_array['properties'] = (array)$p_result->getProperties();  | 
            ||
| 424 | ApiResult::setArrayType( $result_array['properties'], 'BCkvp', 'name' );  | 
            ||
| 425 | }  | 
            ||
| 426 | |||
| 427 | 		if ( isset( $prop['limitreportdata'] ) ) { | 
            ||
| 428 | $result_array['limitreportdata'] =  | 
            ||
| 429 | $this->formatLimitReportData( $p_result->getLimitReportData() );  | 
            ||
| 430 | }  | 
            ||
| 431 | 		if ( isset( $prop['limitreporthtml'] ) ) { | 
            ||
| 432 | $result_array['limitreporthtml'] = EditPage::getPreviewLimitReport( $p_result );  | 
            ||
| 433 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'limitreporthtml';  | 
            ||
| 434 | }  | 
            ||
| 435 | |||
| 436 | 		if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) { | 
            ||
| 437 | 			if ( $this->content->getModel() != CONTENT_MODEL_WIKITEXT ) { | 
            ||
| 438 | $this->dieUsage( 'parsetree is only supported for wikitext content', 'notwikitext' );  | 
            ||
| 439 | }  | 
            ||
| 440 | |||
| 441 | $wgParser->startExternalParse( $titleObj, $popts, Parser::OT_PREPROCESS );  | 
            ||
| 442 | $dom = $wgParser->preprocessToDom( $this->content->getNativeData() );  | 
            ||
| 443 | View Code Duplication | 			if ( is_callable( [ $dom, 'saveXML' ] ) ) { | 
            |
| 444 | $xml = $dom->saveXML();  | 
            ||
| 445 | 			} else { | 
            ||
| 446 | $xml = $dom->__toString();  | 
            ||
| 447 | }  | 
            ||
| 448 | $result_array['parsetree'] = $xml;  | 
            ||
| 449 | $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsetree';  | 
            ||
| 450 | }  | 
            ||
| 451 | |||
| 452 | $result_mapping = [  | 
            ||
| 453 | 'redirects' => 'r',  | 
            ||
| 454 | 'langlinks' => 'll',  | 
            ||
| 455 | 'categories' => 'cl',  | 
            ||
| 456 | 'links' => 'pl',  | 
            ||
| 457 | 'templates' => 'tl',  | 
            ||
| 458 | 'images' => 'img',  | 
            ||
| 459 | 'externallinks' => 'el',  | 
            ||
| 460 | 'iwlinks' => 'iw',  | 
            ||
| 461 | 'sections' => 's',  | 
            ||
| 462 | 'headitems' => 'hi',  | 
            ||
| 463 | 'modules' => 'm',  | 
            ||
| 464 | 'indicators' => 'ind',  | 
            ||
| 465 | 'modulescripts' => 'm',  | 
            ||
| 466 | 'modulestyles' => 'm',  | 
            ||
| 467 | 'properties' => 'pp',  | 
            ||
| 468 | 'limitreportdata' => 'lr',  | 
            ||
| 469 | ];  | 
            ||
| 470 | $this->setIndexedTagNames( $result_array, $result_mapping );  | 
            ||
| 471 | $result->addValue( null, $this->getModuleName(), $result_array );  | 
            ||
| 472 | }  | 
            ||
| 473 | |||
| 847 | 
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.