r110330 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110329‎ | r110330 | r110331 >
Date:21:31, 30 January 2012
Author:foxtrott
Status:deferred
Tags:
Comment:
Creating new extension
Modified paths:
  • /trunk/extensions/SemanticPageSeries/SemanticPageSeries.alias.php (added) (history)
  • /trunk/extensions/SemanticPageSeries/SemanticPageSeries.i18n.php (added) (history)
  • /trunk/extensions/SemanticPageSeries/SemanticPageSeries.magic.php (added) (history)
  • /trunk/extensions/SemanticPageSeries/SemanticPageSeries.php (added) (history)
  • /trunk/extensions/SemanticPageSeries/includes (added) (history)
  • /trunk/extensions/SemanticPageSeries/includes/SPSException.php (added) (history)
  • /trunk/extensions/SemanticPageSeries/includes/SPSPageCreationJob.php (added) (history)
  • /trunk/extensions/SemanticPageSeries/includes/SPSSpecialSeriesEdit.php (added) (history)
  • /trunk/extensions/SemanticPageSeries/includes/SPSUtils.php (added) (history)
  • /trunk/extensions/SemanticPageSeries/includes/iterators (added) (history)
  • /trunk/extensions/SemanticPageSeries/includes/iterators/SPSDateIterator.php (added) (history)
  • /trunk/extensions/SemanticPageSeries/includes/iterators/SPSIterator.php (added) (history)

Diff [purge]

Index: trunk/extensions/SemanticPageSeries/SemanticPageSeries.i18n.php
@@ -0,0 +1,49 @@
 2+<?php
 3+/**
 4+ * Language file for Semantic Pages Series
 5+ */
 6+
 7+$messages = array();
 8+
 9+/** English
 10+ * @author F.trott
 11+ */
 12+$messages['en'] = array(
 13+ 'semanticpageseries-desc' => 'An extension creating a series of pages from one [https://www.mediawiki.org/wiki/Extension:Semantic_Forms Semantic Form]',
 14+ 'spssuccesstitle' => 'Creating $1 pages',
 15+ 'spssuccess' => '$1 pages will be created.',
 16+ 'spserror' => 'An error occurred',
 17+
 18+ 'spserror_diffnotsupported' => 'The Diff action is not supported for page series.',
 19+ 'spserror_previewnotsupported' => 'The Preview action is not supported for page series.',
 20+ 'spserror_noiteratorname' => 'No iterator name given.',
 21+ 'spserror_iteratorunknown' => 'Iterator "$1" does not exist.',
 22+ 'spserror_noformname' => 'No form name given.',
 23+ 'spserror_formunknown' => 'Form "$1" does not exist.',
 24+ 'spserror_notargetformname' => 'No target form name given.',
 25+ 'spserror_notargetfieldname' => 'No target field name given.',
 26+ 'spserror_iteratorparammissing' => "The following iterator parameters are missing in the #seriesformlink call:\n$1",
 27+ 'spserror_noiteratordata' => 'No iterator parameters found in the sent data.',
 28+ 'spserror_pagegenerationlimitexeeded' => 'You tried to generate $1 pages. Your limit is $2 pages.',
 29+);
 30+
 31+/** Message documentation (Message documentation)
 32+ * @author F.trott
 33+ */
 34+$messages['qqq'] = array(
 35+ 'semanticpageseries-desc' => '{{desc}}',
 36+ 'spssuccesstitle' => 'The title of a page containing a success message. The parameter will contain the category of pages to be created, e.g. Event',
 37+ 'spssuccess' => 'A success message. The parameter will contain a number.',
 38+ 'spserror' => 'The title of en error page',
 39+
 40+ 'spserror_diffnotsupported' => 'An error message',
 41+ 'spserror_previewnotsupported' => 'An error message',
 42+ 'spserror_noiteratorname' => 'An error message',
 43+ 'spserror_iteratorunknown' => 'An error message',
 44+ 'spserror_noformname' => 'An error message',
 45+ 'spserror_formunknown' => 'An error message',
 46+ 'spserror_notargetformname' => 'An error message',
 47+ 'spserror_notargetfieldname' => 'An error message',
 48+ 'spserror_iteratorparammissing' => 'An error message'
 49+);
 50+
