Demon has submitted this change and it was merged.

Change subject: (bug 45845) Allow for docs at non-subpages
......................................................................


(bug 45845) Allow for docs at non-subpages

It has been claimed that some wiki might want to place module
documentation at a location other than as a subpage of the module, for
example under "Project:Module documentation/$1". It's possible to
support this, so we may as well.

This also involves renaming the "scribunto-doc-subpage-*" messages to
"scribunto-doc-page-*", since the interpretation of
scribunto-doc-subpage-name would be drastically changed.

Note that any wiki that has customized scribunto-doc-subpage-name will
need to re-customize scribunto-doc-page-name, the old value will not be
transferred.

Bug: 45845
Change-Id: Ic453561691e04b5250d219cc7d871c17e60b9912
---
M Scribunto.i18n.php
M Scribunto.php
M common/Common.php
M common/Hooks.php
M common/ScribuntoContent.php
5 files changed, 44 insertions(+), 35 deletions(-)

Approvals:
  Demon: Verified; Looks good to me, approved



diff --git a/Scribunto.i18n.php b/Scribunto.i18n.php
index 5b910bd..c5c8253 100644
--- a/Scribunto.i18n.php
+++ b/Scribunto.i18n.php
@@ -22,11 +22,11 @@
        'scribunto-error-long' => 'Script errors:
 
 $1',
-       'scribunto-doc-subpage-name' => 'doc',
-       'scribunto-doc-subpage-does-not-exist' => "''Documentation for this 
module may be created at [[$1]]''",
-       'scribunto-doc-subpage-show' => '{{$1}}
+       'scribunto-doc-page-name' => 'Module:$1/doc',
+       'scribunto-doc-page-does-not-exist' => "''Documentation for this module 
may be created at [[$1]]''",
+       'scribunto-doc-page-show' => '{{$1}}
 <hr />',
