r56744 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56743‎ | r56744 | r56745 >
Date:00:28, 22 September 2009
Author:aaron
Status:deferred
Tags:
Comment:
* Refactored Stabilization; backend and UI separated more
* Fixed JS from someone S&R'd on "elseif"
Modified paths:
  • /trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php
@@ -30,14 +30,32 @@
3131 return $wgOut->readOnlyPage();
3232 }
3333 }
34 -
 34+ # Set page title
3535 $this->setHeaders();
 36+
3637 $this->skin = $wgUser->getSkin();
37 -
38 - $isValid = true;
3938 # Our target page
4039 $this->target = $wgRequest->getText( 'page', $par );
41 - $this->page = Title::newFromUrl( $this->target );
 40+ # Watch checkbox
 41+ $this->watchThis = $wgRequest->getCheck( 'wpWatchthis' );
 42+ # Reason
 43+ $this->reason = $wgRequest->getVal( 'wpReason' );
 44+ $this->reasonSelection = $wgRequest->getText( 'wpReasonSelection' );
 45+ # Expiry
 46+ $this->expiry = $wgRequest->getText( 'mwStabilize-expiry' );
 47+ $this->expirySelection = $wgRequest->getVal( 'wpExpirySelection' );
 48+ # Precedence
 49+ $this->select = $wgRequest->getInt( 'wpStableconfig-select' );
 50+ $this->override = (int)$wgRequest->getBool( 'wpStableconfig-override' );
 51+ # Get autoreview restrictions...
 52+ $this->autoreview = $wgRequest->getVal( 'mwProtect-level-autoreview' );
 53+ # Get auto-review option...
 54+ $this->reviewThis = $wgRequest->getBool( 'wpReviewthis', true );
 55+ $this->wasPosted = $wgRequest->wasPosted();
 56+
 57+ # Fill in & validate some parameters
 58+ $isValid = $this->handleParams();
 59+
4260 # We need a page...
4361 if( is_null($this->page) ) {
4462 return $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
@@ -48,35 +66,44 @@
4967 return $wgOut->addHTML( wfMsgExt( 'stabilization-notcontent', array('parseinline'),
5068 $this->page->getPrefixedText() ) );
5169 }
52 -
 70+
5371 # Users who cannot edit or review the page cannot set this
54 - if( $this->isAllowed && !($this->page->userCan('edit') && $this->page->userCan('review')) )
 72+ if( $this->isAllowed && !($this->page->userCan('edit') && $this->page->userCan('review')) ) {
5573 $this->isAllowed = false;
 74+ }
5675
57 - # Watch checkbox
58 - $this->watchThis = $wgRequest->getCheck( 'wpWatchthis' );
59 - # Reason
60 - $this->reason = $wgRequest->getVal( 'wpReason' );
61 - $this->reasonSelection = $wgRequest->getText( 'wpReasonSelection' );
62 - $this->expiry = $wgRequest->getText( 'mwStabilize-expiry' );
63 - $this->expirySelection = $wgRequest->getVal( 'wpExpirySelection' );
64 - # Get visiblity settings...
65 - $this->config = FlaggedRevs::getPageVisibilitySettings( $this->page, true );
66 - $this->select = $this->config['select'];
67 - $this->override = $this->config['override'];
68 - # Get auto-review option...
69 - $this->reviewThis = $wgRequest->getBool( 'wpReviewthis', true );
70 - # Get autoreview restrictions...
71 - $this->autoreview = $this->config['autoreview'];
72 - # Make user readable date for GET requests
73 - $this->oldExpiry = $this->config['expiry'] !== 'infinity' ?
74 - wfTimestamp( TS_RFC2822, $this->config['expiry'] ) : 'infinite';
 76+ // Show form or submit...
 77+ if( $this->isAllowed && $isValid && $confirm && $this->submit() ) {
 78+ $wgOut->redirect( $this->page->getFullUrl( $query ) );
 79+ } else {
 80+ $this->showSettings();
 81+ }
 82+ }
 83+
 84+ /*
 85+ * Fetch and check parameters. Items may not all be set if false is returned.
 86+ * @returns bool success
 87+ */
 88+ public function handleParams() {
 89+ # Our target page
 90+ $this->page = Title::newFromUrl( $this->target );
 91+ # We need a page...
 92+ if( is_null($this->page) ) {
 93+ return false; // can't continue
 94+ }
 95+ # If not posted, then fill in existing values/defaults
 96+ if( !$this->wasPosted ) {
 97+ # Get visiblity settings...
 98+ $this->config = FlaggedRevs::getPageVisibilitySettings( $this->page, true );
 99+ $this->select = $this->config['select'];
 100+ $this->override = $this->config['override'];
 101+ # Get autoreview restrictions...
 102+ $this->autoreview = $this->config['autoreview'];
 103+ # Make user readable date for GET requests
 104+ $this->oldExpiry = $this->config['expiry'] !== 'infinity' ?
 105+ wfTimestamp( TS_RFC2822, $this->config['expiry'] ) : 'infinite';
75106 # Handle submission data
76 - if( $wgRequest->wasPosted() ) {
77 - $this->select = $wgRequest->getInt( 'wpStableconfig-select' );
78 - $this->override = intval( $wgRequest->getBool( 'wpStableconfig-override' ) );
79 - # Get autoreview restrictions...
80 - $this->autoreview = $wgRequest->getVal( 'mwProtect-level-autoreview' );
 107+ } else {
81108 // Custom expiry takes precedence
82109 $this->expiry = strlen($this->expiry) ? $this->expiry : $this->expirySelection;
83110 if( $this->expiry == 'existing' ) $this->expiry = $this->oldExpiry;
@@ -86,15 +113,10 @@
87114 // Validate precedence setting
88115 $allowed = array(FLAGGED_VIS_QUALITY,FLAGGED_VIS_LATEST,FLAGGED_VIS_PRISTINE);
89116 if( $this->select && !in_array( $this->select, $allowed ) ) {
90 - $isValid = false;
 117+ return false; // invalid value
91118 }
92119 }
93 - // Show form or submit...
94 - if( $this->isAllowed && $isValid && $confirm ) {
95 - $this->submit();
96 - } else {
97 - $this->showSettings();
98 - }
 120+ return true;
99121 }
100122
101123 protected function showSettings( $err = null ) {
@@ -118,7 +140,7 @@
119141 if( val == 'existing' )
120142 document.getElementById('mwStabilize-expiry').value = ".
121143 Xml::encodeJsVar($this->oldExpiry).";
122 - elseif( val != 'othertime' )
 144+ else if( val != 'othertime' )
123145 document.getElementById('mwStabilize-expiry').value = val;
124146 }
125147 </script>"
@@ -317,8 +339,8 @@
318340 }
319341 }
320342
321 - protected function submit() {
322 - global $wgOut, $wgUser, $wgContLang;
 343+ public function submit() {
 344+ global $wgUser, $wgContLang;
323345 $changed = $reset = false;
324346 $defaultPrecedence = FlaggedRevs::getPrecedence();
325347 $defaultOverride = FlaggedRevs::showStableByDefault();
@@ -461,7 +483,6 @@
462484 } else {
463485 $wgUser->removeWatch( $this->page );
464486 }
465 - $wgOut->redirect( $this->page->getFullUrl( $query ) );
466487 return true;
467488 }
468489 }

Status & tagging log