Property changes on: trunk/extensions/SemanticPageSeries/SemanticPageSeries.i18n.php
___________________________________________________________________
Added: svn:eol-style
151 + native
Index: trunk/extensions/SemanticPageSeries/SemanticPageSeries.magic.php
@@ -0,0 +1,17 @@
 2+<?php
 3+
 4+/**
 5+ * Association of magic words with their magic word ids
 6+ *
 7+ * @author Stephan Gambke
 8+ * @file
 9+ * @ingroup SemanticPageSeries
 10+ */
 11+
 12+$magicWords = array();
 13+
 14+/** English
 15+ */
 16+$magicWords['en'] = array(
 17+ 'serieslink' => array( 1, 'serieslink' ),
 18+);
Property changes on: trunk/extensions/SemanticPageSeries/SemanticPageSeries.magic.php
___________________________________________________________________
Added: svn:eol-style
119 + native
Index: trunk/extensions/SemanticPageSeries/SemanticPageSeries.php
@@ -0,0 +1,87 @@
 2+<?php
 3+
 4+/**
 5+ * An extension creating a series of pages from one Semantic Form.
 6+ *
 7+ * @defgroup SemanticPageSeries Semantic Page Series
 8+ * @author Stephan Gambke
 9+ * @version 0.1
 10+ */
 11+/**
 12+ * The main file of the SemanticPageSeries extension
 13+ *
 14+ * @author Stephan Gambke
 15+ *
 16+ * @file
 17+ * @ingroup SemanticPageSeries
 18+ */
 19+if ( !defined( 'MEDIAWIKI' ) ) {
 20+ die( 'This file is part of a MediaWiki extension, it is not a valid entry point.' );
 21+}
 22+
 23+if ( !defined( 'SMW_VERSION' ) ) {
 24+ die( '<b>Error:</b> <a href="https://www.mediawiki.org/wiki/Extension:Semantic_Page_Series">Semantic Page Series</a> depends on the Semantic MediaWiki extension. You need to install <a href="https://www.mediawiki.org/wiki/Extension:Semantic_MediaWiki">Semantic MediaWiki</a> first.' );
 25+}
 26+
 27+if ( !defined( 'SF_VERSION' ) ) {
 28+ die( '<b>Error:</b> <a href="https://www.mediawiki.org/wiki/Extension:Semantic_Page_Series">Semantic Page Series</a> depends on the Semantic Forms extension. You need to install <a href="https://www.mediawiki.org/wiki/Extension:Semantic_Forms">Semantic Forms</a> first.' );
 29+}
 30+
 31+/**
 32+ * The Semantic Page Series version
 33+ */
 34+define( 'SPS_VERSION', '0.1 alpha' );
 35+
 36+// register the extension
 37+$wgExtensionCredits[defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'other'][] = array(
 38+ 'path' => __FILE__,
 39+ 'name' => 'Semantic Page Series',
 40+ 'author' => '[http://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]',
 41+ 'url' => 'https://www.mediawiki.org/wiki/Extension:Semantic_Page_Series',
 42+ 'descriptionmsg' => 'SemanticPageSeries-desc',
 43+ 'version' => SPS_VERSION,
 44+);
 45+
 46+
 47+// server-local path to this file
 48+$dir = dirname( __FILE__ );
 49+
 50+// register message files
 51+$wgExtensionMessagesFiles['SemanticPageSeries'] = $dir . '/SemanticPageSeries.i18n.php';
 52+$wgExtensionMessagesFiles['SemanticPageSeriesMagic'] = $dir . '/SemanticPageSeries.magic.php';
 53+$wgExtensionMessagesFiles['SemanticPageSeriesAlias'] = $dir . '/SemanticPageSeries.alias.php';
 54+
 55+// register class files with the Autoloader
 56+$wgAutoloadClasses['SPSUtils'] = $dir . '/includes/SPSUtils.php';
 57+$wgAutoloadClasses['SPSSpecialSeriesEdit'] = $dir . '/includes/SPSSpecialSeriesEdit.php';
 58+$wgAutoloadClasses['SPSException'] = $dir . '/includes/SPSException.php';
 59+$wgAutoloadClasses['SPSPageCreationJob'] = $dir . '/includes/SPSPageCreationJob.php';
 60+
 61+$wgAutoloadClasses['SPSIterator'] = $dir . '/includes/iterators/SPSIterator.php';
 62+$wgAutoloadClasses['SPSDateIterator'] = $dir . '/includes/iterators/SPSDateIterator.php';
 63+
 64+
 65+// register Special page
 66+$wgSpecialPages['SeriesEdit'] = 'SPSSpecialSeriesEdit'; # Tell MediaWiki about the new special page and its class name
 67+
 68+// register hook handlers
 69+
 70+// Specify the function that will initialize the parser function.
 71+$wgHooks['ParserFirstCallInit'][] = 'SPSUtils::initParserFunction';
 72+
 73+// define constants
 74+define('SPS_NOLIMIT', PHP_INT_MAX);
 75+
 76+// register iterators
 77+$spsgIterators = array (
 78+ 'date' => 'SPSDateIterator'
 79+);
 80+
 81+$spsgPageGenerationLimits = array(
 82+ '*' => 0,
 83+ 'user' => 10,
 84+ 'sysop' => SPS_NOLIMIT
 85+);
 86+
 87+
 88+$wgJobClasses['spsCreatePage'] = 'SPSPageCreationJob';
