r68597 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68596‎ | r68597 | r68598 >
Date:03:07, 26 June 2010
Author:aaron
Status:ok
Tags:
Comment:
* Renamed tab action/view hooks
* Removed some wasted CPU effort in onSkinTemplateTabs() for Vector
* Cleaned up setViewTabs()/addDraftTab()
* Added 'collapsible' to draft tab CSS
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticleView.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
@@ -411,8 +411,8 @@
412412 # Override redirect behavior...
413413 $wgHooks['InitializeArticleMaybeRedirect'][] = 'FlaggedRevsHooks::overrideRedirect';
414414 # Set page view tabs
415 -$wgHooks['SkinTemplateTabs'][] = 'FlaggedRevsHooks::setActionTabs'; // Most skins
416 -$wgHooks['SkinTemplateNavigation'][] = 'FlaggedRevsHooks::setNavigation'; // Vector
 415+$wgHooks['SkinTemplateTabs'][] = 'FlaggedRevsHooks::onSkinTemplateTabs'; // All skins
 416+$wgHooks['SkinTemplateNavigation'][] = 'FlaggedRevsHooks::onSkinTemplateNavigation'; // Vector
417417 # Add notice tags to edit view
418418 $wgHooks['EditPage::showEditForm:initial'][] = 'FlaggedRevsHooks::addToEditView';
419419 # Tweak submit button name/title
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -1610,22 +1610,29 @@
16111611 return true;
16121612 }
16131613
1614 - public static function setActionTabs( $skin, &$contentActions ) {
 1614+ // MonoBook et al: $contentActions is all the tabs
 1615+ // Vector et al: $contentActions is all the action tabs...unused
 1616+ public static function onSkinTemplateTabs( Skin $skin, array &$contentActions ) {
 1617+ if ( $skin instanceof SkinVector ) {
 1618+ // *sigh*...skip, dealt with in setNavigation()
 1619+ return true;
 1620+ }
16151621 // Note: $wgArticle sometimes not set here
16161622 if ( FlaggedArticleView::globalArticleInstance() != null ) {
16171623 $view = FlaggedArticleView::singleton();
16181624 $view->setActionTabs( $skin, $contentActions );
1619 - $view->setViewTabs( $skin, $contentActions );
 1625+ $view->setViewTabs( $skin, $contentActions, 'flat' );
16201626 }
16211627 return true;
16221628 }
16231629
1624 - public static function setNavigation( $skin, &$links ) {
 1630+ // Vector et al: $links is all the tabs (2 levels)
 1631+ public static function onSkinTemplateNavigation( Skin $skin, array &$links ) {
16251632 // Note: $wgArticle sometimes not set here
16261633 if ( FlaggedArticleView::globalArticleInstance() != null ) {
16271634 $view = FlaggedArticleView::singleton();
16281635 $view->setActionTabs( $skin, $links['actions'] );
1629 - $view->setViewTabs( $skin, $links['views'] );
 1636+ $view->setViewTabs( $skin, $links['views'], 'nav' );
16301637 }
16311638 return true;
16321639 }
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
@@ -1123,31 +1123,30 @@
11241124 }
11251125 return true;
11261126 }
1127 -
 1127+
