r110692 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110691‎ | r110692 | r110693 >
Date:00:10, 4 February 2012
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
importing CreatePage extension
Modified paths:
  • /trunk/extensions/CreatePage (added) (history)
  • /trunk/extensions/CreatePage/CreatePage.alias.php (added) (history)
  • /trunk/extensions/CreatePage/CreatePage.i18n.php (added) (history)
  • /trunk/extensions/CreatePage/CreatePage.magic.php (added) (history)
  • /trunk/extensions/CreatePage/CreatePage.php (added) (history)
  • /trunk/extensions/CreatePage/SpecialCreatePage.php (added) (history)

Diff [purge]

Index: trunk/extensions/CreatePage/CreatePage.i18n.php
@@ -0,0 +1,23 @@
 2+<?php
 3+
 4+/**
 5+ * Internationalization file for the Create Page extension.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file CreatePage.i18n.php
 10+ * @ingroup CreatePage
 11+ *
 12+ * @licence GNU GPL v3+
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+
 16+$messages = array();
 17+
 18+/** English
 19+ * @author Jeroen De Dauw
 20+ */
 21+$messages['en'] = array(
 22+ 'cp-desc' => 'Allows placing an input that takes the name of a new page into pages.',
 23+ 'cp-create' => 'Create page',
 24+);
Property changes on: trunk/extensions/CreatePage/CreatePage.i18n.php
___________________________________________________________________
Added: svn:eol-style
125 + native
Index: trunk/extensions/CreatePage/CreatePage.magic.php
@@ -0,0 +1,22 @@
 2+<?php
 3+
 4+/**
 5+ * Internationalization file for the Create Page extension.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file CreatePage.magic.php
 10+ * @ingroup CreatePage
 11+ *
 12+ * @licence GNU GPL v3+
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+
 16+$magicWords = array();
 17+
 18+/** English
 19+ * @author Jeroen De Dauw
 20+ */
 21+$magicWords['en'] = array(
 22+ 'createpage' => array( 0, 'createpage' ),
 23+);
Property changes on: trunk/extensions/CreatePage/CreatePage.magic.php
___________________________________________________________________
Added: svn:eol-style
124 + native
Index: trunk/extensions/CreatePage/CreatePage.php
@@ -0,0 +1,82 @@
 2+<?php
 3+
 4+/**
 5+ * Initialization file for the Create Page extension.
 6+ *
 7+ * Documentation: https://www.mediawiki.org/wiki/Extension:Create_Page
 8+ * Support https://www.mediawiki.org/wiki/Extension_talk:Create_Page
 9+ * Source code: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/CreatePage
 10+ *
 11+ * @file CreatePage.php
 12+ * @ingroup CreatePage
 13+ *
 14+ * @licence GNU GPL v3+
 15+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 16+ */
 17+
 18+/**
 19+ * This documentation group collects source code files belonging to Create Page.
 20+ *
 21+ * @defgroup CreatePage Create Page
 22+ */
 23+
 24+if ( !defined( 'MEDIAWIKI' ) ) {
 25+ die( 'Not an entry point.' );
 26+}
 27+
 28+if ( version_compare( $wgVersion, '1.18c', '<' ) ) { // Needs to be 1.18c because version_compare() works in confusing ways.
 29+ die( '<b>Error:</b> Create Page requires MediaWiki 1.18 or above.' );
 30+}
 31+
 32+define( 'CP_VERSION', '0.1' );
 33+
 34+$wgExtensionCredits['other'][] = array(
 35+ 'path' => __FILE__,
 36+ 'name' => 'Create Page',
 37+ 'version' => CP_VERSION,
 38+ 'author' => array(
 39+ '[http://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]',
 40+ ),
 41+ 'url' => 'https://www.mediawiki.org/wiki/Extension:Create_Page',
 42+ 'descriptionmsg' => 'cp-desc'
 43+);
 44+
 45+// i18n
 46+$wgExtensionMessagesFiles['CreatePage'] = dirname( __FILE__ ) . '/CreatePage.i18n.php';
 47+$wgExtensionMessagesFiles['CreatePageAlias'] = dirname( __FILE__ ) . '/CreatePage.alias.php';
 48+$wgExtensionMessagesFiles['CreatePageMagic'] = dirname( __FILE__ ) . '/CreatePage.magic.php';
 49+
 50+$wgAutoloadClasses['SpecialCreatePage'] = dirname( __FILE__ ) . '/SpecialCreatePage.php';
 51+$wgSpecialPages['CreatePage'] = 'SpecialCreatePage';
 52+
 53+$wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) {
 54+ $parser->setFunctionHook( 'createpage', function( Parser $parser, PPFrame $frame, array $args ) {
 55+ $html = Html::openElement( 'form', array(
 56+ 'action' => SpecialPage::getTitleFor( 'CreatePage' )->getLocalURL(),
 57+ 'method' => 'post',
 58+ ) );
 59+
 60+ $html .= Html::input(
 61+ 'pagename',
 62+ array_key_exists( 1, $args ) ? trim( $frame->expand( $args[1] ) ) : ''
 63+ );
 64+
 65+ if ( array_key_exists( 0, $args ) ) {
 66+ $html .= Html::hidden( 'pagens', trim( $frame->expand( $args[0] ) ) );
 67+ }
 68+
 69+ $html .= '&#160;';
 70+
 71+ $html .= Html::input(
 72+ 'createpage',
 73+ array_key_exists( 2, $args ) ? trim( $frame->expand( $args[2] ) ) : wfMsg( 'cp-create' ),
 74+ 'submit'
 75+ );
 76+
 77+ $html .= '</form>';
 78+
 79+ return array( $html, 'isHTML' => true );
 80+ }, SFH_OBJECT_ARGS );
 81+
 82+ return true;
 83+};
