/**
  * @see SMWStore::deleteSubject
  *
  * @since 1.8
  * @param Title $title
  */
 public function deleteSubject(Title $title)
 {
     // @deprecated since 2.1, use 'SMW::SQLStore::BeforeDeleteSubjectComplete'
     wfRunHooks('SMWSQLStore3::deleteSubjectBefore', array($this->store, $title));
     wfRunHooks('SMW::SQLStore::BeforeDeleteSubjectComplete', array($this->store, $title));
     $id = $this->store->getObjectIds()->getSMWPageID($title->getDBkey(), $title->getNamespace(), $title->getInterwiki(), '', false);
     $emptySemanticData = new SemanticData(DIWikiPage::newFromTitle($title));
     $subobjects = $this->getSubobjects($emptySemanticData->getSubject());
     $this->doDataUpdate($emptySemanticData);
     if ($title->getNamespace() === SMW_NS_CONCEPT) {
         // make sure to clear caches
         $db = $this->store->getConnection();
         $db->delete('smw_fpt_conc', array('s_id' => $id), 'SMW::deleteSubject::Conc');
         $db->delete(SMWSQLStore3::CONCEPT_CACHE_TABLE, array('o_id' => $id), 'SMW::deleteSubject::Conccache');
     }
     // Mark subject/subobjects with a special IW, the final removal is being
     // triggered by the `ByIdDataRebuildDispatcher`
     $this->store->getObjectIds()->updateInterwikiField($id, $emptySemanticData->getSubject(), SMW_SQL3_SMWDELETEIW);
     foreach ($subobjects as $smw_id => $subobject) {
         $this->store->getObjectIds()->updateInterwikiField($smw_id, $subobject, SMW_SQL3_SMWDELETEIW);
     }
     // 1.9.0.1
     // The update of possible associative entities is handled by DeleteSubjectJob which is invoked during
     // the ArticleDelete hook
     // @deprecated since 2.1, use 'SMW::SQLStore::AfterDeleteSubjectComplete'
     wfRunHooks('SMWSQLStore3::deleteSubjectAfter', array($this->store, $title));
     wfRunHooks('SMW::SQLStore::AfterDeleteSubjectComplete', array($this->store, $title));
 }
