r61966 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61965‎ | r61966 | r61967 >
Date:00:52, 4 February 2010
Author:werdna
Status:reverted
Tags:
Comment:
LiquidThreads: Implement simple embedding of LiquidThreads discussion pages in other parts of the software (including on regular wiki pages). Can be disabled with $wgLiquidThreadsAllowEmbedding
Modified paths:
  • /trunk/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/LqtFunctions.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/ParserFunctions.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/View.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/TalkpageView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/LqtFunctions.php
@@ -56,6 +56,12 @@
5757 'lqtpagelimit',
5858 array( 'LqtParserFunctions', 'lqtPageLimit' )
5959 );
 60+
 61+ global $wgLiquidThreadsAllowEmbedding;
 62+
 63+ if ($wgLiquidThreadsAllowEmbedding) {
 64+ $parser->setHook( 'talkpage', array( 'LqtParserFunctions', 'lqtTalkPage' ) );
 65+ }
6066
6167 return true;
6268 }
Index: trunk/extensions/LiquidThreads/LiquidThreads.php
@@ -212,3 +212,6 @@
213213
214214 /** Whether or not to allow users to activate/deactivate LiquidThreads per-page */
215215 $wgLiquidThreadsAllowUserControl = true;
 216+
 217+/** Allow embedding */
 218+$wgLiquidThreadsAllowEmbedding = true;
Index: trunk/extensions/LiquidThreads/classes/View.php
@@ -843,25 +843,50 @@
844844 return;
845845 }
846846
847 - global $wgOut, $wgStylePath;
848 - global $wgScriptPath, $wgStyleVersion;
849 - global $wgEnableJS2system;
850 - global $wgLiquidThreadsExtensionName;
 847+ global $wgOut;
 848+
 849+ $info = self::getScriptsAndStyles();
 850+
 851+ foreach( $info['inlineScripts'] as $script ) {
 852+ $wgOut->addInlineScript( $script );
 853+ }
 854+
 855+ foreach( $info['scripts'] as $script ) {
 856+ $wgOut->addScriptFile( $script );
 857+ }
 858+
 859+ foreach( $info['styles'] as $style ) {
 860+ $wgOut->addExtensionStyle( $style );
 861+ }
851862
852 - $wgOut->addInlineScript( 'var wgLqtMessages = ' . self::exportJSLocalisation() . ';' );
853 -
854 - $basePath = "$wgScriptPath/extensions/$wgLiquidThreadsExtensionName";
855 -
856 - $wgOut->addScriptFile( "$basePath/jquery/js2.combined.js" );
857 - $wgOut->addExtensionStyle( "$basePath/jquery/jquery-ui-1.7.2.css" );
858 -
859 - $wgOut->addScriptFile( "$basePath/jquery/jquery.autogrow.js" );
860 -
861 - $wgOut->addScriptFile( "$basePath/lqt.js" );
862 - $wgOut->addExtensionStyle( "$basePath/lqt.css?{$wgStyleVersion}" );
863 -
864863 self::$stylesAndScriptsDone = true;
865864 }
 865+
 866+ static function getScriptsAndStyles() {
 867+ global $wgLiquidThreadsExtensionName, $wgStylePath, $wgScriptPath, $wgStyleVersion;
 868+ $basePath = "$wgScriptPath/extensions/$wgLiquidThreadsExtensionName";
 869+
 870+ $inlineScripts = array(
 871+ 'var wgLqtMessages = ' . self::exportJSLocalisation() . ';',
 872+ );
 873+
 874+ $scripts = array(
 875+ "$basePath/jquery/js2.combined.js",
 876+ "$basePath/jquery/jquery.autogrow.js",
 877+ "$basePath/lqt.js",
 878+ );
 879+
 880+ $styles = array(
 881+ "$basePath/jquery/jquery-ui-1.7.2.css",
 882+ "$basePath/lqt.css?{$wgStyleVersion}",
 883+ );
 884+
 885+ return array(
 886+ 'inlineScripts' => $inlineScripts,
 887+ 'scripts' => $scripts,
 888+ 'styles' => $styles,
 889+ );
 890+ }
