jenkins-bot has submitted this change and it was merged.

Change subject: Modify Drafts::display to return HTML instead of a count
......................................................................


Modify Drafts::display to return HTML instead of a count

Change-Id: I4464cc41e89bda872eb1ef5ec4ba8503772dc6c8
---
M Drafts.classes.php
M Drafts.hooks.php
M SpecialDrafts.php
3 files changed, 63 insertions(+), 78 deletions(-)

Approvals:
  Addshore: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Drafts.classes.php b/Drafts.classes.php
index 8c03932..28383cd 100644
--- a/Drafts.classes.php
+++ b/Drafts.classes.php
@@ -169,44 +169,39 @@
         *
         * @param $title Title [optional] Title of article, defaults to all 
articles
         * @param $userID Integer: [optional] ID of user, defaults to current 
user
-        * @return int Number of drafts in the table
+        * @return string HTML to be shown to the user
         */
        public static function display( $title = null, $userID = null ) {
-               global $wgOut, $wgRequest, $wgUser, $wgLang;
+               global $wgRequest, $wgUser, $wgLang;
                // Gets draftID
                $currentDraft = Draft::newFromID( $wgRequest->getIntOrNull( 
'draft' ) );
                // Output HTML for list of drafts
                $drafts = Drafts::get( $title, $userID );
                if ( count( $drafts ) > 0 ) {
-                       // Internationalization
+                       $html = '';
 
                        // Build XML
-                       $wgOut->addHTML(
-                               Xml::openElement( 'table',
-                                       array(
-                                               'cellpadding' => 5,
-                                               'cellspacing' => 0,
-                                               'width' => '100%',
-                                               'border' => 0,
-                                               'id' => 'drafts-list-table'
-                                       )
+                       $html .= Xml::openElement( 'table',
+                               array(
+                                       'cellpadding' => 5,
+                                       'cellspacing' => 0,
+                                       'width' => '100%',
+                                       'border' => 0,
+                                       'id' => 'drafts-list-table'
                                )
                        );
-                       $wgOut->addHTML( Xml::openElement( 'tr' ) );
-                       $wgOut->addHTML(
-                               Xml::element( 'th',
-                                       array( 'width' => '75%', 'nowrap' => 
'nowrap' ),
-                                       wfMessage( 'drafts-view-article' 
)->text()
-                               )
+
+                       $html .= Xml::openElement( 'tr' );
+                       $html .= Xml::element( 'th',
+                               array( 'width' => '75%', 'nowrap' => 'nowrap' ),
+                               wfMessage( 'drafts-view-article' )->text()
                        );
-                       $wgOut->addHTML(
-                               Xml::element( 'th',
-                                       null,
-                                       wfMessage( 'drafts-view-saved' )->text()
-                               )
+                       $html .=  Xml::element( 'th',
+                               null,
+                               wfMessage( 'drafts-view-saved' )->text()
                        );
-                       $wgOut->addHTML( Xml::element( 'th' ) );
-                       $wgOut->addHTML( Xml::closeElement( 'tr' ) );
+                       $html .= Xml::element( 'th' );
+                       $html .= Xml::closeElement( 'tr' );
                        // Add existing drafts for this page and user
                        /**
                         * @var $draft Draft
@@ -249,54 +244,44 @@
                                                urlencode( $draft->getSection() 
);
                                }
                                // Build XML
-                               $wgOut->addHTML( Xml::openElement( 'tr' ) );
-                               $wgOut->addHTML(
-                                       Xml::openElement( 'td' )
+                               $html .= Xml::openElement( 'tr' );
+                               $html .= Xml::openElement( 'td' );
+                               $html .= Xml::element( 'a',
+                                       array(
+                                               'href' => $urlLoad,
+                                               'style' => 'font-weight:' .
+                                                       (
+                                                               
$currentDraft->getID() == $draft->getID() ?
+                                                               'bold' : 
'normal'
+                                                       )
+                                       ),
+                                       $htmlTitle
                                );
-                               $wgOut->addHTML(
-                                       Xml::element( 'a',
-                                               array(
-                                                       'href' => $urlLoad,
-                                                       'style' => 
'font-weight:' .
-                                                               (
-                                                                       
$currentDraft->getID() == $draft->getID() ?
-                                                                       'bold' 
: 'normal'
-                                                               )
-                                               ),
-                                               $htmlTitle
-                                       )
+                               $html .= Xml::closeElement( 'td' );
+                               $html .= Xml::element( 'td',
+                                       null,
+                                       MWTimestamp::getInstance( 
$draft->getSaveTime() )->getHumanTimestamp()
                                );
-                               $wgOut->addHTML( Xml::closeElement( 'td' ) );
-                               $wgOut->addHTML(
-                                       Xml::element( 'td',
-                                               null,
-                                               MWTimestamp::getInstance( 
$draft->getSaveTime() )->getHumanTimestamp()
-                                       )
-                               );
-                               $wgOut->addHTML(
-                                       Xml::openElement( 'td' )
-                               );
+                               $html .= Xml::openElement( 'td' );
                                $jsClick = "if( wgDraft.getState() !== 
'unchanged' )" .
                                        "return confirm('" .
                                        Xml::escapeJsString( wfMessage( 
'drafts-view-warn' )->escaped() ) .
                                        "')";
-                               $wgOut->addHTML(
-                                       Xml::element( 'a',
-                                               array(
-                                                       'href' => $urlDiscard,
-                                                       'onclick' => $jsClick
-                                               ),
-                                               wfMessage( 
'drafts-view-discard' )->text()
-                                       )
-                               );
-                               $wgOut->addHTML( Xml::closeElement( 'td' ) );
-                               $wgOut->addHTML( Xml::closeElement( 'tr' ) );
+                               $html .= Xml::element( 'a',
+                                       array(
+                                               'href' => $urlDiscard,
+                                               'onclick' => $jsClick
+                                       ),
+                                       wfMessage( 'drafts-view-discard' 
)->text()
+                                       );
+                               $html .= Xml::closeElement( 'td' );
+                               $html .= Xml::closeElement( 'tr' );
                        }
-                       $wgOut->addHTML( Xml::closeElement( 'table' ) );
-                       // Return number of drafts
-                       return count( $drafts );
+                       $html .= Xml::closeElement( 'table' );
+                       // Return html
+                       return $html;
                }
-               return 0;
+               return '';
        }
 }
 
diff --git a/Drafts.hooks.php b/Drafts.hooks.php
index b3069fd..1de222d 100644
--- a/Drafts.hooks.php
+++ b/Drafts.hooks.php
@@ -141,7 +141,7 @@
                                $out->addHTML( Xml::element(
                                        'h3', null, $context->msg( 
'drafts-view-existing' )->text() )
                                );
-                               Drafts::display( $context->getTitle() );
+                               $out->addHTML( Drafts::display( 
$context->getTitle() ) );
                                $out->addHTML( Xml::closeElement( 'div' ) );
                        } else {
                                $jsWarn = "if( !wgAjaxSaveDraft.insync ) return 
confirm('" .
diff --git a/SpecialDrafts.php b/SpecialDrafts.php
index 29ba669..a52d9d3 100644
--- a/SpecialDrafts.php
+++ b/SpecialDrafts.php
@@ -53,19 +53,19 @@
                                        break;
                        }
                }
-
-               // Add a summary
-               $out->wrapWikiMsg(
-                       '<div class="mw-drafts-summary">$1</div>',
-                       array(
-                               'drafts-view-summary',
-                               $this->getLanguage()->formatNum( 
$egDraftsLifeSpan )
-                       )
-               );
-
-               // Show list of drafts, or a message that there are none
-               if ( Drafts::display() == 0 ) {
+               $count = Drafts::num();
+               if ( $count === 0 ) {
                        $out->addWikiMsg( 'drafts-view-nonesaved' );
+               } else {
+                       // Add a summary
+                       $out->wrapWikiMsg(
+                               '<div class="mw-drafts-summary">$1</div>',
+                               array(
+                                       'drafts-view-summary',
+                                       $this->getLanguage()->formatNum( 
$egDraftsLifeSpan )
+                               )
+                       );
+                       $out->addHTML( Drafts::display() );
                }
        }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4464cc41e89bda872eb1ef5ec4ba8503772dc6c8
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Drafts
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to