wfProfileOut( __METHOD__ );
}
+ /**
+ * Extract the section title from current section text, if any.
+ *
+ * @param string $text
+ * @return Mixed|string or false
+ */
+ public static function extractSectionTitle( $text ) {
+ preg_match( "/^(=+)(.+)\\1/mi", $text, $matches );
+ if ( !empty( $matches[2] ) ) {
+ global $wgParser;
+ return $wgParser->stripSectionName(trim($matches[2]));
+ } else {
+ return false;
+ }
+ }
+
protected function showHeader() {
global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
if ( $this->isConflict ) {
if ( $this->section != '' && $this->section != 'new' ) {
$matches = array();
if ( !$this->summary && !$this->preview && !$this->diff ) {
- preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1, $matches );
- if ( !empty( $matches[2] ) ) {
- global $wgParser;
- $this->summary = "/* " .
- $wgParser->stripSectionName(trim($matches[2])) .
- " */ ";
+ $sectionTitle = self::extractSectionTitle( $this->textbox1 );
+ if ( $sectionTitle !== false ) {
+ $this->summary = "/* $sectionTitle */ ";
}
}
}
--- /dev/null
+<?php
+
+class EditPageTest extends MediaWikiTestCase {
+
+ /**
+ * @dataProvider dataExtractSectionTitle
+ */
+ function testExtractSectionTitle( $section, $title ) {
+ $extracted = EditPage::extractSectionTitle( $section );
+ $this->assertEquals( $title, $extracted );
+ }
+
+ function dataExtractSectionTitle() {
+ return array(
+ array(
+ "== Test ==\n\nJust a test section.",
+ "Test"
+ ),
+ array(
+ "An initial section, no header.",
+ false
+ ),
+ array(
+ "An initial section with a fake heder (bug 32617)\n\n== Test == ??\nwtf",
+ false
+ ),
+ array(
+ "== Section ==\nfollowed by a fake == Non-section == ??\nnoooo",
+ "Section"
+ )
+ );
+ }
+}