r96085 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96084‎ | r96085 | r96086 >
Date:08:37, 2 September 2011
Author:siebrand
Status:resolved
Tags:
Comment:
Use Linker statically.
No constant check needed for files only containing a class.
Update formatting and whitespace.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/Hooks.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/SpecialNewMessages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/Hooks.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 class LqtHooks {
45 // Used to inform hooks about edits that are taking place.
56 public static $editType = null;
@@ -7,7 +8,7 @@
89 public static $editArticle = null;
910 public static $editTalkpage = null;
1011 public static $scriptVariables = array();
11 -
 12+
1213 public static $editedStati = array(
1314 Threads::EDITED_NEVER => 'never',
1415 Threads::EDITED_HAS_REPLY => 'has-reply',
@@ -21,28 +22,28 @@
2223 );
2324
2425 static function customizeOldChangesList( &$changeslist, &$s, $rc ) {
25 - if ( $rc->getTitle()->getNamespace() != NS_LQT_THREAD )
 26+ if ( $rc->getTitle()->getNamespace() != NS_LQT_THREAD ) {
2627 return true;
 28+ }
2729
2830 $thread = Threads::withRoot( new Article( $rc->getTitle() ) );
2931 if ( !$thread ) {
3032 return true;
3133 }
3234
33 - global $wgUser, $wgLang, $wgOut;
34 - $sk = $wgUser->getSkin();
 35+ global $wgLang, $wgOut;
3536 $wgOut->addModules( 'ext.liquidThreads' );
3637
3738 // Custom display for new posts.
3839 if ( $rc->mAttribs['rc_new'] ) {
3940 // Article link, timestamp, user
4041 $s = '';
41 - $s .= $sk->link( $thread->getTitle() );
 42+ $s .= Linker::link( $thread->getTitle() );
4243 $changeslist->insertTimestamp( $s, $rc );
4344 $changeslist->insertUserRelatedLinks( $s, $rc );
4445
4546 // Action text
46 - $msg = $thread->isTopmostThread()
 47+ $msg = $thread->isTopmostThread()
4748 ? 'lqt_rc_new_discussion' : 'lqt_rc_new_reply';
4849 $link = LqtView::linkInContext( $thread );
4950 $s .= ' ' . wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
@@ -52,18 +53,19 @@
5354 // add the truncated post content
5455 $quote = $thread->root()->getContent();
5556 $quote = $wgLang->truncate( $quote, 200 );
56 - $s .= ' ' . $sk->commentBlock( $quote );
 57+ $s .= ' ' . Linker::commentBlock( $quote );
5758
5859 $classes = array();
5960 $changeslist->insertTags( $s, $rc, $classes );
6061 $changeslist->insertExtra( $s, $rc, $classes );
6162 }
 63+
6264 return true;
6365 }
6466
6567 static function setNewtalkHTML( $skintemplate, $tpl ) {
6668 global $wgUser, $wgTitle, $wgOut;
67 -
 69+
6870 // If the user isn't using LQT on their talk page, bail out
6971 if ( ! LqtDispatch::isLqtPage( $wgUser->getTalkPage() ) ) {
7072 return true;
@@ -89,7 +91,7 @@
9092 }
9193
9294 static function beforeWatchlist( &$conds, &$tables, &$join_conds, &$fields ) {
93 - global $wgOut, $wgUser;
 95+ global $wgOut;
9496
9597 $db = wfGetDB( DB_SLAVE );
9698
@@ -113,8 +115,7 @@
114116 $messages_title = SpecialPage::getTitleFor( 'NewMessages' );
115117 $new_messages = wfMsgExt( 'lqt-new-messages', 'parseinline' );
116118
117 - $sk = $wgUser->getSkin();
118 - $link = $sk->link( $messages_title, $new_messages,
 119+ $link = Linker::link( $messages_title, $new_messages,
119120 array( 'class' => 'lqt_watchlist_messages_notice' ) );
120121 $wgOut->addHTML( $link );
121122
@@ -173,25 +174,29 @@
174175 if ( empty( $row->thread_id ) ) {
175176 return true;
176177 }
177 -
 178+
178179 $thread = Thread::newFromRow( $row );
179180 $threadInfo = "\n";
180181 $attribs = array();
181182 $attribs['ThreadSubject'] = $thread->subject();
 183+
182184 if ( $thread->hasSuperThread() ) {
183185 if ( $thread->superThread()->title() ) {
184186 $attribs['ThreadParent'] = $thread->superThread()->title()->getPrefixedText();
185187 }
186 -
 188+
187189 if ( $thread->topmostThread()->title() ) {
188190 $attribs['ThreadAncestor'] = $thread->topmostThread()->title()->getPrefixedText();
189191 }
190192 }
 193+
191194 $attribs['ThreadPage'] = $thread->getTitle()->getPrefixedText();
192195 $attribs['ThreadID'] = $thread->id();
 196+
193197 if ( $thread->hasSummary() && $thread->summary() ) {
194198 $attribs['ThreadSummaryPage'] = $thread->summary()->getTitle()->getPrefixedText();
195199 }
 200+
196201 $attribs['ThreadAuthor'] = $thread->author()->getName();
197202 $attribs['ThreadEditStatus'] = self::$editedStati[$thread->editedness()];
198203 $attribs['ThreadType'] = self::$threadTypes[$thread->type()];
@@ -250,11 +255,13 @@
251256 array( 'thread_author_name', 'thread_author_id', 'thread_modified' );
252257 $renameUserSQL->tablesJob['thread_history'] =
253258 array( 'th_user_text', 'th_user', 'th_timestamp' );
 259+
254260 return true;
255261 }
256262
257263 static function editCheckboxes( $editPage, &$checkboxes, &$tabIndex ) {
258264 global $wgRequest;
 265+
259266 $article = $editPage->getArticle();
260267 $title = $article->getTitle();
261268
@@ -399,8 +406,9 @@
400407 // If the page actually exists, allow the user to edit posts on their own talk page.
401408 $thread = Threads::withRoot( new Article( $title ) );
402409
403 - if ( !$thread )
 410+ if ( !$thread ) {
404411 return true;
 412+ }
405413
406414 $articleTitle = $thread->getTitle();
407415
@@ -547,12 +555,14 @@
548556
549557 static function afterUserMessage( $user, $article, $subject, $text, $signature, $summary, $editor ) {
550558 global $wgLqtTalkPages;
 559+
551560 $talk = $user->getTalkPage();
552561
553562 if ( $wgLqtTalkPages && LqtDispatch::isLqtPage( $talk ) ) {
554563 // Need to edit as another user. Lqt does not provide an interface to alternative users,
555564 // so replacing $wgUser here.
556565 global $wgUser;
 566+
557567 $parkedUser = $wgUser;
558568 $wgUser = $editor;
559569
@@ -573,13 +583,16 @@
574584
575585 // Set $wgUser back to the newly created user
576586 $wgUser = $parkedUser;
 587+
577588 return false;
578589 }
 590+
579591 return true;
580592 }
581593
582594 public static function onMakeGlobalVariablesScript( &$vars ) {
583595 $vars += self::$scriptVariables;
 596+
584597 return true;
585598 }
586599
@@ -607,7 +620,7 @@
608621 return '';
609622 }
610623 }
611 -
 624+
612625 /**
613626 * Handles tags in Page sections of XML dumps
614627 */
@@ -617,7 +630,7 @@
618631 $reader->name == 'DiscussionThreading' ) ) {
619632 return true;
620633 }
621 -
 634+
