r67060 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67059‎ | r67060 | r67061 >
Date:00:49, 30 May 2010
Author:aaron
Status:ok
Tags:
Comment:
* Change submit button text if edit will need review
* Clarified some messages
* made onUserCan() cache page visibility settings
* getVisibilitySettings()/isStableShownByDefault() cleanup
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedArticleView.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/client/flaggedrevs.js (modified) (history)
  • /trunk/extensions/FlaggedRevs/language/FlaggedRevs.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -416,6 +416,11 @@
417417 $wgHooks['SkinTemplateNavigation'][] = 'FlaggedRevsHooks::setNavigation'; // Vector
418418 # Add notice tags to edit view
419419 $wgHooks['EditPage::showEditForm:initial'][] = 'FlaggedRevsHooks::addToEditView';
 420+# Tweak submit button name/title
 421+$wgHooks['EditPageBeforeEditButtons'][] = 'FlaggedRevsHooks::onBeforeEditButtons';
 422+# Autoreview information from form
 423+$wgHooks['EditPageBeforeEditChecks'][] = 'FlaggedRevsHooks::addReviewCheck';
 424+$wgHooks['EditPage::showEditForm:fields'][] = 'FlaggedRevsHooks::addRevisionIDField';
420425 # Add draft link to section edit error
421426 $wgHooks['EditPageNoSuchSection'][] = 'FlaggedRevsHooks::onNoSuchSection';
422427 # Add notice tags to history
@@ -437,9 +442,6 @@
438443 $wgHooks['DiffViewHeader'][] = 'FlaggedRevsHooks::onDiffViewHeader';
439444 # Add diff=review url param alias
440445 $wgHooks['NewDifferenceEngine'][] = 'FlaggedRevsHooks::checkDiffUrl';
441 -# Autoreview stuff
442 -$wgHooks['EditPage::showEditForm:fields'][] = 'FlaggedRevsHooks::addRevisionIDField';
443 -$wgHooks['EditPageBeforeEditChecks'][] = 'FlaggedRevsHooks::addReviewCheck';
444446 # Local user account preference
445447 $wgHooks['GetPreferences'][] = 'FlaggedRevsHooks::onGetPreferences';
446448 # Show unreviewed pages links
Index: trunk/extensions/FlaggedRevs/language/FlaggedRevs.i18n.php
@@ -49,9 +49,9 @@
5050 'revreview-hist-basic-auto' => '[{{fullurl:$1|stableid=$2}} automatically checked]',
5151 'revreview-hist-quality-auto' => '[{{fullurl:$1|stableid=$2}} automatically approved]',
5252 'revreview-hist-pending' => '\'\'\'[[{{fullurl:$1|oldid=$2&diff=$3}} pending review]]\'\'\'',
53 - 'review-edit-diff' => '\'\'\'NOTICE: Some pending changes to the accepted version are incorporated into the edit form below.\'\'\'',
54 - 'revreview-diff-toggle-show' => 'show changes',
55 - 'revreview-diff-toggle-hide' => 'hide changes',
 53+ 'review-edit-diff' => '\'\'\'NOTICE: Some of the pending changes affect the area of the page you are editing.\'\'\'',
 54+ 'revreview-diff-toggle-show' => 'show those changes',
 55+ 'revreview-diff-toggle-hide' => 'hide those changes',
5656 'revreview-diff-toggle-title' => 'Toggle display of pending changes to the accepted version',
5757 'revreview-log-toggle-show' => 'show stability log',
5858 'revreview-log-toggle-hide' => 'hide stability log',
@@ -111,7 +111,9 @@
112112 'revreview-draft-title' => 'Pending changes are displayed on this page',
113113 'revreview-edit' => 'Edit',
114114 'revreview-editnotice' => '\'\'\'Your changes will be accepted once an authorized user reviews them. ([[{{MediaWiki:Validationpage}}|?]])\'\'\'',
115 - 'revreview-check-flag' => 'Accept currently pending changes',
 115+ 'revreview-check-flag' => 'Accept the pending changes',
 116+ 'revreview-submitedit' => 'Submit changes',
 117+ 'revreview-submitedit-title' => 'Submit your changes for review',
116118 'revreview-edited' => '\'\'\'Changes will be accepted once an authorized user reviews them. ([[{{MediaWiki:Validationpage}}|?]])\'\'\'
117119
118120 There {{PLURAL:$2|is|are}} [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur&diffonly=0}} $2 pending {{PLURAL:$2|change|changes}}] \'\'(shown below)\'\' awaiting review.',
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -5,7 +5,7 @@
66 * FlaggedArticle::getTitleInstance() is preferred over constructor calls
77 */
88 class FlaggedArticle extends Article {
9 - # Process cache variables
 9+ /* Process cache variables */
1010 protected $stableRev = null;
1111 protected $pageConfig = null;
1212
@@ -43,6 +43,39 @@
4444 }
4545
4646 /**
 47+ * Do edits have to be reviewed before being shown by default?
 48+ * @param int $flags, FR_MASTER
 49+ * @returns bool
 50+ */
 51+ public function editsRequireReview( $flags = 0 ) {
 52+ return (
 53+ $this->isReviewable( $flags ) && // reviewable page
 54+ $this->isStableShownByDefault( $flags ) && // and stable versions override
 55+ $this->getStableRev( $flags ) // and there is a stable version
 56+ );
 57+ }
 58+
 59+ /**
 60+ * Are edits to this page currently pending?
 61+ * @param int $flags, FR_MASTER
 62+ * @returns bool
 63+ */
 64+ public function editsArePending( $flags = 0 ) {
 65+ if ( $this->isReviewable() ) {
 66+ $srev = $this->getStableRev( $flags );
 67+ if ( $srev ) {
 68+ if ( $flags & FR_MASTER ) {
 69+ $latest = $this->getTitle()->getLatestRevID( GAID_FOR_UPDATE );
 70+ } else {
 71+ $latest = $this->getLatest();
 72+ }
 73+ return ( $srev->getRevId() != $latest ); // edits need review
 74+ }
 75+ }
 76+ return false; // all edits go live
 77+ }
 78+
 79+ /**
4780 * Is this page less open than the site defaults?
4881 * @returns bool
4982 */
@@ -122,9 +155,7 @@
123156 if ( !( $flags & FR_MASTER ) && $this->pageConfig !== null ) {
124157 return $this->pageConfig;
125158 }
126 - # Get the content page, skip talk
127 - $title = $this->getTitle()->getSubjectPage();
128 - $config = FlaggedRevs::getPageVisibilitySettings( $title, $flags );
 159+ $config = FlaggedRevs::getPageVisibilitySettings( $this->getTitle(), $flags );
129160 $this->pageConfig = $config;
130161 return $config;
131162 }
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -67,8 +67,8 @@
6868 $encJsFile = htmlspecialchars( "$stylePath/review.js?$wgFlaggedRevStyleVersion" );
6969 $head .= "\n<script type=\"{$wgJsMimeType}\" src=\"{$encJsFile}\"></script>";
7070 }
71 - # Set basic messages
72 - $msgs = (object) array(
 71+ # Set basic messages for all users...
 72+ $msgs = array(
7373 'diffToggleShow' => wfMsgHtml( 'revreview-diff-toggle-show' ),
7474 'diffToggleHide' => wfMsgHtml( 'revreview-diff-toggle-hide' ),
7575 'logToggleShow' => wfMsgHtml( 'revreview-log-toggle-show' ),
@@ -78,8 +78,16 @@
7979 'toggleShow' => wfMsgHtml( 'revreview-toggle-show' ),
8080 'toggleHide' => wfMsgHtml( 'revreview-toggle-hide' )
8181 );
 82+ # Extra reviewer messages...
 83+ if ( $wgUser->isAllowed( 'review' ) ) {
 84+ $msgs['saveArticle'] = wfMsgHtml( 'savearticle' );
 85+ $msgs['tooltipSave'] = wfMsgHtml( 'tooltip-save' ).' ['.wfMsgHtml( 'accesskey-save' ).']';
 86+ $msgs['submitArticle'] = wfMsg( 'revreview-submitedit' );
 87+ $msgs['tooltipSubmit'] = wfMsg( 'revreview-submitedit-title' ) .
 88+ ' ['. wfMsg( 'accesskey-save' ) . ']';
 89+ }
8290 $head .= "\n<script type=\"{$wgJsMimeType}\">" .
83 - "FlaggedRevs.messages = " . Xml::encodeJsVar( $msgs ) . ";</script>\n";
 91+ "FlaggedRevs.messages = " . Xml::encodeJsVar( (object)$msgs ) . ";</script>\n";
8492 $wgOut->addHeadItem( 'FlaggedRevs', $head );
8593
8694 return true;
@@ -814,7 +822,8 @@
815823 # Enforce autoreview/review restrictions
816824 } else if ( $action === 'autoreview' || $action === 'review' ) {
817825 # Get autoreview restriction settings...
818 - $config = FlaggedRevs::getPageVisibilitySettings( $title, FR_MASTER );
 826+ $fa = FlaggedArticle::getTitleInstance( $title );
 827+ $config = $fa->getVisibilitySettings();
819828 # Convert Sysop -> protect
820829 $right = ( $config['autoreview'] === 'sysop' ) ?
821830 'protect' : $config['autoreview'];
@@ -1704,6 +1713,12 @@
17051714 return true;
17061715 }
17071716
 1717+ public static function onBeforeEditButtons( &$editPage, &$buttons ) {
 1718+ $view = FlaggedArticleView::singleton();
 1719+ $view->changeSaveButton( $editPage, $buttons );
 1720+ return true;
 1721+ }
 1722+
17081723 public static function onNoSuchSection( &$editPage, &$s ) {
17091724 $view = FlaggedArticleView::singleton();
17101725 $view->addToNoSuchSection( $editPage, $s );
@@ -1983,6 +1998,8 @@
19841999 return true;
19852000 }
19862001
 2002+ // TODO: move to articleview class?
 2003+ // FIXME: add title attrib
19872004 public static function addReviewCheck( $editPage, &$checkboxes, &$tabindex ) {
19882005 global $wgUser, $wgRequest;
19892006 if ( !$wgUser->isAllowed( 'review' ) ) {
@@ -1998,7 +2015,7 @@
19992016 # the user decide if he/she wants it reviewed on the spot. One might
20002017 # do this if he/she just saw the diff-to-stable and *then* decided to edit.
20012018 if ( !$srev || $srev->getRevId() != $editPage->getArticle()->getLatest() ) {
2002 - $reviewLabel = wfMsgExt( 'revreview-check-flag', array( 'parseinline' ) );
 2019+ $reviewLabel = wfMsgExt( 'revreview-check-flag', 'parseinline' );
20032020 $attribs = array( 'tabindex' => ++$tabindex, 'id' => 'wpReviewEdit' );
20042021 $checkboxes['reviewed'] = Xml::check( 'wpReviewEdit',
20052022 $wgRequest->getCheck( 'wpReviewEdit' ), $attribs ) .
Index: trunk/extensions/FlaggedRevs/client/flaggedrevs.js
@@ -151,3 +151,28 @@
152152 };
153153
154154 addOnloadHook(FlaggedRevs.enableShowhide);
 155+
 156+FlaggedRevs.setCheckTrigger = function() {
 157+ var checkbox = document.getElementById("wpReviewEdit");
 158+ if( checkbox ) {
 159+ checkbox.onclick = FlaggedRevs.updateSaveButton;
 160+ }
 161+}
 162+
 163+hookEvent("load", FlaggedRevs.setCheckTrigger);
 164+
 165+FlaggedRevs.updateSaveButton = function() {
 166+ var checkbox = document.getElementById("wpReviewEdit");
 167+ var save = document.getElementById("wpSave");
 168+ if( checkbox && save ) {
 169+ // Review pending changes
 170+ if ( checkbox.checked ) {
 171+ save.value = FlaggedRevs.messages.saveArticle;
 172+ save.title = FlaggedRevs.messages.tooltipSave;
 173+ // Submit for review
 174+ } else {
 175+ save.value = FlaggedRevs.messages.submitArticle;
 176+ save.title = FlaggedRevs.messages.tooltipSubmit;
 177+ }
 178+ }
 179+}
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
@@ -100,8 +100,11 @@
101101 */
102102 public function isStableShownByDefaultUser() {
103103 $this->load();
104 - $config = $this->article->getVisibilitySettings(); // page configuration
105 - return ( $config['override'] && !FlaggedRevs::ignoreDefaultVersion() );
 104+ if ( $this->article->isReviewable() ) {
 105+ $config = $this->article->getVisibilitySettings(); // page configuration
 106+ return ( $config['override'] && !FlaggedRevs::ignoreDefaultVersion() );
 107+ }
 108+ return false; // no stable
106109 }
107110
108111 /**
@@ -1492,6 +1495,36 @@
14931496 }
14941497
14951498 /**
 1499+ * If submitting the edit will leave it pending, then change the button text
 1500+ * Note: interacts with 'review pending changes' checkbox
 1501+ * @TODO: would be nice if hook passed in button attribs, not XML
 1502+ */
 1503+ public function changeSaveButton( EditPage $editPage, array &$buttons ) {
 1504+ if ( !$this->article->editsRequireReview() ) {
 1505+ return true; // edit will go live immediatly
 1506+ } elseif ( !$this->article->editsArePending()
 1507+ && $this->article->getTitle()->userCan( 'autoreview' ) )
 1508+ {
 1509+ return true; // edit will be autoreviewed anyway
 1510+ }
 1511+ if ( extension_loaded( 'domxml' ) ) {
 1512+ wfDebug( "Warning: you have the obsolete domxml extension for PHP. Please remove it!\n" );
 1513+ return true; # PECL extension conflicts with the core DOM extension (see bug 13770)
 1514+ } elseif ( isset( $buttons['save'] ) && extension_loaded( 'dom' ) ) {
 1515+ $dom = new DOMDocument();
 1516+ $result = $dom->loadXML( $buttons['save'] ); // load button XML from hook
 1517+ foreach ( $dom->getElementsByTagName( 'input' ) as $input ) { // one <input>
 1518+ $input->setAttribute( 'value', wfMsg( 'revreview-submitedit' ) );
 1519+ $input->setAttribute( 'title', // keep accesskey
 1520+ wfMsg( 'revreview-submitedit-title' ).' ['.wfMsg( 'accesskey-save' ).']' );
 1521+ # Change submit button text & title
 1522+ $buttons['save'] = $dom->saveXML( $dom->documentElement );
 1523+ }
 1524+ }
 1525+ return true;
 1526+ }
 1527+
 1528+ /**
14961529 * (a) Add a hidden field that has the rev ID the text is based off.
14971530 * (b) If an edit was undone, add a hidden field that has the rev ID of that edit.
14981531 * Needed for autoreview and user stats (for autopromote).

Follow-up revisions

RevisionCommit summaryAuthorDate
r67296MFT r67060-r67291aaron20:20, 3 June 2010

Status & tagging log