r51512 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51511‎ | r51512 | r51513 >
Date:17:31, 5 June 2009
Author:werdna
Status:deferred
Tags:
Comment:
Rewrite LiquidThreads TOC code:
* Use Xml:: shortcuts instead of inline HTML, reduces the risk of XSS and gives overall more readable code.
* Use a proper <h2> element for the contents link, instead of one styled down to look like ordinary bold text.
* Present in a table with other relevant information, instead of a long thin list.
* Remove strange, unnecessary code.
Modified paths:
  • /trunk/extensions/LiquidThreads/Lqt.i18n.php (modified) (history)
  • /trunk/extensions/LiquidThreads/lqt.css (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/TalkpageView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/Lqt.i18n.php
@@ -22,7 +22,11 @@
2323 'lqt_browse_archive_without_recent' => 'View archived threads',
2424 'lqt_browse_archive_with_recent' => 'older',
2525 'lqt_recently_archived' => 'Recently archived:',
26 - 'lqt_contents_title' => 'Contents:',
 26+ 'lqt_contents_title' => 'Contents',
 27+ 'lqt_toc_thread_title' => 'Thread Title',
 28+ 'lqt_toc_thread_author' => 'Started By',
 29+ 'lqt_toc_thread_replycount' => 'Replies',
 30+ 'lqt_toc_thread_modified' => 'Last Modified',
2731 'lqt_add_header' => 'Add header',
2832 'lqt_new_thread' => 'Start a new discussion',
2933 'lqt_invalid_subject' => 'The subject you entered is invalid. It may:
Index: trunk/extensions/LiquidThreads/lqt.css
@@ -134,7 +134,6 @@
135135 .lqt_toc_archive_wrapper {
136136 margin-top: 0.5em;
137137 margin-bottom: 1.5em;
138 - float: left;
139138 }
140139 .lqt_archive_teaser ul,
141140 .lqt_toc_wrapper ul {
@@ -442,3 +441,15 @@
443442 .lqt_rc_author_notice_others {
444443 color: #cd9800;
445444 }
 445+
 446+.lqt_toc {
 447+ width: 80%;
 448+ border-collapse: collapse;
 449+}
 450+
 451+.lqt_toc td,.lqt_toc th {
 452+ margin: 0;
 453+ padding: 0.2em;
 454+ border-bottom: 1px solid #aaaaaa;
 455+ text-align: left;
 456+}
Index: trunk/extensions/LiquidThreads/pages/TalkpageView.php
@@ -69,28 +69,53 @@
7070 }
7171 $this->output->addHTML( Xml::closeElement( $kind ) );
7272 }
73 -
 73+
7474 function showTOC( $threads ) {
 75+ global $wgLang;
 76+
7577 wfLoadExtensionMessages( 'LiquidThreads' );
7678
7779 $sk = $this->user->getSkin();
78 - $toclines = array();
79 - $i = 1;
80 - $toclines[] = $sk->tocIndent();
81 - foreach ( $threads as $t ) {
82 - $toclines[] = $sk->tocLine( $this->anchorName( $t ), $t->subjectWithoutIncrement(), $i, 1 );
83 - $i++;
 80+
 81+ $title = Xml::tags( 'h2', null, wfMsgExt( 'lqt_contents_title', 'parseinline' ) );
 82+ $this->output->addHTML( $title );
 83+
 84+ $html = '';
 85+
 86+ // Header row
 87+ $headerRow = '';
 88+ $headers = array( 'lqt_toc_thread_title', 'lqt_toc_thread_author',
 89+ 'lqt_toc_thread_replycount', 'lqt_toc_thread_modified' );
 90+ foreach( $headers as $msg ) {
 91+ $headerRow .= Xml::tags( 'th', null, wfMsgExt( $msg, 'parseinline' ) );
8492 }
85 - $toclines[] = $sk->tocUnindent( 1 );
86 -
87 - $this->openDiv( 'lqt_toc_wrapper' );
88 - $this->output->addHTML( '<h2 class="lqt_toc_title">' . wfMsg( 'lqt_contents_title' ) . '</h2> <ul>' );
89 -
90 - foreach ( $threads as $t ) {
91 - $this->output->addHTML( '<li><a href="#' . $this->anchorName( $t ) . '">' . $t->subjectWithoutIncrement() . '</a></li>' );
 93+ $headerRow = Xml::tags( 'tr', null, $headerRow );
 94+ $headerRow = Xml::tags( 'thead', null, $headerRow );
 95+
 96+ // Table body
 97+ $rows = array();
 98+ foreach( $threads as $thread ) {
 99+ $row = '';
 100+ $subject = $this->output->parseInline( $thread->subjectWithoutIncrement() );
 101+ $row .= Xml::tags( 'td', null, $subject );
 102+
 103+ $author = $thread->root()->originalAuthor();
 104+ $authorLink = $sk->userLink( $author->getID(), $author->getName() );
 105+ $row .= Xml::tags( 'td', null, $authorLink );
 106+
 107+ $row .= Xml::element( 'td', null, count( $thread->replies() ) );
 108+
 109+ $timestamp = $wgLang->timeanddate( $thread->created(), true );
 110+ $row .= Xml::element( 'td', null, $timestamp );
 111+
 112+ $row = Xml::tags( 'tr', null, $row );
 113+ $rows[] = $row;
92114 }
93 -
94 - $this->output->addHTML( '</ul></div>' );
 115+
 116+ $html = $headerRow . "\n" . Xml::tags( 'tbody', null, implode( "\n", $rows ) );
 117+ $html = Xml::tags( 'table', array( 'class' => 'lqt_toc' ), $html );
 118+
 119+ $this->output->addHTML( $html );
95120 }
96121
97122 function showArchiveWidget( $threads ) {

Status & tagging log