Author: bnospam
Description:
It is difficult to specify alternative namespaces when submitting new articles.
It would be beneficial to have manual overrides of namespaces with a
namespace=NNN in the index.php? arguments.
Ideally, I imagine this would properly go in
includes/Title.php:1408 /* private */ function secureAndSplit() {
But would require access to $wgRequest by side-effect. The cleaner but lengthier
alternative is changing:
-includes/Title.php:165 function newFromURL( $url ) {
+includes/Title.php:165 function newFromURL( $url, $namespace_override = null ) {
global $wgLegalTitleChars; $t = new Title(); # For compatibility with old buggy URLs. "+" is usually not valid in titles, # but some URLs used it as a space replacement and they still come # from some external search tools. if ( strpos( $wgLegalTitleChars, '+' ) === false ) { $url = str_replace( '+', ' ', $url ); } $t->mDbkeyform = str_replace( ' ', '_', $url ); if( $t->secureAndSplit() ) {
+ if ($namespace_override) { $t->setNamespace($namespace_override); }
return $t; } else { return NULL; } }
+ ## [TODO] assertions should be done to make sure this is a number.
+ # alternatively, if it isn't a number, check to see if it
$wgContLang->getNsText($namespace)
+ # returns something valid.
+ function setNamespace( $namespace ) {
+ if ( is_int($namespace) ) {
+ $this->mNamespace = $namespace;
+ # TODO test: is this a valid namespace? if not, throw error
+ } else {
+ $this->mNamespace = $wgContLang->getNsText($namespace);
+ if (!$this->mNamespace) {
+ # TODO throw some canonical error?
+ }
+ }
+ }
and then, change
-includes/Wiki.php:79 $ret = Title::newFromURL( $title );
+includes/Wiki.php:79 $ret = Title::newFromURL( $title,
$request->getVal('namespace') );
Thus a URL of:
index.php?action=edit&title=New+article&create=Create+article&namespace=100
will give an article {100}:New_Article, where {100} is the name for namespace 100.
This cleans up a lot of headaches. Sorry it's not in a patch.
Version: unspecified
Severity: enhancement