Index: trunk/extensions/WikiLove/ApiWikiLove.php |
— | — | @@ -1,9 +1,12 @@ |
2 | 2 | <?php |
3 | 3 | class ApiWikiLove extends ApiBase { |
4 | 4 | public function execute() { |
5 | | - global $wgRequest, $wgWikiLoveLogging, $wgParser; |
| 5 | + global $wgRequest, $wgWikiLoveLogging, $wgParser, $wgVersion; |
6 | 6 | |
7 | 7 | $params = $this->extractRequestParams(); |
| 8 | + |
| 9 | + // In some cases we need the wiki mark-up stripped from the subject |
| 10 | + $strippedSubject = $wgParser->stripSectionName( $params['subject'] ); |
8 | 11 | |
9 | 12 | $title = Title::newFromText( $params['title'] ); |
10 | 13 | if ( is_null( $title ) ) { |
— | — | @@ -19,22 +22,37 @@ |
20 | 23 | $this->saveInDb( $talk, $params['subject'], $params['message'], $params['type'], isset( $params['email'] ) ? 1 : 0 ); |
21 | 24 | } |
22 | 25 | |
23 | | - // not using section => 'new' here, as we like to give our own edit summary |
| 26 | + // MediaWiki did not allow specifying separate edit summaries and section titles until 1.19 |
| 27 | + $oldVersion = version_compare( $wgVersion, '1.18', '<=' ); |
| 28 | + if ( $oldVersion ) { |
| 29 | + $apiParamArray = array( |
| 30 | + 'action' => 'edit', |
| 31 | + 'title' => $talk->getFullText(), |
| 32 | + // need to do this, as Article::replaceSection fails for non-existing pages |
| 33 | + 'appendtext' => ( $talk->exists() ? "\n\n" : '' ) . |
| 34 | + wfMsgForContent( 'newsectionheaderdefaultlevel', $params['subject'] ) |
| 35 | + . "\n\n" . $params['text'], |
| 36 | + 'token' => $params['token'], |
| 37 | + 'summary' => wfMsgForContent( 'wikilove-summary', $strippedSubject ), |
| 38 | + 'notminor' => true |
| 39 | + ); |
| 40 | + } else { |
| 41 | + $apiParamArray = array( |
| 42 | + 'action' => 'edit', |
| 43 | + 'title' => $talk->getFullText(), |
| 44 | + 'section' => 'new', |
| 45 | + 'sectiontitle' => $params['subject'], |
| 46 | + 'text' => $params['text'], |
| 47 | + 'token' => $params['token'], |
| 48 | + 'summary' => wfMsgForContent( 'wikilove-summary', $strippedSubject ), |
| 49 | + 'notminor' => true |
| 50 | + ); |
| 51 | + } |
| 52 | + |
24 | 53 | $api = new ApiMain( |
25 | 54 | new DerivativeRequest( |
26 | 55 | $wgRequest, |
27 | | - array( |
28 | | - 'action' => 'edit', |
29 | | - 'title' => $talk->getFullText(), |
30 | | - // need to do this, as Article::replaceSection fails for non-existing pages |
31 | | - 'appendtext' => ( $talk->exists() ? "\n\n" : '' ) . |
32 | | - wfMsgForContent( 'newsectionheaderdefaultlevel', $params['subject'] ) |
33 | | - . "\n\n" . $params['text'], |
34 | | - 'token' => $params['token'], |
35 | | - 'summary' => wfMsgForContent( 'wikilove-summary', |
36 | | - $wgParser->stripSectionName( $params['subject'] ) ), |
37 | | - 'notminor' => true |
38 | | - ), |
| 56 | + $apiParamArray, |
39 | 57 | false // was posted? |
40 | 58 | ), |
41 | 59 | true // enable write? |
— | — | @@ -43,11 +61,11 @@ |
44 | 62 | $api->execute(); |
45 | 63 | |
46 | 64 | if ( isset( $params['email'] ) ) { |
47 | | - $this->emailUser( $talk, $params['subject'], $params['email'], $params['token'] ); |
| 65 | + $this->emailUser( $talk, $strippedSubject, $params['email'], $params['token'] ); |
48 | 66 | } |
49 | 67 | |
50 | 68 | $this->getResult()->addValue( 'redirect', 'pageName', $talk->getPrefixedDBkey() ); |
51 | | - $this->getResult()->addValue( 'redirect', 'fragment', Title::escapeFragmentForURL( $params['subject'] ) ); |
| 69 | + $this->getResult()->addValue( 'redirect', 'fragment', Title::escapeFragmentForURL( $strippedSubject ) ); |
52 | 70 | // note that we cannot use Title::makeTitle here as it doesn't sanitize the fragment |
53 | 71 | } |
54 | 72 | |