/** * Secure and split - main initialisation function for this object * * Assumes that mDbkeyform has been set, and is urldecoded * and uses underscores, but not otherwise munged. This function * removes illegal characters, splits off the interwiki and * namespace prefixes, sets the other forms, and canonicalizes * everything. * @return bool true on success */ private function secureAndSplit() { global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks; # 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 $dbkey = $this->mDbkeyform; # Strip Unicode bidi override characters. # Sometimes they slip into cut-n-pasted page titles, where the # override chars get included in list displays. $dbkey = str_replace("", '', $dbkey); // 200E LEFT-TO-RIGHT MARK $dbkey = str_replace("", '', $dbkey); // 200F RIGHT-TO-LEFT MARK # Clean up whitespace # $dbkey = preg_replace('/[ _]+/', '_', $dbkey); $dbkey = trim($dbkey, '_'); if ('' == $dbkey) { return false; } if (false !== strpos($dbkey, UTF8_REPLACEMENT)) { # Contained illegal UTF-8 sequences or forbidden Unicode chars. return false; } $this->mDbkeyform = $dbkey; # Initial colon indicates main namespace rather than specified default # but should not create invalid {ns,title} pairs such as {0,Project:Foo} if (':' == $dbkey[0]) { $this->mNamespace = NS_MAIN; $dbkey = substr($dbkey, 1); # remove the colon but continue processing $dbkey = trim($dbkey, '_'); # remove any subsequent whitespace } # Namespace or interwiki prefix $firstPass = true; do { $m = array(); if (preg_match("/^(.+?)_*:_*(.*)\$/S", $dbkey, $m)) { $p = $m[1]; if ($ns = $wgContLang->getNsIndex($p)) { # Ordinary namespace $dbkey = $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 $dbkey = $m[2]; $this->mInterwiki = $wgContLang->lc($p); # Redundant interwiki prefix to the local wiki if (0 == strcasecmp($this->mInterwiki, $wgLocalInterwiki)) { if ($dbkey == '') { # 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 ($dbkey !== '' && $dbkey[0] == ':') { $this->mNamespace = NS_MAIN; $dbkey = substr($dbkey, 1); } } # If there's no recognized interwiki or namespace, # then let the colon expression be part of the title. } break; } while (true); # We already know that some pages won't be in the database! # if ('' != $this->mInterwiki || NS_SPECIAL == $this->mNamespace) { $this->mArticleID = 0; } $fragment = strstr($dbkey, '#'); if (false !== $fragment) { $this->setFragment($fragment); $dbkey = substr($dbkey, 0, strlen($dbkey) - strlen($fragment)); # remove whitespace again: prevents "Foo_bar_#" # becoming "Foo_bar_" $dbkey = preg_replace('/_*$/', '', $dbkey); } # Reject illegal characters. # if (preg_match($rxTc, $dbkey)) { 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($dbkey, '.') !== false && ($dbkey === '.' || $dbkey === '..' || strpos($dbkey, './') === 0 || strpos($dbkey, '../') === 0 || strpos($dbkey, '/./') !== false || strpos($dbkey, '/../') !== false)) { return false; } /** * Magic tilde sequences? Nu-uh! */ if (strpos($dbkey, '~~~') !== false) { return false; } /** * Limit the size of titles to 255 bytes. * This is typically the size of the underlying database field. * We make an exception for special pages, which don't need to be stored * in the database, and may edge over 255 bytes due to subpage syntax * for long titles, e.g. [[Special:Block/Long name]] */ if ($this->mNamespace != NS_SPECIAL && strlen($dbkey) > 255 || strlen($dbkey) > 512) { 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 == '') { $dbkey = $wgContLang->ucfirst($dbkey); } /** * Can't make a link to a namespace alone... * "empty" local links can only be self-links * with a fragment identifier. */ if ($dbkey == '' && $this->mInterwiki == '' && $this->mNamespace != NS_MAIN) { return false; } // Any remaining initial :s are illegal. if ($dbkey !== '' && ':' == $dbkey[0]) { return false; } # Fill fields $this->mDbkeyform = $dbkey; $this->mUrlform = ilWikiUtil::wfUrlencode($dbkey); $this->mTextform = str_replace('_', ' ', $dbkey); return true; }
/** * Set page parameter for Url Embedding */ static function makeUrlTitle($a_par) { $a_par = ilWikiUtil::removeUnsafeCharacters($a_par); $a_par = str_replace(" ", "_", $a_par); return ilWikiUtil::wfUrlencode($a_par); }