r52181 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52180‎ | r52181 | r52182 >
Date:22:17, 19 June 2009
Author:aaron
Status:ok
Tags:
Comment:
Refactored massive setPageContent() function by breaking it up
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -268,10 +268,9 @@
269269 # Load required messages
270270 wfLoadExtensionMessages( 'FlaggedRevs' );
271271 $simpleTag = $old = $stable = false;
272 - $tag = $prot = $pending = '';
 272+ $tag = $prot = '';
273273 # Check the newest stable version.
274 - $srev = $this->getStableRev();
275 - $frev = $srev;
 274+ $frev = $srev = $this->getStableRev();
276275 $stableId = $frev ? $frev->getRevId() : 0;
277276 # Also, check for any explicitly requested old stable version...
278277 $reqId = $wgRequest->getVal('stableid');
@@ -337,167 +336,17 @@
338337 // requesting the stable revision ("&stableid=x"), defer to override
339338 // behavior below, since it is the same as ("&stable=1").
340339 if( $old ) {
341 - $revsSince = FlaggedRevs::getRevCountSince( $this->parent, $srev->getRevId() );
342 - $text = $frev->getRevText();
343 - $parserOut = FlaggedRevs::parseStableText( $this->parent, $text, $frev->getRevId() );
344 - # Construct some tagging for non-printable outputs. Note that the pending
345 - # notice has all this info already, so don't do this if we added that already.
346 - if( !$wgOut->isPrintable() ) {
347 - $class = $quality ? 'fr-icon-quality' : 'fr-icon-stable';
348 - $tooltip = $quality ? 'revreview-quality-title' : 'revreview-stable-title';
349 - $tooltip = wfMsgHtml($tooltip);
350 - // Simple icon-based UI
351 - if( FlaggedRevs::useSimpleUI() ) {
352 - $msg = $quality ? 'revreview-quick-quality-old' : 'revreview-quick-basic-old';
353 - $html = "{$prot}<span class='{$class}' title=\"{$tooltip}\"></span>" .
354 - wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $time );
355 - $tag .= FlaggedRevsXML::prettyRatingBox( $frev, $html, $revsSince,
356 - true, false, $old );
357 - // Standard UI
358 - } else {
359 - $msg = $quality ? 'revreview-quality-old' : 'revreview-basic-old';
360 - $tag .= "{$prot}<span class='{$class}' title=\"{$tooltip}\"></span>" .
361 - wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $time );
362 - # Hide clutter
363 - if( !empty($flags) ) {
364 - $tag .= " " . FlaggedRevsXML::ratingToggle();
365 - $tag .= "<span id='mw-revisionratings' style='display:block;'><br/>" .
366 - wfMsgHtml('revreview-oldrating') .
367 - FlaggedRevsXML::addTagRatings( $flags ) . '</span>';
368 - }
369 - }
370 - }
371 - # Output HTML
372 - $this->getReviewNotes( $frev );
373 - $wgOut->addParserOutput( $parserOut );
374 - $wgOut->setRevisionId( $frev->getRevId() );
375 - # Index the stable version only
376 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
377 - # Tell MW that parser output is done
378 - $outputDone = true;
 340+ $this->showOldReviewedVersion( $srev, $frev, $tag, $prot );
 341+ $outputDone = true; # Tell MW that parser output is done
