EBernhardson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/103064


Change subject: Simplify header and edit-header templates
......................................................................

Simplify header and edit-header templates

Change-Id: I1a7ba4ab9e19bed34a9e17e95d321a0d909deedd
---
M includes/Block/Header.php
M templates/edit-header.html.php
M templates/header.html.php
3 files changed, 84 insertions(+), 96 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/64/103064/1

diff --git a/includes/Block/Header.php b/includes/Block/Header.php
index 4dec609..61e3d00 100644
--- a/includes/Block/Header.php
+++ b/includes/Block/Header.php
@@ -19,6 +19,7 @@
 class HeaderBlock extends AbstractBlock {
 
        protected $header;
+       protected $origHeader;
        protected $needCreate = false;
        protected $supportedActions = array( 'edit-header' );
 
@@ -42,7 +43,7 @@
                );
 
                if ( $found ) {
-                       $this->header = reset( $found );
+                       $this->header = $this->origHeader = reset( $found );
                }
 
                $this->permissions = new RevisionActionPermissions( 
Container::get( 'flow_actions' ), $user );
@@ -147,16 +148,34 @@
                        }
 
                        $templating->render( "flow:board-history.html.php", 
$tplVars );
-               } else {
-                       $templating->getOutput()->addModuleStyles( array( 
'ext.flow.header' ) );
-                       $templating->getOutput()->addModules( array( 
'ext.flow.header' ) );
-                       $templateName = ( $this->action == 'edit-header' ) ? 
'edit-header' : 'header';
-                       $templating->render( "flow:$templateName.html.php", 
array(
+                       return;
+               }
+               $templating->getOutput()->addModuleStyles( array( 
'ext.flow.header' ) );
+               $templating->getOutput()->addModules( array( 'ext.flow.header' 
) );
+               if ( $this->action === 'edit-header' ) {
+                       $tplVars = array(
                                'block' => $this,
-                               'workflow' => $this->workflow,
-                               'header' => $this->header,
-                               'user' => $this->user,
-                       ) );
+                               'content' => '',
+                               'formUrl' => $templating->generateUrl( 
$this->workflow, 'edit-header' ),
+                               'revisionId' => '',
+                       );
+                       if ( $this->header ) {
+                               // On a submitted but failed form $this->header 
will have a unique unsaved rev id
+                               $tplVars['content'] = $templating->getContent( 
$this->header, 'wikitext', $this->user );
+                               $tplVars['revisionId'] = 
$this->origHeader->getRevisionId()->getHex();
+                       }
+                       $templating->render( "flow:edit-header.html.php", 
$tplVars );
+               } else {
+                       // default view action
+                       $tplVars = array(
+                               'block' => $this,
+                               'content' => '',
+                               'editUrl' => $templating->generateUrl( 
$this->workflow, 'edit-header' ),
+                       );
+                       if ( $this->header ) {
+                               $tplVars['content'] = $templating->getContent( 
$this->header, 'html', $this->user );
+                       }
+                       $templating->render( "flow:header.html.php", $tplVars );
                }
        }
 
diff --git a/templates/edit-header.html.php b/templates/edit-header.html.php
index 57ce488..ec69ef3 100644
--- a/templates/edit-header.html.php
+++ b/templates/edit-header.html.php
@@ -1,53 +1,42 @@
 <?php
+/**
+ * Variables passed in:
+ *
+ *     $block - instance of Flow\Block\Block
+ *     $content - The content of the header, as wikitext
+ *     $formUrl - String url for form submission
+ *     $revisionId - The id of the most recent header for this block
+ */
 
-// owning workflow
-echo Html::openElement( 'div', array(
-       'id' => 'flow-header',
-) );
-echo Html::openElement( 'div', array(
-       'class' => 'flow-edit-header-form flow-element-container'
-) );
-echo Html::openElement( 'form', array(
-       'method' => 'POST',
-       'action' => $this->generateUrl( $workflow, 'edit-header' ),
-       'class' => 'flow-header-form',
-) );
+$errors = array();
 if ( $block->hasErrors() ) {
-       echo '<ul>';
        foreach ( $block->getErrors() as $error ) {
-               echo '<li>', $block->getErrorMessage( $error )->escaped() . 
'</li>';
+               $errors[] = $block->getErrorMessage( $error )->escaped();
        }
-       echo '</ul>';
 }
 
-echo Html::element( 'input', array( 'type' => 'hidden', 'name' => 
'wpEditToken', 'value' => $editToken) );
-if ( $header ) {
-       echo Html::element( 'input', array(
-               'type' => 'hidden',
-               'name' => $block->getName()."[prev_revision]",
-               'value' => $header->getRevisionId()->getHex(),
-       ) );
-}
+?>
 
