http://www.mediawiki.org/wiki/Special:Code/MediaWiki/65236

Revision: 65236
Author:   ishimatsu
Date:     2010-04-18 15:54:13 +0000 (Sun, 18 Apr 2010)

Log Message:
-----------
Upload new multilingual lqt code

Modified Paths:
--------------
    trunk/extensions/MultilingualLiquidThreads/api/ApiFeedLQTThreads.php
    trunk/extensions/MultilingualLiquidThreads/api/ApiQueryLQTThreads.php
    trunk/extensions/MultilingualLiquidThreads/api/ApiThreadAction.php

Modified: trunk/extensions/MultilingualLiquidThreads/api/ApiFeedLQTThreads.php
===================================================================
--- trunk/extensions/MultilingualLiquidThreads/api/ApiFeedLQTThreads.php        
2010-04-18 15:38:28 UTC (rev 65235)
+++ trunk/extensions/MultilingualLiquidThreads/api/ApiFeedLQTThreads.php        
2010-04-18 15:54:13 UTC (rev 65236)
@@ -1,5 +1,4 @@
 <?php
-
 /*
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -28,7 +27,6 @@
  * @ingroup API
  */
 class ApiFeedLQTThreads extends ApiBase {
-
        public function __construct( $main, $action ) {
                parent :: __construct( $main, $action );
        }
@@ -41,7 +39,7 @@
        }
 
        /**
-        * Make a nested call to the API to request watchlist items in the last 
$hours.
+        * Make a nested call to the API to request items in the last $hours.
         * Wrap the result as an RSS/Atom feed.
         */
        public function execute() {
@@ -54,7 +52,7 @@
                $feedTitle = self::createFeedTitle( $params );
                $feedClass = $wgFeedClasses[$params['feedformat']];
                $feedItems = array();
-               
+
                $feedUrl = Title::newMainPage()->getFullURL();
 
                $tables = array( 'thread' );
@@ -181,6 +179,10 @@
                        $root = new Article( Title::newFromText( $thread ) );
                        $thread = Threads::withRoot( $root );
 
+                       if ( ! $thread ) {
+                               continue;
+                       }
+
                        $threadCond = array(
                                'thread_ancestor' => $thread->id(),
                                'thread_id' => $thread->id()

Modified: trunk/extensions/MultilingualLiquidThreads/api/ApiQueryLQTThreads.php
===================================================================
--- trunk/extensions/MultilingualLiquidThreads/api/ApiQueryLQTThreads.php       
2010-04-18 15:38:28 UTC (rev 65235)
+++ trunk/extensions/MultilingualLiquidThreads/api/ApiQueryLQTThreads.php       
2010-04-18 15:54:13 UTC (rev 65236)
@@ -17,27 +17,26 @@
  */
 
 class ApiQueryLQTThreads extends ApiQueryBase {
-
        // Property definitions
        static $propRelations = array(
-                       'id' => 'thread_id',
-                       'subject' => 'thread_subject',
-                       'page' => array(
-                               'namespace' => 'thread_article_namespace',
-                               'title' => 'thread_article_title'
-                       ),
-                       'parent' => 'thread_parent',
-                       'ancestor' => 'thread_ancestor',
-                       'created' => 'thread_created',
-                       'modified' => 'thread_modified',
-                       'author' => array(
-                               'id' => 'thread_author_id',
-                               'name' => 'thread_author_name'
-                       ),
-                       'summaryid' => 'thread_summary_page',
-                       'rootid' => 'thread_root',
-                       'type' => 'thread_type',
-               );
+               'id' => 'thread_id',
+               'subject' => 'thread_subject',
+               'page' => array(
+                       'namespace' => 'thread_article_namespace',
+                       'title' => 'thread_article_title'
+               ),
+               'parent' => 'thread_parent',
+               'ancestor' => 'thread_ancestor',
+               'created' => 'thread_created',
+               'modified' => 'thread_modified',
+               'author' => array(
+                       'id' => 'thread_author_id',
+                       'name' => 'thread_author_name'
+               ),
+               'summaryid' => 'thread_summary_page',
+               'rootid' => 'thread_root',
+               'type' => 'thread_type',
+       );
 
        public function __construct( $query, $moduleName ) {
                parent :: __construct( $query, $moduleName, 'th' );
@@ -83,18 +82,18 @@
                                'thread_article_title', 'thread_summary_page', 
'thread_ancestor',
                                'thread_parent', 'thread_modified', 
'thread_created', 'thread_type',
                                'thread_editedness', 'thread_subject', 
'thread_author_id',
-                               'thread_author_name',
+                               'thread_author_name', 'thread_signature'
                        );
 
                        $this->addFields( $allFields );
                }
 
                $res = $this->select( __METHOD__ );
-               
+
                if ( $params['render'] ) {
                        $threads = Threads::loadFromResult( $res, 
$this->getDB() );
                }
-               
+
                $count = 0;
                foreach ( $res as $row )
                {
@@ -350,6 +349,6 @@
        }
 
        public function getVersion() {
-               return __CLASS__ . '$Id: ApiQueryLQTThreads.php 58150 
2009-10-26 17:38:38Z werdna $';
+               return __CLASS__ . ': $Id: ApiQueryLQTThreads.php 62609 
2010-02-16 22:36:05Z reedy $';
        }
 }

