Exemple #1
0
 /**
  * Does various sanity checks that the move is
  * valid. Only things based on the two titles
  * should be checked here.
  *
  * @return Status
  */
 public function isValidMove()
 {
     global $wgContentHandlerUseDB;
     $status = new Status();
     if ($this->oldTitle->equals($this->newTitle)) {
         $status->fatal('selfmove');
     }
     if (!$this->oldTitle->isMovable()) {
         $status->fatal('immobile-source-namespace', $this->oldTitle->getNsText());
     }
     if ($this->newTitle->isExternal()) {
         $status->fatal('immobile-target-namespace-iw');
     }
     if (!$this->newTitle->isMovable()) {
         $status->fatal('immobile-target-namespace', $this->newTitle->getNsText());
     }
     $oldid = $this->oldTitle->getArticleID();
     if (strlen($this->newTitle->getDBkey()) < 1) {
         $status->fatal('articleexists');
     }
     if ($this->oldTitle->getDBkey() == '' || !$oldid || $this->newTitle->getDBkey() == '') {
         $status->fatal('badarticleerror');
     }
     # The move is allowed only if (1) the target doesn't exist, or
     # (2) the target is a redirect to the source, and has no history
     # (so we can undo bad moves right after they're done).
     if ($this->newTitle->getArticleID() && !$this->isValidMoveTarget()) {
         $status->fatal('articleexists');
     }
     // Content model checks
     if (!$wgContentHandlerUseDB && $this->oldTitle->getContentModel() !== $this->newTitle->getContentModel()) {
         // can't move a page if that would change the page's content model
         $status->fatal('bad-target-model', ContentHandler::getLocalizedName($this->oldTitle->getContentModel()), ContentHandler::getLocalizedName($this->newTitle->getContentModel()));
     } elseif (!ContentHandler::getForTitle($this->oldTitle)->canBeUsedOn($this->newTitle)) {
         $status->fatal('content-not-allowed-here', ContentHandler::getLocalizedName($this->oldTitle->getContentModel()), $this->newTitle->getPrefixedText());
     }
     // Image-specific checks
     if ($this->oldTitle->inNamespace(NS_FILE)) {
         $status->merge($this->isValidFileMove());
     }
     if ($this->newTitle->inNamespace(NS_FILE) && !$this->oldTitle->inNamespace(NS_FILE)) {
         $status->fatal('nonfile-cannot-move-to-file');
     }
     // Hook for extensions to say a title can't be moved for technical reasons
     Hooks::run('MovePageIsValidMove', [$this->oldTitle, $this->newTitle, $status]);
     return $status;
 }
	/**
	 * return the page titles of the subpages in an array
	 * @return array all titles
	 * @private
	 */
	function getTitles() {
		wfProfileIn( __METHOD__ );

		$dbr = wfGetDB( DB_SLAVE );

		$conditions = array();
		$options = array();
		$order = strtoupper( $this->order );

		if( $this->ordermethod == 'title' ) {
			$options['ORDER BY'] = 'page_title ' . $order;
		} elseif( $this->ordermethod == 'lastedit' ) {
			$options['ORDER BY'] = 'page_touched ' . $order;
		}
		if( $this->parent !== -1) {
			$this->ptitle = Title::newFromText( $this->parent );
			# note that non-existent pages may nevertheless have valid subpages
			# on the other hand, not checking that the page exists can let input through which causes database errors
			if ( $this->ptitle instanceof Title && $this->ptitle->exists() && $this->ptitle->userCanRead() ) {
				$parent = $this->ptitle->getDBkey();
				$this->parent = $parent;
				$this->namespace = $this->ptitle->getNsText();
				$nsi = $this->ptitle->getNamespace();
			} else {
				$this->error( wfMsg('spl3_debug','parent') );
				return null;
			}
		} else {
			$this->ptitle = $this->title;
			$parent = $this->title->getDBkey();
			$this->parent = $parent;
			$this->namespace = $this->title->getNsText();
			$nsi = $this->title->getNamespace();
		}

		// don't let list cross namespaces
		if ( strlen( $nsi ) > 0 ) {
			$conditions['page_namespace'] = $nsi;
		}
		$conditions['page_is_redirect'] = 0;
		$conditions[] = 'page_title ' . $dbr->buildLike( $parent . '/', $dbr->anyString() );

		$fields = array();
		$fields[] = 'page_title';
		$fields[] = 'page_namespace';
		$res = $dbr->select( 'page', $fields, $conditions, __METHOD__, $options );

		$titles = array();
		foreach ( $res as $row ) {
			$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
			if( $title ) {
				$titles[] = $title;
			}
		}
		wfProfileOut( __METHOD__ );
		return $titles;
	}
 public function getHtml()
 {
     $html = '';
     if ($this->title->getNamespace() != NS_MAIN) {
         $html .= self::getHtmlSeparator($this->title->getNsText() . ':');
     }
     if ($this->isFile()) {
         $html .= $this->getHtmlForFile();
     } else {
         $html .= $this->getHtmlDefault();
     }
     return $html;
 }
 /**
  * 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;
 }
 /**
  * Does various sanity checks that the move is
  * valid. Only things based on the two titles
  * should be checked here.
  *
  * @return Status
  */
 public function isValidMove()
 {
     global $wgContentHandlerUseDB;
     $status = new Status();
     if ($this->oldTitle->equals($this->newTitle)) {
         $status->fatal('selfmove');
     }
     if (!$this->oldTitle->isMovable()) {
         $status->fatal('immobile-source-namespace', $this->oldTitle->getNsText());
     }
     if ($this->newTitle->isExternal()) {
         $status->fatal('immobile-target-namespace-iw');
     }
     if (!$this->newTitle->isMovable()) {
         $status->fatal('immobile-target-namespace', $this->newTitle->getNsText());
     }
     $oldid = $this->oldTitle->getArticleID();
     if (strlen($this->newTitle->getDBkey()) < 1) {
         $status->fatal('articleexists');
     }
     if ($this->oldTitle->getDBkey() == '' || !$oldid || $this->newTitle->getDBkey() == '') {
         $status->fatal('badarticleerror');
     }
     // Content model checks
     if (!$wgContentHandlerUseDB && $this->oldTitle->getContentModel() !== $this->newTitle->getContentModel()) {
         // can't move a page if that would change the page's content model
         $status->fatal('bad-target-model', ContentHandler::getLocalizedName($this->oldTitle->getContentModel()), ContentHandler::getLocalizedName($this->newTitle->getContentModel()));
     }
     // Image-specific checks
     if ($this->oldTitle->inNamespace(NS_FILE)) {
         $status->merge($this->isValidFileMove());
     }
     if ($this->newTitle->inNamespace(NS_FILE) && !$this->oldTitle->inNamespace(NS_FILE)) {
         $status->fatal('nonfile-cannot-move-to-file');
     }
     // Hook for extensions to say a title can't be moved for technical reasons
     Hooks::run('MovePageIsValidMove', array($this->oldTitle, $this->newTitle, $status));
     return $status;
 }
