| Conditions | 45 |
| Paths | > 20000 |
| Total Lines | 366 |
| Code Lines | 233 |
| Lines | 50 |
| Ratio | 13.66 % |
| 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 |
||
| 141 | function showForm( $err ) { |
||
| 142 | global $wgContLang; |
||
| 143 | |||
| 144 | $this->getSkin()->setRelevantTitle( $this->oldTitle ); |
||
| 145 | |||
| 146 | $out = $this->getOutput(); |
||
| 147 | $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) ); |
||
| 148 | $out->addModules( 'mediawiki.special.movePage' ); |
||
| 149 | $out->addModuleStyles( 'mediawiki.special.movePage.styles' ); |
||
| 150 | $this->addHelpLink( 'Help:Moving a page' ); |
||
| 151 | |||
| 152 | $out->addWikiMsg( $this->getConfig()->get( 'FixDoubleRedirects' ) ? |
||
| 153 | 'movepagetext' : |
||
| 154 | 'movepagetext-noredirectfixer' |
||
| 155 | ); |
||
| 156 | |||
| 157 | if ( $this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) { |
||
| 158 | $out->wrapWikiMsg( |
||
| 159 | "<div class=\"warningbox mw-moveuserpage-warning\">\n$1\n</div>", |
||
| 160 | 'moveuserpage-warning' |
||
| 161 | ); |
||
| 162 | } elseif ( $this->oldTitle->getNamespace() == NS_CATEGORY ) { |
||
| 163 | $out->wrapWikiMsg( |
||
| 164 | "<div class=\"warningbox mw-movecategorypage-warning\">\n$1\n</div>", |
||
| 165 | 'movecategorypage-warning' |
||
| 166 | ); |
||
| 167 | } |
||
| 168 | |||
| 169 | $deleteAndMove = false; |
||
| 170 | $moveOverShared = false; |
||
| 171 | |||
| 172 | $newTitle = $this->newTitle; |
||
| 173 | |||
| 174 | if ( !$newTitle ) { |
||
| 175 | # Show the current title as a default |
||
| 176 | # when the form is first opened. |
||
| 177 | $newTitle = $this->oldTitle; |
||
| 178 | } elseif ( !count( $err ) ) { |
||
| 179 | # If a title was supplied, probably from the move log revert |
||
| 180 | # link, check for validity. We can then show some diagnostic |
||
| 181 | # information and save a click. |
||
| 182 | $newerr = $this->oldTitle->isValidMoveOperation( $newTitle ); |
||
|
|
|||
| 183 | if ( is_array( $newerr ) ) { |
||
| 184 | $err = $newerr; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | $user = $this->getUser(); |
||
| 189 | |||
| 190 | View Code Duplication | if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists' |
|
| 191 | && $newTitle->quickUserCan( 'delete', $user ) |
||
| 192 | ) { |
||
| 193 | $out->wrapWikiMsg( |
||
| 194 | "<div class='warningbox'>\n$1\n</div>\n", |
||
| 195 | [ 'delete_and_move_text', $newTitle->getPrefixedText() ] |
||
| 196 | ); |
||
| 197 | $deleteAndMove = true; |
||
| 198 | $err = []; |
||
| 199 | } |
||
| 200 | |||
| 201 | View Code Duplication | if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'file-exists-sharedrepo' |
|
| 202 | && $user->isAllowed( 'reupload-shared' ) |
||
| 203 | ) { |
||
| 204 | $out->wrapWikiMsg( |
||
| 205 | "<div class='warningbox'>\n$1\n</div>\n", |
||
| 206 | [ |
||
| 207 | 'move-over-sharedrepo', |
||
| 208 | $newTitle->getPrefixedText() |
||
| 209 | ] |
||
| 210 | ); |
||
| 211 | $moveOverShared = true; |
||
| 212 | $err = []; |
||
| 213 | } |
||
| 214 | |||
| 215 | $oldTalk = $this->oldTitle->getTalkPage(); |
||
| 216 | $oldTitleSubpages = $this->oldTitle->hasSubpages(); |
||
| 217 | $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages(); |
||
| 218 | |||
| 219 | $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) && |
||
| 220 | !count( $this->oldTitle->getUserPermissionsErrors( 'move-subpages', $user ) ); |
||
| 221 | |||
| 222 | # We also want to be able to move assoc. subpage talk-pages even if base page |
||
| 223 | # has no associated talk page, so || with $oldTitleTalkSubpages. |
||
| 224 | $considerTalk = !$this->oldTitle->isTalkPage() && |
||
| 225 | ( $oldTalk->exists() |
||
| 226 | || ( $oldTitleTalkSubpages && $canMoveSubpage ) ); |
||
| 227 | |||
| 228 | $dbr = wfGetDB( DB_SLAVE ); |
||
| 229 | if ( $this->getConfig()->get( 'FixDoubleRedirects' ) ) { |
||
| 230 | $hasRedirects = $dbr->selectField( 'redirect', '1', |
||
| 231 | [ |
||
| 232 | 'rd_namespace' => $this->oldTitle->getNamespace(), |
||
| 233 | 'rd_title' => $this->oldTitle->getDBkey(), |
||
| 234 | ], __METHOD__ ); |
||
| 235 | } else { |
||
| 236 | $hasRedirects = false; |
||
| 237 | } |
||
| 238 | |||
| 239 | if ( count( $err ) ) { |
||
| 240 | $out->addHTML( "<div class='errorbox'>\n" ); |
||
| 241 | $action_desc = $this->msg( 'action-move' )->plain(); |
||
| 242 | $out->addWikiMsg( 'permissionserrorstext-withaction', count( $err ), $action_desc ); |
||
| 243 | |||
| 244 | if ( count( $err ) == 1 ) { |
||
| 245 | $errMsg = $err[0]; |
||
| 246 | $errMsgName = array_shift( $errMsg ); |
||
| 247 | |||
| 248 | if ( $errMsgName == 'hookaborted' ) { |
||
| 249 | $out->addHTML( "<p>{$errMsg[0]}</p>\n" ); |
||
| 250 | } else { |
||
| 251 | $out->addWikiMsgArray( $errMsgName, $errMsg ); |
||
| 252 | } |
||
| 253 | } else { |
||
| 254 | $errStr = []; |
||
| 255 | |||
| 256 | foreach ( $err as $errMsg ) { |
||
| 257 | if ( $errMsg[0] == 'hookaborted' ) { |
||
| 258 | $errStr[] = $errMsg[1]; |
||
| 259 | } else { |
||
| 260 | $errMsgName = array_shift( $errMsg ); |
||
| 261 | $errStr[] = $this->msg( $errMsgName, $errMsg )->parse(); |
||
| 262 | } |
||
| 263 | } |
||
| 264 | |||
| 265 | $out->addHTML( '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n" ); |
||
| 266 | } |
||
| 267 | $out->addHTML( "</div>\n" ); |
||
| 268 | } |
||
| 269 | |||
| 270 | if ( $this->oldTitle->isProtected( 'move' ) ) { |
||
| 271 | # Is the title semi-protected? |
||
| 272 | if ( $this->oldTitle->isSemiProtected( 'move' ) ) { |
||
| 273 | $noticeMsg = 'semiprotectedpagemovewarning'; |
||
| 274 | $classes[] = 'mw-textarea-sprotected'; |
||
| 275 | } else { |
||
| 276 | # Then it must be protected based on static groups (regular) |
||
| 277 | $noticeMsg = 'protectedpagemovewarning'; |
||
| 278 | $classes[] = 'mw-textarea-protected'; |
||
| 279 | } |
||
| 280 | $out->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" ); |
||
| 281 | $out->addWikiMsg( $noticeMsg ); |
||
| 282 | LogEventsList::showLogExtract( |
||
| 283 | $out, |
||
| 284 | 'protect', |
||
| 285 | $this->oldTitle, |
||
| 286 | '', |
||
| 287 | [ 'lim' => 1 ] |
||
| 288 | ); |
||
| 289 | $out->addHTML( "</div>\n" ); |
||
| 290 | } |
||
| 291 | |||
| 292 | // Byte limit (not string length limit) for wpReason and wpNewTitleMain |
||
| 293 | // is enforced in the mediawiki.special.movePage module |
||
| 294 | |||
| 295 | $immovableNamespaces = []; |
||
| 296 | foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) { |
||
| 297 | if ( !MWNamespace::isMovable( $nsId ) ) { |
||
| 298 | $immovableNamespaces[] = $nsId; |
||
| 299 | } |
||
| 300 | } |
||
| 301 | |||
| 302 | $handler = ContentHandler::getForTitle( $this->oldTitle ); |
||
| 303 | |||
| 304 | $out->enableOOUI(); |
||
| 305 | $fields = []; |
||
| 306 | |||
| 307 | $fields[] = new OOUI\FieldLayout( |
||
| 308 | new MediaWiki\Widget\ComplexTitleInputWidget( [ |
||
| 309 | 'id' => 'wpNewTitle', |
||
| 310 | 'namespace' => [ |
||
| 311 | 'id' => 'wpNewTitleNs', |
||
| 312 | 'name' => 'wpNewTitleNs', |
||
| 313 | 'value' => $newTitle->getNamespace(), |
||
| 314 | 'exclude' => $immovableNamespaces, |
||
| 315 | ], |
||
| 316 | 'title' => [ |
||
| 317 | 'id' => 'wpNewTitleMain', |
||
| 318 | 'name' => 'wpNewTitleMain', |
||
| 319 | 'value' => $wgContLang->recodeForEdit( $newTitle->getText() ), |
||
| 320 | // Inappropriate, since we're expecting the user to input a non-existent page's title |
||
| 321 | 'suggestions' => false, |
||
| 322 | ], |
||
| 323 | 'infusable' => true, |
||
| 324 | ] ), |
||
| 325 | [ |
||
| 326 | 'label' => $this->msg( 'newtitle' )->text(), |
||
| 327 | 'align' => 'top', |
||
| 328 | ] |
||
| 329 | ); |
||
| 330 | |||
| 331 | $fields[] = new OOUI\FieldLayout( |
||
| 332 | new OOUI\TextInputWidget( [ |
||
| 333 | 'name' => 'wpReason', |
||
| 334 | 'id' => 'wpReason', |
||
| 335 | 'maxLength' => 200, |
||
| 336 | 'infusable' => true, |
||
| 337 | 'value' => $this->reason, |
||
| 338 | ] ), |
||
| 339 | [ |
||
| 340 | 'label' => $this->msg( 'movereason' )->text(), |
||
| 341 | 'align' => 'top', |
||
| 342 | ] |
||
| 343 | ); |
||
| 344 | |||
| 345 | if ( $considerTalk ) { |
||
| 346 | $fields[] = new OOUI\FieldLayout( |
||
| 347 | new OOUI\CheckboxInputWidget( [ |
||
| 348 | 'name' => 'wpMovetalk', |
||
| 349 | 'id' => 'wpMovetalk', |
||
| 350 | 'value' => '1', |
||
| 351 | 'selected' => $this->moveTalk, |
||
| 352 | ] ), |
||
| 353 | [ |
||
| 354 | 'label' => $this->msg( 'movetalk' )->text(), |
||
| 355 | 'help' => new OOUI\HtmlSnippet( $this->msg( 'movepagetalktext' )->parseAsBlock() ), |
||
| 356 | 'align' => 'inline', |
||
| 357 | 'infusable' => true, |
||
| 358 | ] |
||
| 359 | ); |
||
| 360 | } |
||
| 361 | |||
| 362 | if ( $user->isAllowed( 'suppressredirect' ) ) { |
||
| 363 | if ( $handler->supportsRedirects() ) { |
||
| 364 | $isChecked = $this->leaveRedirect; |
||
| 365 | $isDisabled = false; |
||
| 366 | } else { |
||
| 367 | $isChecked = false; |
||
| 368 | $isDisabled = true; |
||
| 369 | } |
||
| 370 | $fields[] = new OOUI\FieldLayout( |
||
| 371 | new OOUI\CheckboxInputWidget( [ |
||
| 372 | 'name' => 'wpLeaveRedirect', |
||
| 373 | 'id' => 'wpLeaveRedirect', |
||
| 374 | 'value' => '1', |
||
| 375 | 'selected' => $isChecked, |
||
| 376 | 'disabled' => $isDisabled, |
||
| 377 | ] ), |
||
| 378 | [ |
||
| 379 | 'label' => $this->msg( 'move-leave-redirect' )->text(), |
||
| 380 | 'align' => 'inline', |
||
| 381 | ] |
||
| 382 | ); |
||
| 383 | } |
||
| 384 | |||
| 385 | View Code Duplication | if ( $hasRedirects ) { |
|
| 386 | $fields[] = new OOUI\FieldLayout( |
||
| 387 | new OOUI\CheckboxInputWidget( [ |
||
| 388 | 'name' => 'wpFixRedirects', |
||
| 389 | 'id' => 'wpFixRedirects', |
||
| 390 | 'value' => '1', |
||
| 391 | 'selected' => $this->fixRedirects, |
||
| 392 | ] ), |
||
| 393 | [ |
||
| 394 | 'label' => $this->msg( 'fix-double-redirects' )->text(), |
||
| 395 | 'align' => 'inline', |
||
| 396 | ] |
||
| 397 | ); |
||
| 398 | } |
||
| 399 | |||
| 400 | if ( $canMoveSubpage ) { |
||
| 401 | $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' ); |
||
| 402 | $fields[] = new OOUI\FieldLayout( |
||
| 403 | new OOUI\CheckboxInputWidget( [ |
||
| 404 | 'name' => 'wpMovesubpages', |
||
| 405 | 'id' => 'wpMovesubpages', |
||
| 406 | 'value' => '1', |
||
| 407 | # Don't check the box if we only have talk subpages to |
||
| 408 | # move and we aren't moving the talk page. |
||
| 409 | 'selected' => $this->moveSubpages && ( $this->oldTitle->hasSubpages() || $this->moveTalk ), |
||
| 410 | ] ), |
||
| 411 | [ |
||
| 412 | 'label' => new OOUI\HtmlSnippet( |
||
| 413 | $this->msg( |
||
| 414 | ( $this->oldTitle->hasSubpages() |
||
| 415 | ? 'move-subpages' |
||
| 416 | : 'move-talk-subpages' ) |
||
| 417 | )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse() |
||
| 418 | ), |
||
| 419 | 'align' => 'inline', |
||
| 420 | ] |
||
| 421 | ); |
||
| 422 | } |
||
| 423 | |||
| 424 | # Don't allow watching if user is not logged in |
||
| 425 | if ( $user->isLoggedIn() ) { |
||
| 426 | $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' ) |
||
| 427 | || $user->isWatched( $this->oldTitle ) ); |
||
| 428 | $fields[] = new OOUI\FieldLayout( |
||
| 429 | new OOUI\CheckboxInputWidget( [ |
||
| 430 | 'name' => 'wpWatch', |
||
| 431 | 'id' => 'watch', # ew |
||
| 432 | 'value' => '1', |
||
| 433 | 'selected' => $watchChecked, |
||
| 434 | ] ), |
||
| 435 | [ |
||
| 436 | 'label' => $this->msg( 'move-watch' )->text(), |
||
| 437 | 'align' => 'inline', |
||
| 438 | ] |
||
| 439 | ); |
||
| 440 | } |
||
| 441 | |||
| 442 | $hiddenFields = ''; |
||
| 443 | if ( $moveOverShared ) { |
||
| 444 | $hiddenFields .= Html::hidden( 'wpMoveOverSharedFile', '1' ); |
||
| 445 | } |
||
| 446 | |||
| 447 | View Code Duplication | if ( $deleteAndMove ) { |
|
| 448 | $fields[] = new OOUI\FieldLayout( |
||
| 449 | new OOUI\CheckboxInputWidget( [ |
||
| 450 | 'name' => 'wpDeleteAndMove', |
||
| 451 | 'id' => 'wpDeleteAndMove', |
||
| 452 | 'value' => '1', |
||
| 453 | ] ), |
||
| 454 | [ |
||
| 455 | 'label' => $this->msg( 'delete_and_move_confirm' )->text(), |
||
| 456 | 'align' => 'inline', |
||
| 457 | ] |
||
| 458 | ); |
||
| 459 | } |
||
| 460 | |||
| 461 | $fields[] = new OOUI\FieldLayout( |
||
| 462 | new OOUI\ButtonInputWidget( [ |
||
| 463 | 'name' => 'wpMove', |
||
| 464 | 'value' => $this->msg( 'movepagebtn' )->text(), |
||
| 465 | 'label' => $this->msg( 'movepagebtn' )->text(), |
||
| 466 | 'flags' => [ 'constructive', 'primary' ], |
||
| 467 | 'type' => 'submit', |
||
| 468 | ] ), |
||
| 469 | [ |
||
| 470 | 'align' => 'top', |
||
| 471 | ] |
||
| 472 | ); |
||
| 473 | |||
| 474 | $fieldset = new OOUI\FieldsetLayout( [ |
||
| 475 | 'label' => $this->msg( 'move-page-legend' )->text(), |
||
| 476 | 'id' => 'mw-movepage-table', |
||
| 477 | 'items' => $fields, |
||
| 478 | ] ); |
||
| 479 | |||
| 480 | $form = new OOUI\FormLayout( [ |
||
| 481 | 'method' => 'post', |
||
| 482 | 'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ), |
||
| 483 | 'id' => 'movepage', |
||
| 484 | ] ); |
||
| 485 | $form->appendContent( |
||
| 486 | $fieldset, |
||
| 487 | new OOUI\HtmlSnippet( |
||
| 488 | $hiddenFields . |
||
| 489 | Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) . |
||
| 490 | Html::hidden( 'wpEditToken', $user->getEditToken() ) |
||
| 491 | ) |
||
| 492 | ); |
||
| 493 | |||
| 494 | $out->addHTML( |
||
| 495 | new OOUI\PanelLayout( [ |
||
| 496 | 'classes' => [ 'movepage-wrapper' ], |
||
| 497 | 'expanded' => false, |
||
| 498 | 'padded' => true, |
||
| 499 | 'framed' => true, |
||
| 500 | 'content' => $form, |
||
| 501 | ] ) |
||
| 502 | ); |
||
| 503 | |||
| 504 | $this->showLogFragment( $this->oldTitle ); |
||
| 505 | $this->showSubpages( $this->oldTitle ); |
||
| 506 | } |
||
| 507 | |||
| 832 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.