r55554 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55553‎ | r55554 | r55555 >
Date:17:12, 24 August 2009
Author:werdna
Status:deferred
Tags:
Comment:
Add missing file
Modified paths:
  • /trunk/extensions/LiquidThreads/pages/SpecialMergeThread.php (added) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/pages/SpecialMergeThread.php
@@ -0,0 +1,139 @@
 2+<?php
 3+
 4+// TODO access control
 5+class SpecialMergeThread extends ThreadActionPage {
 6+
 7+ function getFormFields() {
 8+ $splitForm = array(
 9+ 'src' =>
 10+ array(
 11+ 'type' => 'info',
 12+ 'label-message' => 'lqt-thread-merge-source',
 13+ 'default' => $this->formatThreadField( 'src', $this->mThread->id() ),
 14+ 'raw' => 1,
 15+ ),
 16+ 'dest' =>
 17+ array(
 18+ 'type' => 'info',
 19+ 'label-message' => 'lqt-thread-merge-dest',
 20+ 'default' =>
 21+ $this->formatThreadField( 'dest', $this->request->getVal( 'dest' ) ),
 22+ 'raw' => 1,
 23+ ),
 24+ 'reason' =>
 25+ array(
 26+ 'label-message' => 'movereason',
 27+ 'type' => 'text',
 28+ ),
 29+ );
 30+
 31+ return $splitForm;
 32+ }
 33+
 34+ protected function getRightRequirement() { return 'lqt-merge'; }
 35+
 36+ public function checkParameters( $par ) {
 37+ if ( !parent::checkParameters($par) ) {
 38+ return false;
 39+ }
 40+
 41+ $dest = $this->request->getVal( 'dest' );
 42+
 43+ if (!$dest) {
 44+ $wgOut->addWikiMsg( 'lqt_threadrequired' );
 45+ return false;
 46+ }
 47+
 48+ $thread = Threads::withId( $dest );
 49+
 50+ if (!$thread) {
 51+ $wgOut->addWikiMsg( 'lqt_nosuchthread' );
 52+ return false;
 53+ }
 54+
 55+ $this->mDestThread = $thread;
 56+
 57+ return true;
 58+ }
 59+
 60+ function formatThreadField( $field, $threadid ) {
 61+
 62+ if ( !is_object($threadid) ) {
 63+ $t = Threads::withId( $threadid );
 64+ } else {
 65+ $t = $threadid;
 66+ $threadid = $t->id();
 67+ }
 68+
 69+ $out = Xml::hidden( $field, $threadid );
 70+ $out .= LqtView::permalink( $t );
 71+
 72+ return $out;
 73+ }
 74+
 75+ /**
 76+ * @see SpecialPage::getDescription
 77+ */
 78+ function getDescription() {
 79+ wfLoadExtensionMessages( 'LiquidThreads' );
 80+ return wfMsg( 'lqt_merge_thread' );
 81+ }
 82+
 83+ function trySubmit( $data ) {
 84+ // Load data
 85+ $srcThread = $this->mThread;
 86+ $dstThread = $this->mDestThread;
 87+ $newSubject = $dstThread->subject();
 88+ $reason = $data['reason'];
 89+
 90+ $oldTopThread = $srcThread->topmostThread();
 91+ $oldParent = $srcThread->superthread();
 92+
 93+ $this->recursiveSet( $srcThread, $newSubject, $dstThread, $dstThread );
 94+
 95+ $dstThread->addReply( $srcThread );
 96+ $oldParent->removeReply( $srcThread );
 97+
 98+ $oldTopThread->commitRevision( Threads::CHANGE_MERGED_FROM, $srcThread, $reason );
 99+ $dstThread->commitRevision( Threads::CHANGE_MERGED_TO, $srcThread, $reason );
 100+
 101+ $srcTitle = clone $srcThread->article()->getTitle();
 102+ $srcTitle->setFragment( '#'.$srcThread->getAnchorName() );
 103+
 104+ $dstTitle = clone $dstThread->article()->getTitle();
 105+ $dstTitle->setFragment( '#'.$dstThread->getAnchorName() );
 106+
 107+ $srcLink = $this->user->getSkin()->link( $srcTitle, $srcThread->subject() );
 108+ $dstLink = $this->user->getSkin()->link( $dstTitle, $dstThread->subject() );
 109+
 110+ global $wgOut;
 111+ $wgOut->addHTML( wfMsgExt( 'lqt-merge-success', array( 'parseinline', 'replaceafter' ),
 112+ $srcLink, $dstLink ) );
 113+
 114+ return true;
 115+ }
 116+
 117+ function recursiveSet( $thread, $subject, $ancestor, $superthread = false ) {
 118+ $thread->setSubject( $subject );
 119+ $thread->setAncestor( $ancestor->id() );
 120+
 121+ if ($superthread) {
 122+ $thread->setSuperThread( $superthread );
 123+ }
 124+
 125+ $thread->save();
 126+
 127+ foreach( $thread->replies() as $subThread ) {
 128+ $this->recursiveSet( $subThread, $subject, $ancestor, $reason );
 129+ }
 130+ }
 131+
 132+ function getPageName() {
 133+ return 'MergeThread';
 134+ }
 135+
 136+ function getSubmitText() {
 137+ wfLoadExtensionMessages( 'LiquidThreads' );
 138+ return wfMsg( 'lqt-merge-submit' );
 139+ }
 140+}

Status & tagging log