379342 $pcache = false;
380343 // Looking at some specific old revision (&oldid=x) or if FlaggedRevs is not
381344 // set to override given the relevant conditions (like &action=protect).
382345 } elseif( !$stable && !$this->pageOverride() ) {
383 - $revsSince = FlaggedRevs::getRevCountSince( $this->parent, $srev->getRevId() );
384 - $synced = false;
385 - # We only care about syncing if not viewing an old stable version
386 - if( $srev->getRevId() == $frev->getRevId() ) {
387 - $synced = FlaggedRevs::stableVersionIsSynced( $frev, $this->parent );
388 - if( $synced ) {
389 - $this->getReviewNotes( $frev ); // Still the same
390 - }
391 - }
392 - # Give notice to newer users if an unreviewed edit was completed...
393 - if( !$synced && $wgRequest->getVal('shownotice') && !$wgUser->isAllowed('review') ) {
394 - $tooltip = wfMsgHtml('revreview-draft-title');
395 - $pending = "{$prot}<span class='fr-icon-current' title=\"{$tooltip}\"></span>" .
396 - wfMsgExt('revreview-edited',array('parseinline'),$frev->getRevId(),$revsSince);
397 - $pending = "<div id='mw-reviewnotice' class='flaggedrevs_preview plainlinks'>$pending</div>";
398 - # Notice should always use subtitle
399 - $this->reviewNotice = $pending;
400 - }
401 - # If they are synced, do special styling
402 - $simpleTag = !$synced;
403 - # Construct some tagging for non-printable outputs. Note that the pending
404 - # notice has all this info already, so don't do this if we added that already.
405 - if( !$wgOut->isPrintable() && !$pending && !($this->lowProfileUI() && $synced) ) {
406 - $class = 'fr-icon-current'; // default
407 - $tooltip = 'revreview-draft-title';
408 - // Simple icon-based UI
409 - if( FlaggedRevs::useSimpleUI() ) {
410 - if( $synced ) {
411 - $msg = $quality ? 'revreview-quick-quality-same' : 'revreview-quick-basic-same';
412 - $class = $quality ? 'fr-icon-quality' : 'fr-icon-stable';
413 - $tooltip = $quality ? 'revreview-quality-title' : 'revreview-stable-title';
414 - $msgHTML = wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $revsSince );
415 - } else {
416 - $msg = $quality ? 'revreview-quick-see-quality' : 'revreview-quick-see-basic';
417 - $msgHTML = wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $revsSince );
418 - }
419 - $tooltip = wfMsgHtml($tooltip);
420 - $msgHTML = "{$prot}<span class='{$class}' title=\"{$tooltip}\"></span>$msgHTML";
421 - $tag .= FlaggedRevsXML::prettyRatingBox( $frev, $msgHTML, $revsSince,
422 - $synced, $synced, $old );
423 - // Standard UI
424 - } else {
425 - if( $synced ) {
426 - $msg = $quality ? 'revreview-quality-same' : 'revreview-basic-same';
427 - $class = $quality ? 'fr-icon-quality' : 'fr-icon-stable';
428 - $tooltip = $quality ? 'revreview-quality-title' : 'revreview-stable-title';
429 - $msgHTML = wfMsgExt( $msg, array('parseinline'), $frev->getRevId(),
430 - $time, $revsSince );
431 - } else {
432 - $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic';
433 - $msg .= ($revsSince == 0) ? '-i' : '';
434 - $msgHTML = wfMsgExt( $msg, array('parseinline'), $frev->getRevId(),
435 - $time, $revsSince );
436 - }
437 - $tooltip = wfMsgHtml($tooltip);
438 - $tag .= "{$prot}<span class='{$class}' title=\"{$tooltip}\"></span>" . $msgHTML;
439 - # Hide clutter
440 - if( !empty($flags) ) {
441 - $tag .= " " . FlaggedRevsXML::ratingToggle();
442 - $tag .= "<span id='mw-revisionratings' style='display:block;'><br/>" .
443 - wfMsgHtml('revreview-oldrating') . FlaggedRevsXML::addTagRatings( $flags ) . '</span>';
444 - }
445 - }
446 - }
447 - # Index the stable version only if it is the default
448 - if( $this->showStableByDefault() ) {
449 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
450 - }
 346+ $this->showRegularVersion( $srev, $frev, $tag, $prot );
