r60173 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60172‎ | r60173 | r60174 >
Date:20:09, 17 December 2009
Author:aaron
Status:ok
Tags:
Comment:
* Refactored/cleaned up setPageContent
* Simplified bad ID case
* Added getRequestedStableId()/showUnreviewedPageNotice()
* Renamed showRegularVersion() -> showDraftVersion()
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticleView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
@@ -160,6 +160,18 @@
161161 }
162162 return true;
163163 }
 164+
 165+ /**
 166+ * @returns mixed int/false/null
 167+ */
 168+ protected function getRequestedStableId() {
 169+ global $wgRequest;
 170+ $reqId = $wgRequest->getVal('stableid');
 171+ if( $reqId === "best" ) {
 172+ $reqId = FlaggedRevs::getPrimeFlaggedRevId( $this->article );
 173+ }
 174+ return $reqId;
 175+ }
164176
165177 /**
166178 * Replaces a page with the last stable version if possible
@@ -184,31 +196,35 @@
185197 $simpleTag = $old = $stable = false;
186198 $tag = $prot = '';
187199 # Check the newest stable version.
188 - $frev = $srev = $this->article->getStableRev();
189 - $stableId = $frev ? $frev->getRevId() : 0;
190 - # Also, check for any explicitly requested old stable version...
191 - $reqId = $wgRequest->getVal('stableid');
192 - if( $reqId === "best" ) {
193 - $reqId = FlaggedRevs::getPrimeFlaggedRevId( $this->article );
194 - }
195 - if( $stableId && $reqId ) {
 200+ $srev = $this->article->getStableRev();
 201+ $stableId = $srev ? $srev->getRevId() : 0;
 202+ $frev = $srev; // $frev is the revision we are looking at
 203+ # Check for any explicitly requested old stable version...
 204+ $reqId = $this->getRequestedStableId();
 205+ if( $reqId ) {
 206+ if( !$stableId ) {
 207+ $reqId = false; // must be invalid
196208 # Treat requesting the stable version by ID as &stable=1
197 - if( $reqId != $stableId ) {
 209+ } else if( $reqId != $stableId ) {
 210+ $old = true; // old reviewed version requested by ID
198211 $frev = FlaggedRevision::newFromTitle( $this->article->getTitle(),
199212 $reqId, FR_TEXT );
200 - $old = true; // old reviewed version requested by ID
201213 if( !$frev ) {
202 - $wgOut->addWikiText( wfMsg('revreview-invalid') );
203 - $wgOut->returnToMain( false, $this->article->getTitle() );
204 - # Tell MW that parser output is done
205 - $outputDone = true;
206 - $pcache = false;
207 - return true;
 214+ $reqId = false; // invalid ID given
208215 }
209216 } else {
210217 $stable = true; // stable version requested by ID
211218 }
212219 }
 220+ // $reqId is null if nothing requested, false if invalid
 221+ if( $reqId === false ) {
 222+ $wgOut->addWikiText( wfMsg('revreview-invalid') );
 223+ $wgOut->returnToMain( false, $this->article->getTitle() );
 224+ # Tell MW that parser output is done
 225+ $outputDone = true;
 226+ $pcache = false;
 227+ return true;
 228+ }
213229 // Is the page config altered?
214230 if( $this->article->isPageLocked() ) {
215231 $prot = "<span class='fr-icon-locked' title=\"".
@@ -217,28 +233,10 @@
218234 $prot = "<span class='fr-icon-unlocked' title=\"".
219235 wfMsgHtml('revreview-unlocked-title')."\"></span>";
220236 }
221 - // RTL langauges
222 - $rtl = $wgContLang->isRTL() ? " rtl" : "";
223237 // Is there no stable version?
224238 if( is_null($frev) ) {
225 - // Add "no reviewed version" tag, but not for printable output.
226 - if( !$wgOut->isPrintable() ) {
227 - // Simple icon-based UI
228 - if( FlaggedRevs::useSimpleUI() ) {
229 - $msg = $old ? 'revreview-quick-invalid' : 'revreview-quick-none';
230 - $tag .= "{$prot}<span class='fr-icon-current plainlinks'></span>" .
231 - wfMsgExt($msg,array('parseinline'));
232 - $tag = "<div id='mw-revisiontag' class='flaggedrevs_short{$rtl} plainlinks noprint'>$tag</div>";
233 - $this->reviewNotice .= $tag;
234 - // Standard UI
235 - } else {
236 - $msg = $old ? 'revreview-invalid' : 'revreview-noflagged';
237 - $tag = "<div id='mw-revisiontag' class='flaggedrevs_notice plainlinks noprint'>" .
238 - "{$prot}<span class='fr-icon-current plainlinks'></span>" .
239 - wfMsgExt($msg, array('parseinline')) . "</div>";
240 - $this->reviewNotice .= $tag;
241 - }
242 - }
 239+ # Add "no reviewed version" tag, but not for printable output
 240+ $this->showUnreviewedPage( $tag, $prot );
243241 # Show notice bar/icon
244242 $this->displayTag();
245243 return true;
@@ -267,7 +265,7 @@
268266 // set to override given the relevant conditions (like &stable=0) or there
269267 // is no stable version.
270268 } else {
271 - $this->showRegularVersion( $srev, $tag, $prot );
 269+ $this->showDraftVersion( $srev, $tag, $prot );
272270 }
273271 # Some checks for which tag CSS to use
274272 if( FlaggedRevs::useSimpleUI() ) $tagClass = 'flaggedrevs_short';
@@ -277,7 +275,9 @@
278276 else $tagClass = 'flaggedrevs_basic';
279277 # Wrap tag contents in a div
280278 if( $tag != '' ) {
281 - $tag = "<div id='mw-revisiontag' class='{$tagClass}{$rtl} plainlinks noprint'>$tag</div>";
 279+ $rtl = $wgContLang->isRTL() ? " rtl" : ""; // RTL langauges
 280+ $tag = "<div id='mw-revisiontag' class='{$tagClass}{$rtl} plainlinks noprint'>" .
 281+ "$tag</div>";
282282 $this->reviewNotice .= $tag;
283283 }
284284 # Show notice bar/icon
@@ -285,6 +285,34 @@
286286
287287 return true;
288288 }
 289+
 290+ /**
 291+ * @param $tag review box/bar info
 292+ * @param $prot protection notice
 293+ * Tag output function must be called by caller
 294+ */
 295+ protected function showUnreviewedPage( $tag, $prot ) {
 296+ global $wgOut, $wgContLang;
 297+ if( $wgOut->isPrintable() )
 298+ return;
 299+ // Simple icon-based UI
 300+ if( FlaggedRevs::useSimpleUI() ) {
 301+ // RTL langauges
 302+ $rtl = $wgContLang->isRTL() ? " rtl" : "";
 303+ $msg = 'revreview-quick-none';
 304+ $tag .= "{$prot}<span class='fr-icon-current plainlinks'></span>" .
 305+ wfMsgExt($msg,array('parseinline'));
 306+ $tag = "<div id='mw-revisiontag' class='flaggedrevs_short{$rtl} plainlinks noprint'>$tag</div>";
 307+ $this->reviewNotice .= $tag;
 308+ // Standard UI
 309+ } else {
 310+ $msg = 'revreview-noflagged';
 311+ $tag = "<div id='mw-revisiontag' class='flaggedrevs_notice plainlinks noprint'>" .
 312+ "{$prot}<span class='fr-icon-current plainlinks'></span>" .
 313+ wfMsgExt($msg, array('parseinline')) . "</div>";
 314+ $this->reviewNotice .= $tag;
 315+ }
 316+ }
289317
290318 /**
291319 * @param $srev stable version
@@ -293,7 +321,7 @@
294322 * Tag output function must be called by caller
295323 * Parser cache control deferred to caller
296324 */
297 - protected function showRegularVersion( $srev, &$tag, $prot ) {
 325+ protected function showDraftVersion( $srev, &$tag, $prot ) {
298326 global $wgUser, $wgOut, $wgLang, $wgRequest;
299327 $this->load();
300328 $flags = $srev->getTags();

Status & tagging log