Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php |
— | — | @@ -1,729 +1,729 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -class FlaggedArticle extends FlaggedRevs {
|
5 | | - /**
|
6 | | - * Does the config and current URL params allow
|
7 | | - * for overriding by stable revisions?
|
8 | | - */
|
9 | | - function pageOverride() {
|
10 | | - global $wgFlaggedRevsAnonOnly, $wgFlaggedRevs,
|
11 | | - $wgTitle, $wgUser, $wgRequest, $action;
|
12 | | - # This only applies to viewing content pages
|
13 | | - if( $action !='view' || !$this->isReviewable( $wgTitle ) )
|
14 | | - return false;
|
15 | | - # Does not apply to diffs/old revisions
|
16 | | - if( $wgRequest->getVal('oldid') || $wgRequest->getVal('diff') )
|
17 | | - return false;
|
18 | | - # Get page config
|
19 | | - $config = $wgFlaggedRevs->getVisibilitySettings( $wgTitle );
|
20 | | - # Does the stable version override the current one?
|
21 | | - if( $config['override'] ) {
|
22 | | - # If $wgFlaggedRevsAnonOnly is set to false, stable version are only requested explicitly
|
23 | | - if( $wgFlaggedRevsAnonOnly && $wgUser->isAnon() ) {
|
24 | | - return !( $wgRequest->getIntOrNull('stable') === 0 );
|
25 | | - } else {
|
26 | | - return ( $wgRequest->getIntOrNull('stable') === 1 );
|
27 | | - }
|
28 | | - # We are explicity requesting the stable version?
|
29 | | - } else if( $wgRequest->getIntOrNull('stable') === 1 ) {
|
30 | | - return true;
|
31 | | - }
|
32 | | - return false;
|
33 | | - }
|
34 | | -
|
35 | | - /**
|
36 | | - * Is this user shown the stable version by default for this page?
|
37 | | - */
|
38 | | - function showStableByDefault() {
|
39 | | - global $wgFlaggedRevsOverride, $wgFlaggedRevsAnonOnly, $wgUser;
|
40 | | -
|
41 | | - $config = $this->getVisibilitySettings();
|
42 | | -
|
43 | | - return ( $config['override'] && !($wgFlaggedRevsAnonOnly && !$wgUser->isAnon()) );
|
44 | | - }
|
45 | | -
|
46 | | - /**
|
47 | | - * Replaces a page with the last stable version if possible
|
48 | | - * Adds stable version status/info tags and notes
|
49 | | - * Adds a quick review form on the bottom if needed
|
50 | | - */
|
51 | | - function setPageContent( $article, &$outputDone, &$pcache ) {
|
52 | | - global $wgRequest, $wgTitle, $wgOut, $action, $wgUser;
|
53 | | - // Only trigger on article view for content pages, not for protect/delete/hist
|
54 | | - if( $action !='view' || !$article || !$article->exists() || !$this->isReviewable( $article->mTitle ) )
|
55 | | - return true;
|
56 | | - // Grab page and rev ids
|
57 | | - $pageid = $article->getId();
|
58 | | - $revid = $article->mRevision ? $article->mRevision->mId : $article->getLatest();
|
59 | | - if( !$revid )
|
60 | | - return true;
|
61 | | -
|
62 | | - $skin = $wgUser->getSkin();
|
63 | | -
|
64 | | - $vis_id = $revid;
|
65 | | - $tag = $notes = '';
|
66 | | - # Check the newest stable version...
|
67 | | - $tfrev = $this->getStableRev( null, true );
|
68 | | - $simpleTag = false;
|
69 | | - if( $wgRequest->getVal('diff') || $wgRequest->getVal('oldid') ) {
|
70 | | - // Do not clutter up diffs any further...
|
71 | | - } else if( !is_null($tfrev) ) {
|
72 | | - global $wgLang;
|
73 | | - # Get flags and date
|
74 | | - $flags = $this->getFlagsForRevision( $tfrev->fr_rev_id );
|
75 | | - # Get quality level
|
76 | | - $quality = $this->isQuality( $flags );
|
77 | | - $pristine = $this->isPristine( $flags );
|
78 | | - $time = $wgLang->date( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true );
|
79 | | - # Looking at some specific old rev or if flagged revs override only for anons
|
80 | | - if( !$this->pageOverride() ) {
|
81 | | - $revs_since = $this->getRevCountSince( $pageid, $tfrev->fr_rev_id );
|
82 | | - $simpleTag = true;
|
83 | | - # Construct some tagging
|
84 | | - if( !$wgOut->isPrintable() ) {
|
85 | | - if( $this->useSimpleUI() ) {
|
86 | | - $msg = $quality ? 'revreview-quick-see-quality' : 'revreview-quick-see-basic';
|
87 | | - $tag .= "<span class='fr_tab_current plainlinks'></span>" .
|
88 | | - wfMsgExt($msg,array('parseinline'), $tfrev->fr_rev_id, $revs_since);
|
89 | | - $tag .= $this->prettyRatingBox( $tfrev, $flags, $revs_since, false );
|
90 | | - } else {
|
91 | | - $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic';
|
92 | | - $tag .= wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since);
|
93 | | - # Hide clutter
|
94 | | - $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' .
|
95 | | - wfMsg('revreview-toggle') . '</a>';
|
96 | | - $tag .= '<span id="mw-revisionratings" style="display:block;">' .
|
97 | | - wfMsg('revreview-oldrating') . $this->addTagRatings( $flags ) . '</span>';
|
98 | | - }
|
99 | | - }
|
100 | | - // Viewing the page normally: override the page
|
101 | | - } else {
|
102 | | - # We will be looking at the reviewed revision...
|
103 | | - $vis_id = $tfrev->fr_rev_id;
|
104 | | - $revs_since = $this->getRevCountSince( $pageid, $vis_id );
|
105 | | - # Construct some tagging
|
106 | | - if( !$wgOut->isPrintable() ) {
|
107 | | - if( $this->useSimpleUI() ) {
|
108 | | - $msg = $quality ? 'revreview-quick-quality' : 'revreview-quick-basic';
|
109 | | - $css = $quality ? 'fr_tab_quality' : 'fr_tab_stable';
|
110 | | - $tag .= "<span class='$css plainlinks'></span>" .
|
111 | | - wfMsgExt($msg,array('parseinline'),$tfrev->fr_rev_id,$revs_since);
|
112 | | - $tag .= $this->prettyRatingBox( $tfrev, $flags, $revs_since );
|
113 | | - } else {
|
114 | | - $msg = $quality ? 'revreview-quality' : 'revreview-basic';
|
115 | | - $tag = wfMsgExt($msg, array('parseinline'), $vis_id, $time, $revs_since);
|
116 | | - $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' .
|
117 | | - wfMsg('revreview-toggle') . '</a>';
|
118 | | - $tag .= '<span id="mw-revisionratings" style="display:block;">' .
|
119 | | - $this->addTagRatings( $flags ) . '</span>';
|
120 | | - }
|
121 | | - }
|
122 | | - # Try the stable page cache
|
123 | | - $parserOut = $this->getPageCache( $article );
|
124 | | - # If no cache is available, get the text and parse it
|
125 | | - if( $parserOut==false ) {
|
126 | | - $text = $this->uncompressText( $tfrev->fr_text, $tfrev->fr_flags );
|
127 | | - $parserOut = $this->parseStableText( $article, $text, $vis_id );
|
128 | | - # Update the general cache
|
129 | | - $this->updatePageCache( $article, $parserOut );
|
130 | | - }
|
131 | | - $wgOut->mBodytext = $parserOut->getText();
|
132 | | - # Show stable categories and interwiki links only
|
133 | | - $wgOut->mCategoryLinks = array();
|
134 | | - $wgOut->addCategoryLinks( $parserOut->getCategories() );
|
135 | | - $wgOut->mLanguageLinks = array();
|
136 | | - $wgOut->addLanguageLinks( $parserOut->getLanguageLinks() );
|
137 | | - $notes = $this->ReviewNotes( $tfrev );
|
138 | | - # Tell MW that parser output is done
|
139 | | - $outputDone = true;
|
140 | | - $pcache = false;
|
141 | | - }
|
142 | | - # Some checks for which tag CSS to use
|
143 | | - if( $this->useSimpleUI() )
|
144 | | - $tagClass = 'flaggedrevs_short';
|
145 | | - else if( $simpleTag )
|
146 | | - $tagClass = 'flaggedrevs_notice';
|
147 | | - else if( $pristine )
|
148 | | - $tagClass = 'flaggedrevs_tag3';
|
149 | | - else if( $quality )
|
150 | | - $tagClass = 'flaggedrevs_tag2';
|
151 | | - else
|
152 | | - $tagClass = 'flaggedrevs_tag1';
|
153 | | - # Wrap tag contents in a div
|
154 | | - if( $tag !='' )
|
155 | | - $tag = '<div id="mw-revisiontag" class="' . $tagClass . ' plainlinks">'.$tag.'</div>';
|
156 | | - # Set the new body HTML, place a tag on top
|
157 | | - $wgOut->mBodytext = $tag . $wgOut->mBodytext . $notes;
|
158 | | - // Add "no reviewed version" tag, but not for main page
|
159 | | - } else if( !$wgOut->isPrintable() && !$this->isMainPage( $article->mTitle ) ) {
|
160 | | - if( $this->useSimpleUI() ) {
|
161 | | - $tag .= "<span class='fr_tab_current plainlinks'></span>" .
|
162 | | - wfMsgExt('revreview-quick-none',array('parseinline'));
|
163 | | - $tag = '<div id="mw-revisiontag" class="flaggedrevs_short plainlinks">'.$tag.'</div>';
|
164 | | - } else {
|
165 | | - $tag = '<div id="mw-revisiontag" class="flaggedrevs_notice plainlinks">' .
|
166 | | - wfMsgExt('revreview-noflagged', array('parseinline')) . '</div>';
|
167 | | - }
|
168 | | - $wgOut->addHTML( $tag );
|
169 | | - }
|
170 | | - return true;
|
171 | | - }
|
172 | | -
|
173 | | - function addToEditView( $editform ) {
|
174 | | - global $wgRequest, $wgTitle, $wgOut;
|
175 | | - # Talk pages cannot be validated
|
176 | | - if( !$editform->mArticle || !$this->isReviewable( $wgTitle ) )
|
177 | | - return false;
|
178 | | - # Find out revision id
|
179 | | - if( $editform->mArticle->mRevision ) {
|
180 | | - $revid = $editform->mArticle->mRevision->mId;
|
181 | | - } else {
|
182 | | - $revid = $editform->mArticle->getLatest();
|
183 | | - }
|
184 | | - # Grab the ratings for this revision if any
|
185 | | - if( !$revid )
|
186 | | - return true;
|
187 | | - # Set new body html text as that of now
|
188 | | - $tag = '';
|
189 | | - # Check the newest stable version
|
190 | | - $tfrev = $this->getStableRev();
|
191 | | - if( is_object($tfrev) ) {
|
192 | | - global $wgLang, $wgUser, $wgFlaggedRevsAutoReview;
|
193 | | -
|
194 | | - $time = $wgLang->date( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true );
|
195 | | - $flags = $this->getFlagsForRevision( $tfrev->fr_rev_id );
|
196 | | - $revs_since = $this->getRevCountSince( $editform->mArticle->getID(), $tfrev->fr_rev_id );
|
197 | | - # Construct some tagging
|
198 | | - $msg = $this->isQuality( $flags ) ? 'revreview-newest-quality' : 'revreview-newest-basic';
|
199 | | - $tag = wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since );
|
200 | | - # Hide clutter
|
201 | | - $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' .
|
202 | | - wfMsg('revreview-toggle') . '</a>';
|
203 | | - $tag .= '<span id="mw-revisionratings" style="display:block;">' .
|
204 | | - wfMsg('revreview-oldrating') . $this->addTagRatings( $flags ) .
|
205 | | - '</span>';
|
206 | | - $wgOut->addHTML( '<div id="mw-revisiontag" class="flaggedrevs_notice plainlinks">' . $tag . '</div>' );
|
207 | | - # If this will be autoreviewed, notify the user...
|
208 | | - if( !$wgFlaggedRevsAutoReview )
|
209 | | - return true;
|
210 | | - if( $wgUser->isAllowed('review') && $tfrev->fr_rev_id==$editform->mArticle->getLatest() ) {
|
211 | | - # Grab the flags for this revision
|
212 | | - $flags = $this->getFlagsForRevision( $tfrev->fr_rev_id );
|
213 | | - # Check if user is allowed to renew the stable version.
|
214 | | - # If it has been reviewed too highly for this user, abort.
|
215 | | - foreach( $flags as $quality => $level ) {
|
216 | | - if( !Revisionreview::userCan($quality,$level) ) {
|
217 | | - return true;
|
218 | | - }
|
219 | | - }
|
220 | | - $msg = ($revid==$tfrev->fr_rev_id) ? 'revreview-auto-w' : 'revreview-auto-w-old';
|
221 | | - $wgOut->addHTML( '<div id="mw-autoreviewtag" class="flaggedrevs_warning plainlinks">' .
|
222 | | - wfMsgExt($msg,array('parseinline')) . '</div>' );
|
223 | | - }
|
224 | | - }
|
225 | | - return true;
|
226 | | - }
|
227 | | -
|
228 | | - function addReviewForm( $out ) {
|
229 | | - global $wgArticle, $wgRequest, $action;
|
230 | | -
|
231 | | - if( !$wgArticle || !$wgArticle->exists() || !$this->isReviewable( $wgArticle->mTitle ) )
|
232 | | - return true;
|
233 | | - # Check if page is protected
|
234 | | - if( $action !='view' || !$wgArticle->mTitle->quickUserCan( 'edit' ) ) {
|
235 | | - return true;
|
236 | | - }
|
237 | | - # Get revision ID
|
238 | | - $revId = $out->mRevisionId ? $out->mRevisionId : $wgArticle->getLatest();
|
239 | | - # We cannot review deleted revisions
|
240 | | - if( is_object($wgArticle->mRevision) && $wgArticle->mRevision->mDeleted )
|
241 | | - return true;
|
242 | | - # Add quick review links IF we did not override, otherwise, they might
|
243 | | - # review a revision that parses out newer templates/images than what they saw.
|
244 | | - # Revisions are always reviewed based on current templates/images.
|
245 | | - if( $this->pageOverride() ) {
|
246 | | - $tfrev = $this->getStableRev();
|
247 | | - if( $tfrev )
|
248 | | - return true;
|
249 | | - }
|
250 | | - $this->addQuickReview( $revId, $out, $wgRequest->getBool('editreview') );
|
251 | | -
|
252 | | - return true;
|
253 | | - }
|
254 | | -
|
255 | | - function addVisibilityLink( $out ) {
|
256 | | - global $wgUser, $wgRequest, $action;
|
257 | | -
|
258 | | - if( $action=='protect' || $action=='unprotect' ) {
|
259 | | - # Check for an overridabe revision
|
260 | | - $tfrev = $this->getStableRev();
|
261 | | - if( !$tfrev )
|
262 | | - return true;
|
263 | | - $title = SpecialPage::getTitleFor( 'Stabilization' );
|
264 | | - # Give a link to the page to configure the stable version
|
265 | | - $out->mBodytext = '<span class="plainlinks">' .
|
266 | | - wfMsgExt( 'revreview-visibility',array('parseinline'), $title->getPrefixedText() ) .
|
267 | | - '</span>' . $out->mBodytext;
|
268 | | - }
|
269 | | - return true;
|
270 | | - }
|
271 | | -
|
272 | | - function setPermaLink( $sktmp, &$nav_urls, &$revid, &$revid ) {
|
273 | | - # Non-content pages cannot be validated
|
274 | | - if( !$this->pageOverride() )
|
275 | | - return true;
|
276 | | - # Check for an overridabe revision
|
277 | | - $tfrev = $this->getStableRev();
|
278 | | - if( !$tfrev )
|
279 | | - return true;
|
280 | | - # Replace "permalink" with an actual permanent link
|
281 | | - $nav_urls['permalink'] = array(
|
282 | | - 'text' => wfMsg( 'permalink' ),
|
283 | | - 'href' => $sktmp->makeSpecialUrl( 'Stableversions', "oldid={$tfrev->fr_rev_id}" )
|
284 | | - );
|
285 | | - # Are we using the popular cite extension?
|
286 | | - global $wgHooks;
|
287 | | - if( in_array('wfSpecialCiteNav',$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink']) ) {
|
288 | | - if( $this->isReviewable( $sktmp->mTitle ) && $revid !== 0 ) {
|
289 | | - $nav_urls['cite'] = array(
|
290 | | - 'text' => wfMsg( 'cite_article_link' ),
|
291 | | - 'href' => $sktmp->makeSpecialUrl( 'Cite', "page=" . wfUrlencode( "{$sktmp->thispage}" ) . "&id={$tfrev->fr_rev_id}" )
|
292 | | - );
|
293 | | - }
|
294 | | - }
|
295 | | - return true;
|
296 | | - }
|
297 | | -
|
298 | | - function setActionTabs( $sktmp, &$content_actions ) {
|
299 | | - global $wgRequest, $wgUser, $action, $wgFlaggedRevsAnonOnly, $wgFlaggedRevTabs;
|
300 | | - # Get the subject page, not all skins have it :(
|
301 | | - if( !isset($sktmp->mTitle) )
|
302 | | - return true;
|
303 | | - $title = $sktmp->mTitle->getSubjectPage();
|
304 | | - # Non-content pages cannot be validated
|
305 | | - if( !$this->isReviewable( $title ) || !$title->exists() )
|
306 | | - return true;
|
307 | | - $article = new Article( $title );
|
308 | | - # If we are viewing a page normally, and it was overridden,
|
309 | | - # change the edit tab to a "current revision" tab
|
310 | | - $tfrev = $this->getStableRev();
|
311 | | - # No quality revs? Find the last reviewed one
|
312 | | - if( !is_object($tfrev) ) {
|
313 | | - return true;
|
314 | | - }
|
315 | | - /*
|
316 | | - // If the stable version is the same is the current, move along...
|
317 | | - if( $article->getLatest() == $tfrev->fr_rev_id ) {
|
318 | | - return true;
|
319 | | - }
|
320 | | - */
|
321 | | - # Be clear about what is being edited...
|
322 | | - if( !$sktmp->mTitle->isTalkPage() && $this->showStableByDefault() ) {
|
323 | | - if( isset( $content_actions['edit'] ) )
|
324 | | - $content_actions['edit']['text'] = wfMsg('revreview-edit');
|
325 | | - if( isset( $content_actions['viewsource'] ) )
|
326 | | - $content_actions['viewsource']['text'] = wfMsg('revreview-source');
|
327 | | - }
|
328 | | - if( !$wgFlaggedRevTabs ) {
|
329 | | - return true;
|
330 | | - }
|
331 | | - // We are looking at the stable version
|
332 | | - if( $this->pageOverride() ) {
|
333 | | - $new_actions = array(); $counter = 0;
|
334 | | - # Straighten out order, set the tab AFTER the main tab is set
|
335 | | - foreach( $content_actions as $tab_action => $data ) {
|
336 | | - if( $counter==1 ) {
|
337 | | - if( $this->showStableByDefault() ) {
|
338 | | - $new_actions['current'] = array(
|
339 | | - 'class' => '',
|
340 | | - 'text' => wfMsg('revreview-current'),
|
341 | | - 'href' => $title->getLocalUrl( 'stable=0' )
|
342 | | - );
|
343 | | - } else {
|
344 | | - $new_actions['stable'] = array(
|
345 | | - 'class' => 'selected',
|
346 | | - 'text' => wfMsg('revreview-stable'),
|
347 | | - 'href' => $title->getLocalUrl( 'stable=1' )
|
348 | | - );
|
349 | | - }
|
350 | | - }
|
351 | | - $new_actions[$tab_action] = $data;
|
352 | | - $counter++;
|
353 | | - }
|
354 | | - # Reset static array
|
355 | | - $content_actions = $new_actions;
|
356 | | - } else if( $action !='view' || $sktmp->mTitle->isTalkPage() ) {
|
357 | | - // We are looking at the talk page or diffs/hist/oldids, or in edit mode
|
358 | | - $new_actions = array(); $counter = 0;
|
359 | | - # Straighten out order, set the tab AFTER the main tab is set
|
360 | | - foreach( $content_actions as $tab_action => $data ) {
|
361 | | - if( $counter==1 ) {
|
362 | | - if( $this->showStableByDefault() ) {
|
363 | | - $new_actions['current'] = array(
|
364 | | - 'class' => '',
|
365 | | - 'text' => wfMsg('revreview-current'),
|
366 | | - 'href' => $title->getLocalUrl( 'stable=0' )
|
367 | | - );
|
368 | | - } else {
|
369 | | - $new_actions['stable'] = array(
|
370 | | - 'class' => '',
|
371 | | - 'text' => wfMsg('revreview-stable'),
|
372 | | - 'href' => $title->getLocalUrl( 'stable=1' )
|
373 | | - );
|
374 | | - }
|
375 | | - }
|
376 | | - $new_actions[$tab_action] = $data;
|
377 | | - $counter++;
|
378 | | - }
|
379 | | - # Reset static array
|
380 | | - $content_actions = $new_actions;
|
381 | | - } else if( $wgFlaggedRevTabs ) {
|
382 | | - // We are looking at the current revision
|
383 | | - $new_actions = array(); $counter = 0;
|
384 | | - # Straighten out order, set the tab AFTER the main tab is set
|
385 | | - foreach( $content_actions as $tab_action => $data ) {
|
386 | | - if( $counter==1 ) {
|
387 | | - if( $this->showStableByDefault() ) {
|
388 | | - $new_actions['current'] = array(
|
389 | | - 'class' => 'selected',
|
390 | | - 'text' => wfMsg('revreview-current'),
|
391 | | - 'href' => $title->getLocalUrl( 'stable=0' )
|
392 | | - );
|
393 | | - } else {
|
394 | | - $new_actions['stable'] = array(
|
395 | | - 'class' => '',
|
396 | | - 'text' => wfMsg('revreview-stable'),
|
397 | | - 'href' => $title->getLocalUrl( 'stable=1' )
|
398 | | - );
|
399 | | - }
|
400 | | - }
|
401 | | - $new_actions[$tab_action] = $data;
|
402 | | - $counter++;
|
403 | | - }
|
404 | | - # Reset static array
|
405 | | - $content_actions = $new_actions;
|
406 | | - }
|
407 | | - return true;
|
408 | | - }
|
409 | | -
|
410 | | - function addToHistLine( $row, &$s ) {
|
411 | | - global $wgUser, $wgTitle;
|
412 | | - # Non-content pages cannot be validated
|
413 | | - if( !$this->isReviewable( $wgTitle ) )
|
414 | | - return true;
|
415 | | -
|
416 | | - if( !isset($this->dbw) ) {
|
417 | | - $this->dbw = wfGetDB( DB_MASTER );
|
418 | | - }
|
419 | | -
|
420 | | - $quality = $this->dbw->selectField( 'flaggedrevs', 'fr_quality',
|
421 | | - array( 'fr_namespace' => $wgTitle->getNamespace(),
|
422 | | - 'fr_title' => $wgTitle->getDBKey(),
|
423 | | - 'fr_rev_id' => $row->rev_id ),
|
424 | | - __METHOD__,
|
425 | | - array( 'FORCE INDEX' => 'PRIMARY') );
|
426 | | -
|
427 | | - if( $quality !== false ) {
|
428 | | - $skin = $wgUser->getSkin();
|
429 | | -
|
430 | | - $msg = ($quality >= 1) ? 'hist-quality' : 'hist-stable';
|
431 | | - $special = SpecialPage::getTitleFor( 'Stableversions' );
|
432 | | - $s .= ' <tt><small><strong>' .
|
433 | | - $skin->makeLinkObj( $special, wfMsgHtml( $msg ),
|
434 | | - 'page=' . urlencode( $wgTitle->getPrefixedText() ) .
|
435 | | - '&oldid=' . $row->rev_id ) .
|
436 | | - '</strong></small></tt>';
|
437 | | - }
|
438 | | -
|
439 | | - return true;
|
440 | | - }
|
441 | | -
|
442 | | - function addQuickReview( $id=NULL, $out, $top=false ) {
|
443 | | - global $wgOut, $wgTitle, $wgUser, $wgRequest, $wgFlaggedRevComments,
|
444 | | - $wgFlaggedRevsOverride, $wgFlaggedRevsWatch;
|
445 | | - # User must have review rights
|
446 | | - if( !$wgUser->isAllowed( 'review' ) )
|
447 | | - return;
|
448 | | - # Looks ugly when printed
|
449 | | - if( $out->isPrintable() )
|
450 | | - return;
|
451 | | -
|
452 | | - $skin = $wgUser->getSkin();
|
453 | | - # If we are reviewing updates to a page, start off with the stable revision's
|
454 | | - # flags. Otherwise, we just fill them in with the selected revision's flags.
|
455 | | - if( $this->isDiffFromStable ) {
|
456 | | - $flags = $this->getFlagsForRevision( $wgRequest->getVal('oldid') );
|
457 | | - # Check if user is allowed to renew the stable version.
|
458 | | - # It may perhaps have been reviewed too highly for this user, if so,
|
459 | | - # then get the flags for the new revision itself.
|
460 | | - foreach( $flags as $quality => $level ) {
|
461 | | - if( !Revisionreview::userCan($quality,$level) ) {
|
462 | | - $flags = $this->getFlagsForRevision( $id );
|
463 | | - break;
|
464 | | - }
|
465 | | - }
|
466 | | - } else {
|
467 | | - $flags = $this->getFlagsForRevision( $id );
|
468 | | - }
|
469 | | -
|
470 | | - $reviewtitle = SpecialPage::getTitleFor( 'Revisionreview' );
|
471 | | - $action = $reviewtitle->escapeLocalUrl( 'action=submit' );
|
472 | | - $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) );
|
473 | | - $form .= "<fieldset><legend>" . wfMsgHtml( 'revreview-flag', $id ) . "</legend>\n";
|
474 | | -
|
475 | | - if( $wgFlaggedRevsOverride )
|
476 | | - $form .= '<p>'.wfMsgExt( 'revreview-text', array('parseinline') ).'</p>';
|
477 | | -
|
478 | | - $form .= Xml::hidden( 'title', $reviewtitle->getPrefixedText() );
|
479 | | - $form .= Xml::hidden( 'target', $wgTitle->getPrefixedText() );
|
480 | | - $form .= Xml::hidden( 'oldid', $id );
|
481 | | - $form .= Xml::hidden( 'action', 'submit');
|
482 | | - $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken() );
|
483 | | -
|
484 | | - foreach( $this->dimensions as $quality => $levels ) {
|
485 | | - $options = array();
|
486 | | - $disabled = false;
|
487 | | - foreach( $levels as $idx => $label ) {
|
488 | | - $selected = ( $flags[$quality]==$idx || $flags[$quality]==0 && $idx==1 );
|
489 | | - # Do not show options user's can't set unless that is the status quo
|
490 | | - if( !Revisionreview::userCan($quality, $flags[$quality]) ) {
|
491 | | - $disabled = true;
|
492 | | - $options[] = Xml::option( wfMsg( "revreview-$label" ), $idx, $selected );
|
493 | | - } else if( Revisionreview::userCan($quality, $idx) ) {
|
494 | | - $options[] = Xml::option( wfMsg( "revreview-$label" ), $idx, $selected );
|
495 | | - }
|
496 | | - }
|
497 | | - $form .= "\n" . wfMsgHtml("revreview-$quality") . ": ";
|
498 | | - $selectAttribs = array( 'name' => "wp$quality" );
|
499 | | - if( $disabled ) $selectAttribs['disabled'] = 'disabled';
|
500 | | - $form .= Xml::openElement( 'select', $selectAttribs );
|
501 | | - $form .= implode( "\n", $options );
|
502 | | - $form .= "</select>\n";
|
503 | | - }
|
504 | | - if( $wgFlaggedRevComments && $wgUser->isAllowed( 'validate' ) ) {
|
505 | | - $form .= "<br/><p>" . wfMsgHtml( 'revreview-notes' ) . "</p>" .
|
506 | | - "<p><textarea tabindex='1' name='wpNotes' id='wpNotes' rows='2' cols='80' style='width:100%'></textarea>" .
|
507 | | - "</p>\n";
|
508 | | - }
|
509 | | -
|
510 | | - $imageParams = $templateParams = '';
|
511 | | - if( !isset($out->mTemplateIds) || !isset($out->mImageSHA1Keys) ) {
|
512 | | - return; // something went terribly wrong...
|
513 | | - }
|
514 | | - # Hack, add NS:title -> rev ID mapping
|
515 | | - foreach( $out->mTemplateIds as $namespace => $title ) {
|
516 | | - foreach( $title as $dbkey => $id ) {
|
517 | | - $title = Title::makeTitle( $namespace, $dbkey );
|
518 | | - $templateParams .= $title->getPrefixedText() . "|" . $id . "#";
|
519 | | - }
|
520 | | - }
|
521 | | - $form .= Xml::hidden( 'templateParams', $templateParams ) . "\n";
|
522 | | - # Hack, image -> timestamp mapping
|
523 | | - foreach( $out->mImageSHA1Keys as $dbkey => $timeAndSHA1 ) {
|
524 | | - foreach( $timeAndSHA1 as $time => $sha1 ) {
|
525 | | - $imageParams .= $dbkey . "|" . $time . "|" . $sha1 . "#";
|
526 | | - }
|
527 | | - }
|
528 | | - $form .= Xml::hidden( 'imageParams', $imageParams ) . "\n";
|
529 | | -
|
530 | | - $watchLabel = wfMsgExt('watchthis', array('parseinline'));
|
531 | | - $watchAttribs = array('accesskey' => wfMsg( 'accesskey-watch' ), 'id' => 'wpWatchthis');
|
532 | | - $watchChecked = ( $wgFlaggedRevsWatch && $wgUser->getOption( 'watchdefault' ) || $wgTitle->userIsWatching() );
|
533 | | - # Not much to say unless you are a validator
|
534 | | - if( $wgUser->isAllowed( 'validate' ) )
|
535 | | - $form .= "<p>".Xml::inputLabel( wfMsg( 'revreview-log' ), 'wpReason', 'wpReason', 60 )."</p>\n";
|
536 | | -
|
537 | | - $form .= "<p> ".Xml::check( 'wpWatchthis', $watchChecked, $watchAttribs );
|
538 | | - $form .= " <label for='wpWatchthis'".$skin->tooltipAndAccesskey('watch').">{$watchLabel}</label>";
|
539 | | -
|
540 | | - $form .= ' '.Xml::submitButton( wfMsg( 'revreview-submit' ) )."</p></fieldset>";
|
541 | | - $form .= Xml::closeElement( 'form' );
|
542 | | -
|
543 | | - if( $top )
|
544 | | - $out->mBodytext = $form . '<span style="clear:both"/>' . $out->mBodytext;
|
545 | | - else
|
546 | | - $wgOut->addHTML( '<hr style="clear:both"/>' . $form );
|
547 | | -
|
548 | | - }
|
549 | | -
|
550 | | - /**
|
551 | | - * @param array $flags
|
552 | | - * @param bool $prettybox
|
553 | | - * @param string $css, class to wrap box in
|
554 | | - * @return string
|
555 | | - * Generates a review box/tag
|
556 | | - */
|
557 | | - public function addTagRatings( $flags, $prettyBox = false, $css='' ) {
|
558 | | - global $wgFlaggedRevTags;
|
559 | | -
|
560 | | - $tag = '';
|
561 | | - if( $prettyBox )
|
562 | | - $tag .= "<table align='center' class='$css' cellpading='0'>";
|
563 | | -
|
564 | | - foreach( $this->dimensions as $quality => $value ) {
|
565 | | - $encValueText = wfMsgHtml('revreview-' . $this->dimensions[$quality][$flags[$quality]]);
|
566 | | - $level = $flags[$quality];
|
567 | | - $minlevel = $wgFlaggedRevTags[$quality];
|
568 | | - if( $level >= $minlevel )
|
569 | | - $classmarker = 2;
|
570 | | - elseif( $level > 0 )
|
571 | | - $classmarker = 1;
|
572 | | - else
|
573 | | - $classmarker = 0;
|
574 | | -
|
575 | | - $levelmarker = $level * 20 + 20; //XXX do this better
|
576 | | - if( $prettyBox ) {
|
577 | | - $tag .= "<tr><td><span class='fr-group'><span class='fr-text'>" .
|
578 | | - wfMsgHtml("revreview-$quality") .
|
579 | | - "</span></td><td><span class='fr-marker fr_value$levelmarker'>" .
|
580 | | - $encValueText . "</span></span></td></tr>\n";
|
581 | | - } else {
|
582 | | - $tag .= " <span class='fr-marker-$levelmarker'><strong>" .
|
583 | | - wfMsgHtml("revreview-$quality") .
|
584 | | - "</strong>: <span class='fr-text-value'>$encValueText </span> " .
|
585 | | - "</span>\n";
|
586 | | - }
|
587 | | - }
|
588 | | - if( $prettyBox )
|
589 | | - $tag .= '</table>';
|
590 | | -
|
591 | | - return $tag;
|
592 | | - }
|
593 | | -
|
594 | | - /**
|
595 | | - * @param Row $trev, flagged revision row
|
596 | | - * @param array $flags
|
597 | | - * @param int $rev_since, revisions since review
|
598 | | - * @param bool $stable, are we referring to the stable revision?
|
599 | | - * @return string
|
600 | | - * Generates a review box using a table using addTagRatings()
|
601 | | - */
|
602 | | - public function prettyRatingBox( $tfrev, $flags, $revs_since, $stable=true ) {
|
603 | | - global $wgLang;
|
604 | | - # Get quality level
|
605 | | - $quality = self::isQuality( $flags );
|
606 | | - $pristine = self::isPristine( $flags );
|
607 | | - $time = $wgLang->date( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true );
|
608 | | - # Some checks for which tag CSS to use
|
609 | | - if( $pristine )
|
610 | | - $tagClass = 'flaggedrevs_box3';
|
611 | | - else if( $quality )
|
612 | | - $tagClass = 'flaggedrevs_box2';
|
613 | | - else
|
614 | | - $tagClass = 'flaggedrevs_box1';
|
615 | | - # Construct some tagging
|
616 | | - $msg = $stable ? 'revreview-' : 'revreview-newest-';
|
617 | | - $msg .= $quality ? 'quality' : 'basic';
|
618 | | - $encRatingLabel = $stable ? '' : ' ' . wfMsgHtml('revreview-oldrating');
|
619 | | -
|
620 | | - $box = ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' .
|
621 | | - wfMsg('revreview-toggle') . '</a>';
|
622 | | - $box .= '<span id="mw-revisionratings">' .
|
623 | | - wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since) .
|
624 | | - $encRatingLabel .
|
625 | | - self::addTagRatings( $flags, true, "{$tagClass}a" ) .
|
626 | | - '</span>';
|
627 | | -
|
628 | | - return $box;
|
629 | | - }
|
630 | | -
|
631 | | - /**
|
632 | | - * @param Row $row
|
633 | | - * @return string
|
634 | | - * Generates revision review notes
|
635 | | - */
|
636 | | - public function ReviewNotes( $row ) {
|
637 | | - global $wgUser, $wgFlaggedRevComments;
|
638 | | -
|
639 | | - if( !$wgFlaggedRevComments || !$row || $row->fr_comment == '' )
|
640 | | - return '';
|
641 | | -
|
642 | | - $skin = $wgUser->getSkin();
|
643 | | - $notes = '<p><div class="flaggedrevs_notes plainlinks">';
|
644 | | - $notes .= wfMsgExt('revreview-note', array('parse'), User::whoIs( $row->fr_user ) );
|
645 | | - $notes .= '<i>' . $skin->formatComment( $row->fr_comment ) . '</i></div></p><br/>';
|
646 | | - return $notes;
|
647 | | - }
|
648 | | -
|
649 | | - /**
|
650 | | - * Get latest quality rev, if not, the latest reviewed one
|
651 | | - * Same params for the sake of inheritance
|
652 | | - * @return Row
|
653 | | - */
|
654 | | - function getStableRev( $t=null, $getText=false, $forUpdate=false ) {
|
655 | | - global $wgTitle, $wgFlaggedRevs;
|
656 | | - # Cached results available?
|
657 | | - if( $getText ) {
|
658 | | - if( isset($this->stablerev) && isset($this->stablerev->fr_text) ) {
|
659 | | - return $this->stablerev;
|
660 | | - }
|
661 | | - } else {
|
662 | | - if( isset($this->stablerev) ) {
|
663 | | - return $this->stablerev;
|
664 | | - }
|
665 | | - }
|
666 | | - # Get the content page, skip talk
|
667 | | - $title = $wgTitle->getSubjectPage();
|
668 | | - # Do we have one?
|
669 | | - $row = $this->getStablePageRev( $title, $getText, $forUpdate );
|
670 | | - if( $row ) {
|
671 | | - $this->stablerev = $row;
|
672 | | - return $row;
|
673 | | - } else {
|
674 | | - $this->stablerev = null;
|
675 | | - return null;
|
676 | | - }
|
677 | | - }
|
678 | | -
|
679 | | - /**
|
680 | | - * Get visiblity restrictions on page
|
681 | | - * Same params for the sake of inheritance
|
682 | | - * @returns Array
|
683 | | - */
|
684 | | - public function getVisibilitySettings( $t=null, $forUpdate=false ) {
|
685 | | - global $wgTitle;
|
686 | | - # Cached results available?
|
687 | | - if( isset($this->pageconfig) ) {
|
688 | | - return $this->pageconfig;
|
689 | | - }
|
690 | | - # Get the content page, skip talk
|
691 | | - $title = $wgTitle->getSubjectPage();
|
692 | | -
|
693 | | - $config = $this->getPageVisibilitySettings( $title, $forUpdate );
|
694 | | - $this->pageconfig = $config;
|
695 | | -
|
696 | | - return $config;
|
697 | | - }
|
698 | | -
|
699 | | - /**
|
700 | | - * @param int $rev_id
|
701 | | - * Return an array output of the flags for a given revision
|
702 | | - */
|
703 | | - public function getFlagsForRevision( $rev_id ) {
|
704 | | - global $wgFlaggedRevTags;
|
705 | | - # Cached results?
|
706 | | - if( isset($this->flags[$rev_id]) && $this->flags[$rev_id] )
|
707 | | - return $this->revflags[$rev_id];
|
708 | | - # Set all flags to zero
|
709 | | - $flags = array();
|
710 | | - foreach( array_keys($wgFlaggedRevTags) as $tag ) {
|
711 | | - $flags[$tag] = 0;
|
712 | | - }
|
713 | | - # Grab all the tags for this revision
|
714 | | - $dbr = wfGetDB( DB_SLAVE );
|
715 | | - $result = $dbr->select( 'flaggedrevtags',
|
716 | | - array( 'frt_dimension', 'frt_value' ),
|
717 | | - array( 'frt_rev_id' => $rev_id ),
|
718 | | - __METHOD__ );
|
719 | | - # Iterate through each tag result
|
720 | | - while( $row = $dbr->fetchObject($result) ) {
|
721 | | - $flags[$row->frt_dimension] = $row->frt_value;
|
722 | | - }
|
723 | | - # Try to cache results
|
724 | | - $this->flags[$rev_id] = true;
|
725 | | - $this->revflags[$rev_id] = $flags;
|
726 | | -
|
727 | | - return $flags;
|
728 | | - }
|
729 | | -
|
730 | | -}
|
| 2 | +<?php |
| 3 | + |
| 4 | +class FlaggedArticle extends FlaggedRevs { |
| 5 | + /** |
| 6 | + * Does the config and current URL params allow |
| 7 | + * for overriding by stable revisions? |
| 8 | + */ |
| 9 | + function pageOverride() { |
| 10 | + global $wgFlaggedRevsAnonOnly, $wgFlaggedRevs, |
| 11 | + $wgTitle, $wgUser, $wgRequest, $action; |
| 12 | + # This only applies to viewing content pages |
| 13 | + if( $action !='view' || !$this->isReviewable( $wgTitle ) ) |
| 14 | + return false; |
| 15 | + # Does not apply to diffs/old revisions |
| 16 | + if( $wgRequest->getVal('oldid') || $wgRequest->getVal('diff') ) |
| 17 | + return false; |
| 18 | + # Get page config |
| 19 | + $config = $wgFlaggedRevs->getVisibilitySettings( $wgTitle ); |
| 20 | + # Does the stable version override the current one? |
| 21 | + if( $config['override'] ) { |
| 22 | + # If $wgFlaggedRevsAnonOnly is set to false, stable version are only requested explicitly |
| 23 | + if( $wgFlaggedRevsAnonOnly && $wgUser->isAnon() ) { |
| 24 | + return !( $wgRequest->getIntOrNull('stable') === 0 ); |
| 25 | + } else { |
| 26 | + return ( $wgRequest->getIntOrNull('stable') === 1 ); |
| 27 | + } |
| 28 | + # We are explicity requesting the stable version? |
| 29 | + } else if( $wgRequest->getIntOrNull('stable') === 1 ) { |
| 30 | + return true; |
| 31 | + } |
| 32 | + return false; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Is this user shown the stable version by default for this page? |
| 37 | + */ |
| 38 | + function showStableByDefault() { |
| 39 | + global $wgFlaggedRevsOverride, $wgFlaggedRevsAnonOnly, $wgUser; |
| 40 | + |
| 41 | + $config = $this->getVisibilitySettings(); |
| 42 | + |
| 43 | + return ( $config['override'] && !($wgFlaggedRevsAnonOnly && !$wgUser->isAnon()) ); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Replaces a page with the last stable version if possible |
| 48 | + * Adds stable version status/info tags and notes |
| 49 | + * Adds a quick review form on the bottom if needed |
| 50 | + */ |
| 51 | + function setPageContent( $article, &$outputDone, &$pcache ) { |
| 52 | + global $wgRequest, $wgTitle, $wgOut, $action, $wgUser; |
| 53 | + // Only trigger on article view for content pages, not for protect/delete/hist |
| 54 | + if( $action !='view' || !$article || !$article->exists() || !$this->isReviewable( $article->mTitle ) ) |
| 55 | + return true; |
| 56 | + // Grab page and rev ids |
| 57 | + $pageid = $article->getId(); |
| 58 | + $revid = $article->mRevision ? $article->mRevision->mId : $article->getLatest(); |
| 59 | + if( !$revid ) |
| 60 | + return true; |
| 61 | + |
| 62 | + $skin = $wgUser->getSkin(); |
| 63 | + |
| 64 | + $vis_id = $revid; |
| 65 | + $tag = $notes = ''; |
| 66 | + # Check the newest stable version... |
| 67 | + $tfrev = $this->getStableRev( null, true ); |
| 68 | + $simpleTag = false; |
| 69 | + if( $wgRequest->getVal('diff') || $wgRequest->getVal('oldid') ) { |
| 70 | + // Do not clutter up diffs any further... |
| 71 | + } else if( !is_null($tfrev) ) { |
| 72 | + global $wgLang; |
| 73 | + # Get flags and date |
| 74 | + $flags = $this->getFlagsForRevision( $tfrev->fr_rev_id ); |
| 75 | + # Get quality level |
| 76 | + $quality = $this->isQuality( $flags ); |
| 77 | + $pristine = $this->isPristine( $flags ); |
| 78 | + $time = $wgLang->date( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true ); |
| 79 | + # Looking at some specific old rev or if flagged revs override only for anons |
| 80 | + if( !$this->pageOverride() ) { |
| 81 | + $revs_since = $this->getRevCountSince( $pageid, $tfrev->fr_rev_id ); |
| 82 | + $simpleTag = true; |
| 83 | + # Construct some tagging |
| 84 | + if( !$wgOut->isPrintable() ) { |
| 85 | + if( $this->useSimpleUI() ) { |
| 86 | + $msg = $quality ? 'revreview-quick-see-quality' : 'revreview-quick-see-basic'; |
| 87 | + $tag .= "<span class='fr_tab_current plainlinks'></span>" . |
| 88 | + wfMsgExt($msg,array('parseinline'), $tfrev->fr_rev_id, $revs_since); |
| 89 | + $tag .= $this->prettyRatingBox( $tfrev, $flags, $revs_since, false ); |
| 90 | + } else { |
| 91 | + $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic'; |
| 92 | + $tag .= wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since); |
| 93 | + # Hide clutter |
| 94 | + $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
| 95 | + wfMsg('revreview-toggle') . '</a>'; |
| 96 | + $tag .= '<span id="mw-revisionratings" style="display:block;">' . |
| 97 | + wfMsg('revreview-oldrating') . $this->addTagRatings( $flags ) . '</span>'; |
| 98 | + } |
| 99 | + } |
| 100 | + // Viewing the page normally: override the page |
| 101 | + } else { |
| 102 | + # We will be looking at the reviewed revision... |
| 103 | + $vis_id = $tfrev->fr_rev_id; |
| 104 | + $revs_since = $this->getRevCountSince( $pageid, $vis_id ); |
| 105 | + # Construct some tagging |
| 106 | + if( !$wgOut->isPrintable() ) { |
| 107 | + if( $this->useSimpleUI() ) { |
| 108 | + $msg = $quality ? 'revreview-quick-quality' : 'revreview-quick-basic'; |
| 109 | + $css = $quality ? 'fr_tab_quality' : 'fr_tab_stable'; |
| 110 | + $tag .= "<span class='$css plainlinks'></span>" . |
| 111 | + wfMsgExt($msg,array('parseinline'),$tfrev->fr_rev_id,$revs_since); |
| 112 | + $tag .= $this->prettyRatingBox( $tfrev, $flags, $revs_since ); |
| 113 | + } else { |
| 114 | + $msg = $quality ? 'revreview-quality' : 'revreview-basic'; |
| 115 | + $tag = wfMsgExt($msg, array('parseinline'), $vis_id, $time, $revs_since); |
| 116 | + $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
| 117 | + wfMsg('revreview-toggle') . '</a>'; |
| 118 | + $tag .= '<span id="mw-revisionratings" style="display:block;">' . |
| 119 | + $this->addTagRatings( $flags ) . '</span>'; |
| 120 | + } |
| 121 | + } |
| 122 | + # Try the stable page cache |
| 123 | + $parserOut = $this->getPageCache( $article ); |
| 124 | + # If no cache is available, get the text and parse it |
| 125 | + if( $parserOut==false ) { |
| 126 | + $text = $this->uncompressText( $tfrev->fr_text, $tfrev->fr_flags ); |
| 127 | + $parserOut = $this->parseStableText( $article, $text, $vis_id ); |
| 128 | + # Update the general cache |
| 129 | + $this->updatePageCache( $article, $parserOut ); |
| 130 | + } |
| 131 | + $wgOut->mBodytext = $parserOut->getText(); |
| 132 | + # Show stable categories and interwiki links only |
| 133 | + $wgOut->mCategoryLinks = array(); |
| 134 | + $wgOut->addCategoryLinks( $parserOut->getCategories() ); |
| 135 | + $wgOut->mLanguageLinks = array(); |
| 136 | + $wgOut->addLanguageLinks( $parserOut->getLanguageLinks() ); |
| 137 | + $notes = $this->ReviewNotes( $tfrev ); |
| 138 | + # Tell MW that parser output is done |
| 139 | + $outputDone = true; |
| 140 | + $pcache = false; |
| 141 | + } |
| 142 | + # Some checks for which tag CSS to use |
| 143 | + if( $this->useSimpleUI() ) |
| 144 | + $tagClass = 'flaggedrevs_short'; |
| 145 | + else if( $simpleTag ) |
| 146 | + $tagClass = 'flaggedrevs_notice'; |
| 147 | + else if( $pristine ) |
| 148 | + $tagClass = 'flaggedrevs_tag3'; |
| 149 | + else if( $quality ) |
| 150 | + $tagClass = 'flaggedrevs_tag2'; |
| 151 | + else |
| 152 | + $tagClass = 'flaggedrevs_tag1'; |
| 153 | + # Wrap tag contents in a div |
| 154 | + if( $tag !='' ) |
| 155 | + $tag = '<div id="mw-revisiontag" class="' . $tagClass . ' plainlinks">'.$tag.'</div>'; |
| 156 | + # Set the new body HTML, place a tag on top |
| 157 | + $wgOut->mBodytext = $tag . $wgOut->mBodytext . $notes; |
| 158 | + // Add "no reviewed version" tag, but not for main page |
| 159 | + } else if( !$wgOut->isPrintable() && !$this->isMainPage( $article->mTitle ) ) { |
| 160 | + if( $this->useSimpleUI() ) { |
| 161 | + $tag .= "<span class='fr_tab_current plainlinks'></span>" . |
| 162 | + wfMsgExt('revreview-quick-none',array('parseinline')); |
| 163 | + $tag = '<div id="mw-revisiontag" class="flaggedrevs_short plainlinks">'.$tag.'</div>'; |
| 164 | + } else { |
| 165 | + $tag = '<div id="mw-revisiontag" class="flaggedrevs_notice plainlinks">' . |
| 166 | + wfMsgExt('revreview-noflagged', array('parseinline')) . '</div>'; |
| 167 | + } |
| 168 | + $wgOut->addHTML( $tag ); |
| 169 | + } |
| 170 | + return true; |
| 171 | + } |
| 172 | + |
| 173 | + function addToEditView( $editform ) { |
| 174 | + global $wgRequest, $wgTitle, $wgOut; |
| 175 | + # Talk pages cannot be validated |
| 176 | + if( !$editform->mArticle || !$this->isReviewable( $wgTitle ) ) |
| 177 | + return false; |
| 178 | + # Find out revision id |
| 179 | + if( $editform->mArticle->mRevision ) { |
| 180 | + $revid = $editform->mArticle->mRevision->mId; |
| 181 | + } else { |
| 182 | + $revid = $editform->mArticle->getLatest(); |
| 183 | + } |
| 184 | + # Grab the ratings for this revision if any |
| 185 | + if( !$revid ) |
| 186 | + return true; |
| 187 | + # Set new body html text as that of now |
| 188 | + $tag = ''; |
| 189 | + # Check the newest stable version |
| 190 | + $tfrev = $this->getStableRev(); |
| 191 | + if( is_object($tfrev) ) { |
| 192 | + global $wgLang, $wgUser, $wgFlaggedRevsAutoReview; |
| 193 | + |
| 194 | + $time = $wgLang->date( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true ); |
| 195 | + $flags = $this->getFlagsForRevision( $tfrev->fr_rev_id ); |
| 196 | + $revs_since = $this->getRevCountSince( $editform->mArticle->getID(), $tfrev->fr_rev_id ); |
| 197 | + # Construct some tagging |
| 198 | + $msg = $this->isQuality( $flags ) ? 'revreview-newest-quality' : 'revreview-newest-basic'; |
| 199 | + $tag = wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since ); |
| 200 | + # Hide clutter |
| 201 | + $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
| 202 | + wfMsg('revreview-toggle') . '</a>'; |
| 203 | + $tag .= '<span id="mw-revisionratings" style="display:block;">' . |
| 204 | + wfMsg('revreview-oldrating') . $this->addTagRatings( $flags ) . |
| 205 | + '</span>'; |
| 206 | + $wgOut->addHTML( '<div id="mw-revisiontag" class="flaggedrevs_notice plainlinks">' . $tag . '</div>' ); |
| 207 | + # If this will be autoreviewed, notify the user... |
| 208 | + if( !$wgFlaggedRevsAutoReview ) |
| 209 | + return true; |
| 210 | + if( $wgUser->isAllowed('review') && $tfrev->fr_rev_id==$editform->mArticle->getLatest() ) { |
| 211 | + # Grab the flags for this revision |
| 212 | + $flags = $this->getFlagsForRevision( $tfrev->fr_rev_id ); |
| 213 | + # Check if user is allowed to renew the stable version. |
| 214 | + # If it has been reviewed too highly for this user, abort. |
| 215 | + foreach( $flags as $quality => $level ) { |
| 216 | + if( !Revisionreview::userCan($quality,$level) ) { |
| 217 | + return true; |
| 218 | + } |
| 219 | + } |
| 220 | + $msg = ($revid==$tfrev->fr_rev_id) ? 'revreview-auto-w' : 'revreview-auto-w-old'; |
| 221 | + $wgOut->addHTML( '<div id="mw-autoreviewtag" class="flaggedrevs_warning plainlinks">' . |
| 222 | + wfMsgExt($msg,array('parseinline')) . '</div>' ); |
| 223 | + } |
| 224 | + } |
| 225 | + return true; |
| 226 | + } |
| 227 | + |
| 228 | + function addReviewForm( $out ) { |
| 229 | + global $wgArticle, $wgRequest, $action; |
| 230 | + |
| 231 | + if( !$wgArticle || !$wgArticle->exists() || !$this->isReviewable( $wgArticle->mTitle ) ) |
| 232 | + return true; |
| 233 | + # Check if page is protected |
| 234 | + if( $action !='view' || !$wgArticle->mTitle->quickUserCan( 'edit' ) ) { |
| 235 | + return true; |
| 236 | + } |
| 237 | + # Get revision ID |
| 238 | + $revId = $out->mRevisionId ? $out->mRevisionId : $wgArticle->getLatest(); |
| 239 | + # We cannot review deleted revisions |
| 240 | + if( is_object($wgArticle->mRevision) && $wgArticle->mRevision->mDeleted ) |
| 241 | + return true; |
| 242 | + # Add quick review links IF we did not override, otherwise, they might |
| 243 | + # review a revision that parses out newer templates/images than what they saw. |
| 244 | + # Revisions are always reviewed based on current templates/images. |
| 245 | + if( $this->pageOverride() ) { |
| 246 | + $tfrev = $this->getStableRev(); |
| 247 | + if( $tfrev ) |
| 248 | + return true; |
| 249 | + } |
| 250 | + $this->addQuickReview( $revId, $out, $wgRequest->getBool('editreview') ); |
| 251 | + |
| 252 | + return true; |
| 253 | + } |
| 254 | + |
| 255 | + function addVisibilityLink( $out ) { |
| 256 | + global $wgUser, $wgRequest, $action; |
| 257 | + |
| 258 | + if( $action=='protect' || $action=='unprotect' ) { |
| 259 | + # Check for an overridabe revision |
| 260 | + $tfrev = $this->getStableRev(); |
| 261 | + if( !$tfrev ) |
| 262 | + return true; |
| 263 | + $title = SpecialPage::getTitleFor( 'Stabilization' ); |
| 264 | + # Give a link to the page to configure the stable version |
| 265 | + $out->mBodytext = '<span class="plainlinks">' . |
| 266 | + wfMsgExt( 'revreview-visibility',array('parseinline'), $title->getPrefixedText() ) . |
| 267 | + '</span>' . $out->mBodytext; |
| 268 | + } |
| 269 | + return true; |
| 270 | + } |
| 271 | + |
| 272 | + function setPermaLink( $sktmp, &$nav_urls, &$revid, &$revid ) { |
| 273 | + # Non-content pages cannot be validated |
| 274 | + if( !$this->pageOverride() ) |
| 275 | + return true; |
| 276 | + # Check for an overridabe revision |
| 277 | + $tfrev = $this->getStableRev(); |
| 278 | + if( !$tfrev ) |
| 279 | + return true; |
| 280 | + # Replace "permalink" with an actual permanent link |
| 281 | + $nav_urls['permalink'] = array( |
| 282 | + 'text' => wfMsg( 'permalink' ), |
| 283 | + 'href' => $sktmp->makeSpecialUrl( 'Stableversions', "oldid={$tfrev->fr_rev_id}" ) |
| 284 | + ); |
| 285 | + # Are we using the popular cite extension? |
| 286 | + global $wgHooks; |
| 287 | + if( in_array('wfSpecialCiteNav',$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink']) ) { |
| 288 | + if( $this->isReviewable( $sktmp->mTitle ) && $revid !== 0 ) { |
| 289 | + $nav_urls['cite'] = array( |
| 290 | + 'text' => wfMsg( 'cite_article_link' ), |
| 291 | + 'href' => $sktmp->makeSpecialUrl( 'Cite', "page=" . wfUrlencode( "{$sktmp->thispage}" ) . "&id={$tfrev->fr_rev_id}" ) |
| 292 | + ); |
| 293 | + } |
| 294 | + } |
| 295 | + return true; |
| 296 | + } |
| 297 | + |
| 298 | + function setActionTabs( $sktmp, &$content_actions ) { |
| 299 | + global $wgRequest, $wgUser, $action, $wgFlaggedRevsAnonOnly, $wgFlaggedRevTabs; |
| 300 | + # Get the subject page, not all skins have it :( |
| 301 | + if( !isset($sktmp->mTitle) ) |
| 302 | + return true; |
| 303 | + $title = $sktmp->mTitle->getSubjectPage(); |
| 304 | + # Non-content pages cannot be validated |
| 305 | + if( !$this->isReviewable( $title ) || !$title->exists() ) |
| 306 | + return true; |
| 307 | + $article = new Article( $title ); |
| 308 | + # If we are viewing a page normally, and it was overridden, |
| 309 | + # change the edit tab to a "current revision" tab |
| 310 | + $tfrev = $this->getStableRev(); |
| 311 | + # No quality revs? Find the last reviewed one |
| 312 | + if( !is_object($tfrev) ) { |
| 313 | + return true; |
| 314 | + } |
| 315 | + /* |
| 316 | + // If the stable version is the same is the current, move along... |
| 317 | + if( $article->getLatest() == $tfrev->fr_rev_id ) { |
| 318 | + return true; |
| 319 | + } |
| 320 | + */ |
| 321 | + # Be clear about what is being edited... |
| 322 | + if( !$sktmp->mTitle->isTalkPage() && $this->showStableByDefault() ) { |
| 323 | + if( isset( $content_actions['edit'] ) ) |
| 324 | + $content_actions['edit']['text'] = wfMsg('revreview-edit'); |
| 325 | + if( isset( $content_actions['viewsource'] ) ) |
| 326 | + $content_actions['viewsource']['text'] = wfMsg('revreview-source'); |
| 327 | + } |
| 328 | + if( !$wgFlaggedRevTabs ) { |
| 329 | + return true; |
| 330 | + } |
| 331 | + // We are looking at the stable version |
| 332 | + if( $this->pageOverride() ) { |
| 333 | + $new_actions = array(); $counter = 0; |
| 334 | + # Straighten out order, set the tab AFTER the main tab is set |
| 335 | + foreach( $content_actions as $tab_action => $data ) { |
| 336 | + if( $counter==1 ) { |
| 337 | + if( $this->showStableByDefault() ) { |
| 338 | + $new_actions['current'] = array( |
| 339 | + 'class' => '', |
| 340 | + 'text' => wfMsg('revreview-current'), |
| 341 | + 'href' => $title->getLocalUrl( 'stable=0' ) |
| 342 | + ); |
| 343 | + } else { |
| 344 | + $new_actions['stable'] = array( |
| 345 | + 'class' => 'selected', |
| 346 | + 'text' => wfMsg('revreview-stable'), |
| 347 | + 'href' => $title->getLocalUrl( 'stable=1' ) |
| 348 | + ); |
| 349 | + } |
| 350 | + } |
| 351 | + $new_actions[$tab_action] = $data; |
| 352 | + $counter++; |
| 353 | + } |
| 354 | + # Reset static array |
| 355 | + $content_actions = $new_actions; |
| 356 | + } else if( $action !='view' || $sktmp->mTitle->isTalkPage() ) { |
| 357 | + // We are looking at the talk page or diffs/hist/oldids, or in edit mode |
| 358 | + $new_actions = array(); $counter = 0; |
| 359 | + # Straighten out order, set the tab AFTER the main tab is set |
| 360 | + foreach( $content_actions as $tab_action => $data ) { |
| 361 | + if( $counter==1 ) { |
| 362 | + if( $this->showStableByDefault() ) { |
| 363 | + $new_actions['current'] = array( |
| 364 | + 'class' => '', |
| 365 | + 'text' => wfMsg('revreview-current'), |
| 366 | + 'href' => $title->getLocalUrl( 'stable=0' ) |
| 367 | + ); |
| 368 | + } else { |
| 369 | + $new_actions['stable'] = array( |
| 370 | + 'class' => '', |
| 371 | + 'text' => wfMsg('revreview-stable'), |
| 372 | + 'href' => $title->getLocalUrl( 'stable=1' ) |
| 373 | + ); |
| 374 | + } |
| 375 | + } |
| 376 | + $new_actions[$tab_action] = $data; |
| 377 | + $counter++; |
| 378 | + } |
| 379 | + # Reset static array |
| 380 | + $content_actions = $new_actions; |
| 381 | + } else if( $wgFlaggedRevTabs ) { |
| 382 | + // We are looking at the current revision |
| 383 | + $new_actions = array(); $counter = 0; |
| 384 | + # Straighten out order, set the tab AFTER the main tab is set |
| 385 | + foreach( $content_actions as $tab_action => $data ) { |
| 386 | + if( $counter==1 ) { |
| 387 | + if( $this->showStableByDefault() ) { |
| 388 | + $new_actions['current'] = array( |
| 389 | + 'class' => 'selected', |
| 390 | + 'text' => wfMsg('revreview-current'), |
| 391 | + 'href' => $title->getLocalUrl( 'stable=0' ) |
| 392 | + ); |
| 393 | + } else { |
| 394 | + $new_actions['stable'] = array( |
| 395 | + 'class' => '', |
| 396 | + 'text' => wfMsg('revreview-stable'), |
| 397 | + 'href' => $title->getLocalUrl( 'stable=1' ) |
| 398 | + ); |
| 399 | + } |
| 400 | + } |
| 401 | + $new_actions[$tab_action] = $data; |
| 402 | + $counter++; |
| 403 | + } |
| 404 | + # Reset static array |
| 405 | + $content_actions = $new_actions; |
| 406 | + } |
| 407 | + return true; |
| 408 | + } |
| 409 | + |
| 410 | + function addToHistLine( $row, &$s ) { |
| 411 | + global $wgUser, $wgTitle; |
| 412 | + # Non-content pages cannot be validated |
| 413 | + if( !$this->isReviewable( $wgTitle ) ) |
| 414 | + return true; |
| 415 | + |
| 416 | + if( !isset($this->dbw) ) { |
| 417 | + $this->dbw = wfGetDB( DB_MASTER ); |
| 418 | + } |
| 419 | + |
| 420 | + $quality = $this->dbw->selectField( 'flaggedrevs', 'fr_quality', |
| 421 | + array( 'fr_namespace' => $wgTitle->getNamespace(), |
| 422 | + 'fr_title' => $wgTitle->getDBKey(), |
| 423 | + 'fr_rev_id' => $row->rev_id ), |
| 424 | + __METHOD__, |
| 425 | + array( 'FORCE INDEX' => 'PRIMARY') ); |
| 426 | + |
| 427 | + if( $quality !== false ) { |
| 428 | + $skin = $wgUser->getSkin(); |
| 429 | + |
| 430 | + $msg = ($quality >= 1) ? 'hist-quality' : 'hist-stable'; |
| 431 | + $special = SpecialPage::getTitleFor( 'Stableversions' ); |
| 432 | + $s .= ' <tt><small><strong>' . |
| 433 | + $skin->makeLinkObj( $special, wfMsgHtml( $msg ), |
| 434 | + 'page=' . urlencode( $wgTitle->getPrefixedText() ) . |
| 435 | + '&oldid=' . $row->rev_id ) . |
| 436 | + '</strong></small></tt>'; |
| 437 | + } |
| 438 | + |
| 439 | + return true; |
| 440 | + } |
| 441 | + |
| 442 | + function addQuickReview( $id=NULL, $out, $top=false ) { |
| 443 | + global $wgOut, $wgTitle, $wgUser, $wgRequest, $wgFlaggedRevComments, |
| 444 | + $wgFlaggedRevsOverride, $wgFlaggedRevsWatch; |
| 445 | + # User must have review rights |
| 446 | + if( !$wgUser->isAllowed( 'review' ) ) |
| 447 | + return; |
| 448 | + # Looks ugly when printed |
| 449 | + if( $out->isPrintable() ) |
| 450 | + return; |
| 451 | + |
| 452 | + $skin = $wgUser->getSkin(); |
| 453 | + # If we are reviewing updates to a page, start off with the stable revision's |
| 454 | + # flags. Otherwise, we just fill them in with the selected revision's flags. |
| 455 | + if( $this->isDiffFromStable ) { |
| 456 | + $flags = $this->getFlagsForRevision( $wgRequest->getVal('oldid') ); |
| 457 | + # Check if user is allowed to renew the stable version. |
| 458 | + # It may perhaps have been reviewed too highly for this user, if so, |
| 459 | + # then get the flags for the new revision itself. |
| 460 | + foreach( $flags as $quality => $level ) { |
| 461 | + if( !Revisionreview::userCan($quality,$level) ) { |
| 462 | + $flags = $this->getFlagsForRevision( $id ); |
| 463 | + break; |
| 464 | + } |
| 465 | + } |
| 466 | + } else { |
| 467 | + $flags = $this->getFlagsForRevision( $id ); |
| 468 | + } |
| 469 | + |
| 470 | + $reviewtitle = SpecialPage::getTitleFor( 'Revisionreview' ); |
| 471 | + $action = $reviewtitle->escapeLocalUrl( 'action=submit' ); |
| 472 | + $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ); |
| 473 | + $form .= "<fieldset><legend>" . wfMsgHtml( 'revreview-flag', $id ) . "</legend>\n"; |
| 474 | + |
| 475 | + if( $wgFlaggedRevsOverride ) |
| 476 | + $form .= '<p>'.wfMsgExt( 'revreview-text', array('parseinline') ).'</p>'; |
| 477 | + |
| 478 | + $form .= Xml::hidden( 'title', $reviewtitle->getPrefixedText() ); |
| 479 | + $form .= Xml::hidden( 'target', $wgTitle->getPrefixedText() ); |
| 480 | + $form .= Xml::hidden( 'oldid', $id ); |
| 481 | + $form .= Xml::hidden( 'action', 'submit'); |
| 482 | + $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ); |
| 483 | + |
| 484 | + foreach( $this->dimensions as $quality => $levels ) { |
| 485 | + $options = array(); |
| 486 | + $disabled = false; |
| 487 | + foreach( $levels as $idx => $label ) { |
| 488 | + $selected = ( $flags[$quality]==$idx || $flags[$quality]==0 && $idx==1 ); |
| 489 | + # Do not show options user's can't set unless that is the status quo |
| 490 | + if( !Revisionreview::userCan($quality, $flags[$quality]) ) { |
| 491 | + $disabled = true; |
| 492 | + $options[] = Xml::option( wfMsg( "revreview-$label" ), $idx, $selected ); |
| 493 | + } else if( Revisionreview::userCan($quality, $idx) ) { |
| 494 | + $options[] = Xml::option( wfMsg( "revreview-$label" ), $idx, $selected ); |
| 495 | + } |
| 496 | + } |
| 497 | + $form .= "\n" . wfMsgHtml("revreview-$quality") . ": "; |
| 498 | + $selectAttribs = array( 'name' => "wp$quality" ); |
| 499 | + if( $disabled ) $selectAttribs['disabled'] = 'disabled'; |
| 500 | + $form .= Xml::openElement( 'select', $selectAttribs ); |
| 501 | + $form .= implode( "\n", $options ); |
| 502 | + $form .= "</select>\n"; |
| 503 | + } |
| 504 | + if( $wgFlaggedRevComments && $wgUser->isAllowed( 'validate' ) ) { |
| 505 | + $form .= "<br/><p>" . wfMsgHtml( 'revreview-notes' ) . "</p>" . |
| 506 | + "<p><textarea tabindex='1' name='wpNotes' id='wpNotes' rows='2' cols='80' style='width:100%'></textarea>" . |
| 507 | + "</p>\n"; |
| 508 | + } |
| 509 | + |
| 510 | + $imageParams = $templateParams = ''; |
| 511 | + if( !isset($out->mTemplateIds) || !isset($out->mImageSHA1Keys) ) { |
| 512 | + return; // something went terribly wrong... |
| 513 | + } |
| 514 | + # Hack, add NS:title -> rev ID mapping |
| 515 | + foreach( $out->mTemplateIds as $namespace => $title ) { |
| 516 | + foreach( $title as $dbkey => $id ) { |
| 517 | + $title = Title::makeTitle( $namespace, $dbkey ); |
| 518 | + $templateParams .= $title->getPrefixedText() . "|" . $id . "#"; |
| 519 | + } |
| 520 | + } |
| 521 | + $form .= Xml::hidden( 'templateParams', $templateParams ) . "\n"; |
| 522 | + # Hack, image -> timestamp mapping |
| 523 | + foreach( $out->mImageSHA1Keys as $dbkey => $timeAndSHA1 ) { |
| 524 | + foreach( $timeAndSHA1 as $time => $sha1 ) { |
| 525 | + $imageParams .= $dbkey . "|" . $time . "|" . $sha1 . "#"; |
| 526 | + } |
| 527 | + } |
| 528 | + $form .= Xml::hidden( 'imageParams', $imageParams ) . "\n"; |
| 529 | + |
| 530 | + $watchLabel = wfMsgExt('watchthis', array('parseinline')); |
| 531 | + $watchAttribs = array('accesskey' => wfMsg( 'accesskey-watch' ), 'id' => 'wpWatchthis'); |
| 532 | + $watchChecked = ( $wgFlaggedRevsWatch && $wgUser->getOption( 'watchdefault' ) || $wgTitle->userIsWatching() ); |
| 533 | + # Not much to say unless you are a validator |
| 534 | + if( $wgUser->isAllowed( 'validate' ) ) |
| 535 | + $form .= "<p>".Xml::inputLabel( wfMsg( 'revreview-log' ), 'wpReason', 'wpReason', 60 )."</p>\n"; |
| 536 | + |
| 537 | + $form .= "<p> ".Xml::check( 'wpWatchthis', $watchChecked, $watchAttribs ); |
| 538 | + $form .= " <label for='wpWatchthis'".$skin->tooltipAndAccesskey('watch').">{$watchLabel}</label>"; |
| 539 | + |
| 540 | + $form .= ' '.Xml::submitButton( wfMsg( 'revreview-submit' ) )."</p></fieldset>"; |
| 541 | + $form .= Xml::closeElement( 'form' ); |
| 542 | + |
| 543 | + if( $top ) |
| 544 | + $out->mBodytext = $form . '<span style="clear:both"/>' . $out->mBodytext; |
| 545 | + else |
| 546 | + $wgOut->addHTML( '<hr style="clear:both"/>' . $form ); |
| 547 | + |
| 548 | + } |
| 549 | + |
| 550 | + /** |
| 551 | + * @param array $flags |
| 552 | + * @param bool $prettybox |
| 553 | + * @param string $css, class to wrap box in |
| 554 | + * @return string |
| 555 | + * Generates a review box/tag |
| 556 | + */ |
| 557 | + public function addTagRatings( $flags, $prettyBox = false, $css='' ) { |
| 558 | + global $wgFlaggedRevTags; |
| 559 | + |
| 560 | + $tag = ''; |
| 561 | + if( $prettyBox ) |
| 562 | + $tag .= "<table align='center' class='$css' cellpading='0'>"; |
| 563 | + |
| 564 | + foreach( $this->dimensions as $quality => $value ) { |
| 565 | + $encValueText = wfMsgHtml('revreview-' . $this->dimensions[$quality][$flags[$quality]]); |
| 566 | + $level = $flags[$quality]; |
| 567 | + $minlevel = $wgFlaggedRevTags[$quality]; |
| 568 | + if( $level >= $minlevel ) |
| 569 | + $classmarker = 2; |
| 570 | + elseif( $level > 0 ) |
| 571 | + $classmarker = 1; |
| 572 | + else |
| 573 | + $classmarker = 0; |
| 574 | + |
| 575 | + $levelmarker = $level * 20 + 20; //XXX do this better |
| 576 | + if( $prettyBox ) { |
| 577 | + $tag .= "<tr><td><span class='fr-group'><span class='fr-text'>" . |
| 578 | + wfMsgHtml("revreview-$quality") . |
| 579 | + "</span></td><td><span class='fr-marker fr_value$levelmarker'>" . |
| 580 | + $encValueText . "</span></span></td></tr>\n"; |
| 581 | + } else { |
| 582 | + $tag .= " <span class='fr-marker-$levelmarker'><strong>" . |
| 583 | + wfMsgHtml("revreview-$quality") . |
| 584 | + "</strong>: <span class='fr-text-value'>$encValueText </span> " . |
| 585 | + "</span>\n"; |
| 586 | + } |
| 587 | + } |
| 588 | + if( $prettyBox ) |
| 589 | + $tag .= '</table>'; |
| 590 | + |
| 591 | + return $tag; |
| 592 | + } |
| 593 | + |
| 594 | + /** |
| 595 | + * @param Row $trev, flagged revision row |
| 596 | + * @param array $flags |
| 597 | + * @param int $rev_since, revisions since review |
| 598 | + * @param bool $stable, are we referring to the stable revision? |
| 599 | + * @return string |
| 600 | + * Generates a review box using a table using addTagRatings() |
| 601 | + */ |
| 602 | + public function prettyRatingBox( $tfrev, $flags, $revs_since, $stable=true ) { |
| 603 | + global $wgLang; |
| 604 | + # Get quality level |
| 605 | + $quality = self::isQuality( $flags ); |
| 606 | + $pristine = self::isPristine( $flags ); |
| 607 | + $time = $wgLang->date( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true ); |
| 608 | + # Some checks for which tag CSS to use |
| 609 | + if( $pristine ) |
| 610 | + $tagClass = 'flaggedrevs_box3'; |
| 611 | + else if( $quality ) |
| 612 | + $tagClass = 'flaggedrevs_box2'; |
| 613 | + else |
| 614 | + $tagClass = 'flaggedrevs_box1'; |
| 615 | + # Construct some tagging |
| 616 | + $msg = $stable ? 'revreview-' : 'revreview-newest-'; |
| 617 | + $msg .= $quality ? 'quality' : 'basic'; |
| 618 | + $encRatingLabel = $stable ? '' : ' ' . wfMsgHtml('revreview-oldrating'); |
| 619 | + |
| 620 | + $box = ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' . |
| 621 | + wfMsg('revreview-toggle') . '</a>'; |
| 622 | + $box .= '<span id="mw-revisionratings">' . |
| 623 | + wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since) . |
| 624 | + $encRatingLabel . |
| 625 | + self::addTagRatings( $flags, true, "{$tagClass}a" ) . |
| 626 | + '</span>'; |
| 627 | + |
| 628 | + return $box; |
| 629 | + } |
| 630 | + |
| 631 | + /** |
| 632 | + * @param Row $row |
| 633 | + * @return string |
| 634 | + * Generates revision review notes |
| 635 | + */ |
| 636 | + public function ReviewNotes( $row ) { |
| 637 | + global $wgUser, $wgFlaggedRevComments; |
| 638 | + |
| 639 | + if( !$wgFlaggedRevComments || !$row || $row->fr_comment == '' ) |
| 640 | + return ''; |
| 641 | + |
| 642 | + $skin = $wgUser->getSkin(); |
| 643 | + $notes = '<p><div class="flaggedrevs_notes plainlinks">'; |
| 644 | + $notes .= wfMsgExt('revreview-note', array('parse'), User::whoIs( $row->fr_user ) ); |
| 645 | + $notes .= '<i>' . $skin->formatComment( $row->fr_comment ) . '</i></div></p><br/>'; |
| 646 | + return $notes; |
| 647 | + } |
| 648 | + |
| 649 | + /** |
| 650 | + * Get latest quality rev, if not, the latest reviewed one |
| 651 | + * Same params for the sake of inheritance |
| 652 | + * @return Row |
| 653 | + */ |
| 654 | + function getStableRev( $t=null, $getText=false, $forUpdate=false ) { |
| 655 | + global $wgTitle, $wgFlaggedRevs; |
| 656 | + # Cached results available? |
| 657 | + if( $getText ) { |
| 658 | + if( isset($this->stablerev) && isset($this->stablerev->fr_text) ) { |
| 659 | + return $this->stablerev; |
| 660 | + } |
| 661 | + } else { |
| 662 | + if( isset($this->stablerev) ) { |
| 663 | + return $this->stablerev; |
| 664 | + } |
| 665 | + } |
| 666 | + # Get the content page, skip talk |
| 667 | + $title = $wgTitle->getSubjectPage(); |
| 668 | + # Do we have one? |
| 669 | + $row = $this->getStablePageRev( $title, $getText, $forUpdate ); |
| 670 | + if( $row ) { |
| 671 | + $this->stablerev = $row; |
| 672 | + return $row; |
| 673 | + } else { |
| 674 | + $this->stablerev = null; |
| 675 | + return null; |
| 676 | + } |
| 677 | + } |
| 678 | + |
| 679 | + /** |
| 680 | + * Get visiblity restrictions on page |
| 681 | + * Same params for the sake of inheritance |
| 682 | + * @returns Array |
| 683 | + */ |
| 684 | + public function getVisibilitySettings( $t=null, $forUpdate=false ) { |
| 685 | + global $wgTitle; |
| 686 | + # Cached results available? |
| 687 | + if( isset($this->pageconfig) ) { |
| 688 | + return $this->pageconfig; |
| 689 | + } |
| 690 | + # Get the content page, skip talk |
| 691 | + $title = $wgTitle->getSubjectPage(); |
| 692 | + |
| 693 | + $config = $this->getPageVisibilitySettings( $title, $forUpdate ); |
| 694 | + $this->pageconfig = $config; |
| 695 | + |
| 696 | + return $config; |
| 697 | + } |
| 698 | + |
| 699 | + /** |
| 700 | + * @param int $rev_id |
| 701 | + * Return an array output of the flags for a given revision |
| 702 | + */ |
| 703 | + public function getFlagsForRevision( $rev_id ) { |
| 704 | + global $wgFlaggedRevTags; |
| 705 | + # Cached results? |
| 706 | + if( isset($this->flags[$rev_id]) && $this->flags[$rev_id] ) |
| 707 | + return $this->revflags[$rev_id]; |
| 708 | + # Set all flags to zero |
| 709 | + $flags = array(); |
| 710 | + foreach( array_keys($wgFlaggedRevTags) as $tag ) { |
| 711 | + $flags[$tag] = 0; |
| 712 | + } |
| 713 | + # Grab all the tags for this revision |
| 714 | + $dbr = wfGetDB( DB_SLAVE ); |
| 715 | + $result = $dbr->select( 'flaggedrevtags', |
| 716 | + array( 'frt_dimension', 'frt_value' ), |
| 717 | + array( 'frt_rev_id' => $rev_id ), |
| 718 | + __METHOD__ ); |
| 719 | + # Iterate through each tag result |
| 720 | + while( $row = $dbr->fetchObject($result) ) { |
| 721 | + $flags[$row->frt_dimension] = $row->frt_value; |
| 722 | + } |
| 723 | + # Try to cache results |
| 724 | + $this->flags[$rev_id] = true; |
| 725 | + $this->revflags[$rev_id] = $flags; |
| 726 | + |
| 727 | + return $flags; |
| 728 | + } |
| 729 | + |
| 730 | +} |
Property changes on: trunk/extensions/FlaggedRevs/FlaggedArticle.php |
___________________________________________________________________ |
Added: svn:eol-style |
731 | 731 | + native |