622635 $pageInfo['DiscussionThreading'] = array();
623636 $fields = array(
624637 'ThreadSubject',
@@ -631,38 +644,38 @@
632645 'ThreadType',
633646 'ThreadSignature',
634647 );
635 -
 648+
636649 $skip = false;
637 -
 650+
638651 while ( $skip ? $reader->next() : $reader->read() ) {
639652 if ( $reader->nodeType == XmlReader::END_ELEMENT &&
640653 $reader->name == 'DiscussionThreading') {
641654 break;
642655 }
643 -
 656+
644657 $tag = $reader->name;
645 -
 658+
646659 if ( in_array( $tag, $fields ) ) {
647660 $pageInfo['DiscussionThreading'][$tag] = $reader->nodeContents();
648661 }
649662 }
650 -
 663+
651664 return false;
652665 }
653 -
 666+
654667 // Processes discussion threading data in XML dumps (extracted in handlePageXMLTag).
655668 public static function afterImportPage( $title, $origTitle, $revCount, $sRevCount, $pageInfo ) {
656669 // in-process cache of pending thread relationships
657670 static $pendingRelationships = null;
658 -
 671+
659672 if ( $pendingRelationships === null ) {
660673 $pendingRelationships = self::loadPendingRelationships();
661674 }
662 -
 675+
663676 $titlePendingRelationships = array();
664677 if ( isset($pendingRelationships[$title->getPrefixedText()]) ) {
665678 $titlePendingRelationships = $pendingRelationships[$title->getPrefixedText()];
666 -
 679+
667680 foreach( $titlePendingRelationships as $k => $v ) {
668681 if ( $v['type'] == 'article' ) {
669682 self::applyPendingArticleRelationship( $v, $title );
@@ -670,34 +683,35 @@
671684 }
672685 }
673686 }
674 -
 687+
675688 if ( ! isset( $pageInfo['DiscussionThreading'] ) ) {
676689 return true;
677690 }
678 -
 691+
679692 $statusValues = array_flip( self::$editedStati );
680693 $typeValues = array_flip( self::$threadTypes );
681 -
 694+
682695 $info = $pageInfo['DiscussionThreading'];
683 -
 696+
684697 $root = new Article( $title );
685698 $article = new Article( Title::newFromText( $info['ThreadPage'] ) );
686699 $type = $typeValues[$info['ThreadType']];
687700 $editedness = $statusValues[$info['ThreadEditStatus']];
688701 $subject = $info['ThreadSubject'];
689702 $summary = wfMsgForContent( 'lqt-imported' );
690 -
 703+
691704 $signature = null;
692705 if ( isset( $info['ThreadSignature'] ) ) {
693706 $signature = $info['ThreadSignature'];
694707 }
695 -
 708+
696709 $thread = Thread::create( $root, $article, null, $type,
697710 $subject, $summary, null, $signature );
698 -
 711+
699712 if ( isset( $info['ThreadSummaryPage'] ) ) {
700713 $summaryPageName = $info['ThreadSummaryPage'];
701714 $summaryPage = new Article( Title::newFromText( $summaryPageName ) );
 715+
702716 if ( $summaryPage->exists() ) {
703717 $thread->setSummaryPage( $summaryPage );
704718 } else {
@@ -705,12 +719,12 @@
706720 $summaryPageName, 'article', $pendingRelationships );
707721 }
708722 }
709 -
 723+
