$modeName: the requested content model name
&$handler: set this to a ContentHandler object, if desired.
+'ContentModelCanBeUsedOn': Called to determine whether that content model can
+be used on a given page. This is especially useful to prevent some content models
+to be used in some special location.
+$contentModel: ID of the content model in question
+$title: the Title in question.
+&$ok: Output parameter, whether it is OK to use $contentModel on $title.
+Handler functions that modify $ok should generally return false to prevent further
+hooks from further modifying $ok.
+
'ConvertContent': Called by AbstractContent::convert when a conversion to another
content model is requested.
$content: The Content object to be converted.
* @return bool
*/
public function importRevision( $revision ) {
+ if ( !$revision->getContent()->getContentHandler()->canBeUsedOn( $revision->getTitle() ) ) {
+ $this->notice( 'import-error-bad-location',
+ $revision->getTitle()->getPrefixedText(),
+ $revision->getID(),
+ $revision->getModel(),
+ $revision->getFormat() );
+
+ return false;
+ }
+
try {
$dbw = wfGetDB( DB_MASTER );
return $dbw->deadlockLoop( array( $revision, 'importOldRevision' ) );
$revision->getModel(),
$revision->getFormat() );
}
+
+ return false;
}
/**
* typically based on the namespace or some other aspect of the title, such as a special suffix
* (e.g. ".svg" for SVG content).
*
+ * @note: this calls the ContentHandlerCanBeUsedOn hook which may be used to override which
+ * content model can be used where.
+ *
* @param Title $title the page's title.
*
* @return bool true if content of this kind can be used on the given page, false otherwise.
*/
public function canBeUsedOn( Title $title ) {
- return true;
+ $ok = true;
+
+ wfRunHooks( 'ContentModelCanBeUsedOn', array( $this->getModelID(), $title, &$ok ) );
+
+ return $ok;
}
/**
A temporary folder is missing.',
'import-parse-failure' => 'XML import parse failure',
'import-noarticle' => 'No page to import!',
-'import-nonewrevisions' => 'All revisions were previously imported.',
+'import-nonewrevisions' => 'No revisions imported (all were either already present, or skipped due to errors).',
'xml-error-string' => '$1 at line $2, col $3 (byte $4): $5',
'import-upload' => 'Upload XML data',
'import-token-mismatch' => 'Loss of session data.
'import-error-special' => 'Page "$1" is not imported because it belongs to a special namespace that does not allow pages.',
'import-error-invalid' => 'Page "$1" is not imported because its name is invalid.',
'import-error-unserialize' => 'Revision $2 of page "$1" could not be unserialized. The revision was reported to use content model $3 serialized as $4.',
+'import-error-bad-location' => 'Revision $2 using content model $3 can not be stored on "$1" on this wiki, since that model is not supported on that page.',
'import-options-wrong' => 'Wrong {{PLURAL:$2|option|options}}: <nowiki>$1</nowiki>',
'import-rootpage-invalid' => 'Given root page is an invalid title.',
'import-rootpage-nosubpage' => 'Namespace "$1" of the root page does not allow subpages.',
See also:
* {{msg-mw|Import-noarticle}}
* {{msg-mw|Importbadinterwiki}}',
-'import-nonewrevisions' => 'Used in [[Special:Import]].',
+'import-nonewrevisions' => 'Used in [[Special:Import]] to indicate that no revisions were imported.
+This may be due to the revisions already being present, or to errors when importing them.',
'xml-error-string' => 'Parameters:
* $1 - Some kind of message, perhaps name of the error?
* $2 - line number
This may happen if the content got corrupted or the serialization format is mis-reported.
+Parameters:
+* $1 - the name of the page the offending revision belongs to
+* $2 - the ID of the offending revision, as reported in the dump that is being imported
+* $3 - the content model reported for the offending revision in the dump that is being imported
+* $4 - the serialization format reported for the offending revision in the dump that is being imported
+{{Related|Import-error}}',
+'import-error-bad location' => 'Import error message displayed when trying to import a page to a title that is not allowed for this kind of content on this wiki.
+
+This may happen for content models bound to specific namespaces or title patterns, if the configuration of the allowed namespaces
+or titles differs from the configuration on the source wiki.
+
Parameters:
* $1 - the name of the page the offending revision belongs to
* $2 - the ID of the offending revision, as reported in the dump that is being imported
'import-error-special',
'import-error-invalid',
'import-error-unserialize',
+ 'import-error-bad-location',
'import-options-wrong',
'import-rootpage-invalid',
'import-rootpage-nosubpage',