Reception123 has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/373736 )
Change subject: Convert CreateRedirect to use extension registration
......................................................................
Convert CreateRedirect to use extension registration
Bug: T174131
Change-Id: I697d2973fbed517801213827fca69472faf1fbfe
---
M CreateRedirect.body.php
M CreateRedirect.php
A extension.json
3 files changed, 65 insertions(+), 51 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CreateRedirect
refs/changes/36/373736/1
diff --git a/CreateRedirect.body.php b/CreateRedirect.body.php
index f959a54..79da848 100644
--- a/CreateRedirect.body.php
+++ b/CreateRedirect.body.php
@@ -206,6 +206,34 @@
END
);
}
+
+ /**
+ * Adds a shortcut link pointing to Special:CreateRedirect to the "toolbox"
menu.
+ * If applicable, also adds a reference to the current title as a GET param.
+ *
+ * @return Boolean: true
+ */
+function createRedirect_AddToolboxLink( &$tpl ) {
+ global $wgRequest;
+
+ // 1. Determine whether to actually add the link at all.
+ // There are certain cases, e.g. in the edit dialog, in a special page,
+ // where it's inappropriate for the link to appear.
+ // 2. Check the title. Is it a "Special:" page? Don't display the link.
+ $action = $wgRequest->getText( 'action', 'view' );
+ $title = $tpl->getSkin()->getTitle();
+
+ if( $action != 'view' && $action != 'purge' && !$title->isSpecialPage()
) {
+ return true;
+ }
+
+ // 3. Add the link!
+ $href = SpecialPage::getTitleFor( 'CreateRedirect',
$title->getPrefixedText() )->getLocalURL();
+ echo Html::rawElement( 'li', null, Html::element( 'a', array( 'href' =>
$href ), wfMessage( 'createredirect' )->text() ) );
+
+ return true;
+}
+
protected function getGroupName() {
return 'pagetools';
diff --git a/CreateRedirect.php b/CreateRedirect.php
index f9b8cc6..b19d219 100644
--- a/CreateRedirect.php
+++ b/CreateRedirect.php
@@ -29,55 +29,14 @@
* along with CreateRedirect. If not, see <http://www.gnu.org/licenses/>.
*/
-if( !defined( 'MEDIAWIKI' ) ) {
- echo( "This file is an extension to the MediaWiki software and cannot
be used standalone.\n" );
- die( 1 );
-}
-
-// Add this extension to Special:Credits.
-$wgExtensionCredits['specialpage'][] = array(
- 'path' => __FILE__,
- 'name' => 'CreateRedirect',
- 'author' => 'Marco Zafra',
- 'version' => '1.1.0',
- 'url' => 'https://www.mediawiki.org/wiki/Extension:CreateRedirect',
- 'descriptionmsg' => 'createredirect-desc',
-);
-
-// Set up the actual extension functionality.
-$dir = dirname( __FILE__ ) . '/';
-$wgAutoloadClasses['SpecialCreateRedirect'] = $dir . 'CreateRedirect.body.php';
-$wgSpecialPages['CreateRedirect'] = 'SpecialCreateRedirect';
-$wgMessagesDirs['CreateRedirect'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['CreateRedirect'] = $dir . 'CreateRedirect.i18n.php';
-$wgExtensionMessagesFiles['CreateRedirectAlias'] = $dir .
'CreateRedirect.alias.php';
-
-// Add a shortcut link to the toolbox.
-$wgHooks['SkinTemplateToolboxEnd'][] = 'createRedirect_addToolboxLink';
-
-/**
- * Adds a shortcut link pointing to Special:CreateRedirect to the "toolbox"
menu.
- * If applicable, also adds a reference to the current title as a GET param.
- *
- * @return Boolean: true
- */
-function createRedirect_AddToolboxLink( &$tpl ) {
- global $wgRequest;
-
- // 1. Determine whether to actually add the link at all.
- // There are certain cases, e.g. in the edit dialog, in a special page,
- // where it's inappropriate for the link to appear.
- // 2. Check the title. Is it a "Special:" page? Don't display the link.
- $action = $wgRequest->getText( 'action', 'view' );
- $title = $tpl->getSkin()->getTitle();
-
- if( $action != 'view' && $action != 'purge' && !$title->isSpecialPage()
) {
- return true;
- }
-
- // 3. Add the link!
- $href = SpecialPage::getTitleFor( 'CreateRedirect',
$title->getPrefixedText() )->getLocalURL();
- echo Html::rawElement( 'li', null, Html::element( 'a', array( 'href' =>
$href ), wfMessage( 'createredirect' )->text() ) );
-
- return true;
+if ( function_exists( 'wfLoadExtension' ) ) {
+ wfLoadExtension( 'CreateRedirect' );
+ $wgMessageDirs['CreateRedirect'] = __DIR__ . '/i18n';
+ wfWarn(
+ 'Deprecated PHP entry point used for CreateRedirect extension.
' .
+ 'Please use wfLoadExtension instead, ' .
+ 'see https://www.mediawiki.org/wiki/Extension_registration for
more details.'
+ );
+} else {
+ die( 'This version of the CreateRedirect extension requires MediaWiki
1.29+' );
}
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..1ee955a
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,27 @@
+{
+ "name": "CreateRedirect",
+ "version": "1.1.0",
+ "author": [
+ "[https://www.mediawiki.org/wiki/User:Digiku Marco Zafra]"
+ ],
+ "type": "specialpage",
+ "url": "https://www.mediawiki.org/wiki/Extension:CreateRedirect",
+ "descriptionmsg": "createredirect-desc",
+ "license-name": "GPL-2.0+",
+ "AutoloadClasses": {
+ "SpecialCreateRedirect": "CreateRedirect.body.php"
+ },
+ "MessagesDirs": {
+ "CreateRedirect": [
+ "i18n"
+ ]
+ },
+ "ExtensionMessagesFiles": {
+ "CreateRedirect": "CreateRedirect.i18n.php",
+ "CreateRedirectAlias": "CreateRedirect.alias.php"
+ },
+ "Hooks": {
+ "SkinTemplateToolboxEnd": "createRedirect_addToolboxLink"
+ },
+ "manifest_version": 2
+}
--
To view, visit https://gerrit.wikimedia.org/r/373736
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I697d2973fbed517801213827fca69472faf1fbfe
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CreateRedirect
Gerrit-Branch: master
Gerrit-Owner: Reception123 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits