r52871 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52870‎ | r52871 | r52872 >
Date:23:10, 7 July 2009
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
Broke out parts of FlaggedArticle::setActionTabs into FlaggedArticle::setViewTabs, making it possible to support both SkinTemplateTabs and SkinTemplateNavigation.
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -431,6 +431,8 @@
432432 $wgHooks['InitializeArticleMaybeRedirect'][] = 'FlaggedRevsHooks::overrideRedirect';
433433 # Sets tabs and permalink
434434 $wgHooks['SkinTemplateTabs'][] = 'FlaggedRevsHooks::setActionTabs';
 435+# Sets navigation
 436+$wgHooks['SkinTemplateNavigation'][] = 'FlaggedRevsHooks::setNavigation';
435437 # Add tags to edit view
436438 $wgHooks['EditPage::showEditForm:initial'][] = 'FlaggedRevsHooks::addToEditView';
437439 # Add review form and visiblity settings link
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -890,108 +890,170 @@
891891 return true;
892892 }
893893
894 - /**
895 - * Add stable version tabs. Rename some of the others if necessary.
 894+ /**
 895+ * Modifies an array of action links, as used by SkinTemplateNavigation and
 896+ * SkinTemplateTabs, to inlude flagged revs UI elements
896897 */
897898 public function setActionTabs( $skin, &$actions ) {
898899 global $wgRequest, $wgUser, $wgFlaggedRevTabs;
 900+
 901+ // Gets the title of the subject page
899902 $title = $this->parent->getTitle()->getSubjectPage();
900 - $action = $wgRequest->getVal( 'action', 'view' );
901 - # Non-content pages cannot be validated
902 - if( !FlaggedRevs::isPageReviewable($title) || !$title->exists() )
 903+ // Checks if page is not a reviewable page
 904+ if ( !FlaggedRevs::isPageReviewable( $title ) || !$title->exists() ) {
 905+ // Exits, since only reviewable pages need these tabs
903906 return true;
904 - # We can change the behavoir of stable version for this page to be different
905 - # than the site default.
906 - if( !$skin->mTitle->isTalkPage() && $wgUser->isAllowed('stablesettings') ) {
907 - if( count($actions) && !isset($actions['protect']) && !isset($actions['unprotect']) ) {
908 - wfLoadExtensionMessages( 'Stabilization' );
909 - $stableTitle = SpecialPage::getTitleFor( 'Stabilization' );
910 - $actions['default'] = array(
911 - 'class' => false,
912 - 'text' => wfMsg('stabilization-tab'),
913 - 'href' => $stableTitle->getLocalUrl('page='.$title->getPrefixedUrl())
914 - );
915 - }
916907 }
917 - # Page must be reviewable. Check if UI should be hidden.
 908+ // Checks if...
 909+ if (
 910+ // This page is a talk page
 911+ !$skin->mTitle->isTalkPage() &&
 912+ // User is allowed to stablize pages
 913+ $wgUser->isAllowed( 'stablesettings' ) &&
 914+ // Actions is an array
 915+ is_array( $actions ) &&
 916+ // A protect tab does not exist
 917+ !isset( $actions['protect'] ) &&
 918+ // An unprtect tab does not exist
 919+ !isset( $actions['unprotect'] )
 920+ ) {
 921+ // Loads messages for stabilization UI
 922+ wfLoadExtensionMessages( 'Stabilization' );
 923+ // Gets the title of the Stabilization special page
 924+ $stableTitle = SpecialPage::getTitleFor( 'Stabilization' );
 925+ // Adds default tab to actions
 926+ $actions['default'] = array(
 927+ 'class' => false,
 928+ 'text' => wfMsg( 'stabilization-tab' ),
 929+ 'href' => $stableTitle->getLocalUrl(
 930+ 'page=' . $title->getPrefixedUrl()
 931+ )
 932+ );
 933+ }
 934+ // Exit
 935+ return true;
 936+ }
 937+
 938+ /**
 939+ * Modifies an array of view links, as used by SkinTemplateNavigation and
 940+ * SkinTemplateTabs, to inlude flagged revs UI elements
 941+ */
 942+ public function setViewTabs( $skin, &$views ) {
 943+ global $wgRequest, $wgUser, $wgFlaggedRevTabs;
 944+
 945+ // Gets the title of the subject page
 946+ $title = $this->parent->getTitle()->getSubjectPage();
 947+ // Gets the value of the action parameter, defaulting to view
 948+ $action = $wgRequest->getVal( 'action', 'view' );
 949+ // Gets the article instance of the page
918950 $fa = FlaggedArticle::getTitleInstance( $title );
919 - if( !$fa->isReviewable() || $this->limitedUI() )
 951+ // Checks if article is not reviewable or the UI should be hidden
 952+ if ( !$fa->isReviewable() || $this->limitedUI() ) {
 953+ // Exits
920954 return true;
921 - # If we are viewing a page normally, and it was overridden,
922 - # change the edit tab to a "current revision" tab.
923 - # For rollbacks, use master per bug 16734.
 955+ }
 956+ // Gets the stable revision
924957 $srev = $this->getStableRev( $action == 'rollback' ? FR_MASTER : 0 );
925 - # No quality revs? Find the last reviewed one
926 - if( is_null($srev) ) {
 958+ // Checks if no stable revision exists
 959+ if( is_null( $srev ) ) {
 960+ // Exits
927961 return true;
928962 }
 963+ // Loads messages for flagged revisions UI
929964 wfLoadExtensionMessages( 'FlaggedRevs' );
930 - $article = new Article( $title );
931 - # Be clear about what is being edited...
 965+ // Creates article object from title
 966+ $article = Article::newFromTitle( $title );
 967+ // Gets the status of whether the article is the stable revision
932968 $synced = FlaggedRevs::stableVersionIsSynced( $srev, $article );
933 - if( !$skin->mTitle->isTalkPage() && !$synced ) {
934 - if( isset( $actions['edit'] ) ) {
935 - if( $this->showStableByDefault() )
936 - $actions['edit']['text'] = wfMsg('revreview-edit');
937 - # If the user is requesting the draft or some revision, they don't need a diff.
938 - if( $this->pageOverride() )
939 - $actions['edit']['href'] = $title->getLocalUrl( 'action=edit' );
940 - } if( isset( $actions['viewsource'] ) ) {
941 - if( $this->showStableByDefault() )
942 - $actions['viewsource']['text'] = wfMsg('revreview-source');
943 - # If the user is requesting the draft or some revision, they don't need a diff.
944 - if( $this->pageOverride() )
945 - $actions['viewsource']['href'] = $title->getLocalUrl( 'action=edit' );
 969+ // Checks if this page is not a talk page and not the stable version
 970+ if ( !$skin->mTitle->isTalkPage() && !$synced ) {
 971+ // Checks if there's an edit tab
 972+ if ( isset( $views['edit'] ) ) {
 973+ // Checks if we should show the stable version by default
 974+ if ( $this->showStableByDefault() ) {
 975+ // Changes the label of the edit button
 976+ $views['edit']['text'] = wfMsg('revreview-edit');
 977+ }
 978+ // Checks if revision overriding is OK
 979+ if ( $this->pageOverride() ) {
 980+ // Changes the href of the edit tab
 981+ $views['edit']['href'] = $title->getLocalUrl( 'action=edit' );
 982+ }
 983+ }
 984+ // Checks if there's a viewsource tab
 985+ if ( isset( $views['viewsource'] ) ) {
 986+ // Checks if we should show the stable version by default
 987+ if ( $this->showStableByDefault() ) {
 988+ // Changes the label of the viewsource button
 989+ $views['viewsource']['text'] = wfMsg('revreview-source');
 990+ }
 991+ // Checks if revision overriding is OK
 992+ if ( $this->pageOverride() ) {
 993+ // Changes the href of the viewsource tab
 994+ $views['viewsource']['href'] = $title->getLocalUrl( 'action=edit' );
 995+ }
946996 }
947997 }
948 - // Add auxillary tabs...
949 - if( !$wgFlaggedRevTabs || $synced )
 998+ // Checks if flagged revisions tabs should not be shown or the page is
 999+ // already the most current revision
 1000+ if( !$wgFlaggedRevTabs || $synced ) {
 1001+ // Exits
9501002 return true;
951 - // We are looking at the stable version
952 - if( $this->pageOverride() || $wgRequest->getVal('stableid') ) {
953 - $draftTabCss = '';
954 - $stableTabCss = 'selected';
955 - // We are looking at the talk page or diffs/hist/oldids
956 - } elseif( !(self::isViewAction($action) || $action=='edit') || $skin->mTitle->isTalkPage() ) {
957 - $draftTabCss = '';
958 - $stableTabCss = '';
959 - // We are looking at the current revision or in edit mode
960 - } else {
961 - $draftTabCss = 'selected';
962 - $stableTabCss = '';
 1003+ }
 1004+ // Create set of tabs to be created
 1005+ $tabs = array(
 1006+ 'stable' => array(
 1007+ 'text' => wfMsg( 'revreview-stable' ),
 1008+ 'href' => $title->getLocalUrl( 'stable=1' ),
 1009+ 'class' => ''
 1010+ ),
 1011+ 'current' => array(
 1012+ 'text' => wfMsg( 'revreview-current' ),
 1013+ 'href' => $title->getLocalUrl( 'stable=0&redirect=no' ),
 1014+ 'class' => ''
 1015+ ),
 1016+ );
 1017+ // Checks if revision overriding is OK and we are at the stable version
 1018+ if ( $this->pageOverride() || $wgRequest->getVal( 'stableid' ) ) {
 1019+ $tabs['stable']['class'] = 'selected';
9631020 }
964 - $newActions = array();
 1021+ // Checks if...
 1022+ elseif (
 1023+ // This is a view or edit page
 1024+ ( self::isViewAction( $action ) || $action == 'edit' ) &&
 1025+ // This is not a talk page
 1026+ !$skin->mTitle->isTalkPage()
 1027+ ) {
 1028+ // We are looking at the current revision or in edit mode
 1029+ $tabs['current']['class'] = 'selected';
 1030+ }
 1031+ // Loops over each action tab
9651032 $first = true;
966 - # Straighten out order, set the tab AFTER the main tab is set
967 - foreach( $actions as $tabAction => $data ) {
968 - # Main page tab...
969 - if( $first ) {
970 - $first = false;
 1033+ $newViews = array();
 1034+ foreach ( $views as $tabAction => $data ) {
 1035+ // Checks if this is the first tab
 1036+ if ( $first ) {
9711037 if( $synced ) {
972 - $newActions[$tabAction] = $data; // keep it
 1038+ // Appends old tab to new tabs, thus keeping the first one
 1039+ $newViews[$tabAction] = $data;
9731040 } else {
974 - # Add new tabs after first one
975 - $newActions['stable'] = array(
976 - 'class' => $stableTabCss,
977 - 'text' => wfMsg('revreview-stable'),
978 - 'href' => $title->getLocalUrl( 'stable=1' )
979 - );
980 - $newActions['current'] = array(
981 - 'class' => $draftTabCss,
982 - 'text' => wfMsg('revreview-current'),
983 - 'href' => $title->getLocalUrl( 'stable=0&redirect=no' )
984 - );
 1041+ // Appends new tabs, thus replacing the first one
 1042+ $newViews['stable'] = $tabs['stable'];
 1043+ $newViews['current'] = $tabs['current'];
9851044 }
986 - # The others...
 1045+ // Marks first as false
 1046+ $first = false;
9871047 } else {
988 - $newActions[$tabAction] = $data;
 1048+ // Appends old tab to new tabs
 1049+ $newViews[$tabAction] = $data;
9891050 }
9901051 }
991 - # Reset static array
992 - $actions = $newActions;
 1052+ // Replaces old tabs with new tabs
 1053+ $views = $newViews;
 1054+ // Exits
9931055 return true;
9941056 }
995 -
 1057+
9961058 /**
9971059 * @param FlaggedRevision $frev
9981060 * @return string, revision review notes
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -1312,10 +1312,20 @@
13131313 $fa = FlaggedArticle::getGlobalInstance();
13141314 if( $fa ) {
13151315 $fa->setActionTabs( $skin, $contentActions );
 1316+ $fa->setViewTabs( $skin, $contentActions );
13161317 }
13171318 return true;
13181319 }
13191320
 1321+ public static function setNavigation( $skin, &$links ) {
 1322+ $fa = FlaggedArticle::getGlobalInstance();
 1323+ if( $fa ) {
 1324+ $fa->setActionTabs( $skin, $links['actions'] );
 1325+ $fa->setViewTabs( $skin, $links['views'] );
 1326+ }
 1327+ return true;
 1328+ }
 1329+
13201330 public static function onArticleViewHeader( &$article, &$outputDone, &$pcache ) {
13211331 $flaggedArticle = FlaggedArticle::getInstance( $article );
13221332 $flaggedArticle->maybeUpdateMainCache( $outputDone, $pcache );
@@ -1323,7 +1333,7 @@
13241334 $flaggedArticle->setPageContent( $outputDone, $pcache );
13251335 return true;
13261336 }
1327 -
 1337+
13281338 public static function addRatingLink( &$skintemplate, &$nav_urls, &$oldid, &$revid ) {
13291339 $fa = FlaggedArticle::getTitleInstance( $skintemplate->mTitle );
13301340 # Add rating tab

Follow-up revisions

RevisionCommit summaryAuthorDate
r53410Merging UI fixes from trunk; second batch from http://www.mediawiki.org/wiki/......brion18:05, 17 July 2009
r60251Changed r52871 spacing style to match the restaaron04:00, 21 December 2009

Comments

#Comment by Tim Starling (talk | contribs)   07:55, 10 July 2009

setActionTabs() and setViewTabs() have far too many comments. Please remove any comments where the function of the documented code is obvious to anyone with an elementary knowledge of MediaWiki, PHP and English. That's at least three quarters of them. We use comments to explain lines which are particularly difficult to understand, and to narrate the broader view.

When you write comments, use imperative phrases instead of the third person. For example, instead of "replaces old tabs with new tabs", use "replace old tabs with new tabs".


#Comment by Trevor Parscal (WMF) (talk | contribs)   18:50, 14 July 2009

r53185 and r53186 resolve this.

Status & tagging log