11281128 /**
1129 - * Modify an array of view links, as used by SkinTemplateNavigation and
1130 - * SkinTemplateTabs, to inlude flagged revs UI elements
 1129+ * Modify an array of tab links to include flagged revs UI elements
 1130+ * @param string $type ('flat' for SkinTemplateTabs, 'nav' for SkinTemplateNavigation)
11311131 */
1132 - public function setViewTabs( $skin, array &$views ) {
 1132+ public function setViewTabs( Skin $skin, array &$views, $type ) {
11331133 global $wgRequest;
11341134 $this->load();
11351135 if ( $skin->mTitle->isTalkPage() ) {
11361136 return true; // leave talk pages alone
11371137 }
1138 - $fa = FlaggedArticle::getTitleInstance( $skin->mTitle );
11391138 // Get the type of action requested
11401139 $action = $wgRequest->getVal( 'action', 'view' );
1141 - if ( !$fa->isReviewable() ) {
 1140+ if ( !$this->article->isReviewable() ) {
11421141 return true; // Not a reviewable page or the UI is hidden
11431142 }
11441143 // XXX: shouldn't the session slave position check handle this?
11451144 $flags = ( $action == 'rollback' ) ? FR_MASTER : 0;
1146 - $srev = $fa->getStableRev( $flags );
 1145+ $srev = $this->article->getStableRev( $flags );
11471146 if ( !$srev ) {
11481147 return true; // No stable revision exists
11491148 }
11501149 $synced = $this->article->stableVersionIsSynced();
1151 - $pendingEdits = !$synced && $fa->isStableShownByDefault();
 1150+ $pendingEdits = !$synced && $this->article->isStableShownByDefault();
11521151 // Set the edit tab names as needed...
11531152 if ( $pendingEdits ) {
11541153 if ( isset( $views['edit'] ) ) {
@@ -1159,26 +1158,27 @@
11601159 }
11611160 # Add "pending changes" tab if the page is not synced
11621161 if ( !$synced ) {
1163 - $this->addDraftTab( $fa, $views, $srev, $action );
 1162+ $this->addDraftTab( $views, $srev, $action, $type );
11641163 }
11651164 return true;
11661165 }
11671166
11681167 // Add "pending changes" tab and set tab selection CSS
11691168 protected function addDraftTab(
1170 - FlaggedArticle $fa, array &$views, FlaggedRevision $srev, $action
 1169+ array &$views, FlaggedRevision $srev, $action, $type
11711170 ) {
11721171 global $wgRequest, $wgOut;
 1172+ $title = $this->article->getTitle(); // convenience
11731173 $tabs = array(
11741174 'read' => array( // view stable
11751175 'text' => '', // unused
1176 - 'href' => $fa->getTitle()->getLocalUrl( 'stable=1' ),
 1176+ 'href' => $title->getLocalUrl( 'stable=1' ),
11771177 'class' => ''
11781178 ),
11791179 'draft' => array( // view draft
11801180 'text' => wfMsg( 'revreview-current' ),
1181 - 'href' => $fa->getTitle()->getLocalUrl( 'stable=0&redirect=no' ),
1182 - 'class' => ''
 1181+ 'href' => $title->getLocalUrl( 'stable=0&redirect=no' ),
 1182+ 'class' => 'collapsible'
11831183 ),
11841184 );
11851185 // Set tab selection CSS
@@ -1189,45 +1189,54 @@
11901190 // Are we looking at a draft/current revision?
11911191 // Note: there may *just* be template/file changes.
11921192 if ( $wgOut->getRevisionId() >= $srev->getRevId() ) {
1193 - $tabs['draft']['class'] = 'selected';
 1193+ $tabs['draft']['class'] .= ' selected';
11941194 // Otherwise, fallback to regular tab behavior
11951195 } else {
11961196 $tabs['read']['class'] = 'selected';
11971197 }
11981198 }
1199 - $first = true;
12001199 $newViews = array();
12011200 // Rebuild tabs array. Deals with Monobook vs Vector differences.
1202 - foreach ( $views as $tabAction => $data ) {
1203 - // The first tab ('page' or 'view')...
1204 - if ( $first ) {
1205 - $first = false;
1206 - // 'view' tab? In this case, the "page"/"discussion" tabs are not
1207 - // part of $views. Also, both the page/talk page have a 'view' tab.
 1201+ if ( $type == 'nav' ) { // Vector et al
 1202+ foreach ( $views as $tabAction => $data ) {
 1203+ // The 'view' tab. Make it go to the stable version...
12081204 if ( $tabAction == 'view' ) {
12091205 // 'view' for content page; make it go to the stable version
12101206 $newViews[$tabAction]['text'] = $data['text']; // keep tab name
12111207 $newViews[$tabAction]['href'] = $tabs['read']['href'];
12121208 $newViews[$tabAction]['class'] = $tabs['read']['class'];
1213 - // 'page' tab? Make it go to the stable version...
 1209+ // All other tabs...
12141210 } else {
 1211+ // Add 'draft' tab to content page to the left of 'edit'...
 1212+ if ( $tabAction == 'edit' || $tabAction == 'viewsource' ) {
 1213+ $newViews['current'] = $tabs['draft'];
 1214+ }
 1215+ $newViews[$tabAction] = $data;
 1216+ }
 1217+ }
 1218+ } elseif ( $type == 'flat' ) { // MonoBook et al
 1219+ $first = true;
 1220+ foreach ( $views as $tabAction => $data ) {
 1221+ // The first tab ('page'). Make it go to the stable version...
 1222+ if ( $first ) {
 1223+ $first = false;
12151224 $newViews[$tabAction]['text'] = $data['text']; // keep tab name
12161225 $newViews[$tabAction]['href'] = $tabs['read']['href'];
12171226 $newViews[$tabAction]['class'] = $data['class']; // keep tab class
 1227+ // All other tabs...
 1228+ } else {
 1229+ // Add 'draft' tab to content page to the left of 'edit'...
 1230+ if ( $tabAction == 'edit' || $tabAction == 'viewsource' ) {
 1231+ $newViews['current'] = $tabs['draft'];
 1232+ }
 1233+ $newViews[$tabAction] = $data;
12181234 }
1219 - // All other tabs...
1220 - } else {
1221 - // Add 'draft' tab to content page to the left of 'edit'...
1222 - if ( $tabAction == 'edit' || $tabAction == 'viewsource' ) {
1223 - $newViews['current'] = $tabs['draft'];
1224 - }
1225 - $newViews[$tabAction] = $data;
12261235 }
1227 - }
 1236+ }
12281237 // Replaces old tabs with new tabs
12291238 $views = $newViews;
12301239 }
1231 -
 1240+
12321241 /**
12331242 * @param FlaggedRevision $frev
12341243 * @return string, revision review notes

Status & tagging log