Property changes on: trunk/extensions/SemanticPageSeries/SemanticPageSeries.php
___________________________________________________________________
Added: svn:eol-style
189 + native
Index: trunk/extensions/SemanticPageSeries/includes/SPSPageCreationJob.php
@@ -0,0 +1,56 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the SPSPageCreationJob class
 6+ *
 7+ * @author Stephan Gambke
 8+ * @file
 9+ * @ingroup SemanticPageSeries
 10+ */
 11+if ( !defined( 'SPS_VERSION' ) ) {
 12+ die( 'This file is part of the SemanticPageSeries extension, it is not a valid entry point.' );
 13+}
 14+
 15+/**
 16+ * The SPSPageCreationJob class.
 17+ *
 18+ * @ingroup SemanticPageSeries
 19+ */
 20+class SPSPageCreationJob extends Job {
 21+
 22+// public function __construct( $command, $title, $params = false, $id = 0 ) {
 23+// parent::__construct( $command, $title, $params, $id );
 24+// }
 25+
 26+ function __construct( $title, $params = '', $id = 0 ) {
 27+ parent::__construct( 'spsCreatePage', $title, $params, $id );
 28+ }
 29+
 30+ /**
 31+ * Run the job
 32+ * @return boolean success
 33+ */
 34+ function run() {
 35+
 36+ $this->params['form'] = $this->title->getText();
 37+
 38+ $handler = new SFAutoeditAPI( null, 'sfautoedit' );
 39+ $handler->isApiQuery( false );
 40+ $handler->setOptions( $this->params );
 41+
 42+ $result = $handler->storeSemanticData( false );
 43+
 44+ // wrap result in ok/error message
 45+ if ( $result === true ) {
 46+
 47+ $options = $handler->getOptions();
 48+ $result = wfMsg( 'sf_autoedit_success', $options['target'], $options['form']) ;
 49+ } else {
 50+
 51+ $result = wfMsgReplaceArgs( '$1', array($result) );
 52+ }
 53+
 54+ wfDebugLog( 'sps', 'Page Creation Job: ' . $result );
 55+ }
 56+
 57+}
Property changes on: trunk/extensions/SemanticPageSeries/includes/SPSPageCreationJob.php
___________________________________________________________________
Added: svn:eol-style
158 + native
Index: trunk/extensions/SemanticPageSeries/includes/SPSException.php
@@ -0,0 +1,58 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the SPSException class
 6+ *
 7+ * @author Stephan Gambke
 8+ * @file
 9+ * @ingroup SemanticPageSeries
 10+ */
 11+if ( !defined( 'SPS_VERSION' ) ) {
 12+ die( 'This file is part of the SemanticPageSeries extension, it is not a valid entry point.' );
 13+}
 14+
 15+/**
 16+ * The SPSException class.
 17+ *
 18+ * @ingroup SemanticPageSeries
 19+ */
 20+class SPSException extends MWException {
 21+
 22+ /**
 23+ * Return a HTML message.
 24+ *
 25+ * Overrides method from MWException: We don't need a backtrace
 26+ *
 27+ * @return String html to output
 28+ */
 29+ function getHTML() {
 30+ return '<p>' . nl2br( htmlspecialchars( $this->getMessage() ) ) .
 31+ "</p>\n";
 32+ }
 33+
 34+ /**
 35+ * Return a text message.
 36+ *
 37+ * Overrides method from MWException: We don't need a backtrace
 38+ *
 39+ */
 40+ function getText() {
 41+ return $this->getMessage();
 42+ }
 43+
 44+ /**
 45+ * Return titles of this error page
 46+ *
 47+ * Overrides method from MWException: We have a different page title
 48+ *
 49+ */
 50+ function getPageTitle() {
 51+ if ( $this->useMessageCache() ) {
 52+ return wfMsg( 'spserror' );
 53+ } else {
 54+ global $wgSitename;
 55+ return "$wgSitename error";
 56+ }
 57+ }
 58+
 59+}