451347 // The relevant conditions are met to override the page with the stable version.
452348 } else {
453 - # We will be looking at the reviewed revision...
454 - $revsSince = FlaggedRevs::getRevCountSince( $this->parent, $frev->getRevId() );
455 - # Get parsed stable version
456 - $parserOut = FlaggedRevs::getPageCache( $this->parent );
457 - if( $parserOut == false ) {
458 - $text = $frev->getRevText();
459 - $parserOut = FlaggedRevs::parseStableText( $this->parent, $text, $frev->getRevId() );
460 - # Update the stable version cache
461 - FlaggedRevs::updatePageCache( $this->parent, $parserOut );
462 - }
463 - $synced = FlaggedRevs::stableVersionIsSynced( $frev, $this->parent, $parserOut, null );
464 - # Construct some tagging
465 - if( !$wgOut->isPrintable() && !($this->lowProfileUI() && $synced) ) {
466 - $class = $quality ? 'fr-icon-quality' : 'fr-icon-stable';
467 - $tooltip = $quality ? 'revreview-quality-title' : 'revreview-stable-title';
468 - $tooltip = wfMsgHtml($tooltip);
469 - // Simple icon-based UI
470 - if( FlaggedRevs::useSimpleUI() ) {
471 - $msg = $quality ? 'revreview-quick-quality' : 'revreview-quick-basic';
472 - # uses messages 'revreview-quick-quality-same', 'revreview-quick-basic-same'
473 - $msg = $synced ? "{$msg}-same" : $msg;
474 - $html = "{$prot}<span class='{$class}' title=\"{$tooltip}\"></span>" .
475 - wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $revsSince );
476 - $tag = FlaggedRevsXML::prettyRatingBox( $frev, $html, $revsSince, true, $synced );
477 - // Standard UI
478 - } else {
479 - $msg = $quality ? 'revreview-quality' : 'revreview-basic';
480 - if( $synced ) {
481 - # uses messages 'revreview-quality-same', 'revreview-basic-same'
482 - $msg .= '-same';
483 - } elseif( $revsSince == 0 ) {
484 - # uses messages 'revreview-quality-i', 'revreview-basic-i'
485 - $msg .= '-i';
486 - }
487 - $tag = "{$prot}<span class='{$class} plainlinks' title=\"{$tooltip}\"></span>" .
488 - wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $time, $revsSince );
489 - if( !empty($flags) ) {
490 - $tag .= " " . FlaggedRevsXML::ratingToggle();
491 - $tag .= "<span id='mw-revisionratings' style='display:block;'><br/>" .
492 - FlaggedRevsXML::addTagRatings( $flags ) . '</span>';
493 - }
494 - }
495 - }
496 - # Output HTML
497 - $this->getReviewNotes( $frev );
498 - $wgOut->addParserOutput( $parserOut );
499 - $wgOut->setRevisionId( $frev->getRevId() );
500 - # Tell MW that parser output is done
501 - $outputDone = true;
 349+ $this->showStableVersion( $srev, $frev, $tag, $prot );
 350+ $outputDone = true; # Tell MW that parser output is done
