PHP namespaces

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

PHP namespaces

Ricordisamoa
With https://gerrit.wikimedia.org/r/288633 some new classes in the Babel
extension were put into a new namespace "MediaWiki\Babel\BabelBox".
Legoktm approved but Thiemo Mättig (WMDE) disagrees. PHPUnit tests are
already in namespace "Babel\Tests".

_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: PHP namespaces

Cyken Zeraux
Is the reason for the new namespaces for testing, or because the classes
are more suitable to a namespace?

On Sat, May 28, 2016 at 9:15 AM, Ricordisamoa <[hidden email]>
wrote:

> With https://gerrit.wikimedia.org/r/288633 some new classes in the Babel
> extension were put into a new namespace "MediaWiki\Babel\BabelBox".
> Legoktm approved but Thiemo Mättig (WMDE) disagrees. PHPUnit tests are
> already in namespace "Babel\Tests".
>
> _______________________________________________
> Wikitech-l mailing list
> [hidden email]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: PHP namespaces

Antoine Musso-3
In reply to this post by Ricordisamoa
Le 28/05/2016 à 16:15, Ricordisamoa a écrit :
> With https://gerrit.wikimedia.org/r/288633 some new classes in the Babel
> extension were put into a new namespace "MediaWiki\Babel\BabelBox".
> Legoktm approved but Thiemo Mättig (WMDE) disagrees. PHPUnit tests are
> already in namespace "Babel\Tests".

Hello,

I believe all extensions/skins should use MediaWiki as a root namespace.
You never know whether one day there will be a global Babel library that
would end up clashing.

One might even ask for the namespace hierarchy to be standardized
somehow. A random example would be:

 MediaWiki/extension - reserved for extensions
 MediaWiki/skin - reserved for skins

With MediaWiki core namespaces directly at the root and the
extensions/skins under the subnamespaces.  Thus we would have:

  MediaWiki/extension/Babel/Box
  MediaWiki/extension/Babel/Tests


So in short: for extensions/skins I would use MediaWiki as a prefix.

For standalone libraries, we already use the lib name as the root
namespace, for example Cdb.

Then Maybe part of the Bable extension could be extracted as a
non-mediawiki standalone extension. In this case it would make sense to
use 'Babel' as the namespace with the MediaWiki glue being under
MediaWiki/extension/Babel.




--
Antoine "hashar" Musso


_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: PHP namespaces

Ricordisamoa
In reply to this post by Cyken Zeraux
According to PSR-4 <http://www.php-fig.org/psr/psr-4/>

    The fully qualified class name MUST have a top-level namespace name,
    also known as a "vendor namespace".

Just like how it is being done within MediaWiki core, it seems wise to
keep existing classes without any top-level namespace for backwards
compatibility, while putting any new or substantially refactored class
into a new namespace to make the break more obvious.

Il 28/05/2016 18:02, Cyken Zeraux ha scritto:

> Is the reason for the new namespaces for testing, or because the classes
> are more suitable to a namespace?
>
> On Sat, May 28, 2016 at 9:15 AM, Ricordisamoa<[hidden email]>
> wrote:
>
>> Withhttps://gerrit.wikimedia.org/r/288633  some new classes in the Babel
>> extension were put into a new namespace "MediaWiki\Babel\BabelBox".
>> Legoktm approved but Thiemo Mättig (WMDE) disagrees. PHPUnit tests are
>> already in namespace "Babel\Tests".
>>
>> _______________________________________________
>> Wikitech-l mailing list
>> [hidden email]
>> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
> _______________________________________________
> Wikitech-l mailing list
> [hidden email]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l

_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: PHP namespaces

Stas Malyshev
Hi!

> According to PSR-4 <http://www.php-fig.org/psr/psr-4/>
>
>    The fully qualified class name MUST have a top-level namespace name,
>    also known as a "vendor namespace".

Does this imply all classes in our code base must start with \Mediawiki?
If so, I don't think this is a very good idea. This is a good idea for
libraries, especially ones that have good functional unity (i.e. largely
do one thing) or part of one big framework (e.g. Zend Framework or
Symphony). For large and mostly stand-alone apps like Mediawiki I wonder
is there's much point to have a thousand classes all prefixed Mediawiki,
given that mostly everything we deal with is Mediawiki, and what is not,
already has its own namespace anyway.

If we have a library that is a) related to Mediawiki in substantial way
and b) reusable outside, then Mediawiki prefix would be appropriate. But
not sure whether it makes much sense for extensions...
--
Stas Malyshev
[hidden email]

_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: PHP namespaces

Brad Jorsch (Anomie)
On Sun, May 29, 2016 at 2:20 AM, Stas Malyshev <[hidden email]>
wrote:

> > According to PSR-4 <http://www.php-fig.org/psr/psr-4/>
> >
> >    The fully qualified class name MUST have a top-level namespace name,
> >    also known as a "vendor namespace".
>
> Does this imply all classes in our code base must start with \Mediawiki?
> If so, I don't think this is a very good idea.


It looks like current usage of namespaces in core disagrees with you.

/usr/local/src/MediaWiki/core$ grep '^namespace ' -hr includes/ languages/
resources/ maintenance/ mw-config/  | sort -u
namespace MediaWiki;
namespace MediaWiki\Auth;
namespace MediaWiki\Diff;
namespace MediaWiki\Interwiki;
namespace MediaWiki\Languages\Data;
namespace MediaWiki\Linker;
namespace MediaWiki\Logger;
namespace MediaWiki\Logger\Monolog;
namespace MediaWiki\Services;
namespace MediaWiki\Session;
namespace MediaWiki\Site;
namespace MediaWiki\Tidy;
namespace MediaWiki\Widget;

Deployed extensions seem to generally use the extension's name as the root
of the namespace, though. The exceptions are OAuth and Babel.

/usr/local/src/MediaWiki/wmf$ grep '^namespace .*;$' -hr extensions/ skins/
--exclude-dir=vendor --exclude-dir=tests | sed 's/\\.*;$/\\*;/' | sort -u
namespace ArticlePlaceholder;
namespace ArticlePlaceholder\*;
namespace Capiunto;
namespace Cards;
namespace CirrusSearch;
namespace CirrusSearch\*;
namespace CommonsMetadata;
namespace ContentTranslation;
namespace DataValues;
namespace EducationProgram;
namespace EducationProgram\*;
namespace Flow;
namespace Flow\*;
namespace FundraisingTranslateWorkflow;
namespace GeoData;
namespace GettingStarted;
namespace Graph;
namespace GWToolset;
namespace GWToolset\*;
namespace JsonConfig;
namespace Kartographer;
namespace Kartographer\*;
namespace LocalisationUpdate;
namespace MediaWiki\*;
namespace MobileFrontend;
namespace ORES;
namespace PageImages\*;
namespace Php;
namespace ProofreadPage;
namespace ProofreadPage\*;
namespace PropertySuggester;
namespace PropertySuggester\*;
namespace QuickSurveys;
namespace RelatedArticles;
namespace TextExtracts;
namespace Wikibase;
namespace Wikibase\*;
namespace WikibaseQuality\*;
namespace Wikidata;
namespace WikidataOrg;
namespace WikimediaBadges;
namespace ZeroBanner;
namespace ZeroPortal;
/usr/local/src/MediaWiki/wmf$ grep '^namespace MediaWiki\\.*;$' -hr
extensions/ skins/ --exclude-dir=vendor --exclude-dir=tests | sort -u
namespace MediaWiki\Babel\BabelBox;
namespace MediaWiki\Extensions\OAuth;


--
Brad Jorsch (Anomie)
Senior Software Engineer
Wikimedia Foundation
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l