Modified: trunk/extensions/MultilingualLiquidThreads/api/ApiThreadAction.php
===================================================================
--- trunk/extensions/MultilingualLiquidThreads/api/ApiThreadAction.php  
2010-04-18 15:38:28 UTC (rev 65235)
+++ trunk/extensions/MultilingualLiquidThreads/api/ApiThreadAction.php  
2010-04-18 15:54:13 UTC (rev 65236)
@@ -1,231 +1,169 @@
 <?php
 
 class ApiThreadAction extends ApiBase {
-       
-       public function getDescription() {
-               return 'Allows actions to be taken on threads and posts in 
threaded discussions.';
-       }
-       
-       public function getActions() {
-               return array(
-                       'markread' => 'actionMarkRead',
-                       'markunread' => 'actionMarkUnread',
-                       'split' => 'actionSplit',
-                       'merge' => 'actionMerge',
-                       'reply' => 'actionReply', // Not implemented
-                       'newthread' => 'actionNewThread',
-                       'setsubject' => 'actionSetSubject',
-               );
-       }
-       
-       protected function getParamDescription() {
-               return array(
-                       'thread' => 'A list (pipe-separated) of thread IDs or 
titles to act on',
-                       'threadaction' => 'The action to take',
-                       'token' => 'An edit token (from 
?action=query&prop=info&intoken=edit)',
-                       'talkpage' => 'The talkpage to act on (if applicable)',
-                       'subject' => 'The subject to set for the new or split 
thread',
-                       'reason' => 'If applicable, the reason/summary for the 
action',
-                       'newparent' => 'If merging a thread, the ID or title 
for its new parent',
-                       'text' => 'The text of the post to create',
-                       'postlang' => 'post language',
-                       'render' => 'If set, on post/reply methods, the 
top-level thread '.
-                               'after the change will be rendered and returned 
in the result.',
-                       'bump' => 'If set, overrides default behaviour as to 
whether or not to ',
-                               "increase the thread's sort key. If true, sets 
it to current ".
-                               "timestamp. If false, does not set it. Default 
depends on ".
-                               "the action being taken. Presently only works 
for newthread ".
-                               "and reply actions.",
-               );
-       }
-       
-       public function getExamples() {
-               return array(
-               
-               );
-       }
-       
-       public function getAllowedParams() {
-               return array(
-                       'thread' => array(
-                                       ApiBase::PARAM_ISMULTI => true,
-                               ),
-                       'talkpage' => null,
-                       'threadaction' => array(
-                                       ApiBase::PARAM_TYPE => array_keys( 
$this->getActions() ),
-                               ),
-                       'token' => null,
-                       'subject' => null,
-                       'reason' => null,
-                       'newparent' => null,
-                       'text' => null,
-                       'postlang' => null,
-                       'render' => null,
-                       'bump' => null,
-               );
-       }
-       
-       public function mustBePosted() { return true; }
 