Property changes on: trunk/extensions/SemanticPageSeries/includes/SPSException.php
___________________________________________________________________
Added: svn:eol-style
160 + native
Index: trunk/extensions/SemanticPageSeries/includes/SPSUtils.php
@@ -0,0 +1,64 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the SPSUtils class
 6+ *
 7+ * @author Stephan Gambke
 8+ * @file
 9+ * @ingroup SemanticPageSeries
 10+ */
 11+if ( !defined( 'SPS_VERSION' ) ) {
 12+ die( 'This file is part of the SemanticPageSeries extension, it is not a valid entry point.' );
 13+}
 14+
 15+/**
 16+ * The SPSUtils class.
 17+ *
 18+ * @ingroup SemanticPageSeries
 19+ */
 20+class SPSUtils {
 21+
 22+ /**
 23+ * Initialize the parser functions of the extension.
 24+ *
 25+ * Currently only #serieslink
 26+ *
 27+ * @param Parser $parser
 28+ * @return bool
 29+ */
 30+ static public function initParserFunction( &$parser ) {
 31+
 32+ // Create a function hook associating the "example" magic word with the
 33+ // efExampleParserFunction_Render() function.
 34+ $parser->setFunctionHook( 'serieslink', array('SPSUtils', 'renderSeriesLink') );
 35+
 36+ // Return true so that MediaWiki continues to load extensions.
 37+ return true;
 38+ }
 39+
 40+ /**
 41+ * Renders the #serieslink parser function.
 42+ *
 43+ * @param Parser $parser
 44+ * @return string the unique tag which must be inserted into the stripped text
 45+ */
 46+ static public function renderSeriesLink( &$parser ) {
 47+
 48+ $params = func_get_args();
 49+ array_shift( $params ); // We don't need the parser.
 50+
 51+ // remove the target parameter should it be present
 52+ foreach ( $params as $key => $value ) {
 53+ $elements = explode( '=', $value, 2 );
 54+ if ( $elements[0] === 'target' ){
 55+ unset($params[$key]);
 56+ }
 57+
 58+ }
 59+
 60+ // hack to remove newline from beginning of output, thanks to
 61+ // http://jimbojw.com/wiki/index.php?title=Raw_HTML_Output_from_a_MediaWiki_Parser_Function
 62+ return $parser->insertStripItem( SFUtils::createFormLink( $parser, 'SeriesEdit', $params ), $parser->mStripState );
 63+ }
 64+
 65+}
Property changes on: trunk/extensions/SemanticPageSeries/includes/SPSUtils.php
___________________________________________________________________
Added: svn:eol-style
166 + native
Index: trunk/extensions/SemanticPageSeries/includes/iterators/SPSDateIterator.php
@@ -0,0 +1,46 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the SPSDateIterator class
 6+ *
 7+ * @author Stephan Gambke
 8+ * @file
 9+ * @ingroup SemanticPageSeries
 10+ */
 11+if ( !defined( 'SPS_VERSION' ) ) {
 12+ die( 'This file is part of the SemanticPageSeries extension, it is not a valid entry point.' );
 13+}
 14+
 15+/**
 16+ * The SPSDateIterator class.
 17+ *
 18+ * @ingroup SemanticPageSeries
 19+ */
 20+class SPSDateIterator extends SPSIterator {
 21+
 22+ /**
 23+ * @return array An array containing the names of the parameters this iterator uses.
 24+ */
 25+ function getParameterNames() {
 26+ return array('start', 'end', 'period', 'unit');
 27+ }
 28+
 29+ /**
 30+ * @return an array of the values to be used in the target field of the target form
 31+ */
 32+ function getValues ( &$data ){
 33+
 34+ //prepare params for getDatesForRecurringEvent
 35+ $params = array (
 36+ 'property=SomeDummyProperty',
 37+ 'start=' . $data['start'],
 38+ 'end=' . $data['end'],
 39+ 'period=' . $data['period'],
 40+ 'unit=' . $data['unit'],
 41+ );
 42+
 43+ $values = SMWSetRecurringEvent::getDatesForRecurringEvent($params);
 44+
 45+ return $values[1];
 46+ }
 47+}
Property changes on: trunk/extensions/SemanticPageSeries/includes/iterators/SPSDateIterator.php
___________________________________________________________________
Added: svn:eol-style
148 + native
Index: trunk/extensions/SemanticPageSeries/includes/iterators/SPSIterator.php
@@ -0,0 +1,31 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the SPSIterator class
 6+ *
 7+ * @author Stephan Gambke
 8+ * @file
 9+ * @ingroup SemanticPageSeries
 10+ */
 11+if ( !defined( 'SPS_VERSION' ) ) {
 12+ die( 'This file is part of the SemanticPageSeries extension, it is not a valid entry point.' );
 13+}
 14+
 15+/**
 16+ * The SPSIterator class.
 17+ *
 18+ * @ingroup SemanticPageSeries
 19+ */
 20+abstract class SPSIterator {
 21+
 22+ /**
 23+ * @return array An array containing the names of the parameters this iterator uses.
 24+ */
 25+ abstract function getParameterNames();
 26+
 27+ /**
 28+ * @return an array of the values to be used in the target field of the target form
 29+ */
 30+ abstract function getValues ( &$data );
 31+
 32+}
Property changes on: trunk/extensions/SemanticPageSeries/includes/iterators/SPSIterator.php
___________________________________________________________________
Added: svn:eol-style
133 + native
Index: trunk/extensions/SemanticPageSeries/includes/SPSSpecialSeriesEdit.php
@@ -0,0 +1,369 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the SPSSpecialSeriesEdit class
 6+ *
 7+ * @author Stephan Gambke
 8+ * @file
 9+ * @ingroup SemanticPageSeries
 10+ */
 11+if ( !defined( 'SPS_VERSION' ) ) {
 12+ die( 'This file is part of the SemanticPageSeries extension, it is not a valid entry point.' );
 13+}
 14+
 15+/**
 16+ * The SPSSpecialSeriesEdit class.
 17+ *
 18+ * @ingroup SemanticPageSeries
 19+ */
 20+class SPSSpecialSeriesEdit extends SpecialPage {
 21+
 22+ public function __construct() {
 23+ parent::__construct( 'SeriesEdit' );
 24+ }
 25+
 26+ public function execute( $parameters ) {
 27+ global $wgRequest, $wgOut;
 28+
 29+ $this->setHeaders();
 30+
 31+ if ( $wgRequest->getCheck( 'wpDiff' ) ) {
 32+ // no support for the diff action
 33+ throw new SPSException( wfMsg( 'spserror_diffnotsupported' ) );
 34+ } elseif ( $wgRequest->getCheck( 'wpPreview' ) ) {
 35+
 36+ // no support for the preview action
 37+ throw new SPSException( wfMsg( 'spserror_previewnotsupported' ) );
 38+ } elseif ( $wgRequest->getCheck( 'wpSave' ) ) {
 39+
 40+ // saving requested
 41+
 42+ $this->evaluateForm( $wgRequest );
 43+ } elseif ( isset( $_SESSION ) && isset( $_SESSION['spsForm'] ) && isset( $_SESSION['spsResult'] ) ) {
 44+
 45+ // cookies enabled and result data stored
 46+ $wgOut->setPageTitle( wfMsg( 'spssuccesstitle', $_SESSION['spsForm'] ) );
 47+ $wgOut->addHTML( wfMsg( 'spssuccess', $_SESSION['spsResult'] ) );
 48+
 49+ unset( $_SESSION['spsForm'] );
 50+ unset( $_SESSION['spsResult'] );
 51+
 52+ } elseif ( !isset( $_SESSION ) && count( $_GET ) === 2 ) {
 53+
 54+ // cookies disabled, try getting result data from URL
 55+ $get = $_GET;
 56+ unset( $get['title'] );
 57+ $keys = array_keys( $get );
 58+
 59+ $wgOut->setPageTitle( wfMsg( 'spssuccesstitle', $keys[0] ) );
 60+ $wgOut->addHTML( wfMsg( 'spssuccess', $get[$keys[0]] ) );
 61+ } else {
 62+
 63+ // no action requested, show form
 64+ $this->printForm( $parameters, $wgRequest );
 65+ }
 66+ }
 67+
 68+ private function printForm( &$parameters, WebRequest &$request ) {
 69+
 70+ global $wgOut, $sfgFormPrinter;
 71+
 72+ // Prepare parameters for SFFormPrinter::formHTML
 73+ // there is no ONE target page
 74+ $targetTitle = null;
 75+
 76+ // formDefinition
 77+ $formName = $request->getText( 'form' );
 78+
 79+ // if query string did not contain these variables, try the URL
 80+ if ( $formName === '' ) {
 81+ $queryparts = explode( '/', $parameters );
 82+ $formName = isset( $queryparts[0] ) ? $queryparts[0] : null;
 83+
 84+ // if the form name wasn't in the URL either, throw an error
 85+ if ( is_null( $formName ) || $formName === '' ) {
 86+ throw new SPSException( wfMsg( 'spserror_noformname' ) );
 87+ }
 88+ }
 89+
 90+ $formTitle = Title::makeTitleSafe( SF_NS_FORM, $formName );
 91+
 92+ if ( !$formTitle->exists() ) {
 93+ throw new SPSException( wfMsg( 'spserror_formunknown', $formName ) );
 94+ }
 95+
 96+ $formArticle = new Article( $formTitle );
 97+ $formDefinition = StringUtils::delimiterReplace( '<noinclude>', '</noinclude>', '', $formArticle->getContent() );
 98+
 99+ // formSubmitted
 100+ $formSubmitted = false;
 101+
 102+ // pageContents
 103+ $pageContents = null;
 104+
 105+ // get 'preload' query value, if it exists
 106+ if ( $request->getCheck( 'preload' ) ) {
 107+ $pageContents = SFFormUtils::getPreloadedText( $request->getVal( 'preload' ) );
 108+ } else {
 109+ // let other extensions preload the page, if they want
 110+ wfRunHooks( 'sfEditFormPreloadText', array(&$pageContents, $targetTitle, $formTitle) );
 111+ }
 112+
 113+ // pageIsSource
 114+ $pageIsSource = ( $pageContents != null );
 115+
 116+ // pageNameFormula
 117+ // parse the form to see if it has a 'page name' value set
 118+ $matches;
 119+ if ( preg_match( '/{{{info.*page name\s*=\s*(.*)}}}/m', $formDefinition, $matches ) ) {
 120+ $pageNameElements = SFUtils::getFormTagComponents( $matches[1] );
 121+ $pageNameFormula = $pageNameElements[0];
 122+ } else {
 123+ return 'sf_formedit_badurl';
 124+ }
 125+
 126+ // get the iterator parameters
 127+ $iteratorData = $this->buildIteratorParameters( $request );
 128+
 129+ // Call SFFormPrinter::formHTML
 130+ list ( $formText, $javascriptText, $dataText, $formPageTitle, $generatedPageName ) =
 131+ $sfgFormPrinter->formHTML( $formDefinition, $formSubmitted, $pageIsSource, $formArticle->getID(), $pageContents, '', $pageNameFormula );
 132+
 133+ // Set Special page main header;
 134+ // override the default title for this page if a title was specified in the form
 135+ if ( $formPageTitle != null ) {
 136+ $wgOut->setPageTitle( $formPageTitle );
 137+ } else {
 138+ $wgOut->setPageTitle( wfMsg( 'sf_formedit_createtitlenotarget', $formTitle->getText() ) );
 139+ }
 140+
 141+ $preFormHtml = '';
 142+ wfRunHooks( 'sfHTMLBeforeForm', array(&$targetTitle, &$preFormHtml) );
 143+
 144+ $text = '<form name="createbox" id="sfForm" action="" method="post" class="createbox">'
 145+ . $preFormHtml
 146+ . "\n"
 147+ . SFFormUtils::hiddenFieldHTML( 'iteratordata', $iteratorData )
 148+ . $formText;
 149+
 150+ SFUtils::addJavascriptAndCSS();
 151+
 152+ if ( !empty( $javascriptText ) ) {
 153+ $wgOut->addScript( ' <script type="text/javascript">' . "\n$javascriptText\n" . '</script>' . "\n" );
 154+ }
 155+
 156+ $wgOut->addHTML( $text );
 157+
 158+ return null;
 159+ }
 160+
 161+ private function evaluateForm( WebRequest &$request ) {
 162+
 163+ global $wgOut, $spsgIterators;
 164+
 165+ $requestValues = $_POST;
 166+
 167+ if ( array_key_exists( 'iteratordata', $requestValues ) ) {
 168+ $iteratorData = FormatJson::decode( $requestValues['iteratordata'], true );
 169+ unset( $requestValues['iteratordata'] );
 170+ } else {
 171+ throw new SPSException( wfMsg( 'spserror_noiteratordata' ) );
 172+ }
 173+
 174+ $iteratorName = null;
 175+ $targetFormName = null;
 176+ $targetFieldName = null;
 177+
 178+ foreach ( $iteratorData as $param => $value ) {
 179+
 180+ switch ( $param ) {
 181+ case 'iterator':
 182+ // iteratorName
 183+ $iteratorName = $value;
 184+ break;
 185+ case 'targetform':
 186+ $targetFormName = $value;
 187+ break;
 188+ case 'targetfield':
 189+ $targetFieldName = $value;
 190+ break;
 191+ default :
 192+ $iteratorParams[$param] = $this->getAndRemoveFromArray( $requestValues, $value );
 193+ }
 194+ }
 195+
 196+ if ( is_null( $iteratorName ) || $iteratorName === '' ) {
 197+ throw new SPSException( wfMsg( 'spserror_noiteratorname' ) );
 198+ }
 199+
 200+ if ( !array_key_exists( $iteratorName, $spsgIterators ) ) {
 201+ throw new SPSException( wfMsg( 'spserror_iteratorunknown', $iteratorName ) );
 202+ }
 203+
 204+ // iterator
 205+ $iterator = new $spsgIterators[$iteratorName];
 206+
 207+ $iteratorValues = $iterator->getValues( $iteratorParams );
 208+ $iteratorValuesCount = count( $iteratorValues );
 209+ $userlimit = $this->getPageGenerationLimit();
 210+
 211+ // check userlimit
 212+ if ( $iteratorValuesCount > $userlimit ) {
 213+ throw new SPSException( wfMsg( 'spserror_pagegenerationlimitexeeded', $iteratorValuesCount, $userlimit ) );
 214+ }
 215+
 216+ $targetFormTitle = Title::makeTitleSafe( SF_NS_FORM, $targetFormName );
 217+
 218+ foreach ( $iteratorValues as $value ) {
 219+ SFAutoeditAPI::addToArray( $requestValues, $targetFieldName, $value, true );
 220+ wfDebugLog( 'sps', 'Insert SPSPageCreationJob' );
 221+ $job = new SPSPageCreationJob( $targetFormTitle, $requestValues );
 222+ $job->insert();
 223+ }
 224+
 225+ if ( isset( $_SESSION ) ) {
 226+ // cookies enabled
 227+ $request->setSessionData( 'spsResult', $iteratorValuesCount );
 228+ $request->setSessionData( 'spsForm', $targetFormName );
 229+ header( 'Location: ' . $this->getTitle()->getFullURL() );
 230+ } else {
 231+
 232+ // cookies disabled, write result data to URL
 233+ header( 'Location: ' . $this->getTitle()->getFullURL() . '?' . "$targetFormName=" . $iteratorValuesCount );
 234+ }
 235+
 236+ return null;
 237+ }
 238+
 239+ /**
 240+ * Builds a JSON blob of the data required to use the iterator.
 241+ * @param WebRequest $request
 242+ * @return type
 243+ */
 244+ private function buildIteratorParameters( WebRequest &$request ) {
 245+
 246+ global $spsgIterators;
 247+
 248+ // iteratorName
 249+ $iteratorName = $request->getVal( 'iterator' );
 250+
 251+ if ( is_null( $iteratorName ) ) {
 252+ throw new SPSException( wfMsg( 'spserror_noiteratorname' ) );
 253+ }
 254+
 255+ if ( !array_key_exists( $iteratorName, $spsgIterators ) ) {
 256+ throw new SPSException( wfMsg( 'spserror_iteratorunknown', $iteratorName ) );
 257+ }
 258+
 259+ // iterator
 260+ $iterator = new $spsgIterators[$iteratorName];
 261+
 262+ // targetFormName
 263+ $targetFormName = $request->getVal( 'target_form' );
 264+
 265+ if ( is_null( $targetFormName ) ) {
 266+ throw new SPSException( wfMsg( 'spserror_notargetformname' ) );
 267+ }
 268+
 269+ // targetFormTitle is not really needed at this stage,
 270+ // but we throw an error early if it does not exist
 271+ $targetFormTitle = Title::makeTitleSafe( SF_NS_FORM, $targetFormName );
 272+
 273+ if ( !$targetFormTitle->exists() ) {
 274+ throw new SPSException( wfMsg( 'spserror_formunknown', $targetFormName ) );
 275+ }
 276+
 277+ // targetFieldName
 278+ $targetFieldName = $request->getVal( 'target_field' );
 279+
 280+ if ( is_null( $targetFieldName ) ) {
 281+ throw new SPSException( wfMsg( 'spserror_notargetfieldname' ) );
 282+ }
 283+
 284+ $params = array(
 285+ 'iterator' => $iteratorName,
 286+ 'targetform' => $targetFormName,
 287+ 'targetfield' => $targetFieldName
 288+ );
 289+
 290+ $paramNames = $iterator->getParameterNames();
 291+ $errors = '';
 292+
 293+ foreach ( $paramNames as $paramName ) {
 294+
 295+ $param = $request->getVal( $paramName );
 296+
 297+ if ( is_null( $param ) ) {
 298+ $errors .= "$paramName\n";
 299+ }
 300+ $params[$paramName] = $param;
 301+ }
 302+
 303+ if ( $errors !== '' ) {
 304+ throw new SPSException( wfMsg( 'spserror_iteratorparammissing', $errors ) );
 305+ }
 306+
 307+ return FormatJson::encode( $params );
 308+ }
 309+
 310+ /**
 311+ * This function recursively retrieves a value from an array of arrays and deletes it.
 312+ * $key identifies path.
 313+ * Format: 1stLevelName[2ndLevel][3rdLevel][...], i.e. normal array notation
 314+ * $toplevel: if this is a toplevel value.
 315+ *
 316+ * @param type $array
 317+ * @param type $key
 318+ * @param type $toplevel
 319+ */
 320+ private function getAndRemoveFromArray( &$array, $key, $toplevel = true ) {
 321+
 322+ $matches = array();
 323+
 324+ if ( array_key_exists( $key, $array ) ) {
 325+ $value = $array[$key];
 326+ unset( $array[$key] );
 327+ return $value;
 328+ } elseif ( preg_match( '/^([^\[\]]*)\[([^\[\]]*)\](.*)/', $key, $matches ) ) {
 329+
 330+ // for some reason toplevel keys get their spaces encoded by MW.
 331+ // We have to imitate that.
 332+ // FIXME: Are there other cases than spaces?
 333+ if ( $toplevel ) {
 334+ $key = str_replace( ' ', '_', $matches[1] );
 335+ } else {
 336+ $key = $matches[1];
 337+ }
 338+
 339+ if ( !array_key_exists( $key, $array ) ) {
 340+ return null;
 341+ }
 342+
 343+ $value = $this->getAndRemoveFromArray( $array[$key], $matches[2] . $matches[3], false );
 344+
 345+ if ( empty( $array[$key] ) ) {
 346+ unset( $array[$key] );
 347+ }
 348+
 349+ return $value;
 350+ } else {
 351+ // key not found in array
 352+ return null;
 353+ }
 354+ }
 355+
 356+ public function getPageGenerationLimit() {
 357+ global $wgUser, $spsgPageGenerationLimits;
 358+
 359+ $limit = 0;
 360+ $groups = $wgUser->getEffectiveGroups();
 361+
 362+ foreach ( $groups as $group ) {
 363+ if ( array_key_exists( $group, $spsgPageGenerationLimits) ) {
 364+ $limit = max($limit, $spsgPageGenerationLimits[$group]);
 365+ }
 366+ }
 367+
 368+ return $limit;
 369+ }
 370+}
Property changes on: trunk/extensions/SemanticPageSeries/includes/SPSSpecialSeriesEdit.php
___________________________________________________________________
Added: svn:eol-style
1371 + native
Index: trunk/extensions/SemanticPageSeries/SemanticPageSeries.alias.php
@@ -0,0 +1,18 @@
 2+<?php
 3+
 4+/**
 5+ * Aliases for SemanticPagesSeries
 6+ *
 7+ * @author Stephan Gambke
 8+ * @file
 9+ * @ingroup SemanticPageSeries
 10+ */
 11+
 12+$specialPageAliases = array();
 13+
 14+/** English
 15+ */
 16+$specialPageAliases['en'] = array(
 17+ 'SeriesEdit' => array( 'SeriesEdit', 'SeriesEdit' ),
 18+);
 19+
Property changes on: trunk/extensions/SemanticPageSeries/SemanticPageSeries.alias.php
___________________________________________________________________
Added: svn:eol-style
120 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r110370r110330: Consistency tweaks in preparation for adding extension to translatew...raymond10:00, 31 January 2012
r110371r110330: Register extension for translatewiki.net.raymond10:04, 31 January 2012