Example #1
0
 /**
  * Please make sure to change testIsTalk() if you change the assertions below
  */
 public function testIsSubject()
 {
     // Special namespaces
     $this->assertIsSubject(NS_MEDIA);
     $this->assertIsSubject(NS_SPECIAL);
     // Subject pages
     $this->assertIsSubject(NS_MAIN);
     $this->assertIsSubject(NS_USER);
     $this->assertIsSubject(100);
     # user defined
     // Talk pages
     $this->assertIsNotSubject(NS_TALK);
     $this->assertIsNotSubject(NS_USER_TALK);
     $this->assertIsNotSubject(101);
     # user defined
     // Back compat
     $this->assertTrue(MWNamespace::isMain(NS_MAIN) == MWNamespace::isSubject(NS_MAIN));
     $this->assertTrue(MWNamespace::isMain(NS_USER_TALK) == MWNamespace::isSubject(NS_USER_TALK));
 }
Example #2
0
 function register()
 {
     global $wgContLang, $wgNamespaceAliases, $wgNonincludableNamespaces;
     $lib = array('loadSiteStats' => array($this, 'loadSiteStats'), 'getNsIndex' => array($this, 'getNsIndex'), 'pagesInCategory' => array($this, 'pagesInCategory'), 'pagesInNamespace' => array($this, 'pagesInNamespace'), 'usersInGroup' => array($this, 'usersInGroup'));
     $info = array('siteName' => $GLOBALS['wgSitename'], 'server' => $GLOBALS['wgServer'], 'scriptPath' => $GLOBALS['wgScriptPath'], 'stylePath' => $GLOBALS['wgStylePath'], 'currentVersion' => SpecialVersion::getVersion());
     if (!self::$namespacesCache) {
         $namespaces = array();
         $namespacesByName = array();
         foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
             $canonical = MWNamespace::getCanonicalName($ns);
             $namespaces[$ns] = array('id' => $ns, 'name' => $title, 'canonicalName' => strtr($canonical, '_', ' '), 'hasSubpages' => MWNamespace::hasSubpages($ns), 'hasGenderDistinction' => MWNamespace::hasGenderDistinction($ns), 'isCapitalized' => MWNamespace::isCapitalized($ns), 'isContent' => MWNamespace::isContent($ns), 'isIncludable' => !($wgNonincludableNamespaces && in_array($ns, $wgNonincludableNamespaces)), 'isMovable' => MWNamespace::isMovable($ns), 'isSubject' => MWNamespace::isSubject($ns), 'isTalk' => MWNamespace::isTalk($ns), 'aliases' => array());
             if ($ns >= NS_MAIN) {
                 $namespaces[$ns]['subject'] = MWNamespace::getSubject($ns);
                 $namespaces[$ns]['talk'] = MWNamespace::getTalk($ns);
                 $namespaces[$ns]['associated'] = MWNamespace::getAssociated($ns);
             } else {
                 $namespaces[$ns]['subject'] = $ns;
             }
             $namespacesByName[strtr($title, ' ', '_')] = $ns;
             if ($canonical) {
                 $namespacesByName[$canonical] = $ns;
             }
         }
         $aliases = array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases());
         foreach ($aliases as $title => $ns) {
             if (!isset($namespacesByName[$title])) {
                 $ct = count($namespaces[$ns]['aliases']);
                 $namespaces[$ns]['aliases'][$ct + 1] = $title;
                 $namespacesByName[$title] = $ns;
             }
         }
         $namespaces[NS_MAIN]['displayName'] = wfMessage('blanknamespace')->text();
         self::$namespacesCache = $namespaces;
     }
     $info['namespaces'] = self::$namespacesCache;
     if (self::$siteStatsLoaded) {
         $stats = $this->loadSiteStats();
         $info['stats'] = $stats[0];
     }
     $this->getEngine()->registerInterface('mw.site.lua', $lib, $info);
 }