-echo Html::textarea(
-       $block->getName() . '[content]',
-       $header ? $this->getContent( $header, 'wikitext', $user ) : '',
-       array(
-               'class' => 'mw-ui-input',
-               'rows' => '10',
-               'data-header-id' => $header ? 
$header->getRevisionId()->getHex() : ''
-       )
-);
-echo Html::openElement( 'div', array(
-       'class' => 'flow-edit-header-controls',
-) );
-
-echo Html::element( 'input', array(
-       'type' => 'submit',
-       'class' => 'mw-ui-button mw-ui-constructive',
-       'value' => wfMessage( 'flow-edit-header-submit' )->plain(),
-) );
-echo Html::closeElement( 'div' );
-echo Html::closeElement( 'form' );
-echo Html::closeElement( 'div' );
-echo Html::closeElement( 'div' );
+<div id="flow-header">
+       <div class="flow-edit-header-form flow-element-container">
+               <form method="POST" action="<?= htmlspecialchars( $formUrl ) 
?>" class="flow-header-form">
+                       <?php if ( $errors ): ?>
+                               <ul><li><?= implode( '</li><li>', $errors ) 
?></li></ul>
+                       <?php endif; ?>
+                       <input type="hidden" name="wpEditToken" value="<?= 
htmlspecialchars( $editToken ) ?>">
+                       <?php if ( $revisionId ): ?>
+                               <input type="hidden"
+                                      name="<?= htmlspecialchars( 
$block->getName() ) ?>[prev_revision]"
+                                          value="<?= htmlspecialchars( 
$revisionId ) ?>">
+                       <?php endif ?>
+                       <textarea name="<?= htmlspecialchars( $block->getName() 
) ?>[content]"
+                                 class="mw-ui-input" rows="10"
+                                         data-header-id="<?= htmlspecialchars( 
$revisionId ) ?>"
+                       ><?= htmlspecialchars( $content ) ?></textarea>
+                       <div class="flow-edit-header-controls">
+                               <input type="submit" class="mw-ui-button 
mw-ui-constructive"
+                                          value="<?= wfMessage( 
'flow-edit-header-submit' )->escaped() ?>">
+                       </div>
+               </form>
+       </div>
+</div>
diff --git a/templates/header.html.php b/templates/header.html.php
index f7c3fa4..89d991b 100644
--- a/templates/header.html.php
+++ b/templates/header.html.php
@@ -1,45 +1,25 @@
 <?php
-echo Html::openElement(
-       'div',
-       array(
-               'id' => 'flow-header',
-               'class' => 'flow-element-container',
-       )
-);
+/**
+ * Variables passed in:
+ *
+ *     $block - instance of Flow\Block\Block
+ *     $content - Fully escaped header content for display
+ *     $editUrl - Url to visit to edit this header
+ */
+?>
 
-if ( $block->hasErrors( 'content' ) ) {
-       echo Html::element(
-               'p',
-               array( 'id' => 'flow-header-error' ),
-               $block->getErrorMessage( 'content' )->text()
-       );
-}
+<div id="flow-header" class="flow-element-container">
+       <?php if ( $error = $block->getErrorMessage( 'content' ) ): ?>
+               <p id="flow-header-error"><?= $error->escaped() ?></p>
+       <?php endif ?>
 
-if ( $header ) {
-       $headerContent = $this->getContent( $header, 'html', $user );
-       $class = 'flow-header-exists';
-} else {
-       $headerContent = wfMessage( 'flow-header-empty' )->parse();
-       $class = 'flow-header-empty';
-}
+       <div id="flow-header-content" class="<?= $content ? 
'flow-header-exists' : 'flow-header-empty' ?>">
+               <?= $content ? $content : wfMessage( 'flow-header-empty' 
)->ecaped() ?>
+       </div>
 
-echo Html::rawElement(
-       'div',
-       array(
-               'id' => 'flow-header-content',
-               'class' => $class,
-       ),
-       $headerContent
-);
-
-echo Html::element(
-       'a',
-       array(
-               'href' => $this->generateUrl( $workflow, 'edit-header' ),
-               'class' => 'flow-header-edit-link flow-icon 
flow-icon-bottom-aligned',
-               'title' => wfMessage( 'flow-edit-header-link' )->text()
-       ),
-       wfMessage( 'flow-edit-header-link' )->text()
-);
-
-echo Html::closeElement( 'div' );
+       <a href="<?= htmlspecialchars( $editUrl ) ?>"
+          class="flow-header-edit-link flow-icon flow-icon-bottom-aligned"
+          title="<?= wfMessage( 'flow-edit-header-link' )->escaped() ?>">
+               <?= wfMessage( 'flow-edit-header-link' )->escaped() ?>
+       </a>
+</div>

-- 
To view, visit https://gerrit.wikimedia.org/r/103064
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a7ba4ab9e19bed34a9e17e95d321a0d909deedd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to