Пример #2
0
 /**
  * Extract inexpensive information from a Title object for return to Lua
  *
  * @param $title Title Title to return
  * @return array Lua data
  */
 private function getInexpensiveTitleData(Title $title)
 {
     $ns = $title->getNamespace();
     $ret = array('isLocal' => (bool) $title->isLocal(), 'interwiki' => $title->getInterwiki(), 'namespace' => $ns, 'nsText' => $title->getNsText(), 'text' => $title->getText(), 'fragment' => $title->getFragment(), 'thePartialUrl' => $title->getPartialURL());
     if ($ns === NS_SPECIAL) {
         // Core doesn't currently record special page links, but it may in the future.
         if ($this->getParser() && !$title->equals($this->getTitle())) {
             $this->getParser()->getOutput()->addLink($title);
         }
         $ret['exists'] = (bool) SpecialPageFactory::exists($title->getDBkey());
     }
     if ($ns !== NS_FILE && $ns !== NS_MEDIA) {
         $ret['file'] = false;
     }
     return $ret;
 }
 /**
  * Returns a WikitextContent object representing a redirect to the given destination page.
  *
  * @param Title $destination The page to redirect to.
  * @param string $text Text to include in the redirect, if possible.
  *
  * @return Content
  *
  * @see ContentHandler::makeRedirectContent
  */
 public function makeRedirectContent(Title $destination, $text = '')
 {
     $optionalColon = '';
     if ($destination->getNamespace() == NS_CATEGORY) {
         $optionalColon = ':';
     } else {
         $iw = $destination->getInterwiki();
         if ($iw && Language::fetchLanguageName($iw, null, 'mw')) {
             $optionalColon = ':';
         }
     }
     $mwRedir = MagicWord::get('redirect');
     $redirectText = $mwRedir->getSynonym(0) . ' [[' . $optionalColon . $destination->getFullText() . ']]';
     if ($text != '') {
         $redirectText .= "\n" . $text;
     }
     return new WikitextContent($redirectText);
 }
 /**
  * @see SMWStore::deleteSubject
  *
  * @since 1.8
  * @param Title $title
  */
 public function deleteSubject(Title $title)
 {
     // @deprecated since 2.1, use 'SMW::SQLStore::BeforeDeleteSubjectComplete'
     \Hooks::run('SMWSQLStore3::deleteSubjectBefore', array($this->store, $title));
     \Hooks::run('SMW::SQLStore::BeforeDeleteSubjectComplete', array($this->store, $title));
     // Fetch all possible matches (including any duplicates created by
     // incomplete rollback or DB deadlock)
     $ids = $this->store->getObjectIds()->getListOfIdMatchesFor($title->getDBkey(), $title->getNamespace(), $title->getInterwiki());
     $subject = DIWikiPage::newFromTitle($title);
     $emptySemanticData = new SemanticData($subject);
     $this->entitySubobjectListIterator->setSubject($emptySemanticData->getSubject());
     $subobjects = $this->entitySubobjectListIterator->getIterator();
     $this->doDataUpdate($emptySemanticData);
     foreach ($ids as $id) {
         $this->doDelete($id, $subject, $subobjects);
     }
     // @deprecated since 2.1, use 'SMW::SQLStore::AfterDeleteSubjectComplete'
     \Hooks::run('SMWSQLStore3::deleteSubjectAfter', array($this->store, $title));
     \Hooks::run('SMW::SQLStore::AfterDeleteSubjectComplete', array($this->store, $title));
 }
 /**
  * @see SMWStore::deleteSubject
  *
  * @since 1.8
  * @param Title $title
  */
 public function deleteSubject(Title $title)
 {
     // @deprecated since 2.1, use 'SMW::SQLStore::BeforeDeleteSubjectComplete'
     \Hooks::run('SMWSQLStore3::deleteSubjectBefore', array($this->store, $title));
     \Hooks::run('SMW::SQLStore::BeforeDeleteSubjectComplete', array($this->store, $title));
     // Fetch all possible matches (including any duplicates created by
     // incomplete rollback or DB deadlock)
     $ids = $this->store->getObjectIds()->getListOfIdMatchesFor($title->getDBkey(), $title->getNamespace(), $title->getInterwiki());
     $subject = DIWikiPage::newFromTitle($title);
     $emptySemanticData = new SemanticData($subject);
     $subobjects = $this->getSubobjects($emptySemanticData->getSubject());
     $this->doDataUpdate($emptySemanticData);
     foreach ($ids as $id) {
         $this->doDeleteReferencesFor($id, $subject, $subobjects);
     }
     // 1.9.0.1
     // The update of possible associative entities is handled by DeleteSubjectJob which is invoked during
     // the ArticleDelete hook
     // @deprecated since 2.1, use 'SMW::SQLStore::AfterDeleteSubjectComplete'
     \Hooks::run('SMWSQLStore3::deleteSubjectAfter', array($this->store, $title));
     \Hooks::run('SMW::SQLStore::AfterDeleteSubjectComplete', array($this->store, $title));
 }
Пример #6
0
 /**
  * Check if this title is a subpage of another title
  *
  * @param Title $title
  * @return bool
  */
 public function isSubpageOf(Title $title)
 {
     return $this->getInterwiki() === $title->getInterwiki() && $this->getNamespace() == $title->getNamespace() && strpos($this->getDBkey(), $title->getDBkey() . '/') === 0;
 }
Пример #7
0
 /**
  * Insert or update the redirect table entry for this page to indicate it redirects to $rt
  * @param Title $rt Redirect target
  * @param int|null $oldLatest Prior page_latest for check and set
  */
 public function insertRedirectEntry(Title $rt, $oldLatest = null)
 {
     $dbw = wfGetDB(DB_MASTER);
     $dbw->startAtomic(__METHOD__);
     if (!$oldLatest || $oldLatest == $this->lockAndGetLatest()) {
         $dbw->replace('redirect', ['rd_from'], ['rd_from' => $this->getId(), 'rd_namespace' => $rt->getNamespace(), 'rd_title' => $rt->getDBkey(), 'rd_fragment' => $rt->getFragment(), 'rd_interwiki' => $rt->getInterwiki()], __METHOD__);
     }
     $dbw->endAtomic(__METHOD__);
 }
Пример #8
0
 /**
  * @param object $row
  * @param Title $title
  */
 protected function moveInconsistentPage($row, $title)
 {
     if ($title->exists() || $title->getInterwiki() || !$title->canExist()) {
         if ($title->getInterwiki() || !$title->canExist()) {
             $prior = $title->getPrefixedDBkey();
         } else {
             $prior = $title->getDBkey();
         }
         # Old cleanupTitles could move articles there. See bug 23147.
         $ns = $row->page_namespace;
         if ($ns < 0) {
             $ns = 0;
         }
         # Namespace which no longer exists. Put the page in the main namespace
         # since we don't have any idea of the old namespace name. See bug 68501.
         if (!MWNamespace::exists($ns)) {
             $ns = 0;
         }
         $clean = 'Broken/' . $prior;
         $verified = Title::makeTitleSafe($ns, $clean);
         if (!$verified || $verified->exists()) {
             $blah = "Broken/id:" . $row->page_id;
             $this->output("Couldn't legalize; form '{$clean}' exists; using '{$blah}'\n");
             $verified = Title::makeTitleSafe($ns, $blah);
         }
         $title = $verified;
     }
     if (is_null($title)) {
         $this->error("Something awry; empty title.", true);
     }
     $ns = $title->getNamespace();
     $dest = $title->getDBkey();
     if ($this->dryrun) {
         $this->output("DRY RUN: would rename {$row->page_id} ({$row->page_namespace}," . "'{$row->page_title}') to ({$ns},'{$dest}')\n");
     } else {
         $this->output("renaming {$row->page_id} ({$row->page_namespace}," . "'{$row->page_title}') to ({$ns},'{$dest}')\n");
         $dbw = wfGetDB(DB_MASTER);
         $dbw->update('page', array('page_namespace' => $ns, 'page_title' => $dest), array('page_id' => $row->page_id), __METHOD__);
         LinkCache::singleton()->clear();
     }
 }
Пример #9
0
 /**
  * Compare with another title.
  *
  * @param Title $title
  * @return bool
  */
 public function equals($title)
 {
     // Note: === is necessary for proper matching of number-like titles.
     return $this->getInterwiki() === $title->getInterwiki() && $this->getNamespace() == $title->getNamespace() && $this->getDbkey() === $title->getDbkey();
 }
Пример #10
0
 /**
  * Insert or update the redirect table entry for this page to indicate
  * it redirects to $rt .
  * @param Title $rt Redirect target
  */
 public function insertRedirectEntry($rt)
 {
     $dbw = wfGetDB(DB_MASTER);
     $dbw->replace('redirect', array('rd_from'), array('rd_from' => $this->getId(), 'rd_namespace' => $rt->getNamespace(), 'rd_title' => $rt->getDBkey(), 'rd_fragment' => $rt->getFragment(), 'rd_interwiki' => $rt->getInterwiki()), __METHOD__);
 }
Пример #11
0
 /**
  * @param Title $title Title object, must be an interwiki link
  * @throws MWException If given invalid input
  */
 public function addInterwikiLink($title)
 {
     if (!$title->isExternal()) {
         throw new MWException('Non-interwiki link passed, internal parser error.');
     }
     $prefix = $title->getInterwiki();
     if (!isset($this->mInterwikiLinks[$prefix])) {
         $this->mInterwikiLinks[$prefix] = array();
     }
     $this->mInterwikiLinks[$prefix][$title->getDBkey()] = 1;
 }
Пример #12
0
 /**
  * Return prefixed text form of title, but using the content language's
  * canonical namespace. This skips any special-casing such as gendered
  * user namespaces -- which while useful, are not yet listed in the
  * XML "<siteinfo>" data so are unsafe in export.
  *
  * @param Title $title
  * @return string
  * @since 1.18
  */
 public static function canonicalTitle(Title $title)
 {
     if ($title->getInterwiki()) {
         return $title->getPrefixedText();
     }
     global $wgContLang;
     $prefix = str_replace('_', ' ', $wgContLang->getNsText($title->getNamespace()));
     if ($prefix !== '') {
         $prefix .= ':';
     }
     return $prefix . $title->getText();
 }