866891
867892 static function exportJSLocalisation() {
868893 wfLoadExtensionMessages( 'LiquidThreads' );
Index: trunk/extensions/LiquidThreads/classes/ParserFunctions.php
@@ -20,4 +20,52 @@
2121 $parser->mOutput->setProperty( 'lqt-page-limit', $param );
2222 }
2323 }
 24+
 25+ static function lqtTalkPage( $parser, $args, $parser, $frame ) {
 26+ global $wgStyleVersion;
 27+
 28+ // Grab article.
 29+ $title = null;
 30+ if ( $args['talkpage'] ) {
 31+ $title = Title::newFromText( $args['talkpage'] );
 32+ }
 33+ if ( is_null($title) ) {
 34+ $title = $parser->getTitle();
 35+ }
 36+
 37+ $article = new Article( $title );
 38+ $out = new OutputPage;
 39+
 40+ global $wgUser, $wgRequest;
 41+ $view = new TalkpageView( $out, $article, $title, $wgUser, $wgRequest );
 42+
 43+ // Handle show/hide preferences. Header gone by default.
 44+ $view->hideItems( 'header' );
 45+
 46+ if ( array_key_exists( 'show', $args ) ) {
 47+ $show = explode( ' ', $args['show'] );
 48+ $view->setShownItems( $show );
 49+ }
 50+
 51+ $view->show();
 52+
 53+ $scriptsStyles = LqtView::getScriptsAndStyles();
 54+ $headItems = '';
 55+
 56+ foreach( $scriptsStyles['inlineScripts'] as $iscript ) {
 57+ $headItems .= Html::inlineScript( "\n$iscript\n" );
 58+ }
 59+
 60+ foreach( $scriptsStyles['scripts'] as $script ) {
 61+ $headItems .= Html::linkedScript( "$script?$wgStyleVersion" );
 62+ }
 63+
 64+ foreach( $scriptsStyles['styles'] as $style ) {
 65+ $headItems .= Html::linkedStyle( $style, 'all' );
 66+ }
 67+
 68+ $parser->getOutput()->addHeadItem( $headItems, 'lqt-talk-page' );
 69+
 70+ return $out->getHTML();
 71+ }
2472 }
Index: trunk/extensions/LiquidThreads/pages/TalkpageView.php
@@ -3,6 +3,8 @@
44 if ( !defined( 'MEDIAWIKI' ) ) die;
55
66 class TalkpageView extends LqtView {
 7+ protected $mShowItems = array( 'toc', 'options', 'header' );
 8+
79 /* Added to SkinTemplateTabs hook in TalkpageView::show(). */
810 static function customizeTalkpageTabs( $skintemplate, &$content_actions, $view ) {
911 // The arguments are passed in by reference.
@@ -241,7 +243,9 @@
242244
243245 }
244246
245 - $this->showHeader();
 247+ if ( $this->shouldShow('header') ) {
 248+ $this->showHeader();
 249+ }
246250
247251 $html = '';
248252
@@ -266,7 +270,9 @@
267271 $talkpageHeader = Xml::tags( 'div', array( 'class' => 'lqt-talkpage-header' ),
268272 $talkpageHeader );
269273
270 - $this->output->addHTML( $talkpageHeader );
 274+ if ( $this->shouldShow('options') ) {
 275+ $this->output->addHTML( $talkpageHeader );
 276+ }
271277
272278 global $wgRequest;
273279 if ( $this->methodApplies( 'talkpage_new_thread' ) ) {
@@ -283,9 +289,9 @@
284290
285291 $threads = $this->getPageThreads( $pager );
286292
287 - if ( count( $threads ) > 0 ) {
 293+ if ( count( $threads ) > 0 && $this->shouldShow('toc') ) {
288294 $html .= $this->getTOC( $threads );
289 - } else {
 295+ } elseif ( count($threads) == 0 ) {
290296 $html .= Xml::tags( 'div', array( 'class' => 'lqt-no-threads' ),
291297 wfMsgExt( 'lqt-no-threads', 'parseinline' ) );
292298 }
@@ -353,6 +359,28 @@
354360 // Default
355361 return LQT_NEWEST_CHANGES;
356362 }
 363+
 364+ // Hide a number of items from the view
 365+ // Valid values: toc, options, header
 366+ function hideItems( $items ) {
 367+ $this->mShowItems = array_diff( $this->mShowItems, (array)$items );
 368+ }
 369+
 370+ // Show a number of items in the view
 371+ // Valid values: toc, options, header
 372+ function showItems( $items ) {
 373+ $this->mShowItems = array_merge( $this->mShowItems, (array)$items );
 374+ }
 375+
 376+ // Whether or not to show an item
 377+ function shouldShow( $item ) {
 378+ return in_array( $item, $this->mShowItems );
 379+ }
 380+
 381+ // Set the items shown
 382+ function setShownItems( $items ) {
 383+ $this->mShowItems = $items;
 384+ }
357385 }
358386
359387 class LqtDiscussionPager extends IndexPager {

Follow-up revisions

RevisionCommit summaryAuthorDate
r61968Revert r61966 for now, still needs some work on post/reply.werdna03:19, 4 February 2010

Status & tagging log