r55925 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55924‎ | r55925 | r55926 >
Date:13:33, 7 September 2009
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads: Add automatic AJAX checking for updates in the background (every 30 seconds for now, adjustable in the future). Uses the new LiquidThreads API module.
Modified paths:
  • /trunk/extensions/LiquidThreads/LqtFunctions.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/View.php (modified) (history)
  • /trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php (modified) (history)
  • /trunk/extensions/LiquidThreads/lqt.css (modified) (history)
  • /trunk/extensions/LiquidThreads/lqt.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/LqtFunctions.php
@@ -49,4 +49,3 @@
5050 array( 'LqtParserFunctions', 'useLiquidThreads' ) );
5151 return true;
5252 }
53 -
Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php
@@ -237,6 +237,10 @@
238238 'lqt-search-legend' => 'Search discussions on this page',
239239 'lqt-search-label' => 'Search terms:',
240240 'lqt-search-button' => 'Search',
 241+
 242+ // Some AJAX stuff
 243+ 'lqt-ajax-updated' => 'This thread has new posts.',
 244+ 'lqt-ajax-update-link' => 'Click here to load the latest posts.',
241245 );
242246
243247 /** Message documentation (Message documentation)
Index: trunk/extensions/LiquidThreads/lqt.css
@@ -451,3 +451,13 @@
452452 /* float: left;*/
453453 font-weight: bold;
454454 }
 455+
 456+.lqt-updated-notification {
 457+ text-align: center;
 458+ margin-left: 20%;
 459+ margin-right: 20%;
 460+ padding: 1em;
 461+ font-weight: bold;
 462+ border: 1px solid #dddddd;
 463+ background-color: #eeeeee;
 464+}
Index: trunk/extensions/LiquidThreads/classes/View.php
@@ -619,7 +619,8 @@
620620 static function exportJSLocalisation() {
621621 wfLoadExtensionMessages( 'LiquidThreads' );
622622
623 - $messages = array( 'lqt-quote-intro', 'lqt-quote' );
 623+ $messages = array( 'lqt-quote-intro', 'lqt-quote', 'lqt-ajax-updated',
 624+ 'lqt-ajax-update-link' );
624625 $data = array();
625626
626627 foreach( $messages as $msg ) {
@@ -978,6 +979,7 @@
979980 $html = '';
980981
981982 $html .= Xml::element( 'a', array( 'name' => $this->anchorName($thread) ), ' ' );
 983+
982984 $html .= $this->showThreadHeading( $thread );
983985
984986 $class = $this->threadDivClass( $thread );
@@ -986,12 +988,20 @@
987989 } elseif ($levelNum == $totalInLevel) {
988990 $class .= ' lqt-thread-last';
989991 }
 992+
990993 $html .= Xml::openElement( 'div', array( 'class' => $class,
991994 'id' => 'lqt_thread_id_'. $thread->id() ) );
992995
 996+ // Modified time for topmost threads...
 997+ if ( $thread->isTopmostThread() ) {
 998+ $html .= Xml::hidden( 'lqt-thread-modified-'.$thread->id(),
 999+ wfTimestamp( TS_MW, $thread->modified() ),
 1000+ array( 'id' => 'lqt-thread-modified-'.$thread->id(),
 1001+ 'class' => 'lqt-thread-modified' ) );
 1002+ }
 1003+
9931004 // Flush output to display thread
9941005 $this->output->addHTML( $html );
995 -
9961006 $this->output->addHTML( Xml::openElement( 'div',
9971007 array( 'class' => 'lqt-post-wrapper' ) ) );
9981008 $this->showSingleThread( $thread );
@@ -1041,8 +1051,9 @@
10421052 $levelClass = 'lqt-thread-nest-'.$this->threadNestingLevel;
10431053 $alternatingType = ($this->threadNestingLevel % 2) ? 'odd' : 'even';
10441054 $alternatingClass = "lqt-thread-$alternatingType";
 1055+ $topmostClass = $thread->isTopmostThread() ? ' lqt-thread-topmost' : '';
10451056
1046 - return "lqt_thread $levelClass $alternatingClass";
 1057+ return "lqt_thread $levelClass $alternatingClass$topmostClass";
10471058 }
10481059
10491060 function getSummary( $t ) {
Index: trunk/extensions/LiquidThreads/lqt.js
@@ -218,6 +218,53 @@
219219
220220 menuTrigger.show();
221221 },
 222+
 223+ 'checkForUpdates' : function() {
 224+ var threadModifiedTS = {};
 225+ var threads = [];
 226+
 227+ $j('.lqt-thread-topmost').each( function() {
 228+ var tsField = $j(this).find('.lqt-thread-modified');
 229+ var oldTS = tsField.val();
 230+ // Prefix is lqt-thread-modified-
 231+ var threadID = tsField.attr('id').substr( "lqt-thread-modified-".length );
 232+
 233+ threadModifiedTS[threadID] = oldTS;
 234+ threads.push(threadID);
 235+ } );
 236+
 237+ var getData = { 'action' : 'query', 'list' : 'threads', 'lqtid' : threads.join('|'),
 238+ 'format' : 'json', 'lqtprop' : 'id|subject|parent|modified' };
 239+
 240+ $j.get( wgScriptPath+'/api.php', getData,
 241+ function(data) {
 242+ var threads = data.query.threads;
 243+
 244+ $j.each( threads, function( i, thread ) {
 245+ var threadID = thread.id;
 246+ var threadModified = thread.modified;
 247+
 248+ if ( threadModified != threadModifiedTS[threadID] ) {
 249+ liquidThreads.showUpdated(threadID);
 250+ }
 251+ } );
 252+ }, 'json' );
 253+ },
 254+
 255+ 'showUpdated' : function(id) {
 256+ // Check if there's already an updated marker here
 257+ var threadObject = $j("#lqt_thread_id_"+id);
 258+
 259+ if ( threadObject.find('.lqt-updated-notification').length ) {
 260+ return;
 261+ }
 262+
 263+ var notifier = $j('<div/>');
 264+ notifier.text( wgLqtMessages['lqt-ajax-updated'] );
 265+ notifier.addClass( 'lqt-updated-notification' );
 266+
 267+ threadObject.prepend(notifier);
 268+ }
222269 }
223270
224271 js2AddOnloadHook( function() {
@@ -253,5 +300,8 @@
254301
255302 // Show quote buttons
256303 liquidThreads.showQuoteButtons();
 304+
 305+ // Set up periodic update checking
 306+ setInterval( liquidThreads.checkForUpdates, 30000 );
257307 } );
258308

Status & tagging log