r53217 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53216‎ | r53217 | r53218 >
Date:11:49, 14 July 2009
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads updates:
* Deprecate the last vestiges of an archive system -- there is no longer any summary nag for old discussions.
* Reuse the parser function code to allow LQT to be turned on and off per-page with a parser function (which is currently kinda ugly, need to figure out the magic-word way of doing it).
* Remove the TOC for pages with no threads, it just looks stupid. Replaced it with a short 'nothing to see here' message.
Modified paths:
  • /trunk/extensions/LiquidThreads/LqtFunctions.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/LqtDispatch.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/LqtParserFunctions.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/LqtThread.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/LqtThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/LqtView.php (modified) (history)
  • /trunk/extensions/LiquidThreads/i18n/LiquidThreads.magic.php (modified) (history)
  • /trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/TalkpageView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/LqtFunctions.php
@@ -133,7 +133,7 @@
134134 function lqtSetupParserFunctions() {
135135 global $wgParser;
136136
137 - $wgParser->setFunctionHook( 'archivestartdays',
138 - array( 'LqtParserFunctions', 'archivestartdays' ) );
 137+ $wgParser->setFunctionHook( 'useliquidthreads',
 138+ array( 'LqtParserFunctions', 'useLiquidThreads' ) );
139139 }
140140
Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php
@@ -166,6 +166,7 @@
167167 'lqt-thread-split-subject'=> 'New thread subject',
168168 'lqt-split-submit' => 'Split',
169169 'lqt_split_badsubject' => 'The subject you entered is invalid.',
 170+ 'lqt-no-threads' => 'There are no threads on this page yet.',
170171
171172 // Logging
172173 'lqt-log-name' => 'Threaded discussion log',
Index: trunk/extensions/LiquidThreads/i18n/LiquidThreads.magic.php
@@ -8,7 +8,7 @@
99 * English
1010 */
1111 $words['en'] = array(
12 - 'archivestartdays' => array( 0, 'archivestartdays' ),
 12+ 'useliquidthreads' => array( 0, 'UseLiquidThreads' ),
1313 );
1414
1515 $magicWords += ( $lang == 'en' || !isset( $words[$lang] ) )
Index: trunk/extensions/LiquidThreads/pages/TalkpageView.php
@@ -254,8 +254,12 @@
255255
256256 // $html .= $this->getArchiveWidget();
257257
258 - $html .= Xml::element( 'br', array( 'style' => 'clear: both;' ) );
259 - $html .= $this->getTOC( $threads );
 258+ if ( count($threads) > 0 ) {
 259+ $html .= Xml::element( 'br', array( 'style' => 'clear: both;' ) );
 260+ $html .= $this->getTOC( $threads );
 261+ } else {
 262+ $html .= wfMsgExt( 'lqt-no-threads', 'parseinline' );
 263+ }
260264
261265 $html .= $pager->getNavigationBar();
262266
Index: trunk/extensions/LiquidThreads/classes/LqtThreads.php
@@ -31,9 +31,6 @@
3232
3333 static $cache_by_root = array();
3434 static $cache_by_id = array();
35 -
36 - /** static cache of per-page archivestartdays setting */
37 - static $archiveStartDays;
3835
3936 static function newThread( $root, $article, $superthread = null,
4037 $type = self::TYPE_NORMAL, $subject = '' ) {
@@ -252,53 +249,4 @@
253250
254251 return $dbr->makeList( $arr, LIST_OR );
255252 }
256 -
257 - static function getArticleArchiveStartDays( $article ) {
258 - global $wgLqtThreadArchiveStartDays;
259 -
260 - $article = $article->getId();
261 -
262 - // Instance cache
263 - if ( isset( self::$archiveStartDays[$article] ) ) {
264 - $cacheVal = self::$archiveStartDays[$article];
265 - if ( !is_null( $cacheVal ) ) {
266 - return $cacheVal;
267 - } else {
268 - return $wgLqtThreadArchiveStartDays;
269 - }
270 - }
271 -
272 - // Memcached: It isn't clear that this is needed yet, but since I already wrote the
273 - // code, I might as well leave it commented out instead of deleting it.
274 - // Main reason I've left this commented out is because it isn't obvious how to
275 - // purge the cache when necessary.
276 -// global $wgMemc;
277 -// $key = wfMemcKey( 'lqt-archive-start-days', $article );
278 -// $cacheVal = $wgMemc->get( $key );
279 -// if ($cacheVal != false) {
280 -// if ( $cacheVal != -1 ) {
281 -// return $cacheVal;
282 -// } else {
283 -// return $wgLqtThreadArchiveStartDays;
284 -// }
285 -// }
286 -
287 - // Load from the database.
288 - $dbr = wfGetDB( DB_SLAVE );
289 -
290 - $dbVal = $dbr->selectField( 'page_props', 'pp_value',
291 - array( 'pp_propname' => 'lqt-archivestartdays',
292 - 'pp_page' => $article ), __METHOD__ );
293 -
294 - if ($dbVal) {
295 - self::$archiveStartDays[$article] = $dbVal;
296 -# $wgMemc->set( $key, $dbVal, 1800 );
297 - return $dbVal;
298 - } else {
299 - // Negative caching.
300 - self::$archiveStartDays[$article] = null;
301 -# $wgMemc->set( $key, -1, 86400 );
302 - return $wgLqtThreadArchiveStartDays;
303 - }
304 - }
305253 }
Index: trunk/extensions/LiquidThreads/classes/LqtView.php
@@ -965,17 +965,6 @@
966966
967967 if ( $thread->summary() ) {
968968 $html .= $this->getSummary( $thread );
969 - } elseif ( $thread->isArchiveEligible() ) {
970 - wfLoadExtensionMessages( 'LiquidThreads' );
971 -
972 - $permalink_text = wfMsgNoTrans( 'lqt_summary_notice_link' );
973 - $permalink = self::permalink( $thread, $permalink_text, 'summarize',
974 - $thread->id() );
975 - $msg = wfMsgExt( 'lqt_summary_notice', array('parseinline', 'replaceafter'),
976 - array( $permalink, $thread->getArchiveStartDays() ) );
977 - $msg = Xml::tags( 'p', array( 'class' => 'lqt_summary_notice' ), $msg );
978 -
979 - $html .= $msg;
980969 }
981970
982971 // Unfortunately, I can't rewrite showRootPost() to pass back HTML
Index: trunk/extensions/LiquidThreads/classes/LqtDispatch.php
@@ -14,6 +14,9 @@
1515 'ThreadWatchView' => 'ThreadWatchView',
1616 'SummaryPageView' => 'SummaryPageView'
1717 );
 18+
 19+ /** static cache of per-page LiquidThreads activation setting */
 20+ static $userLQTActivated;