-       public function isWriteMode() {
-               return true;
-       }
-       
        public function execute() {
                $params = $this->extractRequestParams();
-               
-               global $wgUser;
-               
-               if ( empty( $params['token'] ) ||
-                               !$wgUser->matchEditToken( $params['token'] ) ) {
-                       $this->dieUsage( 'sessionfailure' );
-                       return;
-               }
-               
+
                if ( empty( $params['threadaction'] ) ) {
-                       $this->dieUsage( 'missing-param', 'action' );
-                       return;
+                       $this->dieUsageMsg( array( 'missingparam', 'action' ) );
                }
-               
+
+               $allowedAllActions = array( 'markread' );
+               $action = $params['threadaction'];
+
                // Pull the threads from the parameters
                $threads = array();
                if ( !empty( $params['thread'] ) ) {
-                       foreach( $params['thread'] as $thread ) {
+                       foreach ( $params['thread'] as $thread ) {
                                $threadObj = null;
                                if ( is_numeric( $thread ) ) {
                                        $threadObj = Threads::withId( $thread );
+                               } elseif ( $thread == 'all' &&
+                                               in_array( $action, 
$allowedAllActions ) ) {
+                                       $threads = array( 'all' );
                                } else {
                                        $title = Title::newFromText( $thread );
                                        $article = new Article( $title );
                                        $threadObj = Threads::withRoot( 
$article );
                                }
-                               
+
                                if ( $threadObj instanceof Thread ) {
                                        $threads[] = $threadObj;
                                }
                        }
                }
-               
+
                // Find the appropriate module
-               $action = $params['threadaction'];
                $actions = $this->getActions();
-               
+
                $method = $actions[$action];
-               
+
                call_user_func_array( array( $this, $method ), array( $threads, 
$params ) );
        }
-       
+
        public function actionMarkRead( $threads, $params ) {
                global $wgUser;
-               
+
                $result = array();
-               
-               foreach( $threads as $t ) {
-                       NewMessages::markThreadAsReadByUser( $t, $wgUser );
-                       $result[] =
-                               array(
+
+               if ( in_array( 'all', $threads ) ) {
+                       NewMessages::markAllReadByUser( $wgUser );
+                       $result[] = array(
+                               'result' => 'Success',
+                               'action' => 'markread',
+                               'threads' => 'all',
+                       );
+               } else {
+                       foreach ( $threads as $t ) {
+                               NewMessages::markThreadAsReadByUser( $t, 
$wgUser );
+                               $result[] = array(
                                        'result' => 'Success',
                                        'action' => 'markread',
                                        'id' => $t->id(),
                                        'title' => 
$t->title()->getPrefixedText()
                                );
+                       }
                }
-               
+
                $this->getResult()->setIndexedTagName( $result, 'thread' );
                $this->getResult()->addValue( null, 'threadactions', $result );
        }
-       
+
        public function actionMarkUnread( $threads, $params ) {
                global $wgUser;
-               
+
                $result = array();
-               
-               foreach( $threads as $t ) {
+
+               foreach ( $threads as $t ) {
                        NewMessages::markThreadAsUnreadByUser( $t, $wgUser );
-                       
-                       $result[] =
-                               array(
-                                       'result' => 'Success',
-                                       'action' => 'markunread',
-                                       'id' => $t->id(),
-                                       'title' => 
$t->title()->getPrefixedText()
-                               );
+
+                       $result[] = array(
+                               'result' => 'Success',
+                               'action' => 'markunread',
+                               'id' => $t->id(),
+                               'title' => $t->title()->getPrefixedText()
+                       );
                }
-               
-               
+
+
                $this->getResult()->setIndexedTagName( $result, 'thread' );
                $this->getResult()->addValue( null, 'threadaction', $result );
        }
-       
+
        public function actionSplit( $threads, $params ) {
                global $wgUser;
-               
-               if ( count($threads) > 1 ) {
+
+               if ( count( $threads ) > 1 ) {
                        $this->dieUsage( 'You may only split one thread at a 
time',
                                        'too-many-threads' );
-                       return;
-               } elseif ( count($threads) < 1 ) {
+               } elseif ( count( $threads ) < 1 ) {
                        $this->dieUsage( 'You must specify a thread to split',
                                        'no-specified-threads' );
-                       return;
                }
-               
+
                $thread = array_pop( $threads );
-               
+
                if ( $thread->isTopmostThread() ) {
                        $this->dieUsage( 'This thread is already a top-level 
thread.',
                                'already-top-level' );
                }
-               
+
                $title = null;
                $article = $thread->article();
-               if ( empty($params['subject'] ) ||
+               if ( empty( $params['subject'] ) ||
                        ! Thread::validateSubject( $params['subject'], $title, 
null, $article ) ) {
-                       
+
                        $this->dieUsage( 'No subject, or an invalid subject, 
was specified',
                                'no-valid-subject' );
                }
-               
+
                $subject = $params['subject'];
-               
+
                // Pull a reason, if applicable.
                $reason = '';
-               if ( !empty($params['reason']) ) {
+               if ( !empty( $params['reason'] ) ) {
                        $reason = $params['reason'];
                }
-               
+
+               // Check if they specified a sortkey
+               $sortkey = null;
+               if ( !empty( $params['sortkey'] ) ) {
+                       $ts = $params['sortkey'];
+                       $ts = wfTimestamp( TS_MW, $ts );
+
+                       $sortkey = $ts;
+               }
+
                // Do the split
-               $thread->split( $subject, $reason );
-               
+               $thread->split( $subject, $reason, $sortkey );
+
                $result = array();
-               $result[] =
-                       array(
-                               'result' => 'Success',
-                               'action' => 'split',
-                               'id' => $thread->id(),
-                               'title' => $thread->title()->getPrefixedText(),
-                               'newsubject' => $subject,
-                       );
-               
+               $result[] = array(
+                       'result' => 'Success',
+                       'action' => 'split',
+                       'id' => $thread->id(),
+                       'title' => $thread->title()->getPrefixedText(),
+                       'newsubject' => $subject,
+               );
+
                $this->getResult()->setIndexedTagName( $result, 'thread' );
                $this->getResult()->addValue( null, 'threadaction', $result );
        }
-       
+
        public function actionMerge( $threads, $params ) {
                global $wgUser;
-               
+
                if ( count( $threads ) < 1 ) {
                        $this->dieUsage( 'You must specify a thread to merge',
                                'no-specified-threads' );
-                       return;
                }
-               
+
                if ( empty( $params['newparent'] ) ) {
                        $this->dieUsage( 'You must specify a new parent thread 
to merge beneath',
-                               'no-parent-thread' );           
-                       return;
+                               'no-parent-thread' );
                }
-               
+
                $newParent = $params['newparent'];
                if ( is_numeric( $newParent ) ) {
                        $newParent = Threads::withId( $newParent );
@@ -234,113 +172,103 @@
                        $article = new Article( $title );
                        $newParent = Threads::withRoot( $article );
                }
-               
+
                if ( !$newParent ) {
-                       $this->dieUsage( 'The parent thread you specified was 
neither the title '.
+                       $this->dieUsage( 'The parent thread you specified was 
neither the title ' .
                                        'of a thread, nor a thread ID.', 
'invalid-parent-thread' );
-                       return;
                }
-               
+
                // Pull a reason, if applicable.
                $reason = '';
-               if ( !empty($params['reason']) ) {
+               if ( !empty( $params['reason'] ) ) {
                        $reason = $params['reason'];
                }
-               
+
                $result = array();
-               
-               foreach( $threads as $thread ) {
+
+               foreach ( $threads as $thread ) {
                        $thread->moveToParent( $newParent, $reason );
-                       $result[] = 
-                               array(
-                                       'result' => 'Success',
-                                       'action' => 'merge',
-                                       'id' => $thread->id(),
-                                       'title' => 
$thread->title()->getPrefixedText(),
-                                       'new-parent-id' => $newParent->id(),
-                                       'new-parent-title' => 
$newParent->title()->getPrefixedText(),
-                                       'new-ancestor-id' => 
$newParent->topmostThread()->id(),
-                                       'new-ancestor-title' => 
$newParent->topmostThread()->title()->getPrefixedText(),
-                               );
+                       $result[] = array(
+                               'result' => 'Success',
+                               'action' => 'merge',
+                               'id' => $thread->id(),
+                               'title' => $thread->title()->getPrefixedText(),
+                               'new-parent-id' => $newParent->id(),
+                               'new-parent-title' => 
$newParent->title()->getPrefixedText(),
+                               'new-ancestor-id' => 
$newParent->topmostThread()->id(),
+                               'new-ancestor-title' => 
$newParent->topmostThread()->title()->getPrefixedText(),
+                       );
                }
-               
+
                $this->getResult()->setIndexedTagName( $result, 'thread' );
                $this->getResult()->addValue( null, 'threadaction', $result );
        }
-       
+
        public function actionNewThread( $threads, $params ) {
                global $wgUser;
-               
+
                // Validate talkpage parameters
                if ( empty( $params['talkpage'] ) ) {
-                       $this->dieUsage( 'You must specify a talk-page to post 
the thread to',
-                               'missing-param' );
-                       
-                       return;
+                       $this->dieUsageMsg( array( 'missingparam', 'talkpage' ) 
);
                }
-               
+
                $talkpageTitle = Title::newFromText( $params['talkpage'] );
-               
-               if (!$talkpageTitle || !LqtDispatch::isLqtPage( $talkpageTitle 
) ) {
-                       $this->dieUsage( 'The talkpage you specified is 
invalid, or does not '.
+
+               if ( !$talkpageTitle || !LqtDispatch::isLqtPage( $talkpageTitle 
) ) {
+                       $this->dieUsage( 'The talkpage you specified is 
invalid, or does not ' .
                                'have discussion threading enabled.', 
'invalid-talkpage' );
-                       return;
                }
                $talkpage = new Article( $talkpageTitle );
-               
+
                // Check if we can post.
                if ( Thread::canUserPost( $wgUser, $talkpage ) !== true ) {
-                       $this->dieUsage( 'You cannot post to the specified 
talkpage, '.
+                       $this->dieUsage( 'You cannot post to the specified 
talkpage, ' .
                                'because it is protected from new posts', 
'talkpage-protected' );
-                       return;
                }
-               
+
                // Validate subject, generate a title
                if ( empty( $params['subject'] ) ) {
-                       $this->dieUsage( 'You must specify a thread subject',
-                               'missing-param' );
-                       return;
+                       $this->dieUsageMsg( array( 'missingparam', 'subject' ) 
);
                }
-               
-               $bump = isset($params['bump']) ? $params['bump'] : null;
-               
+
+               $bump = isset( $params['bump'] ) ? $params['bump'] : null;
+
                $subject = $params['subject'];
                $title = null;
                $subjectOk = Thread::validateSubject( $subject, $title, null, 
$talkpage );
-               
+
                if ( !$subjectOk ) {
                        $this->dieUsage( 'The subject you specified is not 
valid',
                                'invalid-subject' );
-                       
-                       return;
                }
                $article = new Article( $title );
-               
+
                // Check for text
                if ( empty( $params['text'] ) ) {
                        $this->dieUsage( 'You must include text in your post', 
'no-text' );
-                       return;
                }
                $text = $params['text'];
-               
+
                // Generate or pull summary
                $summary = wfMsgForContent( 'lqt-newpost-summary', $subject );
                if ( !empty( $params['reason'] ) ) {
                        $summary = $params['reason'];
                }
-               
+
+               $signature = null;
+               if ( isset( $params['signature'] ) ) {
+                       $signature = $params['signature'];
+               }
+
                // Inform hooks what we're doing
                LqtHooks::$editTalkpage = $talkpage;
                LqtHooks::$editArticle = $article;
                LqtHooks::$editThread = null;
                LqtHooks::$editType = 'new';
                LqtHooks::$editAppliesTo = null;
-               
+
                $token = $params['token'];
-               
-               // Get post language
-               $postlang = $params['postlang'];
-               
+
                // All seems in order. Construct an API edit request
                $requestData = array(
                        'action' => 'edit',
@@ -351,31 +279,153 @@
                        'basetimestamp' => wfTimestampNow(),
                        'format' => 'json',
                );
-               
+
                $editReq = new FauxRequest( $requestData, true );
                $internalApi = new ApiMain( $editReq, true );
                $internalApi->execute();
-               
+
                $editResult = $internalApi->getResultData();
-               
+
                if ( $editResult['edit']['result'] != 'Success' ) {
                        $result = array( 'result' => 'EditFailure', 'details' 
=> $editResult );
                        $this->getResult()->addValue( null, 
$this->getModuleName(), $result );
                        return;
                }
-               
+
                $articleId = $editResult['edit']['pageid'];
-               
+
                $article->getTitle()->resetArticleID( $articleId );
                $title->resetArticleID( $articleId );
+
+               $thread = LqtView::newPostMetadataUpdates(
+                       array( 
+                               'root' => $article,
+                               'talkpage' => $talkpage,
+                               'subject' => $subject,
+                               'signature' => $signature,
+                               'summary' => $summary,
+                               'text' => $text,
+                       ) );
+
+               $maxLag = wfGetLB()->getMaxLag();
+               $maxLag = $maxLag[1];
+
+               if ( $maxLag == - 1 ) {
+                       $maxLag = 0;
+               }
+
+               $result = array(
+                       'result' => 'Success',
+                       'thread-id' => $thread->id(),
+                       'thread-title' => $title->getPrefixedText(),
+                       'max-lag' => $maxLag,
+               );
+
+               if ( !empty( $params['render'] ) ) {
+                       $result['html'] = self::renderThreadPostAction( $thread 
);
+               }
+
+               $result = array( 'thread' => $result );
+
+               $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
+       }
+       
+       public function actionEdit( $threads, $params ) {
+               if ( count($threads) > 1 ) {
+                       $this->dieUsage( 'You may only edit one thread at a 
time',
+                                       'too-many-threads' );
+               } elseif ( count($threads) < 1 ) {
+                       $this->dieUsage( 'You must specify a thread to edit',
+                                       'no-specified-threads' );
+               }
                
-               $thread = LqtView::postEditUpdates( 'new', null, $article, 
$talkpage,
-                                       $subject, $summary, null, $text, $bump, 
$postlang );
+               $thread = array_pop( $threads );
+               $talkpage = $thread->article();
+               
+               $bump = isset( $params['bump'] ) ? $params['bump'] : null;
 
+               // Validate subject
+               $subjectOk = true;
+               if ( !empty($params['subject']) ) {
+                       $subject = $params['subject'];
+                       $title = null;
+                       $subjectOk = empty($subject) ||
+                               Thread::validateSubject( $subject, $title, 
null, $talkpage );
+               } else {
+                       $subject = $thread->subject();
+               }
+
+               if ( !$subjectOk ) {
+                       $this->dieUsage( 'The subject you specified is not 
valid',
+                               'invalid-subject' );
+               }
+               
+               // Check for text
+               if ( empty( $params['text'] ) ) {
+                       $this->dieUsage( 'You must include text in your post', 
'no-text' );
+               }
+               $text = $params['text'];
+               
+               $summary = '';
+               if ( !empty( $params['reason'] ) ) {
+                       $summary = $params['reason'];
+               }
+               
+               $article = $thread->root();
+               $title = $article->getTitle();
+               
+               $signature = null;
+               if ( isset( $params['signature'] ) ) {
+                       $signature = $params['signature'];
+               }
+
+               // Inform hooks what we're doing
+               LqtHooks::$editTalkpage = $talkpage;
+               LqtHooks::$editArticle = $article;
+               LqtHooks::$editThread = $thread;
+               LqtHooks::$editType = 'edit';
+               LqtHooks::$editAppliesTo = null;
+
+               $token = $params['token'];
+               
+               // All seems in order. Construct an API edit request
+               $requestData = array(
+                       'action' => 'edit',
+                       'title' => $title->getPrefixedText(),
+                       'text' => $text,
+                       'summary' => $summary,
+                       'token' => $token,
+                       'basetimestamp' => wfTimestampNow(),
+                       'format' => 'json',
+               );
+
+               $editReq = new FauxRequest( $requestData, true );
+               $internalApi = new ApiMain( $editReq, true );
+               $internalApi->execute();
+
+               $editResult = $internalApi->getResultData();
+
+               if ( $editResult['edit']['result'] != 'Success' ) {
+                       $result = array( 'result' => 'EditFailure', 'details' 
=> $editResult );
+                       $this->getResult()->addValue( null, 
$this->getModuleName(), $result );
+                       return;
+               }
+               
+               $thread = LqtView::editMetadataUpdates(
+                       array( 
+                               'root' => $article,
+                               'thread' => $thread,
+                               'subject' => $subject,
+                               'signature' => $signature,
+                               'summary' => $summary,
+                               'text' => $text,
+                               'bump' => $bump,
+                       ) );
+
                $maxLag = wfGetLB()->getMaxLag();
                $maxLag = $maxLag[1];
-               
-               if ($maxLag == -1) {
+
+               if ( $maxLag == - 1 ) {
                        $maxLag = 0;
                }
 
@@ -385,79 +435,77 @@
                        'thread-title' => $title->getPrefixedText(),
                        'max-lag' => $maxLag,
                );
-               
+
                if ( !empty( $params['render'] ) ) {
                        $result['html'] = self::renderThreadPostAction( $thread 
);
                }
-               
+
                $result = array( 'thread' => $result );
-               
+
                $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
        }
        
        public function actionReply( $threads, $params ) {
                global $wgUser;
-               
+
                // Validate thread parameter
-               if ( count($threads) > 1 ) {
+               if ( count( $threads ) > 1 ) {
                        $this->dieUsage( 'You may only reply to one thread at a 
time',
                                        'too-many-threads' );
-                       return;
-               } elseif ( count($threads) < 1 ) {
+               } elseif ( count( $threads ) < 1 ) {
                        $this->dieUsage( 'You must specify a thread to reply 
to',
                                        'no-specified-threads' );
-                       return;
                }
                $replyTo = array_pop( $threads );
-               
+
                // Check if we can reply to that thread.
                $perm_result = $replyTo->canUserReply( $wgUser );
                if ( $perm_result !== true ) {
-                       $this->dieUsage( "You cannot reply to this thread, 
because the ".
-                               $perm_result." is protected from replies.",
-                               $perm_result.'-protected' );
-                       return;
+                       $this->dieUsage( "You cannot reply to this thread, 
because the " .
+                               $perm_result . " is protected from replies.",
+                               $perm_result . '-protected' );
                }
-               
+
                // Validate text parameter
                if ( empty( $params['text'] ) ) {
                        $this->dieUsage( 'You must include text in your post', 
'no-text' );
-                       return;
                }
-               
+
                $text = $params['text'];
-               
-               $bump = isset($params['bump']) ? $params['bump'] : null;
-               
+
+               $bump = isset( $params['bump'] ) ? $params['bump'] : null;
+
                // Generate/pull summary
                $summary = wfMsgForContent( 'lqt-reply-summary', 
$replyTo->subject(),
                                $replyTo->title()->getPrefixedText() );
-               
+
                if ( !empty( $params['reason'] ) ) {
                        $summary = $params['reason'];
                }
-               
+
+               $signature = null;
+               if ( isset( $params['signature'] ) ) {
+                       $signature = $params['signature'];
+               }
+
                // Grab data from parent
                $talkpage = $replyTo->article();
                $subject = $replyTo->subject();
-               
+
                // Generate a reply title.
                $title = Threads::newReplyTitle( $replyTo, $wgUser );
                $article = new Article( $title );
-               
+
                // Inform hooks what we're doing
                LqtHooks::$editTalkpage = $talkpage;
                LqtHooks::$editArticle = $article;
                LqtHooks::$editThread = null;
                LqtHooks::$editType = 'reply';
                LqtHooks::$editAppliesTo = $replyTo;
-               
+
                // Pull token in
                $token = $params['token'];
-               
-               // Get post language
-               $postlang = $params['postlang'];
-               
+
                // All seems in order. Construct an API edit request
                $requestData = array(
                        'action' => 'edit',
@@ -468,33 +516,40 @@
                        'basetimestamp' => wfTimestampNow(),
                        'format' => 'json',
                );
-               
+
                $editReq = new FauxRequest( $requestData, true );
                $internalApi = new ApiMain( $editReq, true );
                $internalApi->execute();
-               
+
                $editResult = $internalApi->getResultData();
-               
+
                if ( $editResult['edit']['result'] != 'Success' ) {
                        $result = array( 'result' => 'EditFailure', 'details' 
=> $editResult );
                        $this->getResult()->addValue( null, 
$this->getModuleName(), $result );
                        return;
                }
-               
+
                $articleId = $editResult['edit']['pageid'];
                $article->getTitle()->resetArticleID( $articleId );
                $title->resetArticleID( $articleId );
-               
-               $thread = LqtView::postEditUpdates( 'reply', $replyTo, 
$article, $talkpage,
-                                       $subject, $summary, null, $text, $bump, 
$postlang );
-               
+
+               $thread = LqtView::replyMetadataUpdates(
+                       array( 
+                               'root' => $article,
+                               'replyTo' => $replyTo,
+                               'signature' => $signature,
+                               'summary' => $summary,
+                               'text' => $text,
+                               'bump' => $bump,
+                       ) );
+
                $maxLag = wfGetLB()->getMaxLag();
                $maxLag = $maxLag[1];
-               
-               if ($maxLag == -1) {
+
+               if ( $maxLag == - 1 ) {
                        $maxLag = 0;
                }
-                                       
+
                $result = array(
                        'action' => 'reply',
                        'result' => 'Success',
@@ -506,19 +561,19 @@
                        'ancestor-title' => 
$replyTo->topmostThread()->title()->getPrefixedText(),
                        'max-lag' => $maxLag,
                );
-               
+
                if ( !empty( $params['render'] ) ) {
                        $result['html'] = self::renderThreadPostAction( $thread 
);
                }
-               
+
                $result = array( 'thread' => $result );
-               
+
                $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
        }
-       
+
        static function renderThreadPostAction( $thread ) {
                $thread = $thread->topmostThread();
-               
+
                // Set up OutputPage
                global $wgOut, $wgUser, $wgRequest;
                $oldOutputText = $wgOut->getHTML();
@@ -528,70 +583,223 @@
                $article = $thread->root();
                $title = $article->getTitle();
                $view = new LqtView( $wgOut, $article, $title, $wgUser, 
$wgRequest );
-               
+
                $view->showThread( $thread );
 
                $result = $wgOut->getHTML();
                $wgOut->clearHTML();
                $wgOut->addHTML( $oldOutputText );
-               
+
                return $result;
        }
-       
+
        public function actionSetSubject( $threads, $params ) {
                // Validate thread parameter
-               if ( count($threads) > 1 ) {
+               if ( count( $threads ) > 1 ) {
                        $this->dieUsage( 'You may only change the subject of 
one thread at a time',
                                        'too-many-threads' );
-                       return;
-               } elseif ( count($threads) < 1 ) {
+               } elseif ( count( $threads ) < 1 ) {
                        $this->dieUsage( 'You must specify a thread to change 
the subject of',
                                        'no-specified-threads' );
-                       return;
                }
                $thread = array_pop( $threads );
-               
+
                // Validate subject
                if ( empty( $params['subject'] ) ) {
-                       $this->dieUsage( 'You must specify a thread subject',
-                               'missing-param' );
-                       return;
+                       $this->dieUsageMsg( array( 'missingparam', 'subject' ) 
);
                }
-               
+
+               $talkpage = $thread->article();
+
                $subject = $params['subject'];
                $title = null;
                $subjectOk = Thread::validateSubject( $subject, $title, null, 
$talkpage );
-               
+
                if ( !$subjectOk ) {
                        $this->dieUsage( 'The subject you specified is not 
valid',
                                'invalid-subject' );
-                       
-                       return;
                }
-               
+
                $reason = null;
-               
+
                if ( isset( $params['reason'] ) ) {
                        $reason = $params['reason'];
                }
-               
+
                $thread->setSubject( $subject );
                $thread->commitRevision( Threads::CHANGE_EDITED_SUBJECT, 
$thread, $reason );
-               
+
                $result = array(
                        'action' => 'setsubject',
                        'result' => 'success',
                        'thread-id' => $thread->id(),
-                       'thread-title' => $thread->title(),
+                       'thread-title' => $thread->title()->getPrefixedText(),
                        'new-subject' => $subject,
                );
-               
+
                $result = array( 'thread' => $result );
-               
+
                $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
        }
+
+       public function actionSetSortkey( $threads, $params ) {
+               // First check for threads
+               if ( !count( $threads ) ) {
+                       $this->dieUsage( 'You must specify a thread to set the 
sortkey of',
+                                       'no-specified-threads' );
+               }
+
+               // Validate timestamp
+               if ( empty( $params['sortkey'] ) ) {
+                       $this->dieUsage( 'You must specify a valid timestamp 
for the sortkey ' .
+                               'parameter. It should be in the form 
YYYYMMddhhmmss, a ' .
+                               'unix timestamp or "now".', 'invalid-sortkey' );
+               }
+
+               $ts = $params['sortkey'];
+
+               if ( $ts == 'now' ) $ts = wfTimestampNow();
+
+               $ts = wfTimestamp( TS_MW, $ts );
+
+               if ( !$ts ) {
+                       $this->dieUsage( 'You must specify a valid timestamp 
for the sortkey' .
+                               'parameter. It should be in the form 
YYYYMMddhhmmss, a ' .
+                               'unix timestamp or "now".', 'invalid-sortkey' );
+               }
+
+               $reason = null;
+
+               if ( isset( $params['reason'] ) ) {
+                       $reason = $params['reason'];
+               }
+
+               $thread = array_pop( $threads );
+               $thread->setSortkey( $ts );
+               $thread->commitRevision( Threads::CHANGE_ADJUSTED_SORTKEY, 
null, $reason );
+
+               $result = array(
+                       'action' => 'setsortkey',
+                       'result' => 'success',
+                       'thread-id' => $thread->id(),
+                       'thread-title' => $thread->title()->getPrefixedText(),
+                       'new-sortkey' => $ts,
+               );
+
+               $result = array( 'thread' => $result );
+
+               $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
+       }
        
+       public function getDescription() {
+               return 'Allows actions to be taken on threads and posts in 
threaded discussions.';
+       }
+
+       public function getActions() {
+               return array(
+                       'markread' => 'actionMarkRead',
+                       'markunread' => 'actionMarkUnread',
+                       'split' => 'actionSplit',
+                       'merge' => 'actionMerge',
+                       'reply' => 'actionReply',
+                       'newthread' => 'actionNewThread',
+                       'setsubject' => 'actionSetSubject',
+                       'setsortkey' => 'actionSetSortkey',
+                       'edit' => 'actionEdit',
+               );
+       }
+
+       public function getParamDescription() {
+               return array(
+                       'thread' => 'A list (pipe-separated) of thread IDs or 
titles to act on',
+                       'threadaction' => 'The action to take',
+                       'token' => 'An edit token (from 
?action=query&prop=info&intoken=edit)',
+                       'talkpage' => 'The talkpage to act on (if applicable)',
+                       'subject' => 'The subject to set for the new or split 
thread',
+                       'reason' => 'If applicable, the reason/summary for the 
action',
+                       'newparent' => 'If merging a thread, the ID or title 
for its new parent',
+                       'text' => 'The text of the post to create',
+                       'render' => 'If set, on post/reply methods, the 
top-level thread ' .
+                               'after the change will be rendered and returned 
in the result.',
+                       'bump' => 'If set, overrides default behaviour as to 
whether or not to ',
+                               "increase the thread's sort key. If true, sets 
it to current " .
+                               "timestamp. If false, does not set it. Default 
depends on " .
+                               "the action being taken. Presently only works 
for newthread " .
+                               "and reply actions.",
+                       'sortkey' => "Specifies the timestamp to which to set a 
thread's " .
+                                       "sort  key. Must be in the form 
YYYYMMddhhmmss, " .
+                                       "a unix timestamp or 'now'.",
+                       'signature' => 'Specifies the signature to use for that 
post. Can be ' .
+                                       'NULL to specify the default signature',
+               );
+       }
+       
+       public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array( 
+                       array( 'missingparam', 'action' ),
+                       array( 'missingparam', 'talkpage' ),
+                       array( 'missingparam', 'subject' ),
+                       array( 'code' => 'too-many-threads', 'info' => 'You may 
only split one thread at a time' ),
+                       array( 'code' => 'no-specified-threads', 'info' => 'You 
must specify a thread to split' ),
+                       array( 'code' => 'already-top-level', 'info' => 'This 
thread is already a top-level thread.' ),
+                       array( 'code' => 'no-valid-subject', 'info' => 'No 
subject, or an invalid subject, was specified' ),
+                       array( 'code' => 'no-specified-threads', 'info' => 'You 
must specify a thread to merge' ),
+                       array( 'code' => 'no-parent-thread', 'info' => 'You 
must specify a new parent thread to merge beneath' ),
+                       array( 'code' => 'invalid-parent-thread', 'info' => 
'The parent thread you specified was neither the title of a thread, nor a 
thread ID.' ),
+                       array( 'code' => 'invalid-talkpage', 'info' => 'The 
talkpage you specified is invalid, or does not have discussion threading 
enabled.' ),
+                       array( 'code' => 'talkpage-protected', 'info' => 'You 
cannot post to the specified talkpage, because it is protected from new posts' 
),
+                       array( 'code' => 'invalid-subject', 'info' => 'The 
subject you specified is not valid' ),
+                       array( 'code' => 'no-text', 'info' => 'You must include 
text in your post' ),
+                       array( 'code' => 'too-many-threads', 'info' => 'You may 
only edit one thread at a time' ),
+                       array( 'code' => 'invalid-subject', 'info' => 'You must 
specify a thread to edit' ),
+                       array( 'code' => 'no-specified-threads', 'info' => 'You 
must specify a thread to reply to' ),
+                       array( 'code' => 'perm_result-protected', 'info' => 
'You cannot reply to this thread, because the perm_result is protected from 
replies.' ),
+                       array( 'code' => 'too-many-threads', 'info' => 'You may 
only change the subject of one thread at a time' ),
+                       array( 'code' => 'no-specified-threads', 'info' => 'You 
must specify a thread to change the subject of' ),
+                       array( 'code' => 'no-specified-threads', 'info' => 'You 
must specify a thread to set the sortkey of' ),
+                       array( 'code' => 'invalid-sortkey', 'info' => 'You must 
specify a valid timestamp for the sortkey parameter. It should be in the form 
YYYYMMddhhmmss, a unix timestamp or "now".' ),
+               ) );
+       }
+
+       public function getExamples() {
+               return array(
+               );
+       }
+       
+       public function getTokenSalt() {
+               return '';
+       }
+
+       public function getAllowedParams() {
+               return array(
+                       'thread' => array(
+                               ApiBase::PARAM_ISMULTI => true,
+                       ),
+                       'talkpage' => null,
+                       'threadaction' => array(
+                               ApiBase::PARAM_TYPE => array_keys( 
$this->getActions() ),
+                       ),
+                       'token' => null,
+                       'subject' => null,
+                       'reason' => null,
+                       'newparent' => null,
+                       'text' => null,
+                       'render' => null,
+                       'bump' => null,
+                       'sortkey' => null,
+                       'signature' => null,
+               );
+       }
+
+       public function mustBePosted() { 
+               return true;
+       }
+
+       public function isWriteMode() {
+               return true;
+       }
+
        public function getVersion() {
-               return __CLASS__ . ': $Id: $';
+               return __CLASS__ . ': $Id: ApiThreadAction.php 62684 2010-02-19 
00:48:59Z werdna $';
        }
 }



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to