Property changes on: trunk/extensions/CreatePage/CreatePage.php
___________________________________________________________________
Added: svn:eol-style
184 + native
Index: trunk/extensions/CreatePage/SpecialCreatePage.php
@@ -0,0 +1,42 @@
 2+<?php
 3+
 4+/**
 5+ * Redirect the submission request of the createpage parser hook to the actual page.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file SpecialCreatePage.php
 10+ * @ingroup CreatePage
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class SpecialCreatePage extends UnlistedSpecialPage {
 16+
 17+ public function __construct() {
 18+ parent::__construct( 'CreatePage' );
 19+ }
 20+
 21+ public function execute( $subPage ) {
 22+ $req = $this->getRequest();
 23+
 24+ if ( $req->wasPosted() && $req->getCheck( 'pagename' ) ) {
 25+ $parts = array( $req->getText( 'pagename' ) );
 26+
 27+ if ( $req->getCheck( 'pagens' ) ) {
 28+ array_unshift( $parts, $req->getText( 'pagens' ) );
 29+ }
 30+
 31+ $target = Title::newFromText( implode( ':', $parts ) )->getLocalUrl( array(
 32+ 'action' => 'edit',
 33+ 'redlink' => '1'
 34+ ) );
 35+ }
 36+ else {
 37+ $target = Title::newMainPage()->getLocalURL();
 38+ }
 39+
 40+ $this->getOutput()->redirect( $target );
 41+ }
 42+
 43+}
\ No newline at end of file
Property changes on: trunk/extensions/CreatePage/SpecialCreatePage.php
___________________________________________________________________
Added: svn:eol-style
144 + native
Index: trunk/extensions/CreatePage/CreatePage.alias.php
@@ -0,0 +1,22 @@
 2+<?php
 3+
 4+/**
 5+ * Aliases for the special pages of the Create Page extension.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file CreatePage.alias.php
 10+ * @ingroup CreatePage
 11+ *
 12+ * @licence GNU GPL v3+
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+
 16+$specialPageAliases = array();
 17+
 18+/** English
 19+ * @author Jeroen De Dauw
 20+ */
 21+$specialPageAliases['en'] = array(
 22+ 'CreatePage' => array( 'CreatePage' ),
 23+);
\ No newline at end of file
Property changes on: trunk/extensions/CreatePage/CreatePage.alias.php
___________________________________________________________________
Added: svn:eol-style
124 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r111748r110692: Consistency tweaks in preparation for adding extension to translatew...raymond14:29, 17 February 2012
r111749r110692: Register extension for translatewiki.net.raymond14:31, 17 February 2012
r112233follow up r111749 r110692jeroendedauw19:49, 23 February 2012

Comments

#Comment by Nikerabbit (talk | contribs)   13:17, 23 February 2012

CreatePage special page name is already in use by Uniwiki extensions.

#Comment by SPQRobin (talk | contribs)   19:38, 23 February 2012

The description message is a bit unclearly worded (and please also add qqq). Also, isn't this nearly the same as InputBox type=create?

#Comment by Jeroen De Dauw (talk | contribs)   19:47, 23 February 2012

It's indeed very similar to InputBox type=create. Did not know that one existed though. Then again, only took 30 mins to write this.

#Comment by 😂 (talk | contribs)   23:48, 27 February 2012

Duplication isn't good :\ Is there anything this does that InputBox doesn't?

#Comment by Jeroen De Dauw (talk | contribs)   00:55, 28 February 2012

It passes redlink=1 and it has a simpler syntax. Plus it allows only having this functionality, rather then all of InputBox.

#Comment by 😂 (talk | contribs)   01:05, 28 February 2012

I'm not convinced, but I'm not going to bikeshed.

#Comment by Jeroen De Dauw (talk | contribs)   01:18, 28 February 2012

But mine is simplest! :)

It's very true we got a lot of feature duplication though. One effect of not having a decent way to browse through existing MediaWiki extensions...

> Duplication isn't good

Choice is. Competition is. If you disagree, please go kill everyone except yourself, their DNA is almost a complete duplicate of yours :D

Status & tagging log