r113321 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113320‎ | r113321 | r113322 >
Date:23:23, 7 March 2012
Author:kaldari
Status:reverted (Comments)
Tags:gerritmigration 
Comment:
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) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/ApiWikiLove.php
@@ -1,9 +1,12 @@
22 <?php
33 class ApiWikiLove extends ApiBase {
44 public function execute() {
5 - global $wgRequest, $wgWikiLoveLogging, $wgParser;
 5+ global $wgRequest, $wgWikiLoveLogging, $wgParser, $wgVersion;
66
77 $params = $this->extractRequestParams();
 8+
 9+ // In some cases we need the wiki mark-up stripped from the subject
 10+ $strippedSubject = $wgParser->stripSectionName( $params['subject'] );
811
912 $title = Title::newFromText( $params['title'] );
1013 if ( is_null( $title ) ) {
@@ -19,22 +22,37 @@
2023 $this->saveInDb( $talk, $params['subject'], $params['message'], $params['type'], isset( $params['email'] ) ? 1 : 0 );
2124 }
2225
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+
2453 $api = new ApiMain(
2554 new DerivativeRequest(
2655 $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,
3957 false // was posted?
4058 ),
4159 true // enable write?
@@ -43,11 +61,11 @@
4462 $api->execute();
4563
4664 if ( isset( $params['email'] ) ) {
47 - $this->emailUser( $talk, $params['subject'], $params['email'], $params['token'] );
 65+ $this->emailUser( $talk, $strippedSubject, $params['email'], $params['token'] );
4866 }
4967
5068 $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 ) );
5270 // note that we cannot use Title::makeTitle here as it doesn't sanitize the fragment
5371 }
5472

Follow-up revisions

RevisionCommit summaryAuthorDate
r114404Revert r113321, unreviewed....catrope20:31, 21 March 2012

Comments

#Comment by Kaldari (talk | contribs)   21:44, 27 March 2012

Status & tagging log