Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/52875


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.

Of the WMF wikis where Scribunto has been deployed as of March 8, 2013
17:00 UTC, only enwiktionary has customized any of these messages, so
the message rename would cause minimal disruption (as long as we update
Scribunto in wmf11 before the wider deploy on March 18).

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


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto 
refs/changes/75/52875/1

diff --git a/Scribunto.i18n.php b/Scribunto.i18n.php
index 4b9f207..d0d3b53 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/common/Common.php b/common/Common.php
index 4b7e5ac..68d6000 100644
--- a/common/Common.php
+++ b/common/Common.php
@@ -70,16 +70,27 @@
        /**
         * Test whether the page should be considered a documentation subpage
         * @param $title Title
+        * @param &$forModule Title Module for which this is a doc subpage
         * @return boolean
         */
-       public static function isDocSubpage( $title ) {
-               $docSubpage = wfMessage( 'scribunto-doc-subpage-name' );
-               if ( $docSubpage->isDisabled() ) {
+       public static function isDocSubpage( $title, &$forModule = null ) {
+               $docPage = wfMessage( 'scribunto-doc-page-name' );
+               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;
+               }
        }
 
        /**
@@ -88,12 +99,12 @@
         * @return Title|null
         */
        public static function getDocSubpage( $title ) {
-               $docSubpage = wfMessage( 'scribunto-doc-subpage-name' );
-               if ( $docSubpage->isDisabled() ) {
+               $docPage = wfMessage( 'scribunto-doc-page-name', 
$title->getText() );
+               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 c5eb761..c858e5f 100644
--- a/common/Hooks.php
+++ b/common/Hooks.php
@@ -331,11 +331,9 @@
                global $wgOut;
 
                $title = $article->getTitle();
-               if( $title->getNamespace() === NS_MODULE && 
Scribunto::isDocSubpage( $title ) ) {
-                       $docSubpage = wfMessage( 'scribunto-doc-subpage-name' 
)->plain();
-                       $title = substr( $title, 0, -strlen( $docSubpage ) - 1 
);
+               if ( Scribunto::isDocSubpage( $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..a036c8b 100644
--- a/common/ScribuntoContent.php
+++ b/common/ScribuntoContent.php
@@ -44,7 +44,7 @@
                $doc = Scribunto::getDocSubpage( $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() ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic453561691e04b5250d219cc7d871c17e60b9912
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

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

Reply via email to