https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113321

Revision: 113321
Author:   kaldari
Date:     2012-03-07 23:23:50 +0000 (Wed, 07 Mar 2012)
Log Message:
-----------
using sweet new 1.19 method! Bodacious! Also making sure that section headers 
(aka subjects) are always handled correctly.

Modified Paths:
--------------
    trunk/extensions/WikiLove/ApiWikiLove.php

Modified: trunk/extensions/WikiLove/ApiWikiLove.php
===================================================================
--- trunk/extensions/WikiLove/ApiWikiLove.php   2012-03-07 23:18:23 UTC (rev 
113320)
+++ trunk/extensions/WikiLove/ApiWikiLove.php   2012-03-07 23:23:50 UTC (rev 
113321)
@@ -1,9 +1,12 @@
 <?php
 class ApiWikiLove extends ApiBase {
        public function execute() {
-               global $wgRequest, $wgWikiLoveLogging, $wgParser;
+               global $wgRequest, $wgWikiLoveLogging, $wgParser, $wgVersion;
 
                $params = $this->extractRequestParams();
+               
+               // In some cases we need the wiki mark-up stripped from the 
subject
+               $strippedSubject = $wgParser->stripSectionName( 
$params['subject'] );
 
                $title = Title::newFromText( $params['title'] );
                if ( is_null( $title ) ) {
@@ -19,22 +22,37 @@
                        $this->saveInDb( $talk, $params['subject'], 
$params['message'], $params['type'], isset( $params['email'] ) ? 1 : 0 );
                }
 
-               // not using section => 'new' here, as we like to give our own 
edit summary
+               // MediaWiki did not allow specifying separate edit summaries 
and section titles until 1.19
+               $oldVersion = version_compare( $wgVersion, '1.18', '<=' );
+               if ( $oldVersion ) {
+                       $apiParamArray = array(
+                               'action' => 'edit',
+                               'title' => $talk->getFullText(),
+                               // need to do this, as Article::replaceSection 
fails for non-existing pages
+                               'appendtext' => ( $talk->exists() ? "\n\n" : '' 
) . 
+                                       wfMsgForContent( 
'newsectionheaderdefaultlevel', $params['subject'] )
+                                       . "\n\n" . $params['text'],
+                               'token' => $params['token'],
+                               'summary' => wfMsgForContent( 
'wikilove-summary', $strippedSubject ),
+                               'notminor' => true
+                       );
+               } else {
+                       $apiParamArray = array(
+                               'action' => 'edit',
+                               'title' => $talk->getFullText(),
+                               'section' => 'new',
+                               'sectiontitle' => $params['subject'],
+                               'text' => $params['text'],
+                               'token' => $params['token'],
+                               'summary' => wfMsgForContent( 
'wikilove-summary', $strippedSubject ),
+                               'notminor' => true
+                       );
+               }
+               
                $api = new ApiMain(
                        new DerivativeRequest(
                                $wgRequest,
-                               array(
-                                       'action'     => 'edit',
-                                       'title'      => $talk->getFullText(),
-                                       // need to do this, as 
Article::replaceSection fails for non-existing pages
-                                       'appendtext' => ( $talk->exists() ? 
"\n\n" : '' ) . 
-                                               wfMsgForContent( 
'newsectionheaderdefaultlevel', $params['subject'] )
-                                               . "\n\n" . $params['text'],
-                                       'token'      => $params['token'],
-                                       'summary'    => wfMsgForContent( 
'wikilove-summary', 
-                                               $wgParser->stripSectionName( 
$params['subject'] ) ),
-                                       'notminor'   => true
-                               ),
+                               $apiParamArray,
                                false // was posted?
                        ),
                        true // enable write?
@@ -43,11 +61,11 @@
                $api->execute();
 
                if ( isset( $params['email'] ) ) {
-                       $this->emailUser( $talk, $params['subject'], 
$params['email'], $params['token'] );
+                       $this->emailUser( $talk, $strippedSubject, 
$params['email'], $params['token'] );
                }
 
                $this->getResult()->addValue( 'redirect', 'pageName', 
$talk->getPrefixedDBkey() );
-               $this->getResult()->addValue( 'redirect', 'fragment', 
Title::escapeFragmentForURL( $params['subject'] ) );
+               $this->getResult()->addValue( 'redirect', 'fragment', 
Title::escapeFragmentForURL( $strippedSubject ) );
                // note that we cannot use Title::makeTitle here as it doesn't 
sanitize the fragment
        }
 


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

Reply via email to