X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=d1e9435b8d3ec0c60a61f412382d363bc4363fb7;hb=982f7637ceb0f81c3897e72f7e8f916ba676a5ce;hp=cfb78cd78d834d09c36c541f1990d08659da287e;hpb=590f1bd8c261c882f23c2a404fbcc40ae4e5d460;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/EditPage.php b/includes/EditPage.php
index cfb78cd78d..d1e9435b8d 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -336,7 +336,7 @@ class EditPage {
/** @var string */
public $edittime = '';
- /** @var integer */
+ /** @var int */
private $editRevId = null;
/** @var string */
@@ -413,11 +413,6 @@ class EditPage {
*/
private $isOldRev = false;
- /**
- * @var bool Whether OOUI should be enabled here
- */
- private $oouiEnabled = false;
-
/**
* @param Article $article
*/
@@ -431,8 +426,6 @@ class EditPage {
$handler = ContentHandler::getForModelID( $this->contentModel );
$this->contentFormat = $handler->getDefaultFormat();
-
- $this->oouiEnabled = $this->context->getConfig()->get( 'OOUIEditPage' );
}
/**
@@ -485,10 +478,11 @@ class EditPage {
/**
* Check if the edit page is using OOUI controls
- * @return bool
+ * @return bool Always true
+ * @deprecated since 1.30
*/
public function isOouiEnabled() {
- return $this->oouiEnabled;
+ return true;
}
/**
@@ -852,15 +846,12 @@ class EditPage {
/**
* This function collects the form data and uses it to populate various member variables.
- * @param WebRequest $request
+ * @param WebRequest &$request
* @throws ErrorPageError
*/
public function importFormData( &$request ) {
global $wgContLang, $wgUser;
- # Allow users to change the mode for testing
- $this->oouiEnabled = $request->getFuzzyBool( 'ooui', $this->oouiEnabled );
-
# Section edit can come from either the form or a link
$this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
@@ -1080,7 +1071,7 @@ class EditPage {
* this method should be overridden and return the page text that will be used
* for saving, preview parsing and so on...
*
- * @param WebRequest $request
+ * @param WebRequest &$request
* @return string|null
*/
protected function importContentFormData( &$request ) {
@@ -1432,7 +1423,7 @@ class EditPage {
/**
* Make sure the form isn't faking a user's credentials.
*
- * @param WebRequest $request
+ * @param WebRequest &$request
* @return bool
* @private
*/
@@ -1475,7 +1466,7 @@ class EditPage {
/**
* Attempt submission
- * @param array|bool $resultDetails See docs for $result in internalAttemptSave
+ * @param array|bool &$resultDetails See docs for $result in internalAttemptSave
* @throws UserBlockedError|ReadOnlyError|ThrottledError|PermissionsError
* @return Status The resulting status object.
*/
@@ -1721,12 +1712,12 @@ class EditPage {
/**
* Attempt submission (no UI)
*
- * @param array $result Array to add statuses to, currently with the
+ * @param array &$result Array to add statuses to, currently with the
* possible keys:
* - spam (string): Spam string from content if any spam is detected by
* matchSpamRegex.
* - sectionanchor (string): Section anchor for a section save.
- * - nullEdit (boolean): Set if doEditContent is OK. True if null edit,
+ * - nullEdit (bool): Set if doEditContent is OK. True if null edit,
* false otherwise.
* - redirect (bool): Set if doEditContent is OK. True if resulting
* revision is a redirect.
@@ -2667,7 +2658,7 @@ class EditPage {
$wgOut->addHTML( Html::openElement(
'form',
[
- 'class' => $this->oouiEnabled ? 'mw-editform-ooui' : 'mw-editform-legacy',
+ 'class' => 'mw-editform',
'id' => self::EDITFORM_ID,
'name' => self::EDITFORM_ID,
'method' => 'post',
@@ -2710,7 +2701,7 @@ class EditPage {
if ( $this->wasDeletedSinceLastEdit() && 'save' == $this->formtype ) {
$username = $this->lastDelete->user_name;
- $comment = $this->lastDelete->log_comment;
+ $comment = CommentStore::newKey( 'log_comment' )->getComment( $this->lastDelete )->text;
// It is better to not parse the comment at all than to have templates expanded in the middle
// TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
@@ -2767,13 +2758,7 @@ class EditPage {
$wgOut->addHTML( Html::hidden( 'format', $this->contentFormat ) );
$wgOut->addHTML( Html::hidden( 'model', $this->contentModel ) );
- // Preserve &ooui=1 / &ooui=0 from URL parameters after submitting the page for preview
- $wgOut->addHTML( Html::hidden( 'ooui', $this->oouiEnabled ? '1' : '0' ) );
-
- // following functions will need OOUI, enable it only once; here.
- if ( $this->oouiEnabled ) {
- $wgOut->enableOOUI();
- }
+ $wgOut->enableOOUI();
if ( $this->section == 'new' ) {
$this->showSummaryInput( true, $this->summary );
@@ -3086,16 +3071,17 @@ class EditPage {
* inferred by the id given to the input. You can remove them both by
* passing [ 'id' => false ] to $userInputAttrs.
*
+ * @deprecated since 1.30 Use getSummaryInputWidget() instead
* @param string $summary The value of the summary input
* @param string $labelText The html to place inside the label
* @param array $inputAttrs Array of attrs to use on the input
* @param array $spanLabelAttrs Array of attrs to use on the span inside the label
- *
* @return array An array in the format [ $label, $input ]
*/
public function getSummaryInput( $summary = "", $labelText = null,
$inputAttrs = null, $spanLabelAttrs = null
) {
+ wfDeprecated( __METHOD__, '1.30' );
$inputAttrs = $this->getSummaryInputAttributes( $inputAttrs );
$inputAttrs += Linker::tooltipAndAccesskeyAttribs( 'summary' );
@@ -3120,9 +3106,9 @@ class EditPage {
}
/**
- * Same as self::getSummaryInput, but uses OOUI, instead of plain HTML.
* Builds a standard summary input with a label.
*
+ * @deprecated since 1.30 Use getSummaryInputWidget() instead
* @param string $summary The value of the summary input
* @param string $labelText The html to place inside the label
* @param array $inputAttrs Array of attrs to use on the input
@@ -3130,6 +3116,20 @@ class EditPage {
* @return OOUI\FieldLayout OOUI FieldLayout with Label and Input
*/
function getSummaryInputOOUI( $summary = "", $labelText = null, $inputAttrs = null ) {
+ wfDeprecated( __METHOD__, '1.30' );
+ $this->getSummaryInputWidget( $summary, $labelText, $inputAttrs );
+ }
+
+ /**
+ * Builds a standard summary input with a label.
+ *
+ * @param string $summary The value of the summary input
+ * @param string $labelText The html to place inside the label
+ * @param array $inputAttrs Array of attrs to use on the input
+ *
+ * @return OOUI\FieldLayout OOUI FieldLayout with Label and Input
+ */
+ function getSummaryInputWidget( $summary = "", $labelText = null, $inputAttrs = null ) {
$inputAttrs = OOUI\Element::configFromHtmlAttributes(
$this->getSummaryInputAttributes( $inputAttrs )
);
@@ -3178,20 +3178,11 @@ class EditPage {
}
$labelText = $this->context->msg( $isSubjectPreview ? 'subject' : 'summary' )->parse();
- if ( $this->oouiEnabled ) {
- $wgOut->addHTML( $this->getSummaryInputOOUI(
+ $wgOut->addHTML( $this->getSummaryInputWidget(
$summary,
$labelText,
[ 'class' => $summaryClass ]
) );
- } else {
- list( $label, $input ) = $this->getSummaryInput(
- $summary,
- $labelText,
- [ 'class' => $summaryClass ]
- );
- $wgOut->addHTML( "{$label} {$input}" );
- }
}
/**
@@ -3230,7 +3221,7 @@ class EditPage {
$wgOut->addHTML( Html::hidden( 'wpStarttime', $this->starttime ) );
$wgOut->addHTML( Html::hidden( 'wpEdittime', $this->edittime ) );
$wgOut->addHTML( Html::hidden( 'editRevId', $this->editRevId ) );
- $wgOut->addHTML( Html::hidden( 'wpScrolltop', $this->scrolltop ) );
+ $wgOut->addHTML( Html::hidden( 'wpScrolltop', $this->scrolltop, [ 'id' => 'wpScrolltop' ] ) );
if ( !$this->checkUnicodeCompliantBrowser() ) {
$wgOut->addHTML( Html::hidden( 'safemode', '1' ) );
@@ -3602,19 +3593,11 @@ class EditPage {
$wgOut->addHTML( $this->getSummaryPreview( false, $this->summary ) );
}
- if ( $this->oouiEnabled ) {
- $checkboxes = $this->getCheckboxesOOUI(
- $tabindex,
- [ 'minor' => $this->minoredit, 'watch' => $this->watchthis ]
- );
- $checkboxesHTML = new OOUI\HorizontalLayout( [ 'items' => $checkboxes ] );
- } else {
- $checkboxes = $this->getCheckboxes(
- $tabindex,
- [ 'minor' => $this->minoredit, 'watch' => $this->watchthis ]
- );
- $checkboxesHTML = implode( $checkboxes, "\n" );
- }
+ $checkboxes = $this->getCheckboxesWidget(
+ $tabindex,
+ [ 'minor' => $this->minoredit, 'watch' => $this->watchthis ]
+ );
+ $checkboxesHTML = new OOUI\HorizontalLayout( [ 'items' => $checkboxes ] );
$wgOut->addHTML( "
" . $checkboxesHTML . "
\n" );
@@ -3704,23 +3687,15 @@ class EditPage {
} elseif ( $this->getContextTitle()->isRedirect() ) {
$cancelParams['redirect'] = 'no';
}
- if ( $this->oouiEnabled ) {
- return new OOUI\ButtonWidget( [
- 'id' => 'mw-editform-cancel',
- 'href' => $this->getContextTitle()->getLinkUrl( $cancelParams ),
- 'label' => new OOUI\HtmlSnippet( $this->context->msg( 'cancel' )->parse() ),
- 'framed' => false,
- 'infusable' => true,
- 'flags' => 'destructive',
- ] );
- } else {
- return MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
- $this->getContextTitle(),
- new HtmlArmor( $this->context->msg( 'cancel' )->parse() ),
- Html::buttonAttributes( [ 'id' => 'mw-editform-cancel' ], [ 'mw-ui-quiet' ] ),
- $cancelParams
- );
- }
+
+ return new OOUI\ButtonWidget( [
+ 'id' => 'mw-editform-cancel',
+ 'href' => $this->getContextTitle()->getLinkUrl( $cancelParams ),
+ 'label' => new OOUI\HtmlSnippet( $this->context->msg( 'cancel' )->parse() ),
+ 'framed' => false,
+ 'infusable' => true,
+ 'flags' => 'destructive',
+ ] );
}
/**
@@ -3768,8 +3743,9 @@ class EditPage {
*/
protected function getLastDelete() {
$dbr = wfGetDB( DB_REPLICA );
+ $commentQuery = CommentStore::newKey( 'log_comment' )->getJoin();
$data = $dbr->selectRow(
- [ 'logging', 'user' ],
+ [ 'logging', 'user' ] + $commentQuery['tables'],
[
'log_type',
'log_action',
@@ -3777,11 +3753,10 @@ class EditPage {
'log_user',
'log_namespace',
'log_title',
- 'log_comment',
'log_params',
'log_deleted',
'user_name'
- ], [
+ ] + $commentQuery['fields'], [
'log_namespace' => $this->mTitle->getNamespace(),
'log_title' => $this->mTitle->getDBkey(),
'log_type' => 'delete',
@@ -3789,7 +3764,10 @@ class EditPage {
'user_id=log_user'
],
__METHOD__,
- [ 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ]
+ [ 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ],
+ [
+ 'user' => [ 'JOIN', 'user_id=log_user' ],
+ ] + $commentQuery['joins']
);
// Quick paranoid permission checks...
if ( is_object( $data ) ) {
@@ -3798,7 +3776,8 @@ class EditPage {
}
if ( $data->log_deleted & LogPage::DELETED_COMMENT ) {
- $data->log_comment = $this->context->msg( 'rev-deleted-comment' )->escaped();
+ $data->log_comment_text = $this->context->msg( 'rev-deleted-comment' )->escaped();
+ $data->log_comment_data = null;
}
}
@@ -4163,7 +4142,7 @@ class EditPage {
* where bool indicates the checked status of the checkbox
* @return array
*/
- protected function getCheckboxesDefinition( $checked ) {
+ public function getCheckboxesDefinition( $checked ) {
global $wgUser;
$checkboxes = [];
@@ -4202,7 +4181,8 @@ class EditPage {
* Returns an array of html code of the following checkboxes old style:
* minor and watch
*
- * @param int $tabindex Current tabindex
+ * @deprecated since 1.30 Use getCheckboxesWidget() or getCheckboxesDefinition() instead
+ * @param int &$tabindex Current tabindex
* @param array $checked See getCheckboxesDefinition()
* @return array
*/
@@ -4257,21 +4237,34 @@ class EditPage {
}
/**
- * Returns an array of html code of the following checkboxes:
- * minor and watch
+ * Returns an array of checkboxes for the edit form, including 'minor' and 'watch' checkboxes and
+ * any other added by extensions.
*
- * @param int $tabindex Current tabindex
+ * @deprecated since 1.30 Use getCheckboxesWidget() or getCheckboxesDefinition() instead
+ * @param int &$tabindex Current tabindex
* @param array $checked Array of checkbox => bool, where bool indicates the checked
* status of the checkbox
*
- * @return array
+ * @return array Associative array of string keys to OOUI\FieldLayout instances
*/
public function getCheckboxesOOUI( &$tabindex, $checked ) {
+ return $this->getCheckboxesWidget( $tabindex, $checked );
+ }
+
+ /**
+ * Returns an array of checkboxes for the edit form, including 'minor' and 'watch' checkboxes and
+ * any other added by extensions.
+ *
+ * @param int &$tabindex Current tabindex
+ * @param array $checked Array of checkbox => bool, where bool indicates the checked
+ * status of the checkbox
+ *
+ * @return array Associative array of string keys to OOUI\FieldLayout instances
+ */
+ public function getCheckboxesWidget( &$tabindex, $checked ) {
$checkboxes = [];
$checkboxesDef = $this->getCheckboxesDefinition( $checked );
- $origTabindex = $tabindex;
-
foreach ( $checkboxesDef as $name => $options ) {
$legacyName = isset( $options['legacy-name'] ) ? $options['legacy-name'] : $name;
@@ -4284,9 +4277,6 @@ class EditPage {
if ( isset( $options['title-message'] ) ) {
$title = $this->context->msg( $options['title-message'] )->text();
}
- if ( isset( $options['label-id'] ) ) {
- $labelAttribs['id'] = $options['label-id'];
- }
$checkboxes[ $legacyName ] = new OOUI\FieldLayout(
new OOUI\CheckboxInputWidget( [
@@ -4310,7 +4300,19 @@ class EditPage {
// Backwards-compatibility hack to run the EditPageBeforeEditChecks hook. It's important,
// people have used it for the weirdest things completely unrelated to checkboxes...
// And if we're gonna run it, might as well allow its legacy checkboxes to be shown.
- $legacyCheckboxes = $this->getCheckboxes( $origTabindex, $checked );
+ $legacyCheckboxes = [];
+ if ( !$this->isNew ) {
+ $legacyCheckboxes['minor'] = '';
+ }
+ $legacyCheckboxes['watch'] = '';
+ // Copy new-style checkboxes into an old-style structure
+ foreach ( $checkboxes as $name => $oouiLayout ) {
+ $legacyCheckboxes[$name] = (string)$oouiLayout;
+ }
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $ep = $this;
+ Hooks::run( 'EditPageBeforeEditChecks', [ &$ep, &$legacyCheckboxes, &$tabindex ], '1.29' );
+ // Copy back any additional old-style checkboxes into the new-style structure
foreach ( $legacyCheckboxes as $name => $html ) {
if ( $html && !isset( $checkboxes[$name] ) ) {
$checkboxes[$name] = new OOUI\Widget( [ 'content' => new OOUI\HtmlSnippet( $html ) ] );
@@ -4333,7 +4335,7 @@ class EditPage {
$newPage = !$this->mTitle->exists();
if ( $labelAsPublish ) {
- $buttonLabelKey = $newPage ? 'publishpage' : 'publishchanges';
+ $buttonLabelKey = $newPage ? 'publishpage' : 'publishchanges';
} else {
$buttonLabelKey = $newPage ? 'savearticle' : 'savechanges';
}
@@ -4345,7 +4347,7 @@ class EditPage {
* Returns an array of html code of the following buttons:
* save, diff and preview
*
- * @param int $tabindex Current tabindex
+ * @param int &$tabindex Current tabindex
*
* @return array
*/
@@ -4358,74 +4360,56 @@ class EditPage {
'name' => 'wpSave',
'tabindex' => ++$tabindex,
];
- if ( $this->oouiEnabled ) {
- $saveConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
- $buttons['save'] = new OOUI\ButtonInputWidget( [
- 'id' => 'wpSaveWidget',
- 'inputId' => 'wpSave',
- // Support: IE 6 â Use , otherwise it can't distinguish which button was clicked
- 'useInputTag' => true,
- 'flags' => [ 'constructive', 'primary' ],
- 'label' => $buttonLabel,
- 'infusable' => true,
- 'type' => 'submit',
- 'title' => Linker::titleAttrib( 'save' ),
- 'accessKey' => Linker::accesskey( 'save' ),
- ] + $saveConfig );
- } else {
- $buttons['save'] = Html::submitButton(
- $buttonLabel,
- $attribs + Linker::tooltipAndAccesskeyAttribs( 'save' ) + [ 'id' => 'wpSave' ],
- [ 'mw-ui-progressive' ]
- );
- }
+
+ $saveConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
+ $buttons['save'] = new OOUI\ButtonInputWidget( [
+ 'id' => 'wpSaveWidget',
+ 'inputId' => 'wpSave',
+ // Support: IE 6 â Use , otherwise it can't distinguish which button was clicked
+ 'useInputTag' => true,
+ 'flags' => [ 'constructive', 'primary' ],
+ 'label' => $buttonLabel,
+ 'infusable' => true,
+ 'type' => 'submit',
+ 'title' => Linker::titleAttrib( 'save' ),
+ 'accessKey' => Linker::accesskey( 'save' ),
+ ] + $saveConfig );
$attribs = [
'name' => 'wpPreview',
'tabindex' => ++$tabindex,
];
- if ( $this->oouiEnabled ) {
- $previewConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
- $buttons['preview'] = new OOUI\ButtonInputWidget( [
- 'id' => 'wpPreviewWidget',
- 'inputId' => 'wpPreview',
- // Support: IE 6 â Use , otherwise it can't distinguish which button was clicked
- 'useInputTag' => true,
- 'label' => $this->context->msg( 'showpreview' )->text(),
- 'infusable' => true,
- 'type' => 'submit',
- 'title' => Linker::titleAttrib( 'preview' ),
- 'accessKey' => Linker::accesskey( 'preview' ),
- ] + $previewConfig );
- } else {
- $buttons['preview'] = Html::submitButton(
- $this->context->msg( 'showpreview' )->text(),
- $attribs + Linker::tooltipAndAccesskeyAttribs( 'preview' ) + [ 'id' => 'wpPreview' ]
- );
- }
+
+ $previewConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
+ $buttons['preview'] = new OOUI\ButtonInputWidget( [
+ 'id' => 'wpPreviewWidget',
+ 'inputId' => 'wpPreview',
+ // Support: IE 6 â Use , otherwise it can't distinguish which button was clicked
+ 'useInputTag' => true,
+ 'label' => $this->context->msg( 'showpreview' )->text(),
+ 'infusable' => true,
+ 'type' => 'submit',
+ 'title' => Linker::titleAttrib( 'preview' ),
+ 'accessKey' => Linker::accesskey( 'preview' ),
+ ] + $previewConfig );
+
$attribs = [
'name' => 'wpDiff',
'tabindex' => ++$tabindex,
];
- if ( $this->oouiEnabled ) {
- $diffConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
- $buttons['diff'] = new OOUI\ButtonInputWidget( [
- 'id' => 'wpDiffWidget',
- 'inputId' => 'wpDiff',
- // Support: IE 6 â Use , otherwise it can't distinguish which button was clicked
- 'useInputTag' => true,
- 'label' => $this->context->msg( 'showdiff' )->text(),
- 'infusable' => true,
- 'type' => 'submit',
- 'title' => Linker::titleAttrib( 'diff' ),
- 'accessKey' => Linker::accesskey( 'diff' ),
- ] + $diffConfig );
- } else {
- $buttons['diff'] = Html::submitButton(
- $this->context->msg( 'showdiff' )->text(),
- $attribs + Linker::tooltipAndAccesskeyAttribs( 'diff' ) + [ 'id' => 'wpDiff' ]
- );
- }
+
+ $diffConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
+ $buttons['diff'] = new OOUI\ButtonInputWidget( [
+ 'id' => 'wpDiffWidget',
+ 'inputId' => 'wpDiff',
+ // Support: IE 6 â Use , otherwise it can't distinguish which button was clicked
+ 'useInputTag' => true,
+ 'label' => $this->context->msg( 'showdiff' )->text(),
+ 'infusable' => true,
+ 'type' => 'submit',
+ 'title' => Linker::titleAttrib( 'diff' ),
+ 'accessKey' => Linker::accesskey( 'diff' ),
+ ] + $diffConfig );
// Avoid PHP 7.1 warning of passing $this by reference
$editPage = $this;