Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -431,6 +431,8 @@ |
432 | 432 | $wgHooks['InitializeArticleMaybeRedirect'][] = 'FlaggedRevsHooks::overrideRedirect'; |
433 | 433 | # Sets tabs and permalink |
434 | 434 | $wgHooks['SkinTemplateTabs'][] = 'FlaggedRevsHooks::setActionTabs'; |
| 435 | +# Sets navigation |
| 436 | +$wgHooks['SkinTemplateNavigation'][] = 'FlaggedRevsHooks::setNavigation'; |
435 | 437 | # Add tags to edit view |
436 | 438 | $wgHooks['EditPage::showEditForm:initial'][] = 'FlaggedRevsHooks::addToEditView'; |
437 | 439 | # Add review form and visiblity settings link |
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php |
— | — | @@ -890,108 +890,170 @@ |
891 | 891 | return true; |
892 | 892 | } |
893 | 893 | |
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 |
896 | 897 | */ |
897 | 898 | public function setActionTabs( $skin, &$actions ) { |
898 | 899 | global $wgRequest, $wgUser, $wgFlaggedRevTabs; |
| 900 | + |
| 901 | + // Gets the title of the subject page |
899 | 902 | $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 |
903 | 906 | 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 | | - } |
916 | 907 | } |
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 |
918 | 950 | $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 |
920 | 954 | 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 |
924 | 957 | $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 |
927 | 961 | return true; |
928 | 962 | } |
| 963 | + // Loads messages for flagged revisions UI |
929 | 964 | 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 |
932 | 968 | $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 | + } |
946 | 996 | } |
947 | 997 | } |
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 |
950 | 1002 | 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'; |
963 | 1020 | } |
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 |
965 | 1032 | $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 ) { |
971 | 1037 | if( $synced ) { |
972 | | - $newActions[$tabAction] = $data; // keep it |
| 1038 | + // Appends old tab to new tabs, thus keeping the first one |
| 1039 | + $newViews[$tabAction] = $data; |
973 | 1040 | } 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']; |
985 | 1044 | } |
986 | | - # The others... |
| 1045 | + // Marks first as false |
| 1046 | + $first = false; |
987 | 1047 | } else { |
988 | | - $newActions[$tabAction] = $data; |
| 1048 | + // Appends old tab to new tabs |
| 1049 | + $newViews[$tabAction] = $data; |
989 | 1050 | } |
990 | 1051 | } |
991 | | - # Reset static array |
992 | | - $actions = $newActions; |
| 1052 | + // Replaces old tabs with new tabs |
| 1053 | + $views = $newViews; |
| 1054 | + // Exits |
993 | 1055 | return true; |
994 | 1056 | } |
995 | | - |
| 1057 | + |
996 | 1058 | /** |
997 | 1059 | * @param FlaggedRevision $frev |
998 | 1060 | * @return string, revision review notes |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -1312,10 +1312,20 @@ |
1313 | 1313 | $fa = FlaggedArticle::getGlobalInstance(); |
1314 | 1314 | if( $fa ) { |
1315 | 1315 | $fa->setActionTabs( $skin, $contentActions ); |
| 1316 | + $fa->setViewTabs( $skin, $contentActions ); |
1316 | 1317 | } |
1317 | 1318 | return true; |
1318 | 1319 | } |
1319 | 1320 | |
| 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 | + |
1320 | 1330 | public static function onArticleViewHeader( &$article, &$outputDone, &$pcache ) { |
1321 | 1331 | $flaggedArticle = FlaggedArticle::getInstance( $article ); |
1322 | 1332 | $flaggedArticle->maybeUpdateMainCache( $outputDone, $pcache ); |
— | — | @@ -1323,7 +1333,7 @@ |
1324 | 1334 | $flaggedArticle->setPageContent( $outputDone, $pcache ); |
1325 | 1335 | return true; |
1326 | 1336 | } |
1327 | | - |
| 1337 | + |
1328 | 1338 | public static function addRatingLink( &$skintemplate, &$nav_urls, &$oldid, &$revid ) { |
1329 | 1339 | $fa = FlaggedArticle::getTitleInstance( $skintemplate->mTitle ); |
1330 | 1340 | # Add rating tab |