Ebe123 has uploaded a new change for review. https://gerrit.wikimedia.org/r/112022
Change subject: Show warning when moving a page to a different test wiki ...................................................................... Show warning when moving a page to a different test wiki This change adds a warning when trying to move a page from one test-wiki to another. This functionality uses the "AbortMove" hook and is basically re-utilizing the code from checkPrefixMovePermissions() to show an error. The analyzePrefix() function is used to compare the two prefixes. If they are the same or both give 'error', the function returns false (or with other conditions from the re-used code) I also added the message "wminc-move-differentprefix" for notifing when the prefixes are different. I used this opportunity to make the "Error:" in the message "wminc-error-move-unprefixed" bold to standardise it, as the word "Error:" is bold in the other messages that have the string. Change-Id: If0148c1a8094b1a73ec728d56eff6b9d187190df --- M WikimediaIncubator.class.php M WikimediaIncubator.i18n.php M WikimediaIncubator.php 3 files changed, 50 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaIncubator refs/changes/22/112022/1 diff --git a/WikimediaIncubator.class.php b/WikimediaIncubator.class.php index 17da13f..0e73ac3 100644 --- a/WikimediaIncubator.class.php +++ b/WikimediaIncubator.class.php @@ -899,7 +899,50 @@ $linktext = ltrim( $url, '/' ); return $callLinker ? Linker::makeExternalLink( $url, $linktext ) : $linktext; } - + + /** + * Whether we should show an error message that the source and target pages + * in a move do not have the same prefix. + * @param $title Title object + * @return Boolean + */ + static function shouldWeShowInterPrefixError( $oldtitle, $newtitle ) { + global $wmincTestWikiNamespaces, $wmincProjectSite, $wmincPseudoCategoryNSes; + $oldtitleprefixdata = self::analyzePrefix( $oldtitle->getText() ); + $newtitleprefixdata = self::analyzePrefix( $newtitle->getText() ); + $ns = $newtitle->getNamespace(); + $categories = array_map( array( __CLASS__, 'preg_quote_slash' ), $wmincPseudoCategoryNSes ); + if ( $oldtitleprefixdata[] == $newtitleprefixdata[] ) { + # no error in prefix -> no error to show + # Or prefixes are the same. + return false; + } elseif ( self::displayPrefix() == $wmincProjectSite['short'] ) { + # If user has "project" (Incubator) as test wiki preference, it isn't needed to check + return false; + } elseif ( !in_array( $ns, $wmincTestWikiNamespaces ) ) { + # OK if it's not in one of the content namespaces + return false; + } elseif ( ( $ns == NS_CATEGORY || $ns == NS_CATEGORY_TALK ) && + preg_match( '/^(' . implode( '|', $categories ) .'):.+$/', $newtitle->getText() ) ) { + # whitelisted unprefixed categories + return false; + } + return true; + } + + /** + * Return a option if user tries to move page to a different prefix. + * @return Boolean true + */ + static function checkInterPrefixMove( $oldtitle, $newtitle, $user, &$error ) { + if ( self::shouldWeShowInterPrefixError( $oldtitle, $newtitle ) ) { + # There might be a error with the page title + $error = wfMessage( 'wminc-move-differentprefix' )->parse(); + return false; + } + return true; + } + /** * @param $files * @return true diff --git a/WikimediaIncubator.i18n.php b/WikimediaIncubator.i18n.php index 8c81c8a..259c7ce 100644 --- a/WikimediaIncubator.i18n.php +++ b/WikimediaIncubator.i18n.php @@ -29,7 +29,8 @@ # Editing/creating pages errors 'wminc-error-help' => 'Help:Contents', - 'wminc-error-move-unprefixed' => "Error: The page you are trying to move to [[{{MediaWiki:Wminc-error-help}}|is unprefixed or has a wrong prefix]]!", + 'wminc-error-move-unprefixed' => "'''Error:''' The page you are trying to move to [[{{MediaWiki:Wminc-error-help}}|is unprefixed or has a wrong prefix]]!", + 'wminc-move-differentprefix' => "'''Error:''' You are moving a prefixed page to another prefix.", 'wminc-error-wronglangcode' => "'''Error:''' This page contains a [[{{MediaWiki:Wminc-error-help}}|wrong language code]] \"$1\"!", 'wminc-error-unprefixed' => "'''Error:''' This page is [[{{MediaWiki:Wminc-error-help}}|unprefixed]]!", 'wminc-error-unprefixed-suggest' => "'''Error:''' This page is [[{{MediaWiki:Wminc-error-help}}|unprefixed]]! You can create a page at [[:$1]].", @@ -136,6 +137,7 @@ 'wminc-prefinfo-code' => 'See [[:File:Incubator-testwiki-preference.jpg]].', 'wminc-prefinfo-project' => 'Explanation for a dropdown box in your preferences, with options: "None/All", "Wikipedia", "Wikibooks", "Wikinews", etc... and "Incubator". See [[:File:Incubator-testwiki-preference.jpg]].', 'wminc-prefinfo-error' => 'See [[:File:Incubator-testwiki-preference.jpg]]. If the user selected a Wikimedia project but not a language code, this error message is shown.', + 'wminc-move-differentprefix' => 'If the user moves a page from one test-wiki to another, it will ask for it to be confirmed.', 'wminc-error-help' => 'Used in: * {{msg-mw|Wminc-error-move-unprefixed}} * {{msg-mw|Wminc-error-wronglangcode}} diff --git a/WikimediaIncubator.php b/WikimediaIncubator.php index 1eb61c3..dff254d 100644 --- a/WikimediaIncubator.php +++ b/WikimediaIncubator.php @@ -103,6 +103,9 @@ $wgHooks['getUserPermissionsErrors'][] = 'WikimediaIncubator::onGetUserPermissionsErrors'; $wgHooks['AbortMove'][] = 'WikimediaIncubator::checkPrefixMovePermissions'; +/* Move page prefixing */ +$wgHooks['AbortMove'][] = 'WikimediaIncubator::checkInterPrefixMove'; + /* Recent Changes */ $wgAutoloadClasses['TestWikiRC'] = $dir . 'TestWikiRC.php'; $wgHooks['SpecialRecentChangesQuery'][] = 'TestWikiRC::onRcQuery'; -- To view, visit https://gerrit.wikimedia.org/r/112022 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If0148c1a8094b1a73ec728d56eff6b9d187190df Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikimediaIncubator Gerrit-Branch: master Gerrit-Owner: Ebe123 <beauleetien...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits