From: Ryan Kaldari Date: Tue, 20 Dec 2011 04:15:21 +0000 (+0000) Subject: adding sectiontitle/wgSectionTitle as a new parameter for page editing (so that it... X-Git-Tag: 1.31.0-rc.0~25888 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22lang_raccourcis%22%2C%22module=%24nom_module%22%29%20.%20%22?a=commitdiff_plain;h=ac64223568a09e3072c15b81226ed873a10179e1;p=lhc%2Fweb%2Fwiklou.git adding sectiontitle/wgSectionTitle as a new parameter for page editing (so that it can be set separately from the edit summary). For right now, this is just for API use, and thus isnt used in the form. As soon as 1.19 is out the door, we should change the form to use this as well. The current implementation is designed to be completely backward-compatible and non-disruptive --- diff --git a/includes/EditPage.php b/includes/EditPage.php index 52831dd176..f821af3e16 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -91,7 +91,7 @@ class EditPage { var $save = false, $preview = false, $diff = false; var $minoredit = false, $watchthis = false, $recreate = false; var $textbox1 = '', $textbox2 = '', $summary = '', $nosummary = false; - var $edittime = '', $section = '', $starttime = ''; + var $edittime = '', $section = '', $sectiontitle = '', $starttime = ''; var $oldid = 0, $editintro = '', $scrolltop = null, $bot = true; # Placeholders for text injection by hooks (must be HTML) @@ -480,7 +480,7 @@ class EditPage { } /** - * @todo document + * This function collects the form data and uses it to populate various member variables. * @param $request WebRequest */ function importFormData( &$request ) { @@ -510,15 +510,25 @@ class EditPage { # Truncate for whole multibyte characters. +5 bytes for ellipsis $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250 ); - # Remove extra headings from summaries and new sections. - $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary); + # If the summary consists of a heading, e.g. '==Foobar==', extract the title from the + # header syntax, e.g. 'Foobar'. This is mainly an issue when we are using wpSummary for + # section titles. + $this->summary = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary ); + + # Treat sectiontitle the same way as summary. + # Note that wpSectionTitle is not yet a part of the actual edit form, as wpSummary is + # currently doing double duty as both edit summary and section title. Right now this + # is just to allow API edits to work around this limitation, but this should be + # incorporated into the actual edit form when EditPage is rewritten (Bugs 18654, 26312). + $this->sectiontitle = $wgLang->truncate( $request->getText( 'wpSectionTitle' ), 250 ); + $this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle ); $this->edittime = $request->getVal( 'wpEdittime' ); $this->starttime = $request->getVal( 'wpStarttime' ); $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' ); - if ($this->textbox1 === '' && $request->getVal( 'wpTextbox1' ) === null) { + if ( $this->textbox1 === '' && $request->getVal( 'wpTextbox1' ) === null ) { // wpTextbox1 field is missing, possibly due to being "too big" // according to some filter rules such as Suhosin's setting for // suhosin.request.max_value_length (d'oh) @@ -585,19 +595,24 @@ class EditPage { } else { # Not a posted form? Start with nothing. wfDebug( __METHOD__ . ": Not a posted form.\n" ); - $this->textbox1 = ''; - $this->summary = ''; - $this->edittime = ''; - $this->starttime = wfTimestampNow(); - $this->edit = false; - $this->preview = false; - $this->save = false; - $this->diff = false; - $this->minoredit = false; - $this->watchthis = $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters - $this->recreate = false; - + $this->textbox1 = ''; + $this->summary = ''; + $this->sectiontitle = ''; + $this->edittime = ''; + $this->starttime = wfTimestampNow(); + $this->edit = false; + $this->preview = false; + $this->save = false; + $this->diff = false; + $this->minoredit = false; + $this->watchthis = $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters + $this->recreate = false; + + // When creating a new section, we can preload a section title by passing it as the + // preloadtitle parameter in the URL (Bug 13100) if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) { + $this->sectiontitle = $request->getVal( 'preloadtitle' ); + // Once wpSummary isn't being use for setting section titles, we should delete this. $this->summary = $request->getVal( 'preloadtitle' ); } elseif ( $this->section != 'new' && $request->getVal( 'summary' ) ) { @@ -1116,16 +1131,32 @@ class EditPage { $text = $this->textbox1; $result['sectionanchor'] == ''; - if ( $this->section == 'new' && $this->summary != '' ) { - $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $text; - - # Jump to the new section - $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->summary ); - - # This is a new section, so create a link to the new section - # in the revision summary. - $cleanSummary = $wgParser->stripSectionName( $this->summary ); - $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary ); + if ( $this->section == 'new' ) { + if ( $this->sectiontitle != '' ) { + // Insert the section title above the content. + $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->sectiontitle ) . "\n\n" . $text; + + // Jump to the new section + $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle ); + + // If no edit summary was specified, create one automatically from the section + // title and have it link to the new section. Otherwise, respect the summary as + // passed. + if ( $this->summary == '' ) { + $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle ); + $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSectionTitle ); + } + } elseif ( $this->summary != '' ) { + // Insert the section title above the content. + $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $text; + + // Jump to the new section + $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->summary ); + + // Create a link to the new section from the edit summary. + $cleanSummary = $wgParser->stripSectionName( $this->summary ); + $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary ); + } } $status->value = self::AS_SUCCESS_NEW_ARTICLE; diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 5179075e71..cfbf4ae39a 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -181,6 +181,10 @@ class ApiEditPage extends ApiBase { if ( !is_null( $params['summary'] ) ) { $reqArr['wpSummary'] = $params['summary']; } + + if ( !is_null( $params['sectiontitle'] ) ) { + $reqArr['wpSectionTitle'] = $params['sectiontitle']; + } // Watch out for basetimestamp == '' // wfTimestamp() treats it as NOW, almost certainly causing an edit conflict @@ -404,6 +408,10 @@ class ApiEditPage extends ApiBase { ApiBase::PARAM_REQUIRED => true ), 'section' => null, + 'sectiontitle' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => false, + ), 'text' => null, 'token' => null, 'summary' => null, @@ -453,6 +461,7 @@ class ApiEditPage extends ApiBase { return array( 'title' => 'Page title', 'section' => 'Section number. 0 for the top section, \'new\' for a new section', + 'sectiontitle' => 'The title for a new section', 'text' => 'Page content', 'token' => array( 'Edit token. You can get one of these through prop=info.', 'The token should always be sent as the last parameter, or at least, after the text parameter'