1821
1922 static function talkpageMain( &$output, &$talk_article, &$title, &$user, &$request ) {
2023 // We are given a talkpage article and title. Find the associated
@@ -96,11 +99,59 @@
97100 static function isLqtPage( $title ) {
98101 global $wgLqtPages, $wgLqtTalkPages;
99102 $isTalkPage = ($title->isTalkPage() && $wgLqtTalkPages) ||
100 - in_array( $title->getPrefixedText(), $wgLqtPages );
 103+ in_array( $title->getPrefixedText(), $wgLqtPages ) ||
 104+ self::hasUserEnabledLQT( $title->getArticleId() );
101105
102106 return $isTalkPage;
103107 }
 108+
 109+ static function hasUserEnabledLQT( $article ) {
 110+
 111+ if (is_object($article)) {
 112+ $article = $article->getId();
 113+ }
 114+
 115+ // Instance cache
 116+ if ( isset( self::$userLQTActivated[$article] ) ) {
 117+ $cacheVal = self::$userLQTActivated[$article];
104118
 119+ return $cacheVal;
 120+ }
 121+
 122+ // Memcached: It isn't clear that this is needed yet, but since I already wrote the
 123+ // code, I might as well leave it commented out instead of deleting it.
 124+ // Main reason I've left this commented out is because it isn't obvious how to
 125+ // purge the cache when necessary.
 126+// global $wgMemc;
 127+// $key = wfMemcKey( 'lqt-archive-start-days', $article );
 128+// $cacheVal = $wgMemc->get( $key );
 129+// if ($cacheVal != false) {
 130+// if ( $cacheVal != -1 ) {
 131+// return $cacheVal;
 132+// } else {
 133+// return $wgLqtThreadArchiveStartDays;
 134+// }
 135+// }
 136+
 137+ // Load from the database.
 138+ $dbr = wfGetDB( DB_SLAVE );
 139+
 140+ $dbVal = $dbr->selectField( 'page_props', 'pp_value',
 141+ array( 'pp_propname' => 'use-liquid-threads',
 142+ 'pp_page' => $article ), __METHOD__ );
 143+
 144+ if ($dbVal) {
 145+ self::$userLQTActivated[$article] = true;
 146+# $wgMemc->set( $key, $dbVal, 1800 );
 147+ return true;
 148+ } else {
 149+ // Negative caching.
 150+ self::$userLQTActivated[$article] = false;
 151+# $wgMemc->set( $key, -1, 86400 );
 152+ return false;
 153+ }
 154+ }
 155+
105156 /**
106157 * If the page we recieve is a Liquid Threads page of any kind, process it
107158 * as needed and return True. If it's a normal, non-liquid page, return false.
Index: trunk/extensions/LiquidThreads/classes/LqtParserFunctions.php
@@ -1,7 +1,7 @@
22 <?php
33
44 class LqtParserFunctions {
5 - static function archivestartdays( &$parser, $param1 ) {
6 - $parser->mOutput->setProperty( 'lqt-archivestartdays', $param1 );
 5+ static function useLiquidThreads( &$parser ) {
 6+ $parser->mOutput->setProperty( 'use-liquid-threads', 1 );
77 }
88 }
Index: trunk/extensions/LiquidThreads/classes/LqtThread.php
@@ -886,22 +886,7 @@
887887 }
888888
889889 }
890 -
891 - /**
892 - * Tells you whether or not the thread is eligible for archival
893 - * (includes a check as to whether or not the thread has already been archived.
894 - */
895 - function isArchiveEligible( ) {
896 - $startDays = $this->getArchiveStartDays();
897890
898 - $timestamp = wfTimestamp( TS_UNIX, $this->modified() );
899 - $archiveCutoff = time() - $startDays * 86400;
900 -
901 - return $timestamp < $archiveCutoff // X days must have elapsed
902 - && !$this->hasSuperthread() // Must be a primary thread (i.e. not a reply)
903 - && !$this->isHistorical(); // Can't have already been archived, obviously
904 - }
905 -
906891 function getArchiveStartDays() {
907892 return Threads::getArticleArchiveStartDays( $this->article() );
908893 }

Status & tagging log