502351 $pcache = false;
503352 }
504353 # Some checks for which tag CSS to use
@@ -516,8 +365,209 @@
517366
518367 return true;
519368 }
 369+
 370+ /**
 371+ * @param $srev stable version
 372+ * @param $frev selected flagged revision
 373+ * @param $tag review box/bar info
 374+ * @param $prot protection notice
 375+ * Tag output function must be called by caller
 376+ * Parser cache control deferred to caller
 377+ */
 378+ protected function showRegularVersion( $srev, $frev, &$tag, $prot ) {
 379+ global $wgUser, $wgOut, $wgLang, $wgRequest;
 380+ $flags = $frev->getTags();
 381+ $time = $wgLang->date( $frev->getTimestamp(), true );
 382+ # Get quality level
 383+ $quality = FlaggedRevs::isQuality( $flags );
 384+ $pristine = FlaggedRevs::isPristine( $flags );
 385+ $revsSince = FlaggedRevs::getRevCountSince( $this->parent, $srev->getRevId() );
 386+ $synced = false;
 387+ # We only care about syncing if not viewing an old stable version
 388+ if( $srev->getRevId() == $frev->getRevId() ) {
 389+ $synced = FlaggedRevs::stableVersionIsSynced( $frev, $this->parent );
 390+ if( $synced ) $this->getReviewNotes( $frev ); // Still the same
 391+ }
 392+ $pending = '';
 393+ # Give notice to newer users if an unreviewed edit was completed...
 394+ if( !$synced && $wgRequest->getVal('shownotice') && !$wgUser->isAllowed('review') ) {
 395+ $tooltip = wfMsgHtml('revreview-draft-title');
 396+ $pending = "{$prot}<span class='fr-icon-current' title=\"{$tooltip}\"></span>" .
 397+ wfMsgExt('revreview-edited',array('parseinline'),$frev->getRevId(),$revsSince);
 398+ $pending = "<div id='mw-reviewnotice' class='flaggedrevs_preview plainlinks'>$pending</div>";
 399+ # Notice should always use subtitle
 400+ $this->reviewNotice = $pending;
 401+ }
 402+ # If they are synced, do special styling
 403+ $simpleTag = !$synced;
 404+ # Construct some tagging for non-printable outputs. Note that the pending
 405+ # notice has all this info already, so don't do this if we added that already.
 406+ if( !$wgOut->isPrintable() && !$pending && !($this->lowProfileUI() && $synced) ) {
 407+ $class = 'fr-icon-current'; // default
 408+ $tooltip = 'revreview-draft-title';
 409+ // Simple icon-based UI
 410+ if( FlaggedRevs::useSimpleUI() ) {
 411+ if( $synced ) {
 412+ $msg = $quality ? 'revreview-quick-quality-same' : 'revreview-quick-basic-same';
 413+ $class = $quality ? 'fr-icon-quality' : 'fr-icon-stable';
 414+ $tooltip = $quality ? 'revreview-quality-title' : 'revreview-stable-title';
 415+ $msgHTML = wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $revsSince );
 416+ } else {
 417+ $msg = $quality ? 'revreview-quick-see-quality' : 'revreview-quick-see-basic';
 418+ $msgHTML = wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $revsSince );
 419+ }
 420+ $tooltip = wfMsgHtml($tooltip);
 421+ $msgHTML = "{$prot}<span class='{$class}' title=\"{$tooltip}\"></span>$msgHTML";
 422+ $tag .= FlaggedRevsXML::prettyRatingBox( $frev, $msgHTML, $revsSince,
 423+ $synced, $synced, false );
 424+ // Standard UI
 425+ } else {
 426+ if( $synced ) {
 427+ $msg = $quality ? 'revreview-quality-same' : 'revreview-basic-same';
 428+ $class = $quality ? 'fr-icon-quality' : 'fr-icon-stable';
 429+ $tooltip = $quality ? 'revreview-quality-title' : 'revreview-stable-title';
 430+ $msgHTML = wfMsgExt( $msg, array('parseinline'), $frev->getRevId(),
 431+ $time, $revsSince );
 432+ } else {
 433+ $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic';
 434+ $msg .= ($revsSince == 0) ? '-i' : '';
 435+ $msgHTML = wfMsgExt( $msg, array('parseinline'), $frev->getRevId(),
 436+ $time, $revsSince );
 437+ }
 438+ $tooltip = wfMsgHtml($tooltip);
 439+ $tag .= "{$prot}<span class='{$class}' title=\"{$tooltip}\"></span>" . $msgHTML;
 440+ # Hide clutter
 441+ if( !empty($flags) ) {
 442+ $tag .= " " . FlaggedRevsXML::ratingToggle();
 443+ $tag .= "<span id='mw-revisionratings' style='display:block;'><br/>" .
 444+ wfMsgHtml('revreview-oldrating') . FlaggedRevsXML::addTagRatings( $flags ) . '</span>';
 445+ }
 446+ }
 447+ }
 448+ # Index the stable version only if it is the default
 449+ if( $this->showStableByDefault() ) {
 450+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
 451+ }
 452+ }
 453+
 454+ /**
 455+ * @param $srev stable version
 456+ * @param $frev selected flagged revision
 457+ * @param $tag review box/bar info
 458+ * @param $prot protection notice
 459+ * Tag output function must be called by caller
 460+ * Parser cache control deferred to caller
 461+ */
 462+ protected function showOldReviewedVersion( $srev, $frev, &$tag, $prot ) {
 463+ global $wgOut, $wgLang;
 464+ $flags = $frev->getTags();
 465+ $time = $wgLang->date( $frev->getTimestamp(), true );
 466+ # Get quality level
 467+ $quality = FlaggedRevs::isQuality( $flags );
 468+ $pristine = FlaggedRevs::isPristine( $flags );
 469+ $revsSince = FlaggedRevs::getRevCountSince( $this->parent, $srev->getRevId() );
 470+ $text = $frev->getRevText();
 471+ $parserOut = FlaggedRevs::parseStableText( $this->parent, $text, $frev->getRevId() );
 472+ # Construct some tagging for non-printable outputs. Note that the pending
 473+ # notice has all this info already, so don't do this if we added that already.
 474+ if( !$wgOut->isPrintable() ) {
 475+ $class = $quality ? 'fr-icon-quality' : 'fr-icon-stable';
 476+ $tooltip = $quality ? 'revreview-quality-title' : 'revreview-stable-title';
 477+ $tooltip = wfMsgHtml($tooltip);
 478+ // Simple icon-based UI
 479+ if( FlaggedRevs::useSimpleUI() ) {
 480+ $msg = $quality ? 'revreview-quick-quality-old' : 'revreview-quick-basic-old';
 481+ $html = "{$prot}<span class='{$class}' title=\"{$tooltip}\"></span>" .
 482+ wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $time );
 483+ $tag = FlaggedRevsXML::prettyRatingBox( $frev, $html, $revsSince,
 484+ true, false, true );
 485+ // Standard UI
 486+ } else {
 487+ $msg = $quality ? 'revreview-quality-old' : 'revreview-basic-old';
 488+ $tag = "{$prot}<span class='{$class}' title=\"{$tooltip}\"></span>" .
 489+ wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $time );
 490+ # Hide clutter
 491+ if( !empty($flags) ) {
 492+ $tag .= " " . FlaggedRevsXML::ratingToggle();
 493+ $tag .= "<span id='mw-revisionratings' style='display:block;'><br/>" .
 494+ wfMsgHtml('revreview-oldrating') .
 495+ FlaggedRevsXML::addTagRatings( $flags ) . '</span>';
 496+ }
 497+ }
 498+ }
 499+ # Output HTML
 500+ $this->getReviewNotes( $frev );
 501+ $wgOut->addParserOutput( $parserOut );
 502+ $wgOut->setRevisionId( $frev->getRevId() );
 503+ # Index the stable version only
 504+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
 505+ }
