示例#1
0
 static function ns($parser, $part1 = '')
 {
     global $wgContLang;
     $found = false;
     if (intval($part1) || $part1 == "0") {
         $text = $wgContLang->getNsText(intval($part1));
         $found = true;
     } else {
         $param = str_replace(' ', '_', strtolower($part1));
         $index = Namespac::getCanonicalIndex(strtolower($param));
         if (!is_null($index)) {
             $text = $wgContLang->getNsText($index);
             $found = true;
         }
     }
     if ($found) {
         return $text;
     } else {
         return array('found' => false);
     }
 }
示例#2
0
文件: Title.php 项目: k-hasan-19/wiki
 function secureAndSplit()
 {
     global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
     $fname = 'Title::secureAndSplit';
     # Initialisation
     static $rxTc = false;
     if (!$rxTc) {
         # % is needed as well
         $rxTc = '/[^' . Title::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
     }
     $this->mInterwiki = $this->mFragment = '';
     $this->mNamespace = $this->mDefaultNamespace;
     # Usually NS_MAIN
     # Clean up whitespace
     #
     $t = preg_replace('/[ _]+/', '_', $this->mDbkeyform);
     $t = trim($t, '_');
     if ('' == $t) {
         return false;
     }
     if (false !== strpos($t, UTF8_REPLACEMENT)) {
         # Contained illegal UTF-8 sequences or forbidden Unicode chars.
         return false;
     }
     $this->mDbkeyform = $t;
     # Initial colon indicates main namespace rather than specified default
     # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
     if (':' == $t[0]) {
         $this->mNamespace = NS_MAIN;
         $t = substr($t, 1);
         # remove the colon but continue processing
     }
     # Namespace or interwiki prefix
     $firstPass = true;
     do {
         if (preg_match("/^(.+?)_*:_*(.*)\$/S", $t, $m)) {
             $p = $m[1];
             $lowerNs = strtolower($p);
             if ($ns = Namespac::getCanonicalIndex($lowerNs)) {
                 # Canonical namespace
                 $t = $m[2];
                 $this->mNamespace = $ns;
             } elseif ($ns = $wgContLang->getNsIndex($lowerNs)) {
                 # Ordinary namespace
                 $t = $m[2];
                 $this->mNamespace = $ns;
             } elseif ($this->getInterwikiLink($p)) {
                 if (!$firstPass) {
                     # Can't make a local interwiki link to an interwiki link.
                     # That's just crazy!
                     return false;
                 }
                 # Interwiki link
                 $t = $m[2];
                 $this->mInterwiki = strtolower($p);
                 # Redundant interwiki prefix to the local wiki
                 if (0 == strcasecmp($this->mInterwiki, $wgLocalInterwiki)) {
                     if ($t == '') {
                         # Can't have an empty self-link
                         return false;
                     }
                     $this->mInterwiki = '';
                     $firstPass = false;
                     # Do another namespace split...
                     continue;
                 }
                 # If there's an initial colon after the interwiki, that also
                 # resets the default namespace
                 if ($t !== '' && $t[0] == ':') {
                     $this->mNamespace = NS_MAIN;
                     $t = substr($t, 1);
                 }
             }
             # If there's no recognized interwiki or namespace,
             # then let the colon expression be part of the title.
         }
         break;
     } while (true);
     $r = $t;
     # We already know that some pages won't be in the database!
     #
     if ('' != $this->mInterwiki || -1 == $this->mNamespace) {
         $this->mArticleID = 0;
     }
     $f = strstr($r, '#');
     if (false !== $f) {
         $this->mFragment = substr($f, 1);
         $r = substr($r, 0, strlen($r) - strlen($f));
         # remove whitespace again: prevents "Foo_bar_#"
         # becoming "Foo_bar_"
         $r = preg_replace('/_*$/', '', $r);
     }
     # Reject illegal characters.
     #
     if (preg_match($rxTc, $r)) {
         return false;
     }
     /**
      * Pages with "/./" or "/../" appearing in the URLs will
      * often be unreachable due to the way web browsers deal
      * with 'relative' URLs. Forbid them explicitly.
      */
     if (strpos($r, '.') !== false && ($r === '.' || $r === '..' || strpos($r, './') === 0 || strpos($r, '../') === 0 || strpos($r, '/./') !== false || strpos($r, '/../') !== false)) {
         return false;
     }
     # We shouldn't need to query the DB for the size.
     #$maxSize = $dbr->textFieldSize( 'page', 'page_title' );
     if (strlen($r) > 255) {
         return false;
     }
     /**
      * Normally, all wiki links are forced to have
      * an initial capital letter so [[foo]] and [[Foo]]
      * point to the same place.
      *
      * Don't force it for interwikis, since the other
      * site might be case-sensitive.
      */
     if ($wgCapitalLinks && $this->mInterwiki == '') {
         $t = $wgContLang->ucfirst($r);
     } else {
         $t = $r;
     }
     /**
      * Can't make a link to a namespace alone...
      * "empty" local links can only be self-links
      * with a fragment identifier.
      */
     if ($t == '' && $this->mInterwiki == '' && $this->mNamespace != NS_MAIN) {
         return false;
     }
     // Any remaining initial :s are illegal.
     if ($t !== '' && ':' == $t[0]) {
         return false;
     }
     # Fill fields
     $this->mDbkeyform = $t;
     $this->mUrlform = wfUrlencode($t);
     $this->mTextform = str_replace('_', ' ', $t);
     return true;
 }
示例#3
0
 /**
  * Get a local URL given any page title (optionally with namespace prefix).
  *
  * This is a rather verbose workaround to avoid Title calling
  * Namespac::getCanonicalIndex() statically and so throwing an error in
  * newer PHP versions. It can be replaced by Title::newFromText($text)->getLocalURL()
  * one day.
  *
  * @param string $title Page title, possibly with colon-separated NS prefix
  * @return string The local URL as given by Title::getLocalURL()
  */
 function getLocalUrl($title)
 {
     global $wgSitename;
     $targetParts = explode(':', $title);
     $ns = count($targetParts) == 2 ? $targetParts[0] : '';
     if ($ns == $wgSitename) {
         $ns = 'Project';
     } else {
         if ($ns == $wgSitename . '_talk') {
             $ns = 'Project_talk';
         }
     }
     $title = count($targetParts) == 2 ? $targetParts[1] : $targetParts[0];
     $namespace = new Namespac();
     $nsIndex = $namespace->getCanonicalIndex(strtolower($ns));
     $url = Title::makeTitle($nsIndex, $title)->getLocalURL();
     return $url;
 }
示例#4
0
function readListParams()
{
    global $wgRequest, $wgUser;
    $userName = $wgRequest->getVal('user');
    if ($userName) {
        $user = User::newFromName($userName);
    } else {
        $user = $wgUser;
    }
    $ns = Namespac::getCanonicalIndex(strtolower($wgRequest->getVal('namespace')));
    if (!$ns) {
        $ns = NS_PERSON;
    }
    $callback = $wgRequest->getVal('callback');
    return array($user, $ns, $callback);
}