r22582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22581‎ | r22582 | r22583 >
Date:23:47, 30 May 2007
Author:david
Status:old
Tags:
Comment:
Nuked hashar's recent changes; will have a look at them later. Archive browser now works. Added lqt.js. Turned of color coding because it's ugly (just in the CSS; the code is still there).
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)
  • /branches/liquidthreads/skins/common/lqt.js (added) (history)
  • /branches/liquidthreads/skins/monobook/main.css (modified) (history)

Diff [purge]

Index: branches/liquidthreads/skins/monobook/main.css
@@ -40,6 +40,10 @@
4141 top:-3.2em;
4242 }
4343
 44+.lqt_hidden {
 45+ display: none;
 46+}
 47+
4448 h1.firstHeading {
4549 padding-right: 4.5em;
4650 }
@@ -110,8 +114,8 @@
111115 font-size: smaller;
112116 color: #777;
113117
114 - padding-left: 0.3em; /* for post colors */
115 - border-left: 0.3em solid;
 118+// padding-left: 0.3em; /* for post colors */
 119+// border-left: 0.3em solid;
116120 }
117121
118122 .lqt_post_color_1 { border-left-color: #cd9800; }
Index: branches/liquidthreads/skins/common/lqt.js
@@ -0,0 +1,25 @@
 2+// http://onlinetools.org/articles/unobtrusivejavascript/chapter4.html
 3+function lqt_add_event(obj, evType, fn){
 4+ if (obj.addEventListener){
 5+ obj.addEventListener(evType, fn, false);
 6+ return true;
 7+ } else if (obj.attachEvent){
 8+ var r = obj.attachEvent("on"+evType, fn);
 9+ return r;
 10+ } else {
 11+ return false;
 12+ }
 13+}
 14+
 15+function lqt_on_load() {
 16+ /* Hide the Go button on the archive widget, because we will
 17+ automatically go when a selection is made. */
 18+ document.getElementById('lqt_archive_go_button').className = "lqt_hidden";
 19+
 20+ var dropdown = document.getElementById('lqt_archive_month');
 21+ lqt_add_event(dropdown, 'change', function(){
 22+ document.getElementById('lqt_archive_browser_form').submit();
 23+ });
 24+}
 25+
 26+addOnloadHook(lqt_on_load);
\ No newline at end of file
Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -246,14 +246,12 @@
247247 $p = new Parser(); $sig = $p->getUserSig( $thread->rootPost()->originalAuthor() );
248248 $this->output->addWikitext( $sig, false );
249249 $this->output->addHTML( wfCloseElement( 'li' ) );
250 -
251 - global $wgContLang;
252 - $this->output->addHTML(
253 - wfOpenElement( 'li' ) .
254 - $wgContLang->timeanddate( $thread->touched() ) .
255 - wfCloseElement( 'li' )
256 - );
257250
 251+ $this->output->addHTML( wfOpenElement( 'li' ) );
 252+ $d = new Date($thread->touched());
 253+ $this->output->addHTML( $d->lastMonth()->text() );
 254+ $this->output->addHTML( wfCloseElement( 'li' ) );
 255+
258256 $commands = array( 'Edit' => $this->lqtTalkpageUrl( $this->title, 'lqt_edit_post', $thread ),
259257 'Reply' => $this->lqtTalkpageUrl( $this->title, 'lqt_reply_to', $thread ),
260258 'Permalink' => $this->permalinkUrl( $thread ) );
@@ -349,6 +347,8 @@
350348 }
351349
352350 function showArchive($month) {
 351+ // TODO having a subtitle screws up our relative positioning on the widget.
 352+// $this->output->setSubtitle("Archived threads from {$this->formattedMonth($month)}.");
353353 $threads = Thread::threadsOfArticleInMonth( $this->article, $month );
354354 foreach($threads as $t) {
355355 $this->showThread($t);
@@ -369,30 +369,55 @@
370370 }
371371 }
372372
 373+ function formattedMonth($yyyymm) {
 374+ global $wgLang; // TODO global.
 375+ return $wgLang->getMonthName( substr($yyyymm, 4, 2) ).' '.substr($yyyymm, 0, 4);
 376+ }
 377+
373378 function showArchiveWidget($month) {
374379 global $wgLang; // TODO global.
375380
376 - $options = Thread::monthsWhereArticleHasThreads($this->article);
377 - array_unshift($options, 'Last 30 days' ); # prepend.
 381+ $sel = $this->request->getVal('lqt_archive_month', 'recent');
378382
 383+ $months = Thread::monthsWhereArticleHasThreads($this->article);
 384+
 385+ $options = array( 'Last 30 days' => 'recent' );
 386+ foreach($months as $m) {
 387+ $options[$this->formattedMonth($m)] = $m;
 388+ }
 389+
379390 $this->openDiv('lqt_archive_widget');
380 - $this->output->addHTML('<form><select>');
381 - foreach( $options as $o ) {
382 - $this->output->addHTML("<option>$o</option>");
 391+ $this->output->addHTML(<<<HTML
 392+ <form id="lqt_archive_browser_form"><select name="lqt_archive_month" id="lqt_archive_month">
 393+HTML
 394+);
 395+ foreach( $options as $label => $value ) {
 396+ $selected = $sel == $value ? 'selected="true"' : '';
 397+ $this->output->addHTML("<option value=\"$value\" $selected>$label");
383398 }
384 - $this->output->addHTML('</select></form>');
 399+ $this->output->addHTML(<<<HTML
 400+ </select><input type="submit" id="lqt_archive_go_button" value="Go"></form>
 401+HTML
 402+ );
385403 $this->closeDiv();
386404 }
387405
 406+ function addJSandCSS() {
 407+ global $wgJsMimeType, $wgStylePath; // TODO globals.
 408+ $s = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/lqt.js\"><!-- lqt js --></script>\n";
 409+ $this->output->addScript($s);
 410+ }
 411+
388412 function show() {
389413 global $wgHooks;
390414 $wgHooks['SkinTemplateTabs'][] = array($this, 'customizeTabs');
391415
392416 $this->output->setPageTitle( "Talk:" . $this->title->getText() );
 417+ $this->addJSandCSS();
393418
394419 $month = $this->request->getVal('lqt_archive_month');
395420 $this->showArchiveWidget($month);
396 - if ( $month ) {
 421+ if ( $month && $month != 'recent' ) {
397422 $this->showArchive($month);
398423 } else {
399424 $this->showLatest();