520506
521507 /**
 508+ * @param $srev stable version
 509+ * @param $frev selected flagged revision
 510+ * @param $tag review box/bar info
 511+ * @param $prot protection notice
 512+ * Tag output function must be called by caller
 513+ * Parser cache control deferred to caller
 514+ */
 515+ protected function showStableVersion( $srev, $frev, &$tag, $prot ) {
 516+ global $wgOut, $wgLang;
 517+ $flags = $frev->getTags();
 518+ $time = $wgLang->date( $frev->getTimestamp(), true );
 519+ # Get quality level
 520+ $quality = FlaggedRevs::isQuality( $flags );
 521+ $pristine = FlaggedRevs::isPristine( $flags );
 522+ # We will be looking at the reviewed revision...
 523+ $revsSince = FlaggedRevs::getRevCountSince( $this->parent, $frev->getRevId() );
 524+ # Get parsed stable version
 525+ $parserOut = FlaggedRevs::getPageCache( $this->parent );
 526+ if( $parserOut == false ) {
 527+ $text = $frev->getRevText();
 528+ $parserOut = FlaggedRevs::parseStableText( $this->parent, $text, $frev->getRevId() );
 529+ # Update the stable version cache
 530+ FlaggedRevs::updatePageCache( $this->parent, $parserOut );
 531+ }
 532+ $synced = FlaggedRevs::stableVersionIsSynced( $frev, $this->parent, $parserOut, null );
 533+ # Construct some tagging
 534+ if( !$wgOut->isPrintable() && !($this->lowProfileUI() && $synced) ) {
 535+ $class = $quality ? 'fr-icon-quality' : 'fr-icon-stable';
 536+ $tooltip = $quality ? 'revreview-quality-title' : 'revreview-stable-title';
 537+ $tooltip = wfMsgHtml($tooltip);
 538+ // Simple icon-based UI
 539+ if( FlaggedRevs::useSimpleUI() ) {
 540+ $msg = $quality ? 'revreview-quick-quality' : 'revreview-quick-basic';
 541+ # uses messages 'revreview-quick-quality-same', 'revreview-quick-basic-same'
 542+ $msg = $synced ? "{$msg}-same" : $msg;
 543+ $html = "{$prot}<span class='{$class}' title=\"{$tooltip}\"></span>" .
 544+ wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $revsSince );
 545+ $tag = FlaggedRevsXML::prettyRatingBox( $frev, $html, $revsSince, true, $synced );
 546+ // Standard UI
 547+ } else {
 548+ $msg = $quality ? 'revreview-quality' : 'revreview-basic';
 549+ if( $synced ) {
 550+ # uses messages 'revreview-quality-same', 'revreview-basic-same'
 551+ $msg .= '-same';
 552+ } elseif( $revsSince == 0 ) {
 553+ # uses messages 'revreview-quality-i', 'revreview-basic-i'
 554+ $msg .= '-i';
 555+ }
 556+ $tag = "{$prot}<span class='{$class} plainlinks' title=\"{$tooltip}\"></span>" .
 557+ wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $time, $revsSince );
 558+ if( !empty($flags) ) {
 559+ $tag .= " " . FlaggedRevsXML::ratingToggle();
 560+ $tag .= "<span id='mw-revisionratings' style='display:block;'><br/>" .
 561+ FlaggedRevsXML::addTagRatings( $flags ) . '</span>';
 562+ }
 563+ }
 564+ }
 565+ # Output HTML
 566+ $this->getReviewNotes( $frev );
 567+ $wgOut->addParserOutput( $parserOut );
 568+ $wgOut->setRevisionId( $frev->getRevId() );
 569+ }
 570+
 571+ /**
522572 * Get the normal and display files for the underlying ImagePage.
523573 * If the a stable version needs to be displayed, this will set $normalFile
524574 * to the current version, and $displayFile to the desired version.

Status & tagging log