Example #3
0
 function register()
 {
     global $wgContLang, $wgNamespaceAliases, $wgDisableCounters;
     $lib = array('getNsIndex' => array($this, 'getNsIndex'), 'pagesInCategory' => array($this, 'pagesInCategory'), 'pagesInNamespace' => array($this, 'pagesInNamespace'), 'usersInGroup' => array($this, 'usersInGroup'), 'interwikiMap' => array($this, 'interwikiMap'));
     $info = array('siteName' => $GLOBALS['wgSitename'], 'server' => $GLOBALS['wgServer'], 'scriptPath' => $GLOBALS['wgScriptPath'], 'stylePath' => $GLOBALS['wgStylePath'], 'currentVersion' => SpecialVersion::getVersion());
     if (!self::$namespacesCache || self::$namespacesCacheLang !== $wgContLang->getCode()) {
         $namespaces = array();
         $namespacesByName = array();
         foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
             $canonical = MWNamespace::getCanonicalName($ns);
             $namespaces[$ns] = array('id' => $ns, 'name' => $title, 'canonicalName' => strtr($canonical, '_', ' '), 'hasSubpages' => MWNamespace::hasSubpages($ns), 'hasGenderDistinction' => MWNamespace::hasGenderDistinction($ns), 'isCapitalized' => MWNamespace::isCapitalized($ns), 'isContent' => MWNamespace::isContent($ns), 'isIncludable' => !MWNamespace::isNonincludable($ns), 'isMovable' => MWNamespace::isMovable($ns), 'isSubject' => MWNamespace::isSubject($ns), 'isTalk' => MWNamespace::isTalk($ns), 'defaultContentModel' => MWNamespace::getNamespaceContentModel($ns), 'aliases' => array());
             if ($ns >= NS_MAIN) {
                 $namespaces[$ns]['subject'] = MWNamespace::getSubject($ns);
                 $namespaces[$ns]['talk'] = MWNamespace::getTalk($ns);
                 $namespaces[$ns]['associated'] = MWNamespace::getAssociated($ns);
             } else {
                 $namespaces[$ns]['subject'] = $ns;
             }
             $namespacesByName[strtr($title, ' ', '_')] = $ns;
             if ($canonical) {
                 $namespacesByName[$canonical] = $ns;
             }
         }
         $aliases = array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases());
         foreach ($aliases as $title => $ns) {
             if (!isset($namespacesByName[$title]) && isset($namespaces[$ns])) {
                 $ct = count($namespaces[$ns]['aliases']);
                 $namespaces[$ns]['aliases'][$ct + 1] = $title;
                 $namespacesByName[$title] = $ns;
             }
         }
         $namespaces[NS_MAIN]['displayName'] = wfMessage('blanknamespace')->inContentLanguage()->text();
         self::$namespacesCache = $namespaces;
         self::$namespacesCacheLang = $wgContLang->getCode();
     }
     $info['namespaces'] = self::$namespacesCache;
     $info['stats'] = array('pages' => (int) SiteStats::pages(), 'articles' => (int) SiteStats::articles(), 'files' => (int) SiteStats::images(), 'edits' => (int) SiteStats::edits(), 'views' => $wgDisableCounters ? null : (int) SiteStats::views(), 'users' => (int) SiteStats::users(), 'activeUsers' => (int) SiteStats::activeUsers(), 'admins' => (int) SiteStats::numberingroup('sysop'));
     return $this->getEngine()->registerInterface('mw.site.lua', $lib, $info);
 }
Example #4
0
 /**
  * Get the preferred destination title for a given target page.
  * @param integer $ns The destination namespace ID
  * @param string $name The conflicting prefix
  * @param integer $sourceNs The source namespace
  * @param integer $sourceDbk The source DB key (i.e. page_title)
  * @param array $options Associative array of validated command-line options
  * @return Title|false
  */
 private function getDestinationTitle($ns, $name, $sourceNs, $sourceDbk, $options)
 {
     $dbk = substr($sourceDbk, strlen("{$name}:"));
     if ($ns == 0) {
         // An interwiki; try an alternate encoding with '-' for ':'
         $dbk = "{$name}-" . $dbk;
     }
     $destNS = $ns;
     if ($sourceNs == NS_TALK && MWNamespace::isSubject($ns)) {
         // This is an associated talk page moved with the --move-talk feature.
         $destNS = MWNamespace::getTalk($destNS);
     }
     $newTitle = Title::makeTitleSafe($destNS, $dbk);
     if (!$newTitle || !$newTitle->canExist()) {
         return false;
     }
     return $newTitle;
 }
 /**
  * If the namespace isn't listed on the priority list return the
  * default priority for the namespace, varies depending on whether it's
  * a talkpage or not.
  *
  * @param $namespace Integer: the namespace to get the priority for
  * @return String
  */
 function guessPriority($namespace)
 {
     return MWNamespace::isSubject($namespace) ? $this->priorities[self::GS_MAIN] : $this->priorities[self::GS_TALK];
 }