710724 if ( isset( $info['ThreadParent'] ) ) {
711725 $threadPageName = $info['ThreadParent'];
712726 $parentArticle = new Article( Title::newFromText( $threadPageName ) );
713727 $superthread = Threads::withRoot( $parentArticle );
714 -
 728+
715729 if ( $superthread ) {
716730 $thread->setSuperthread( $superthread );
717731 } else {
@@ -718,48 +732,48 @@
719733 $threadPageName, 'thread', $pendingRelationships );
720734 }
721735 }
722 -
 736+
723737 $thread->save();
724 -
 738+
725739 foreach( $titlePendingRelationships as $k => $v ) {
726740 if ( $v['type'] == 'thread' ) {
727741 self::applyPendingThreadRelationship( $v, $thread );
728742 unset( $titlePendingRelationships[$k] );
729743 }
730744 }
731 -
 745+
732746 return true;
733747 }
734 -
 748+
735749 public static function applyPendingThreadRelationship( $pendingRelationship, $thread ) {
736750 if ( $pendingRelationship['relationship'] == 'thread_parent' ) {
737751 $childThread = Threads::withID( $pendingRelationship['thread'] );
738 -
 752+
739753 $childThread->setSuperthread( $thread );
740754 $childThread->save();
741755 $thread->save();
742756 }
743757 }
744 -
 758+
745759 public static function applyPendingArticleRelationship( $pendingRelationship, $title ) {
746760 $articleID = $title->getArticleId();
747 -
 761+
748762 $dbw = wfGetDB( DB_MASTER );
749 -
 763+
750764 $dbw->update( 'thread', array( $pendingRelationship['relationship'] => $articleID ),
751765 array( 'thread_id' => $pendingRelationship['thread'] ),
752766 __METHOD__ );
753 -
 767+
754768 $dbw->delete( 'thread_pending_relationship',
755769 array( 'tpr_title' => $pendingRelationship['title'] ), __METHOD__ );
756770 }
757 -
 771+
758772 public static function loadPendingRelationships() {
759773 $dbr = wfGetDB( DB_MASTER );
760774 $arr = array();
761 -
 775+
762776 $res = $dbr->select( 'thread_pending_relationship', '*', array(1), __METHOD__ );
763 -
 777+
764778 foreach( $res as $row ) {
765779 $title = $row->tpr_title;
766780 $entry = array(
@@ -768,17 +782,17 @@
769783 'title' => $title,
770784 'type' => $row->tpr_type,
771785 );
772 -
 786+
773787 if ( !isset($arr[$title]) ) {
774788 $arr[$title] = array();
775789 }
776 -
 790+
777791 $arr[$title][] = $entry;
778792 }
779 -
 793+
780794 return $arr;
781795 }
782 -
 796+
783797 public static function addPendingRelationship( $thread, $relationship, $title, $type, &$array ) {
784798 $entry = array(
785799 'thread' => $thread,
@@ -786,19 +800,19 @@
787801 'title' => $title,
788802 'type' => $type,
789803 );
790 -
 804+
791805 $row = array();
792806 foreach( $entry as $k => $v ) {
793807 $row['tpr_'.$k] = $v;
794808 }
795 -
 809+
796810 $dbw = wfGetDB( DB_MASTER );
797811 $dbw->insert( 'thread_pending_relationship', $row, __METHOD__ );
798 -
 812+
799813 if ( !isset( $array[$title] ) ) {
800814 $array[$title] = array();
801815 }
802 -
 816+
803817 $array[$title][] = $entry;
804818 }
805819
@@ -809,8 +823,9 @@
810824
811825 $thread = Threads::withRoot( new Article($title) );
812826
813 - if ( ! $thread )
 827+ if ( ! $thread ) {
814828 return true;
 829+ }
815830
816831 $talkpage = $thread->article();
817832
@@ -834,9 +849,9 @@
835850 'lqtpagelimit',
836851 array( 'LqtParserFunctions', 'lqtPageLimit' )
837852 );
838 -
 853+
839854 global $wgLiquidThreadsAllowEmbedding;
840 -
 855+
841856 if ( $wgLiquidThreadsAllowEmbedding ) {
842857 $parser->setHook( 'talkpage', array( 'LqtParserFunctions', 'lqtTalkPage' ) );
843858 $parser->setHook( 'thread', array( 'LqtParserFunctions', 'lqtThread' ) );
Index: trunk/extensions/LiquidThreads/pages/SpecialNewMessages.php
@@ -1,5 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die;
43
54 class SpecialNewMessages extends SpecialPage {
65 private $user, $output, $request;
@@ -10,8 +9,8 @@
1110 }
1211
1312 /**
14 - * @see SpecialPage::getDescription
15 - */
 13+ * @see SpecialPage::getDescription
 14+ */
1615 function getDescription() {
1716 return wfMsg( 'lqt_newmessages-title' );
1817 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r96086Follow-up r96085: Put $wgUser back. Was still needed.siebrand09:55, 2 September 2011

Status & tagging log