-       'scribunto-doc-subpage-header' => "'''This is the documentation subpage 
for [[$1]]'''",
+       'scribunto-doc-page-header' => "'''This is the documentation page for 
[[$1]]'''",
 
        'scribunto-console-intro' => '* The module exports are available as the 
variable "p", including unsaved modifications.
 * Precede a line with "=" to evaluate it as an expression, or use print().
@@ -83,10 +83,10 @@
 * $1 are the error details.',
        'scribunto-error-long' => 'Error message. Parameters:
 * $1 are the error details.',
-       'scribunto-doc-subpage-name' => 'Subpage name for module 
documentation.',
-       'scribunto-doc-subpage-does-not-exist' => 'Message displayed if the 
documentation subpage does not exist. $1 is the prefixed title of the subpage.',
-       'scribunto-doc-subpage-show' => 'Message displayed if the documentation 
subpage does exist. $1 is the prefixed title of the subpage. Should probably 
transclude that page.',
-       'scribunto-doc-subpage-header' => 'Message displayed at the top of the 
documentation subpage. $1 is the prefixed title of the module.',
+       'scribunto-doc-page-name' => 'Page name for module documentation. $1 is 
the unprefixed name of the module.',
+       'scribunto-doc-page-does-not-exist' => 'Message displayed if the 
documentation page does not exist. $1 is the prefixed title of the doc page.',
+       'scribunto-doc-page-show' => 'Message displayed if the documentation 
page does exist. $1 is the prefixed title of the doc page. Should probably 
transclude that page.',
+       'scribunto-doc-page-header' => 'Message displayed at the top of the 
documentation page. $1 is the prefixed title of the module.',
        'scribunto-console-intro' => 'An explanatory message shown to module 
programmers in the debug console, where they can run Lua commands and see how 
they work.
 
 "Module exports" are the names that are exported. See the chapter 
[http://www.lua.org/pil/15.2.html Privacy] in the book "Programming in Lua".',
diff --git a/Scribunto.php b/Scribunto.php
index c83a599..0e6763f 100644
--- a/Scribunto.php
+++ b/Scribunto.php
@@ -55,7 +55,7 @@
 $wgHooks['EditPageBeforeEditChecks'][] = 'ScribuntoHooks::beforeEditChecks';
 $wgHooks['EditPageBeforeEditButtons'][] = 'ScribuntoHooks::beforeEditButtons';
 $wgHooks['EditFilterMerged'][] = 'ScribuntoHooks::validateScript';
-$wgHooks['ArticleViewHeader'][] = 'ScribuntoHooks::showDocSubpageHeader';
+$wgHooks['ArticleViewHeader'][] = 'ScribuntoHooks::showDocPageHeader';
 $wgHooks['ContentHandlerDefaultModelFor'][] = 
'ScribuntoHooks::contentHandlerDefaultModelFor';
 
 $wgHooks['UnitTestsList'][] = 'ScribuntoHooks::unitTestsList';
diff --git a/common/Common.php b/common/Common.php
index 880be32..1e4a4c6 100644
--- a/common/Common.php
+++ b/common/Common.php
@@ -68,32 +68,43 @@
        }
 
        /**
-        * Test whether the page should be considered a documentation subpage
+        * Test whether the page should be considered a documentation page
         * @param $title Title
+        * @param &$forModule Title Module for which this is a doc page
         * @return boolean
         */
-       public static function isDocSubpage( $title ) {
-               $docSubpage = wfMessage( 'scribunto-doc-subpage-name' 
)->inContentLanguage();
-               if ( $docSubpage->isDisabled() ) {
+       public static function isDocPage( $title, &$forModule = null ) {
+               $docPage = wfMessage( 'scribunto-doc-page-name' 
)->inContentLanguage();
+               if ( $docPage->isDisabled() ) {
                        return false;
                }
 
-               $docSubpage = '/' . $docSubpage->plain();
-               return ( substr( $title->getText(), -strlen( $docSubpage ) ) 
=== $docSubpage );
+               // Canonicalize the input pseudo-title. The unreplaced "$1" 
shouldn't
+               // cause a problem.
+               $docPage = Title::newFromText( $docPage->plain() 
)->getPrefixedText();
+
+               // Make it into a regex, and match it against the input title
+               $docPage = str_replace( '\\$1', '(.+)', preg_quote( $docPage, 
'/' ) );
+               if ( preg_match( "/^$docPage$/", $title->getPrefixedText(), $m 
) ) {
+                       $forModule = Title::makeTitleSafe( NS_MODULE, $m[1] );
+                       return true;
+               } else {
+                       return false;
+               }
        }
 
        /**
-        * Return the Title for the documentation subpage
+        * Return the Title for the documentation page
         * @param $title Title
         * @return Title|null
         */
-       public static function getDocSubpage( $title ) {
-               $docSubpage = wfMessage( 'scribunto-doc-subpage-name' 
)->inContentLanguage();
-               if ( $docSubpage->isDisabled() ) {
+       public static function getDocPage( $title ) {
+               $docPage = wfMessage( 'scribunto-doc-page-name', 
$title->getText() )->inContentLanguage();
+               if ( $docPage->isDisabled() ) {
                        return null;
                }
 
-               return $title->getSubpage( $docSubpage->plain() );
+               return Title::newFromText( $docPage->plain() );
        }
 }
 
diff --git a/common/Hooks.php b/common/Hooks.php
index 0d2a22c..3e44585 100644
--- a/common/Hooks.php
+++ b/common/Hooks.php
@@ -81,7 +81,7 @@
                        $moduleName = trim( $frame->expand( $args[0] ) );
                        $engine = Scribunto::getParserEngine( $parser );
                        $title = Title::makeTitleSafe( NS_MODULE, $moduleName );
-                       if ( !$title || Scribunto::isDocSubpage( $title ) ) {
+                       if ( !$title || Scribunto::isDocPage( $title ) ) {
                                throw new ScribuntoException( 
'scribunto-common-nosuchmodule' );
                        }
                        $module = $engine->fetchModuleFromParser( $title );
@@ -134,7 +134,7 @@
        public static function getCodeLanguage( $title, &$lang ) {
                global $wgScribuntoUseCodeEditor;
                if( $wgScribuntoUseCodeEditor && $title->getNamespace() == 
NS_MODULE &&
-                       !Scribunto::isDocSubpage( $title )
+                       !Scribunto::isDocPage( $title )
                ) {
                        $engine = Scribunto::newDefaultEngine();
                        if( $engine->getCodeEditorLanguage() ) {
@@ -153,7 +153,7 @@
         * @return bool
         */
        public static function contentHandlerDefaultModelFor( $title, &$model ) 
{
-               if( $title->getNamespace() == NS_MODULE && 
!Scribunto::isDocSubpage( $title ) ) {
+               if( $title->getNamespace() == NS_MODULE && 
!Scribunto::isDocPage( $title ) ) {
                        $model = 'Scribunto';
                        return false;
                }
@@ -195,7 +195,7 @@
                        return true;
                }
 
-               if ( Scribunto::isDocSubpage( $editor->getTitle() ) ) {
+               if ( Scribunto::isDocPage( $editor->getTitle() ) ) {
                        return true;
                }
 
@@ -229,7 +229,7 @@
                        return true;
                }
 
-               if ( Scribunto::isDocSubpage( $editor->getTitle() ) ) {
+               if ( Scribunto::isDocPage( $editor->getTitle() ) ) {
                        return true;
                }
 
@@ -252,7 +252,7 @@
                        return true;
                }
 
-               if ( Scribunto::isDocSubpage( $title ) ) {
+               if ( Scribunto::isDocPage( $title ) ) {
                        return true;
                }
 
@@ -327,15 +327,13 @@
         * @param &$pcache boolean
         * @return boolean
         */
-       public static function showDocSubpageHeader( &$article, &$outputDone, 
&$pcache ) {
+       public static function showDocPageHeader( &$article, &$outputDone, 
&$pcache ) {
                global $wgOut;
 
                $title = $article->getTitle();
-               if( $title->getNamespace() === NS_MODULE && 
Scribunto::isDocSubpage( $title ) ) {
-                       $docSubpage = wfMessage( 'scribunto-doc-subpage-name' 
)->inContentLanguage()->plain();
-                       $title = substr( $title, 0, -strlen( $docSubpage ) - 1 
);
+               if ( Scribunto::isDocPage( $title, $forModule ) ) {
                        $wgOut->addHTML(
-                               wfMessage( 'scribunto-doc-subpage-header', 
$title )->parseAsBlock()
+                               wfMessage( 'scribunto-doc-page-header', 
$forModule->getPrefixedText() )->parseAsBlock()
                        );
                }
                return true;
diff --git a/common/ScribuntoContent.php b/common/ScribuntoContent.php
index b5bf023..4f777db 100644
--- a/common/ScribuntoContent.php
+++ b/common/ScribuntoContent.php
@@ -41,10 +41,10 @@
 
                // Get documentation, if any
                $output = new ParserOutput();
-               $doc = Scribunto::getDocSubpage( $title );
+               $doc = Scribunto::getDocPage( $title );
                if ( $doc ) {
                        $msg = wfMessage(
-                               $doc->exists() ? 'scribunto-doc-subpage-show' : 
'scribunto-doc-subpage-does-not-exist',
+                               $doc->exists() ? 'scribunto-doc-page-show' : 
'scribunto-doc-page-does-not-exist',
                                $doc->getPrefixedText()
                        )->inContentLanguage();
                        if ( !$msg->isDisabled() ) {
@@ -53,8 +53,8 @@
                                $output = $wgParser->parse( $msg->plain(), 
$title, $options, true, true, $revId );
                        }
 
-                       // Mark the /doc subpage as a transclusion, so we get 
purged when
-                       // it changes.
+                       // Mark the doc page as a transclusion, so we get 
purged when it
+                       // changes.
                        $output->addTemplate( $doc, $doc->getArticleID(), 
$doc->getLatestRevID() );
                }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/52875
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic453561691e04b5250d219cc7d871c17e60b9912
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Danny B. <[email protected]>
Gerrit-Reviewer: Demon <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to