r73454 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73453‎ | r73454 | r73455 >
Date:09:40, 21 September 2010
Author:jojo
Status:resolved (Comments)
Tags:
Comment:
added $wgCollectionHierarchyDelimiter
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)
  • /trunk/extensions/Collection/Collection.php (modified) (history)
  • /trunk/extensions/Collection/Collection.session.php (modified) (history)
  • /trunk/extensions/Collection/README.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/Collection.php
@@ -51,6 +51,10 @@
5252 /** PEM-encoded SSL certificate for the mw-serve render server to pass to CURL */
5353 $wgCollectionMWServeCert = null;
5454
 55+/** if not null, treat this string as hierarchy delimiter in page titles,
 56+ * i.e. support subpages */
 57+$wgCollectionHierarcyDelimiter = null;
 58+
5559 /** Array of namespaces that can be added to a collection */
5660 $wgCollectionArticleNamespaces = array(
5761 NS_MAIN,
Index: trunk/extensions/Collection/Collection.session.php
@@ -126,7 +126,7 @@
127127 foreach ( $coll['items'] as $index => $item ) {
128128 if ( $item['type'] == 'article' ) {
129129 $t = Title::newFromText( $item['title'] );
130 - if ( !$lc->isBadLink( $t->getPrefixedDbKey() ) ) {
 130+ if ( $t && !$lc->isBadLink( $t->getPrefixedDbKey() ) ) {
131131 $newitems[] = $item;
132132 }
133133 } else {
Index: trunk/extensions/Collection/README.txt
@@ -126,6 +126,20 @@
127127
128128 i.e. there's one link "Download as PDF".
129129
 130+ *$wgCollectionHierarchyDelimiter (string or null)*
 131+ If not null, treat wiki pages whose title contains the configured delimiter
 132+ as subpages.
 133+
 134+ For example, to treat article [[Foo/Bar]] as subpage of article [[Foo]]
 135+ set this variable to "/". This makes sense e.g. on wikibooks.org, but it's
 136+ questionable on wikipedia.org (cf. [[AC/DC]]).
 137+
 138+ The (only) effect is that the display title for subpages in collections
 139+ is set to the title of the (deepest) subpage. For example, the title of
 140+ article [[Foo/Bar]] will be displayed/rendered as "Bar".
 141+
 142+ The defaul value is null, which means that no hierarchy is assumed.
 143+
130144 *$wgCollectionArticleNamespaces (array)*
131145 List of namespace numbers for pages which can be added to a collection.
132146 Category pages (NS_CATEGORY) are always an exception (all articles in a
Index: trunk/extensions/Collection/Collection.body.php
@@ -606,6 +606,8 @@
607607 }
608608
609609 static function addArticle( $title, $oldid = 0 ) {
 610+ global $wgCollectionHierarchyDelimiter;
 611+
610612 $article = new Article( $title, $oldid );
611613 $latest = $article->getLatest();
612614
@@ -614,7 +616,10 @@
615617 $currentVersion = 1;
616618 $oldid = $latest;
617619 }
618 - $index = CollectionSession::findArticle( $title->getPrefixedText(), $oldid );
 620+
 621+ $prefixedText = $title->getPrefixedText();
 622+
 623+ $index = CollectionSession::findArticle( $prefixedText, $oldid );
619624 if ( $index != - 1 ) {
620625 return false;
621626 }
@@ -624,16 +629,26 @@
625630 }
626631 $collection = CollectionSession::getCollection();
627632 $revision = Revision::newFromTitle( $title, $oldid );
628 - $collection['items'][] = array(
 633+
 634+ $item = array(
629635 'type' => 'article',
630636 'content_type' => 'text/x-wiki',
631 - 'title' => $title->getPrefixedText(),
 637+ 'title' => $prefixedText,
632638 'revision' => strval( $oldid ),
633639 'latest' => strval( $latest ),
634640 'timestamp' => wfTimestamp( TS_UNIX, $revision->mTimestamp ),
635641 'url' => $title->getFullURL(),
636642 'currentVersion' => $currentVersion,
637643 );
 644+
 645+ if ($wgCollectionHierarchyDelimiter != null) {
 646+ $parts = explode( $wgCollectionHierarchyDelimiter, $prefixedText );
 647+ if ( count( $parts > 1 ) && end( $parts ) != '' ) {
 648+ $item['displaytitle'] = end( $parts );
 649+ }
 650+ }
 651+
 652+ $collection['items'][] = $item;
638653 CollectionSession::setCollection( $collection );
639654 return true;
640655 }

Comments

#Comment by Nikerabbit (talk | contribs)   10:34, 21 September 2010

Ahem, count( $parts > 1 ). Should be outside of the count. The '> 1' is redundant but some people prefer to keep it.

This commit includes small bugfix too?

+if ($wgCollectionHierarchyDelimiter != null) {

Should have spaces around parenthesis.

#Comment by Jbeigel (talk | contribs)   11:17, 21 September 2010

Ooops. Thanks a lot! Should be fixed in r73456.

#Comment by He7d3r (talk | contribs)   12:21, 10 January 2011

Is this feature live on Wikimedia projects, like pt.wikibooks?

Could it be enabled by default on all Wikibooks projects?

#Comment by Catrope (talk | contribs)   13:49, 10 January 2011

It's not live yet AFAIK, but it will go live with the next general software update, which should hopefully be in a few weeks.

For enabling it on all Wikibooks projects (presumably with '/' as the delimiter?), please file a bug in Bugzilla.

#Comment by He7d3r (talk | contribs)   13:59, 10 January 2011

Yep! I think "/" is currently used by most (all?) Wikibooks projects as a delimiter.

Would we need consensus on all Wikibooks projects before requesting this on bugzilla? Or can I suppose this is desirable and just file the bug right now, and then if it is not desirable in one or another project, they can request it to be disabled? Or, instead, each individual wikibooks projects should make individual requests for enabling it?

#Comment by Catrope (talk | contribs)   14:12, 10 January 2011

Either can work. We'd go with opt-out if most Wikibooks projects want it, and opt-in if most don't want it, so as to minimize the number of config change requests. Maybe you could start a discussion on Meta to try to gauge which is the case (i.e. whether the majority of Wikibooks communities is for or against enabling this)?

#Comment by He7d3r (talk | contribs)   13:54, 10 January 2011

Note that by default, MediaWiki shows below the title of a page (in a span inside of the element with id="contentSub") the names of "existing pages above" each page in a namespace with subpages enabled.

I think the same kind of test should be made before the line

$item['displaytitle'] = end( $parts );

so that in a page like

Guia do Linux/Avançado/Personalização do Sistema/Arquivo /etc/profile

the "displaytitle" would be correctly defined to "Arquivo /etc/profile" instead of "profile". In this example, the last "/" is part of the chapter name, which is "Arquivo /etc/profile", and not a separator.

Status & tagging log