API: Internationalize all remaining core API modules
[lhc/web/wiklou.git] / includes / EditPage.php
index 87bdf91..764f413 100644 (file)
@@ -779,7 +779,8 @@ class EditPage {
                                // TODO: softened the check for cutover.  Once we determine
                                // that it is safe, we should complete the transition by
                                // removing the "edittime" clause.
-                               $this->incompleteForm = ( !$request->getVal( 'wpUltimateParam' ) && is_null( $this->edittime ) );
+                               $this->incompleteForm = ( !$request->getVal( 'wpUltimateParam' )
+                                       && is_null( $this->edittime ) );
                        }
                        if ( $this->incompleteForm ) {
                                # If the form is incomplete, force to preview.
@@ -1892,8 +1893,14 @@ class EditPage {
                        ( ( $this->minoredit && !$this->isNew ) ? EDIT_MINOR : 0 ) |
                        ( $bot ? EDIT_FORCE_BOT : 0 );
 
-               $doEditStatus = $this->mArticle->doEditContent( $content, $this->summary, $flags,
-                                                                                                               false, null, $this->contentFormat );
+               $doEditStatus = $this->mArticle->doEditContent(
+                       $content,
+                       $this->summary,
+                       $flags,
+                       false,
+                       null,
+                       $content->getDefaultFormat()
+               );
 
                if ( !$doEditStatus->isOK() ) {
                        // Failure from doEdit()
@@ -1938,9 +1945,7 @@ class EditPage {
                        // Do this in its own transaction to reduce contention...
                        $dbw = wfGetDB( DB_MASTER );
                        $dbw->onTransactionIdle( function () use ( $dbw, $title, $watch, $wgUser, $fname ) {
-                               $dbw->begin( $fname );
                                WatchAction::doWatchOrUnwatch( $watch, $title, $wgUser );
-                               $dbw->commit( $fname );
                        } );
                }
        }
@@ -2102,6 +2107,17 @@ class EditPage {
                if ( $namespace == NS_MEDIAWIKI ) {
                        # Show a warning if editing an interface message
                        $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
+                       # If this is a default message (but not css or js),
+                       # show a hint that it is translatable on translatewiki.net
+                       if ( !$this->mTitle->hasContentModel( CONTENT_MODEL_CSS )
+                               && !$this->mTitle->hasContentModel( CONTENT_MODEL_JAVASCRIPT )
+                       ) {
+                               $defaultMessageText = $this->mTitle->getDefaultMessageText();
+                               if ( $defaultMessageText !== false ) {
+                                       $wgOut->wrapWikiMsg( "<div class='mw-translateinterface'>\n$1\n</div>",
+                                               'translateinterface' );
+                               }
+                       }
                } elseif ( $namespace == NS_FILE ) {
                        # Show a hint to shared repo
                        $file = wfFindFile( $this->mTitle );
@@ -2133,7 +2149,8 @@ class EditPage {
                        if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
                                $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
                                        array( 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ) );
-                       } elseif ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) { # Show log extract if the user is currently blocked
+                       } elseif ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) {
+                               # Show log extract if the user is currently blocked
                                LogEventsList::showLogExtract(
                                        $wgOut,
                                        'block',
@@ -2200,7 +2217,10 @@ class EditPage {
                        if ( $title instanceof Title && $title->exists() && $title->userCan( 'read' ) ) {
                                global $wgOut;
                                // Added using template syntax, to take <noinclude>'s into account.
-                               $wgOut->addWikiTextTitleTidy( '<div class="mw-editintro">{{:' . $title->getFullText() . '}}</div>', $this->mTitle );
+                               $wgOut->addWikiTextTitleTidy(
+                                       '<div class="mw-editintro">{{:' . $title->getFullText() . '}}</div>',
+                                       $this->mTitle
+                               );
                                return true;
                        }
                }
@@ -2226,11 +2246,7 @@ class EditPage {
         *   $this->allowNonTextContent is not true.
         */
        protected function toEditText( $content ) {
-               if ( $content === null || $content === false ) {
-                       return $content;
-               }
-
-               if ( is_string( $content ) ) {
+               if ( $content === null || $content === false || is_string( $content ) ) {
                        return $content;
                }
 
@@ -3190,7 +3206,7 @@ HTML
        }
 
        protected function showStandardInputs( &$tabindex = 2 ) {
-               global $wgOut, $wgUseMediaWikiUIEverywhere;
+               global $wgOut;
                $wgOut->addHTML( "<div class='editOptions'>\n" );
 
                if ( $this->section != 'new' ) {
@@ -3222,10 +3238,9 @@ HTML
                        'target' => 'helpwindow',
                        'href' => $edithelpurl,
                );
-               if ( $wgUseMediaWikiUIEverywhere ) {
-                       $attrs['class'] = 'mw-ui-button mw-ui-quiet';
-               }
-               $edithelp = Html::element( 'a', $attrs, wfMessage( 'edithelp' )->text() ) .
+               $edithelp = Html::linkButton( wfMessage( 'edithelp' )->text(),
+                       $attrs, array( 'mw-ui-quiet' ) ) .
+                       wfMessage( 'word-separator' )->escaped() .
                        wfMessage( 'newwindow' )->parse();
 
                $wgOut->addHTML( "      <span class='cancelLink'>{$cancel}</span>\n" );
@@ -3267,20 +3282,16 @@ HTML
         * @return string
         */
        public function getCancelLink() {
-               global $wgUseMediaWikiUIEverywhere;
                $cancelParams = array();
                if ( !$this->isConflict && $this->oldid > 0 ) {
                        $cancelParams['oldid'] = $this->oldid;
                }
                $attrs = array( 'id' => 'mw-editform-cancel' );
-               if ( $wgUseMediaWikiUIEverywhere ) {
-                       $attrs['class'] = 'mw-ui-button mw-ui-quiet';
-               }
 
                return Linker::linkKnown(
                        $this->getContextTitle(),
                        wfMessage( 'cancel' )->parse(),
-                       $attrs,
+                       Html::buttonAttributes( $attrs, array( 'mw-ui-quiet' ) ),
                        $cancelParams
                );
        }
@@ -3548,22 +3559,22 @@ HTML
         * @return string
         */
        static function getEditToolbar() {
-               global $wgStylePath, $wgContLang, $wgLang, $wgOut;
+               global $wgContLang, $wgOut;
                global $wgEnableUploads, $wgForeignFileRepos;
 
                $imagesAvailable = $wgEnableUploads || count( $wgForeignFileRepos );
 
                /**
                 * $toolarray is an array of arrays each of which includes the
-                * filename of the button image (without path), the opening
-                * tag, the closing tag, optionally a sample text that is
+                * opening tag, the closing tag, optionally a sample text that is
                 * inserted between the two when no selection is highlighted
                 * and.  The tip text is shown when the user moves the mouse
                 * over the button.
+                *
+                * Images are defined in ResourceLoaderEditToolbarModule.
                 */
                $toolarray = array(
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-bold' ),
                                'id'     => 'mw-editbutton-bold',
                                'open'   => '\'\'\'',
                                'close'  => '\'\'\'',
@@ -3571,7 +3582,6 @@ HTML
                                'tip'    => wfMessage( 'bold_tip' )->text(),
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-italic' ),
                                'id'     => 'mw-editbutton-italic',
                                'open'   => '\'\'',
                                'close'  => '\'\'',
@@ -3579,7 +3589,6 @@ HTML
                                'tip'    => wfMessage( 'italic_tip' )->text(),
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-link' ),
                                'id'     => 'mw-editbutton-link',
                                'open'   => '[[',
                                'close'  => ']]',
@@ -3587,7 +3596,6 @@ HTML
                                'tip'    => wfMessage( 'link_tip' )->text(),
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-extlink' ),
                                'id'     => 'mw-editbutton-extlink',
                                'open'   => '[',
                                'close'  => ']',
@@ -3595,7 +3603,6 @@ HTML
                                'tip'    => wfMessage( 'extlink_tip' )->text(),
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-headline' ),
                                'id'     => 'mw-editbutton-headline',
                                'open'   => "\n== ",
                                'close'  => " ==\n",
@@ -3603,7 +3610,6 @@ HTML
                                'tip'    => wfMessage( 'headline_tip' )->text(),
                        ),
                        $imagesAvailable ? array(
-                               'image'  => $wgLang->getImageFile( 'button-image' ),
                                'id'     => 'mw-editbutton-image',
                                'open'   => '[[' . $wgContLang->getNsText( NS_FILE ) . ':',
                                'close'  => ']]',
@@ -3611,7 +3617,6 @@ HTML
                                'tip'    => wfMessage( 'image_tip' )->text(),
                        ) : false,
                        $imagesAvailable ? array(
-                               'image'  => $wgLang->getImageFile( 'button-media' ),
                                'id'     => 'mw-editbutton-media',
                                'open'   => '[[' . $wgContLang->getNsText( NS_MEDIA ) . ':',
                                'close'  => ']]',
@@ -3619,7 +3624,6 @@ HTML
                                'tip'    => wfMessage( 'media_tip' )->text(),
                        ) : false,
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-nowiki' ),
                                'id'     => 'mw-editbutton-nowiki',
                                'open'   => "<nowiki>",
                                'close'  => "</nowiki>",
@@ -3627,7 +3631,6 @@ HTML
                                'tip'    => wfMessage( 'nowiki_tip' )->text(),
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-sig' ),
                                'id'     => 'mw-editbutton-signature',
                                'open'   => '--~~~~',
                                'close'  => '',
@@ -3635,7 +3638,6 @@ HTML
                                'tip'    => wfMessage( 'sig_tip' )->text(),
                        ),
                        array(
-                               'image'  => $wgLang->getImageFile( 'button-hr' ),
                                'id'     => 'mw-editbutton-hr',
                                'open'   => "\n----\n",
                                'close'  => '',
@@ -3644,14 +3646,15 @@ HTML
                        )
                );
 
-               $script = 'mw.loader.using("mediawiki.action.edit", function() {';
+               $script = 'mw.loader.using("mediawiki.toolbar", function () {';
                foreach ( $toolarray as $tool ) {
                        if ( !$tool ) {
                                continue;
                        }
 
                        $params = array(
-                               $wgStylePath . '/common/images/' . $tool['image'],
+                               // Images are defined in ResourceLoaderEditToolbarModule
+                               false,
                                // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
                                // Older browsers show a "speedtip" type message only for ALT.
                                // Ideally these should be different, realistically they
@@ -3666,12 +3669,6 @@ HTML
                        $script .= Xml::encodeJsCall( 'mw.toolbar.addButton', $params );
                }
 
-               // This used to be called on DOMReady from mediawiki.action.edit, which
-               // ended up causing race conditions with the setup code above.
-               $script .= "\n" .
-                       "// Create button bar\n" .
-                       "$(function() { mw.toolbar.init(); } );\n";
-
                $script .= '});';
                $wgOut->addScript( Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ) );
 
@@ -3757,47 +3754,33 @@ HTML
         * @return array
         */
        public function getEditButtons( &$tabindex ) {
-               global $wgUseMediaWikiUIEverywhere;
-
                $buttons = array();
 
                $attribs = array(
                        'id' => 'wpSave',
                        'name' => 'wpSave',
-                       'type' => 'submit',
                        'tabindex' => ++$tabindex,
-                       'value' => wfMessage( 'savearticle' )->text(),
                ) + Linker::tooltipAndAccesskeyAttribs( 'save' );
-               if ( $wgUseMediaWikiUIEverywhere ) {
-                       $attribs['class'] = 'mw-ui-button mw-ui-constructive';
-               }
-               $buttons['save'] = Xml::element( 'input', $attribs, '' );
+               $buttons['save'] = Html::submitButton( wfMessage( 'savearticle' )->text(),
+                       $attribs, array( 'mw-ui-constructive' ) );
 
                ++$tabindex; // use the same for preview and live preview
                $attribs = array(
                        'id' => 'wpPreview',
                        'name' => 'wpPreview',
-                       'type' => 'submit',
                        'tabindex' => $tabindex,
-                       'value' => wfMessage( 'showpreview' )->text(),
                ) + Linker::tooltipAndAccesskeyAttribs( 'preview' );
-               if ( $wgUseMediaWikiUIEverywhere ) {
-                       $attribs['class'] = 'mw-ui-button mw-ui-progressive';
-               }
-               $buttons['preview'] = Xml::element( 'input', $attribs, '' );
+               $buttons['preview'] = Html::submitButton( wfMessage( 'showpreview' )->text(),
+                       $attribs );
                $buttons['live'] = '';
 
                $attribs = array(
                        'id' => 'wpDiff',
                        'name' => 'wpDiff',
-                       'type' => 'submit',
                        'tabindex' => ++$tabindex,
-                       'value' => wfMessage( 'showdiff' )->text(),
                ) + Linker::tooltipAndAccesskeyAttribs( 'diff' );
-               if ( $wgUseMediaWikiUIEverywhere ) {
-                       $attribs['class'] = 'mw-ui-button mw-ui-progressive';
-               }
-               $buttons['diff'] = Xml::element( 'input', $attribs, '' );
+               $buttons['diff'] = Html::submitButton( wfMessage( 'showdiff' )->text(),
+                       $attribs );
 
                wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
                return $buttons;