FreedomFighterSparrow has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/361238 )
Change subject: Add option 'hide when empty' to wiki sections in forms ...................................................................... Add option 'hide when empty' to wiki sections in forms If specified for a section and it is empty, its heading will not be created in the wikitext when saving the page through the form. Change-Id: I7ac6ca80848166b517f4afc44368773f091da6c9 --- M includes/PF_FormPrinter.php M includes/PF_PageSection.php M includes/wikipage/PF_WikiPage.php M includes/wikipage/PF_WikiPageSection.php 4 files changed, 31 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms refs/changes/38/361238/1 diff --git a/includes/PF_FormPrinter.php b/includes/PF_FormPrinter.php index cbdf276..b9a20c5 100644 --- a/includes/PF_FormPrinter.php +++ b/includes/PF_FormPrinter.php @@ -1279,7 +1279,10 @@ if ( ( ! $source_is_page ) && $wgRequest ) { $text_per_section = $wgRequest->getArray( '_section' ); $section_text = $text_per_section[trim( $section_name )]; - $wiki_page->addSection( $section_name, $page_section_in_form->getSectionLevel(), $section_text ); + + // $section_options will allow to pass additional options in the future without breaking backword compatibility + $section_options = array( 'isDisplayedEmpty' => $page_section_in_form->isDisplayedEmpty() ); + $wiki_page->addSection( $section_name, $page_section_in_form->getSectionLevel(), $section_text, $section_options ); } $section_text = trim( $section_text ); @@ -1624,4 +1627,4 @@ return $text; } -} \ No newline at end of file +} diff --git a/includes/PF_PageSection.php b/includes/PF_PageSection.php index 3f41377..71b87d1 100644 --- a/includes/PF_PageSection.php +++ b/includes/PF_PageSection.php @@ -14,6 +14,7 @@ private $mIsMandatory = false; private $mIsHidden = false; private $mIsRestricted = false; + private $mIsDisplayedEmpty = true; private $mSectionArgs = array(); static function create( $section_name ) { @@ -42,6 +43,8 @@ $ps->mIsRestricted = !( $wgUser && $wgUser->isAllowed( 'editrestrictedfields' ) ); } elseif ( $component === 'autogrow' ) { $ps->mSectionArgs['autogrow'] = true; + } elseif ( $component === 'hide when empty' ) { + $ps->mIsDisplayedEmpty = false; } $sub_components = array_map( 'trim', explode( '=', $component, 2 ) ); @@ -102,6 +105,10 @@ return $this->mIsRestricted; } + public function isDisplayedEmpty() { + return $this->mIsDisplayedEmpty; + } + public function setSectionArgs( $key, $value ) { $this->mSectionArgs[$key] = $value; } diff --git a/includes/wikipage/PF_WikiPage.php b/includes/wikipage/PF_WikiPage.php index 374ccab..a70cc26 100644 --- a/includes/wikipage/PF_WikiPage.php +++ b/includes/wikipage/PF_WikiPage.php @@ -47,8 +47,8 @@ return null; } - function addSection( $sectionName, $headerLevel, $sectionText ) { - $this->mComponents[] = new PFWikiPageSection( $sectionName, $headerLevel, $sectionText ); + function addSection( $sectionName, $headerLevel, $sectionText, $sectionOptions ) { + $this->mComponents[] = new PFWikiPageSection( $sectionName, $headerLevel, $sectionText, $sectionOptions ); } function addFreeTextSection() { @@ -168,15 +168,17 @@ $pageText .= $this->createTemplateCall( $component ) . "\n"; } } elseif ( get_class( $component ) == 'PFWikiPageSection' ) { - $sectionName = $component->getHeader(); - for ( $i = 0; $i < $component->getHeaderLevel(); $i++ ) { - $sectionName = "=$sectionName="; + if ( $component->getText() !== "" || $component->isDisplayedEmpty() ) { + $sectionName = $component->getHeader(); + for ( $i = 0; $i < $component->getHeaderLevel(); $i++ ) { + $sectionName = "=$sectionName="; + } + $pageText .= "$sectionName\n"; + if ( $component->getText() != '' ) { + $pageText .= $component->getText() . "\n"; + } + $pageText .= "\n"; } - $pageText .= "$sectionName\n"; - if ( $component->getText() != '' ) { - $pageText .= $component->getText() . "\n"; - } - $pageText .= "\n"; } elseif ( get_class( $component ) == 'PFWikiPageFreeText' ) { $freeText = $component->getText(); if ( $this->mFreeTextOnlyInclude ) { diff --git a/includes/wikipage/PF_WikiPageSection.php b/includes/wikipage/PF_WikiPageSection.php index 31beda8..bc8ab4b 100644 --- a/includes/wikipage/PF_WikiPageSection.php +++ b/includes/wikipage/PF_WikiPageSection.php @@ -9,12 +9,17 @@ * Represents a section (header and contents) in a wiki page. */ class PFWikiPageSection { - private $mHeader, $mHeaderLevel, $mText; + private $mHeader, $mHeaderLevel, $mText, $mIsDisplayedEmpty; - function __construct( $sectionName, $headerLevel, $sectionText ) { + function __construct( $sectionName, $headerLevel, $sectionText, $sectionOptions ) { $this->mHeader = $sectionName; $this->mHeaderLevel = $headerLevel; $this->mText = $sectionText; + $this->mIsDisplayedEmpty = $sectionOptions['isDisplayedEmpty']; + } + + function isDisplayedEmpty() { + return $this->mIsDisplayedEmpty; } function getHeader() { -- To view, visit https://gerrit.wikimedia.org/r/361238 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7ac6ca80848166b517f4afc44368773f091da6c9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PageForms Gerrit-Branch: master Gerrit-Owner: FreedomFighterSparrow <freedomfighterspar...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits