Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php |
— | — | @@ -30,14 +30,32 @@ |
31 | 31 | return $wgOut->readOnlyPage(); |
32 | 32 | } |
33 | 33 | } |
34 | | - |
| 34 | + # Set page title |
35 | 35 | $this->setHeaders(); |
| 36 | + |
36 | 37 | $this->skin = $wgUser->getSkin(); |
37 | | - |
38 | | - $isValid = true; |
39 | 38 | # Our target page |
40 | 39 | $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 | + |
42 | 60 | # We need a page... |
43 | 61 | if( is_null($this->page) ) { |
44 | 62 | return $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); |
— | — | @@ -48,35 +66,44 @@ |
49 | 67 | return $wgOut->addHTML( wfMsgExt( 'stabilization-notcontent', array('parseinline'), |
50 | 68 | $this->page->getPrefixedText() ) ); |
51 | 69 | } |
52 | | - |
| 70 | + |
53 | 71 | # 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')) ) { |
55 | 73 | $this->isAllowed = false; |
| 74 | + } |
56 | 75 | |
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'; |
75 | 106 | # 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 { |
81 | 108 | // Custom expiry takes precedence |
82 | 109 | $this->expiry = strlen($this->expiry) ? $this->expiry : $this->expirySelection; |
83 | 110 | if( $this->expiry == 'existing' ) $this->expiry = $this->oldExpiry; |
— | — | @@ -86,15 +113,10 @@ |
87 | 114 | // Validate precedence setting |
88 | 115 | $allowed = array(FLAGGED_VIS_QUALITY,FLAGGED_VIS_LATEST,FLAGGED_VIS_PRISTINE); |
89 | 116 | if( $this->select && !in_array( $this->select, $allowed ) ) { |
90 | | - $isValid = false; |
| 117 | + return false; // invalid value |
91 | 118 | } |
92 | 119 | } |
93 | | - // Show form or submit... |
94 | | - if( $this->isAllowed && $isValid && $confirm ) { |
95 | | - $this->submit(); |
96 | | - } else { |
97 | | - $this->showSettings(); |
98 | | - } |
| 120 | + return true; |
99 | 121 | } |
100 | 122 | |
101 | 123 | protected function showSettings( $err = null ) { |
— | — | @@ -118,7 +140,7 @@ |
119 | 141 | if( val == 'existing' ) |
120 | 142 | document.getElementById('mwStabilize-expiry').value = ". |
121 | 143 | Xml::encodeJsVar($this->oldExpiry)."; |
122 | | - elseif( val != 'othertime' ) |
| 144 | + else if( val != 'othertime' ) |
123 | 145 | document.getElementById('mwStabilize-expiry').value = val; |
124 | 146 | } |
125 | 147 | </script>" |
— | — | @@ -317,8 +339,8 @@ |
318 | 340 | } |
319 | 341 | } |
320 | 342 | |
321 | | - protected function submit() { |
322 | | - global $wgOut, $wgUser, $wgContLang; |
| 343 | + public function submit() { |
| 344 | + global $wgUser, $wgContLang; |
323 | 345 | $changed = $reset = false; |
324 | 346 | $defaultPrecedence = FlaggedRevs::getPrecedence(); |
325 | 347 | $defaultOverride = FlaggedRevs::showStableByDefault(); |
— | — | @@ -461,7 +483,6 @@ |
462 | 484 | } else { |
463 | 485 | $wgUser->removeWatch( $this->page ); |
464 | 486 | } |
465 | | - $wgOut->redirect( $this->page->getFullUrl( $query ) ); |
466 | 487 | return true; |
467 | 488 | } |
468 | 489 | } |