Пример #13
0
 /**
  * Create a data item from a MediaWiki Title.
  *
  * @param $title Title
  * @return SMWDIWikiPage
  */
 public static function newFromTitle(Title $title)
 {
     return new SMWDIWikiPage($title->getDBkey(), $title->getNamespace(), $title->getInterwiki(), str_replace(' ', '_', $title->getFragment()));
 }
Пример #14
0
 /**
  * @covers Title::createFragmentTarget
  * @dataProvider provideCreateFragmentTitle
  */
 public function testCreateFragmentTitle(Title $title, $fragment)
 {
     $this->mergeMwGlobalArrayValue('wgHooks', ['InterwikiLoadPrefix' => [function ($prefix, &$iwdata) {
         if ($prefix === 'interwiki') {
             $iwdata = ['iw_url' => 'http://example.com/', 'iw_local' => 0, 'iw_trans' => 0];
             return false;
         }
     }]]);
     $fragmentTitle = $title->createFragmentTarget($fragment);
     $this->assertEquals($title->getNamespace(), $fragmentTitle->getNamespace());
     $this->assertEquals($title->getText(), $fragmentTitle->getText());
     $this->assertEquals($title->getInterwiki(), $fragmentTitle->getInterwiki());
     $this->assertEquals($fragment, $fragmentTitle->getFragment());
 }
 /**
  * ArticleFromTitle
  *
  * hook handler for redirecting pages from old central to new community wiki
  *
  * @author Marooned
  */
 static function ArticleFromTitle(Title &$title, &$article)
 {
     global $wgRequest, $wgCorporatePageRedirectWiki;
     //do not redirect for action different than view (allow creating, deleting, etc)
     if ($wgRequest->getVal('action', 'view') != 'view') {
         return true;
     }
     wfProfileIn(__METHOD__);
     switch ($title->getNamespace()) {
         case NS_USER:
         case NS_USER_TALK:
         case NS_FILE_TALK:
         case NS_HELP:
         case NS_HELP_TALK:
         case NS_CATEGORY_TALK:
         case NS_FORUM:
         case NS_FORUM_TALK:
         case 150:
             //NS_HUB
         //NS_HUB
         case 151:
             //NS_HUB_TALK
         //NS_HUB_TALK
         case 400:
             //NS_VIDEO
         //NS_VIDEO
         case 401:
             //NS_VIDEO_TALK
         //NS_VIDEO_TALK
         case 500:
             //NS_BLOG_ARTICLE
         //NS_BLOG_ARTICLE
         case 501:
             //NS_BLOG_ARTICLE_TALK
         //NS_BLOG_ARTICLE_TALK
         case 502:
             //NS_BLOG_LISTING
         //NS_BLOG_LISTING
         case 503:
             //NS_BLOG_LISTING_TALK
         //NS_BLOG_LISTING_TALK
         case 1200:
             // NS_WALL
             if (!$title->exists() && !empty($wgCorporatePageRedirectWiki)) {
                 $redirect = $wgCorporatePageRedirectWiki . self::getPrefixedText($title->getPartialURL(), array($title->getInterwiki(), $title->getNsText()));
             }
             break;
         case NS_FILE:
             $file = wfFindFile($title);
             if (empty($file) && !empty($wgCorporatePageRedirectWiki)) {
                 $redirect = $wgCorporatePageRedirectWiki . self::getPrefixedText($title->getPartialURL(), array($title->getInterwiki(), $title->getNsText()));
             }
             break;
         case NS_PROJECT:
         case NS_PROJECT_TALK:
             if (!$title->exists()) {
                 //"Project" namespace hardcoded because MW will rename it to name of redirecting page - not the destination wiki
                 $redirect = 'http://community.wikia.com/wiki/Project:' . $title->getPartialURL();
             }
             break;
         case NS_TALK:
             $t = $title->getSubjectPage();
             if ($t->exists()) {
                 $redirect = 'http://www.wikia.com/' . $t->getPartialURL();
             }
             break;
     }
     if (!wfRunHooks('CorporateBeforeRedirect', array(&$title))) {
         wfProfileOut(__METHOD__);
         return true;
     }
     if (!empty($redirect)) {
         header("Location: {$redirect}");
         wfProfileOut(__METHOD__);
         exit;
     }
     wfProfileOut(__METHOD__);
     return true;
 }