Exemple #6
0
 /**
  * getFullNamespacePageTitle
  *
  * This function returns the namespace:title string from the URI
  * corresponding to this resource.  It is meant to be the URI version,
  * without spaces, hence we cannot use Title::getPrefixedText.
  *
  * @param Title $titleObj title object corresponding to this resource
  *
  * @return string $title the URL-like (without spaces) namespace:title string for the given page
  */
 public function getFullNamespacePageTitle(Title $titleObj)
 {
     $title = $titleObj->getDBkey();
     $namespace = $titleObj->getNsText();
     if ($namespace) {
         $title = "{$namespace}:{$title}";
     }
     return $title;
 }
Exemple #7
0
 /**
  *
  * Load page-specific permission settings.
  * @param Title $title
  * @param Boolean pageself: whether to lookup the rule in pageitself or in the acl page.
  * 		Return a associative array
  * 		groupperms->{Grant:Grant|Reject,UserGroup, Permissions->(read, write..)}
  * 		userperms->{Grant:Grant|Reject,User,Permissions->(read,write..)}
  */
 public static function loadPageSpecificPermissions($title, $pageself = false)
 {
     if ($pageself) {
         $pageProps = array();
         if (!$title->exists()) {
             return null;
         }
         $fullname = $title->getNsText() . ":" . $title->getDBkey();
         $groupPermissions = SMWUtil::getSemanticInternalObjects($fullname, self::$PAGE_GROUP, $title->getNamespace());
         $gps = array();
         foreach ($groupPermissions as $gp) {
             //convert permission to an array
             $gp[self::$PERMISSIONS] = array_map("trim", explode(",", $gp[self::$PERMISSIONS]));
             $gps[] = $gp;
         }
         $userPermissions = SMWUtil::getSemanticInternalObjects($fullname, self::$PAGE_USER, $title->getNamespace());
         $ups = array();
         foreach ($userPermissions as $up) {
             $up[self::$PERMISSIONS] = array_map("trim", explode(",", $up[self::$PERMISSIONS]));
             $ups[] = $up;
         }
         $pageProps[self::$PAGE_GROUP] = $gps;
         $pageProps[self::$PAGE_USER] = $ups;
         //error_log(print_r($pageProps, true));
         return $pageProps;
     } else {
         $id = $title->getArticleID();
         $aclTitle = Title::newFromText($id, ACL_NS_ACL);
         if (!$aclTitle->exists()) {
             return null;
         }
         $pageProps = SMWUtil::loadSemanticProperties($id, ACL_NS_ACL, false);
         $aclpagename = ACL_ACL . ":" . $id;
         $groupPermissions = SMWUtil::getSemanticInternalObjects($aclpagename, self::$PAGE_GROUP, ACL_NS_ACL);
         $gps = array();
         foreach ($groupPermissions as $gp) {
             //convert permission to an array
             $gp[self::$PERMISSIONS] = array_map("trim", explode(",", $gp[self::$PERMISSIONS]));
             $gps[] = $gp;
         }
         $userPermissions = SMWUtil::getSemanticInternalObjects($aclpagename, self::$PAGE_USER, ACL_NS_ACL);
         $ups = array();
         foreach ($userPermissions as $up) {
             $up[self::$PERMISSIONS] = array_map("trim", explode(",", $up[self::$PERMISSIONS]));
             $ups[] = $up;
         }
         $pageProps[self::$PAGE_GROUP] = $gps;
         $pageProps[self::$PAGE_USER] = $ups;
         return $pageProps;
     }
 }
 public function inflateWithVideoData(&$arr, Title $title, $width = 150, $height = 75)
 {
     $arr['ns'] = $title->getNamespace();
     $arr['nsText'] = $title->getNsText();
     $arr['dbKey'] = $title->getDbKey();
     $arr['title'] = $title->getText();
     if ($title instanceof GlobalTitle) {
         //wfFindFile works with Title only
         $oTitle = Title::newFromText($arr['nsText'] . ':' . $arr['dbKey']);
     } else {
         $oTitle = $title;
     }
     $file = wfFindFile($oTitle);
     $thumb = $file->transform(array('width' => $width, 'height' => $height));
     $arr['thumbnail'] = $thumb->toHtml(array('custom-title-link' => $oTitle, 'duration' => true, 'linkAttribs' => array('class' => 'video-thumbnail')));
 }
 /**
  * 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;
 }
 /**
  * Gathers information about a video
  *
  * @deprecated Use VideoHandlerHelper::getVideoDetailFromWiki or VideoHandlerHelper::getVideoDetail instead
  *
  * @param $arr
  * @param Title $title
  * @param int $width
  * @param int $height
  * @param bool $force16x9Ratio
  */
 public static function inflateArrayWithVideoData(&$arr, Title $title, $width = 150, $height = 75, $force16x9Ratio = false)
 {
     $arr['ns'] = $title->getNamespace();
     $arr['nsText'] = $title->getNsText();
     $arr['dbKey'] = $title->getDbKey();
     $arr['title'] = $title->getText();
     if ($title instanceof GlobalTitle) {
         //wfFindFile works with Title only
         $oTitle = Title::newFromText($arr['nsText'] . ':' . $arr['dbKey']);
     } else {
         $oTitle = $title;
     }
     $arr['url'] = $oTitle->getFullURL();
     $file = wfFindFile($oTitle);
     if (!empty($file)) {
         $thumb = $file->transform(array('width' => $width, 'height' => $height));
         $htmlParams = array('custom-title-link' => $oTitle, 'duration' => true, 'linkAttribs' => array('class' => 'video-thumbnail'));
         if ($force16x9Ratio) {
             $htmlParams['src'] = self::thumbUrl2thumbUrl($thumb->getUrl(), 'video', $width, $height);
             $thumb->width = $width;
             $thumb->height = $height;
         }
         $arr['thumbnail'] = $thumb->toHtml($htmlParams);
     }
 }