
werdna at svn
Nov 24, 2009, 9:48 AM
Post #1 of 1
(83 views)
Permalink
|
|
SVN: [59386] trunk/extensions/LiquidThreads
|
|
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/59386 Revision: 59386 Author: werdna Date: 2009-11-24 17:48:55 +0000 (Tue, 24 Nov 2009) Log Message: ----------- LiquidThreads tab re-working. Previously, there was a hook being added in the constructor for most views, in which confusing and vector-incompatible changes were made to the tabs. This is different now, the tab modifications are consistent within each talkpage/view domain, and they are done centrally where appropriate, and they work with vector. Modified Paths: -------------- trunk/extensions/LiquidThreads/LiquidThreads.php trunk/extensions/LiquidThreads/classes/Dispatch.php trunk/extensions/LiquidThreads/classes/View.php trunk/extensions/LiquidThreads/pages/IndividualThreadHistoryView.php trunk/extensions/LiquidThreads/pages/TalkpageHeaderView.php trunk/extensions/LiquidThreads/pages/TalkpageHistoryView.php trunk/extensions/LiquidThreads/pages/TalkpageView.php trunk/extensions/LiquidThreads/pages/ThreadDiffView.php trunk/extensions/LiquidThreads/pages/ThreadHistoricalRevisionView.php trunk/extensions/LiquidThreads/pages/ThreadHistoryListingView.php trunk/extensions/LiquidThreads/pages/ThreadPermalinkView.php trunk/extensions/LiquidThreads/pages/ThreadProtectionFormView.php trunk/extensions/LiquidThreads/pages/ThreadWatchView.php Modified: trunk/extensions/LiquidThreads/LiquidThreads.php =================================================================== --- trunk/extensions/LiquidThreads/LiquidThreads.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/LiquidThreads.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -47,6 +47,8 @@ // Hooks // Main dispatch hook $wgHooks['MediaWikiPerformAction'][] = 'LqtDispatch::tryPage'; +$wgHooks['SkinTemplateTabs'][] = 'LqtDispatch::onSkinTemplateTabs'; +$wgHooks['SkinTemplateNavigation'][] = 'LqtDispatch::onSkinTemplateNavigation'; // Customisation of recentchanges //$wgHooks['OldChangesListRecentChangesLine'][] = 'LqtHooks::customizeOldChangesList'; Modified: trunk/extensions/LiquidThreads/classes/Dispatch.php =================================================================== --- trunk/extensions/LiquidThreads/classes/Dispatch.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/classes/Dispatch.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -3,6 +3,7 @@ class LqtDispatch { /** static cache of per-page LiquidThreads activation setting */ static $userLqtOverride; + static $primaryView = null; static function talkpageMain( &$output, &$article, &$title, &$user, &$request ) { // We are given a talkpage article and title. Fire up a TalkpageView @@ -48,7 +49,9 @@ } else { $viewname = 'TalkpageView'; } + $view = new $viewname( $output, $article, $title, $user, $request ); + self::$primaryView = $view; return $view->show(); } @@ -79,12 +82,14 @@ } $view = new $viewname( $output, $article, $title, $user, $request ); + self::$primaryView = $view; return $view->show(); } static function threadSummaryMain( &$output, &$article, &$title, &$user, &$request ) { $viewname = 'SummaryPageView'; $view = new $viewname( $output, $article, $title, $user, $request ); + self::$primaryView = $view; return $view->show(); } @@ -167,4 +172,20 @@ } return true; } + + static function onSkinTemplateNavigation( $skinTemplate, &$links ) { + if ( !self::$primaryView ) return; + + self::$primaryView->customizeNavigation( $skinTemplate, $links ); + + return true; + } + + static function onSkinTemplateTabs( $skinTemplate, &$links ) { + if ( !self::$primaryView ) return; + + self::$primaryView->customizeTabs( $skinTemplate, $links ); + + return true; + } } Modified: trunk/extensions/LiquidThreads/classes/View.php =================================================================== --- trunk/extensions/LiquidThreads/classes/View.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/classes/View.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -1606,4 +1606,16 @@ return $sig; } + + function customizeTabs( $skin, &$links ) { + // No-op + } + + function customizeNavigation( $skin, &$links ) { + // No-op + } + + function show() { + return true; // No-op + } } Modified: trunk/extensions/LiquidThreads/pages/IndividualThreadHistoryView.php =================================================================== --- trunk/extensions/LiquidThreads/pages/IndividualThreadHistoryView.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/pages/IndividualThreadHistoryView.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -5,11 +5,17 @@ class IndividualThreadHistoryView extends ThreadPermalinkView { protected $oldid; - function customizeTabs( $skintemplate, $content_actions ) { + function customizeTabs( $skintemplate, &$content_actions ) { $content_actions['history']['class'] = 'selected'; parent::customizeTabs( $skintemplate, $content_actions ); return true; } + + function customizeNavigation( $skin, &$links ) { + $links['views']['history']['class'] = 'selected'; + parent::customizeNavigation( $skin, $links ); + return true; + } /* This customizes the subtitle of a history *listing* from the hook, and of an old revision from getSubtitle() below. */ @@ -40,8 +46,6 @@ return false; } - $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' ); - $wgHooks['PageHistoryBeforeList'][] = array( $this, 'customizeSubtitle' ); return true; Modified: trunk/extensions/LiquidThreads/pages/TalkpageHeaderView.php =================================================================== --- trunk/extensions/LiquidThreads/pages/TalkpageHeaderView.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/pages/TalkpageHeaderView.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -15,16 +15,28 @@ $content_actions['header'] = array( 'class' => 'selected', 'text' => wfMsg( 'lqt-talkpage-history-tab' ), - 'href' => '' + 'href' => '', ); - - return true; } + + function customizeNavigation( $skin, &$links ) { + $remove = array( 'actions/edit', 'actions/addsection', 'views/history', + 'actions/watch', 'actions/move' ); + + foreach( $remove as $rem ) { + list($section, $item) = explode( '/', $rem, 2 ); + unset( $links[$section][$item] ); + } + + $links['views']['header'] = array( + 'class' => 'selected', + 'text' => wfMsg( 'lqt-talkpage-history-tab' ), + 'href' => '', + ); + } function show() { - global $wgHooks, $wgOut, $wgTitle, $wgRequest; - // Why is a hook added here? - $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' ); + global $wgOut, $wgTitle, $wgRequest; if ( $wgRequest->getVal( 'action' ) === 'edit' ) { wfLoadExtensionMessages( 'LiquidThreads' ); Modified: trunk/extensions/LiquidThreads/pages/TalkpageHistoryView.php =================================================================== --- trunk/extensions/LiquidThreads/pages/TalkpageHistoryView.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/pages/TalkpageHistoryView.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -4,9 +4,8 @@ class TalkpageHistoryView extends TalkpageView { function show() { - global $wgHooks, $wgUser; - $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' ); - + global $wgUser; + self::addJSandCSS(); wfLoadExtensionMessages( 'LiquidThreads' ); @@ -32,6 +31,19 @@ return false; } + + function customizeTabs( $skin, &$links ) { + TalkpageView::customizeTalkpageTabs( $skin, $links, $this ); + + $tabid = $this->article->getTitle()->getNamespaceKey(); + $links['history']['class'] = 'selected'; + } + + function customizeNavigation( $skin, &$links ) { + TalkpageView::customizeTalkpageNavigation( $skin, $links, $this ); + $links['views']['history']['class'] = 'selected'; + $links['views']['view']['class'] = ''; + } } class TalkpageHistoryPager extends ThreadHistoryPager { Modified: trunk/extensions/LiquidThreads/pages/TalkpageView.php =================================================================== --- trunk/extensions/LiquidThreads/pages/TalkpageView.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/pages/TalkpageView.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -4,7 +4,7 @@ class TalkpageView extends LqtView { /* Added to SkinTemplateTabs hook in TalkpageView::show(). */ - function customizeTabs( $skintemplate, &$content_actions ) { + static function customizeTalkpageTabs( $skintemplate, &$content_actions, $view ) { // The arguments are passed in by reference. unset( $content_actions['edit'] ); unset( $content_actions['viewsource'] ); @@ -12,13 +12,34 @@ # Protection against non-SkinTemplate skins if ( isset( $content_actions['history'] ) ) { - $thisTitle = $this->article->getTitle(); + $thisTitle = $view->article->getTitle(); $history_url = $thisTitle->getFullURL( 'lqt_method=talkpage_history' ); $content_actions['history']['href'] = $history_url; } - - return true; } + + static function customizeTalkpageNavigation( $skin, &$links, $view ) { + $remove = array( 'views/edit', 'views/viewsource', 'actions/delete' ); + + foreach( $remove as $rem ) { + list($section, $item) = explode( '/', $rem, 2 ); + unset( $links[$section][$item] ); + } + + if ( isset( $links['views']['history'] ) ) { + $title = $view->article->getTitle(); + $history_url = $title->getFullURL( 'lqt_method=talkpage_history' ); + $links['views']['history']['href'] = $history_url; + } + } + + function customizeTabs( $skintemplate, &$links ) { + self::customizeTalkpageTabs( $skintemplate, $links, $this ); + } + + function customizeNavigation( $skintemplate, &$links ) { + self::customizeTalkpageNavigation( $skintemplate, $links, $this ); + } function showHeader() { /* Show the contents of the actual talkpage article if it exists. */ @@ -178,10 +199,7 @@ } function show() { - global $wgHooks; wfLoadExtensionMessages( 'LiquidThreads' ); - // FIXME Why is a hook added here? - $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' ); $this->output->setPageTitle( $this->title->getPrefixedText() ); self::addJSandCSS(); Modified: trunk/extensions/LiquidThreads/pages/ThreadDiffView.php =================================================================== --- trunk/extensions/LiquidThreads/pages/ThreadDiffView.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/pages/ThreadDiffView.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -3,20 +3,22 @@ if ( !defined( 'MEDIAWIKI' ) ) die; class ThreadDiffView { - function customizeTabs( $skintemplate, $content_actions ) { + function customizeTabs( $skintemplate, &$content_actions ) { unset( $content_actions['edit'] ); unset( $content_actions['viewsource'] ); unset( $content_actions['talk'] ); - $content_actions['talk']['class'] = false; $content_actions['history']['class'] = 'selected'; - - return true; } + + function customizeNavigation( $skin, &$links ) { + $remove = array( 'views/edit', 'views/viewsource' ); - function show() { - global $wgHooks; - $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' ); - return true; + foreach( $remove as $rem ) { + list($section, $item) = explode( '/', $rem, 2 ); + unset( $links[$section][$item] ); + } + + $links['views']['history']['class'] = 'selected'; } } Modified: trunk/extensions/LiquidThreads/pages/ThreadHistoricalRevisionView.php =================================================================== --- trunk/extensions/LiquidThreads/pages/ThreadHistoricalRevisionView.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/pages/ThreadHistoricalRevisionView.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -114,9 +114,6 @@ $this->showHistoryInfo(); - global $wgHooks; - $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' ); - if ( !$this->thread ) { $this->showMissingThreadPage(); return false; Modified: trunk/extensions/LiquidThreads/pages/ThreadHistoryListingView.php =================================================================== --- trunk/extensions/LiquidThreads/pages/ThreadHistoryListingView.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/pages/ThreadHistoryListingView.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -4,9 +4,6 @@ class ThreadHistoryListingView extends ThreadPermalinkView { function show() { - global $wgHooks; - $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' ); - if ( ! $this->thread ) { $this->showMissingThreadPage(); return false; @@ -33,5 +30,16 @@ return false; } + + function customizeTabs( $skin, &$links ) { + parent::customizeTabs( $skin, $links ); + $links['history']['class'] = 'selected'; + } + + function customizeNavigation( $skin, &$links ) { + parent::customizeNavigation( $skin, $links ); + $links['views']['history']['class'] = 'selected'; + $links['views']['view']['class'] = ''; + } } Modified: trunk/extensions/LiquidThreads/pages/ThreadPermalinkView.php =================================================================== --- trunk/extensions/LiquidThreads/pages/ThreadPermalinkView.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/pages/ThreadPermalinkView.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -4,62 +4,131 @@ class ThreadPermalinkView extends LqtView { protected $thread; + + function customizeTabs( $skin, &$links ) { + self::customizeThreadTabs( $skin, $links, $this ); + } + + function customizeNavigation( $skin, &$links ) { + self::customizeThreadNavigation( $skin, $links, $this ); + } - function customizeTabs( $skintemplate, $content_actions ) { + static function customizeThreadTabs( $skintemplate, &$content_actions, $view ) { wfLoadExtensionMessages( 'LiquidThreads' ); - // Insert fake 'article' and 'discussion' tabs before the thread tab. - // If you call the key 'talk', the url gets re-set later. TODO: - // the access key for the talk tab doesn't work. - if ( $this->thread ) { - $article_t = $this->thread->article()->getTitle(); - $talk_t = $this->thread->article()->getTitle(); - } else { + + if ( !$view->thread ) { return true; } - $articleTab = - array( - 'text' => wfMsg( $article_t->getNamespaceKey() ), - 'href' => $article_t->getFullURL(), - 'class' => $article_t->exists() ? '' : 'new' - ); - efInsertIntoAssoc( 'article', $articleTab, 'nstab-thread', $content_actions ); + // Insert 'article' and 'discussion' tabs before the thread tab. - $talkTab = - array( - // talkpage certainly exists since this thread is from it. - 'text' => wfMsg( 'talk' ), - 'href' => $talk_t->getFullURL() - ); - - efInsertIntoAssoc( 'not_talk', $talkTab, 'nstab-thread', $content_actions ); + $tabs = self::getCustomTabs( $view ); + $content_actions = $tabs + $content_actions; unset( $content_actions['edit'] ); unset( $content_actions['viewsource'] ); unset( $content_actions['talk'] ); - $subpage = $this->thread->title()->getPrefixedText(); + $subpage = $view->thread->title()->getPrefixedText(); - if ( array_key_exists( 'move', $content_actions ) && $this->thread ) { + // Repoint move/delete/history tabs + if ( array_key_exists( 'move', $content_actions ) && $view->thread ) { $content_actions['move']['href'] = - SpecialPage::getTitleFor( 'MoveThread', $subpage )->getFullURL(); + SpecialPage::getTitleFor( 'MoveThread', $subpage )->getFullURL(); } - if ( array_key_exists( 'delete', $content_actions ) && $this->thread ) { + if ( array_key_exists( 'delete', $content_actions ) && $view->thread ) { $content_actions['delete']['href'] = - $this->thread->title()->getFullURL( 'action=delete' ); + $view->thread->title()->getFullURL( 'action=delete' ); } if ( array_key_exists( 'history', $content_actions ) ) { - $content_actions['history']['href'] = self::permalinkUrl( $this->thread, 'thread_history' ); - if ( $this->methodApplies( 'thread_history' ) ) { + $content_actions['history']['href'] = self::permalinkUrl( $view->thread, 'thread_history' ); + if ( $view->methodApplies( 'thread_history' ) ) { $content_actions['history']['class'] = 'selected'; } } return true; } + + static function customizeThreadNavigation( $skin, &$links, $view ) { + if ( !$view->thread ) { + return true; + } + + // Insert 'article' and 'discussion' namespace-tabs + $new_nstabs = self::getCustomTabs( $view ); + + $nstabs =& $links['namespaces']; + $talkKey = $view->thread->title()->getNamespaceKey('').'_talk'; + unset( $nstabs[$talkKey] ); + $nstabs = $new_nstabs + $nstabs; + + // Remove some views. + $views =& $links['views']; + unset( $views['viewsource'] ); + unset( $views['edit'] ); + + // Re-point move, delete and history actions + $subpage = $view->thread->title()->getPrefixedText(); + $actions =& $links['actions']; + if ( isset($actions['move']) ) { + $actions['move']['href'] = + SpecialPage::getTitleFor( 'MoveThread', $subpage )->getFullURL(); + } + + if ( isset($actions['delete']) ) { + $actions['delete']['href'] = + $view->thread->title()->getFullURL( 'action=delete' ); + } + + if ( isset($views['history']) ) { + $views['history']['href'] = + self::permalinkUrl( $view->thread, 'thread_history' ); + if ( $view->methodApplies( 'thread_history' ) ) { + $views['history']['class'] = 'selected'; + } + } + } + + // Pre-generates the tabs to be included, for customizeTabs and customizeNavigation + // to insert in the appropriate place + static function getCustomTabs( $view ) { + $tabs = array(); + + $articleTitle = $view->thread->article()->getTitle()->getSubjectPage(); + $talkTitle = $view->thread->article()->getTitle()->getTalkPage(); + + $articleClasses = array(); + if ( !$articleTitle->exists() ) $articleClasses[] = 'new'; + if ( $articleTitle->equals( $view->thread->article()->getTitle() ) ) + $articleClasses[] = 'selected'; + + $talkClasses = array(); + if ( !$talkTitle->exists() ) $talkClasses[] = 'new'; + if ( $talkTitle->equals( $view->thread->article()->getTitle() ) ) + $talkClasses[] = 'selected'; + + $tabs['article'] = + array( + 'text' => wfMsg( $articleTitle->getNamespaceKey() ), + 'href' => $articleTitle->getFullURL(), + 'class' => implode( ' ', $articleClasses ), + ); + + $tabs['lqt_talk'] = + array( + // talkpage certainly exists since this thread is from it. + 'text' => wfMsg( 'talk' ), + 'href' => $talkTitle->getFullURL(), + 'class' => implode( ' ', $talkClasses ), + ); + + return $tabs; + } + function showThreadHeading( $thread ) { parent::showThreadHeading( $thread ); } @@ -108,26 +177,21 @@ } function __construct( &$output, &$article, &$title, &$user, &$request ) { - parent::__construct( $output, $article, $title, $user, $request ); $t = Threads::withRoot( $this->article ); $this->thread = $t; if ( !$t ) { - return; // error reporting is handled in show(). this kinda sucks. + return; } // $this->article gets saved to thread_article, so we want it to point to the // subject page associated with the talkpage, always, not the permalink url. $this->article = $t->article(); # for creating reply threads. - } function show() { - global $wgHooks; - $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' ); - if ( !$this->thread ) { $this->showMissingThreadPage(); return false; Modified: trunk/extensions/LiquidThreads/pages/ThreadProtectionFormView.php =================================================================== --- trunk/extensions/LiquidThreads/pages/ThreadProtectionFormView.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/pages/ThreadProtectionFormView.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -3,25 +3,38 @@ if ( !defined( 'MEDIAWIKI' ) ) die; // Pass-through wrapper -class ThreadProtectionFormView { - function customizeTabs( $skintemplate, $content_actions ) { - unset( $content_actions['edit'] ); - unset( $content_actions['addsection'] ); - unset( $content_actions['viewsource'] ); - unset( $content_actions['talk'] ); - - $content_actions['talk']['class'] = false; +class ThreadProtectionFormView extends LqtView { + function customizeTabs( $skintemplate, &$content_actions ) { + ThreadPermalinkView::customizeThreadTabs( $skintemplate, $content_actions, $this ); + if ( array_key_exists( 'protect', $content_actions ) ) $content_actions['protect']['class'] = 'selected'; else if ( array_key_exists( 'unprotect', $content_actions ) ) $content_actions['unprotect']['class'] = 'selected'; - - return true; } + + function customizeNavigation( $skintemplate, &$links ) { + ThreadPermalinkView::customizeThreadNavigation( $skintemplate, $links, $this ); + + if ( isset( $links['actions']['protect'] ) ) { + $links['actions']['protect']['class'] = 'selected'; + } + + if ( isset( $links['actions']['unprotect'] ) ) { + $links['actions']['unprotect']['class'] = 'selected'; + } + } + + function __construct( &$output, &$article, &$title, &$user, &$request ) { + parent::__construct( $output, $article, $title, $user, $request ); - function show() { - global $wgHooks; - $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' ); - return true; + $t = Threads::withRoot( $this->article ); + + $this->thread = $t; + if ( !$t ) { + return; + } + + $this->article = $t->article(); } } Modified: trunk/extensions/LiquidThreads/pages/ThreadWatchView.php =================================================================== --- trunk/extensions/LiquidThreads/pages/ThreadWatchView.php 2009-11-24 17:31:06 UTC (rev 59385) +++ trunk/extensions/LiquidThreads/pages/ThreadWatchView.php 2009-11-24 17:48:55 UTC (rev 59386) @@ -3,9 +3,4 @@ if ( !defined( 'MEDIAWIKI' ) ) die; class ThreadWatchView extends ThreadPermalinkView { - function show() { - global $wgHooks; - $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' ); - return true; - } } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS [at] lists https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
|